Skip to content

Commit

Permalink
Convert ids to uuid
Browse files Browse the repository at this point in the history
Signed-off-by: Mehmet Baran Geylani <[email protected]>
  • Loading branch information
brngylni authored and abompard committed Jul 24, 2024
1 parent c5d101f commit 83cf322
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
22 changes: 11 additions & 11 deletions webhook_to_fedora_messaging/endpoints/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def create_service():
return abort(409, {'message': 'Service Already Exists'})
else:
db.session.commit()
return {'message': 'Created', 'uuid': service.id, 'token': service.token}, 201
return {'message': 'Created', 'uuid': service.uuid, 'token': service.token}, 201


@service_endpoint.route("/search", methods=["GET"])
Expand All @@ -39,8 +39,8 @@ def list_services():
return {'message': 'Not Found'}, 404
services = db.session.query(Service).filter(Service.user_id == user.id).all()
return {'service_list': [{
'id': service.id,
'user_id': service.user_id,
'id': service.uuid,
'username': user.username,
'name': service.name,
'type': service.type,
'desc': service.desc,
Expand All @@ -58,11 +58,11 @@ def lookup_service():
Request Body:
service_uuid: Service UUID
"""
service = db.session.query(Service).filter(Service.id == request.json['service_uuid']).first()
service = db.session.query(Service).filter(Service.uuid == request.json['service_uuid']).first()
if service is None:
return {'message': 'Not Found'}, 404
else:
return {'uuid': service.id, 'name': service.name, 'type': service.type, 'desc': service.desc}, 200
return {'uuid': service.uuid, 'name': service.name, 'type': service.type, 'desc': service.desc}, 200


@service_endpoint.route("/revoke", methods=["PUT"])
Expand All @@ -79,14 +79,14 @@ def revoke_service():
if user is None:
return {'message': 'Not Found'}, 404

service = db.session.query(Service).filter(Service.user_id == user.id).filter(Service.id == request.json['service_uuid']).first()
service = db.session.query(Service).filter(Service.user_id == user.id).filter(Service.uuid == request.json['service_uuid']).first()
if service is None:
return {'message': 'Not Found'}, 404

service.disabled = True
db.session.commit()

return {'uuid': service.id, 'is_valid': not service.disabled}, 200
return {'uuid': service.uuid, 'is_valid': not service.disabled}, 200


@service_endpoint.route("/", methods=["PUT"])
Expand All @@ -101,23 +101,23 @@ def update_service():
mesg_body: Updated message body (optional)
"""
service = db.session.query(Service).filter(Service.id == request.json['service_uuid']).first()
service = db.session.query(Service).filter(Service.uuid == request.json['service_uuid']).first()
if service is None:
return {'message': 'Not Found'}, 404

service.name = request.json['name'] if "name" in request.json and request.json['name'] != "" else service.name
service.desc = request.json['mesg_body'] if "mesg_body" in request.json and request.json['mesg_body'] != "" else service.desc
db.session.commit()
return {'uuid': service.id, 'name': service.name, 'mesg_body': service.desc, 'is_valid': not service.disabled}, 200
return {'uuid': service.uuid, 'name': service.name, 'mesg_body': service.desc, 'is_valid': not service.disabled}, 200


@service_endpoint.route("/token", methods=['POST'])
@validate_request(['service_uuid'])
def refresh_token():
service = db.session.query(Service).filter(Service.id == request.json['service_uuid']).first()
service = db.session.query(Service).filter(Service.uuid == request.json['service_uuid']).first()
if service is None:
return {'message': 'Not Found'}, 404

service.token = uuid.uuid4().hex
db.session.commit()
return {'uuid': service.id, 'name': service.name, 'mesg_body': service.desc, 'is_valid': not service.disabled, 'token': service.token}, 200
return {'uuid': service.uuid, 'name': service.name, 'mesg_body': service.desc, 'is_valid': not service.disabled, 'token': service.token}, 200
6 changes: 3 additions & 3 deletions webhook_to_fedora_messaging/endpoints/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def create_user():
if not is_created:
return {'message': 'User Already Exists'}, 409
else:
return {'uuid': user.id}, 201
return {'uuid': user.uuid}, 201


@user_endpoint.route("/search", methods=["GET"])
Expand All @@ -38,7 +38,7 @@ def get_user():
if users is None or users == []:
return {'message': 'Not Found'}, 404
else:
return {'user_list': [{'uuid': user.id, 'username': user.username} for user in users]}, 200
return {'user_list': [{'uuid': user.uuid, 'username': user.username} for user in users]}, 200


@user_endpoint.route("/", methods=["GET"])
Expand All @@ -53,4 +53,4 @@ def lookup_user():
if user is None:
return {'message': 'Not Found'}, 404
else:
return {'uuid': user.id, 'username': user.username}, 200
return {'uuid': user.uuid, 'username': user.username}, 200

0 comments on commit 83cf322

Please sign in to comment.