update to registrations
This commit is contained in:
@@ -33,12 +33,12 @@ def get_list(exchange=None, target=None):
|
||||
@marshal_with(registration_schema)
|
||||
def create(name, routing_key, targets):
|
||||
target_ids = [t.id for t in targets]
|
||||
xchanges = Target.query.filter(Target.target_exchange_id.in_(target_ids))
|
||||
if len(xchanges) != len(target_ids):
|
||||
xchange_ids = [t.id for t in xchanges]
|
||||
db_targets = Target.query.filter(Target.id.in_(target_ids))
|
||||
if len(db_targets) != len(targets):
|
||||
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])
|
||||
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()
|
||||
return registration
|
||||
|
||||
|
||||
Reference in New Issue
Block a user