mirror of
https://github.com/GSA/notifications-api.git
synced 2026-02-01 07:35:34 -05:00
Work in progress, skeleton of the api created and testing started. Need to fix authentication tests.
This commit is contained in:
5
app/user/__init__.py
Normal file
5
app/user/__init__.py
Normal file
@@ -0,0 +1,5 @@
|
||||
from flask import Blueprint
|
||||
|
||||
user = Blueprint('user', __name__)
|
||||
|
||||
from app.user.views import rest
|
||||
0
app/user/views/__init__.py
Normal file
0
app/user/views/__init__.py
Normal file
27
app/user/views/rest.py
Normal file
27
app/user/views/rest.py
Normal file
@@ -0,0 +1,27 @@
|
||||
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)
|
||||
Reference in New Issue
Block a user