mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-15 01:32:20 -05:00
28 lines
981 B
Python
28 lines
981 B
Python
|
|
from flask import jsonify
|
||
|
|
from sqlalchemy.exc import DataError
|
||
|
|
from sqlalchemy.orm.exc import NoResultFound
|
||
|
|
from app.dao.services_dao import get_services
|
||
|
|
from app.dao.users_dao import get_users
|
||
|
|
from .. import user
|
||
|
|
|
||
|
|
|
||
|
|
# TODO auth to be added
|
||
|
|
@user.route('/<int:user_id>/service', methods=['GET'])
|
||
|
|
@user.route('/<int:user_id>/service/<int:service_id>', methods=['GET'])
|
||
|
|
def get_service_by_user_id(user_id, service_id=None):
|
||
|
|
try:
|
||
|
|
user = get_users(user_id=user_id)
|
||
|
|
except DataError:
|
||
|
|
return jsonify(result="error", message="Invalid user id"), 400
|
||
|
|
except NoResultFound:
|
||
|
|
return jsonify(result="error", message="User doesn't exist"), 400
|
||
|
|
|
||
|
|
try:
|
||
|
|
services = get_services(user_id=user.id, service_id=service_id)
|
||
|
|
except DataError:
|
||
|
|
return jsonify(result="error", message="Invalid service id"), 400
|
||
|
|
except NoResultFound:
|
||
|
|
return jsonify(result="error", message="Service doesn't exist"), 404
|
||
|
|
|
||
|
|
return jsonify(data=services)
|