update to registrations
This commit is contained in:
@@ -13,7 +13,7 @@ registration_target_assoc = db.Table(
|
|||||||
class Registration(SurrogatePK, Model):
|
class Registration(SurrogatePK, Model):
|
||||||
__tablename__ = "registration"
|
__tablename__ = "registration"
|
||||||
name = Column(String(255), unique=True, nullable=False)
|
name = Column(String(255), unique=True, nullable=False)
|
||||||
routing_key = Column(String(255), nullable=False)
|
token = Column(String(255), nullable=False)
|
||||||
targets = relationship(
|
targets = relationship(
|
||||||
"Target", secondary=registration_target_assoc, backref=db.backref("registrations"))
|
"Target", secondary=registration_target_assoc, backref=db.backref("registrations"))
|
||||||
|
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ from api.target.serializers import TargetSchema
|
|||||||
class Registration(Schema):
|
class Registration(Schema):
|
||||||
id = fields.Int()
|
id = fields.Int()
|
||||||
name = fields.Str()
|
name = fields.Str()
|
||||||
Token = fields.Str(dump_only=True)
|
token = fields.Str(dump_only=True)
|
||||||
exchange = fields.Nested(TargetSchema, required=True)
|
targets = fields.Nested(TargetSchema, required=True, many=True)
|
||||||
|
|
||||||
|
|
||||||
registration_schema = Registration()
|
registration_schema = Registration()
|
||||||
|
|||||||
@@ -33,12 +33,12 @@ def get_list(exchange=None, target=None):
|
|||||||
@marshal_with(registration_schema)
|
@marshal_with(registration_schema)
|
||||||
def create(name, routing_key, targets):
|
def create(name, routing_key, targets):
|
||||||
target_ids = [t.id for t in targets]
|
target_ids = [t.id for t in targets]
|
||||||
xchanges = Target.query.filter(Target.target_exchange_id.in_(target_ids))
|
db_targets = Target.query.filter(Target.id.in_(target_ids))
|
||||||
if len(xchanges) != len(target_ids):
|
if len(db_targets) != len(targets):
|
||||||
xchange_ids = [t.id for t in xchanges]
|
xchange_ids = [t.id for t in db_targets]
|
||||||
not_found = ','.join([f'{t.name}({t.id})' for t in targets if t.id not in xchange_ids])
|
not_found = ','.join([f'{t.name}({t.id})' for t in targets if t.id not in xchange_ids])
|
||||||
raise BadRequestException(f"the target {not_found} could not be found")
|
raise BadRequestException(f"the target {not_found} could not be found")
|
||||||
registration = Registration(name=name, routing_key=routing_key, registration_exchange_id=xchanges.id)
|
registration = Registration(name=name, token=routing_key, targets=db_targets)
|
||||||
registration.save()
|
registration.save()
|
||||||
return registration
|
return registration
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ def upgrade():
|
|||||||
op.create_table('registration',
|
op.create_table('registration',
|
||||||
sa.Column('id', sa.Integer(), nullable=False),
|
sa.Column('id', sa.Integer(), nullable=False),
|
||||||
sa.Column('name', sa.String(length=255), nullable=False),
|
sa.Column('name', sa.String(length=255), nullable=False),
|
||||||
sa.Column('routing_key', sa.String(length=255), nullable=False),
|
sa.Column('token', sa.String(length=255), nullable=False),
|
||||||
sa.PrimaryKeyConstraint('id'),
|
sa.PrimaryKeyConstraint('id'),
|
||||||
sa.UniqueConstraint('name')
|
sa.UniqueConstraint('name')
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user