mirror of
https://github.com/GSA/notifications-api.git
synced 2026-08-23 07:46:06 -04:00
Work in progress, skeleton of the api created and testing started. Need to fix authentication tests.
This commit is contained in:
@@ -1,15 +1,5 @@
|
||||
from flask import Blueprint
|
||||
from app.main.authentication.auth import requires_auth
|
||||
|
||||
AUTHORIZATION_HEADER = 'Authorization'
|
||||
AUTHORIZATION_SCHEME = 'Bearer'
|
||||
WINDOW = 1
|
||||
|
||||
main = Blueprint('main', __name__)
|
||||
|
||||
|
||||
main.before_request(requires_auth)
|
||||
|
||||
|
||||
from app.main.views import notifications, index
|
||||
from app.main import errors
|
||||
from app.main.views import index
|
||||
|
||||
@@ -1,31 +0,0 @@
|
||||
from datetime import datetime
|
||||
|
||||
from sqlalchemy.orm import load_only
|
||||
|
||||
from app import db
|
||||
from app.models import Service
|
||||
|
||||
|
||||
def create_service(service_name,
|
||||
user,
|
||||
limit=1000,
|
||||
active=False,
|
||||
restricted=True):
|
||||
service = Service(name=service_name,
|
||||
created_at=datetime.now(),
|
||||
limit=limit,
|
||||
active=active,
|
||||
restricted=restricted)
|
||||
db.session.add(service)
|
||||
service.users.append(user)
|
||||
db.session.commit()
|
||||
return service.id
|
||||
|
||||
|
||||
def get_services(service_id=None, user_id=None):
|
||||
# TODO need better mapping from function params to sql query.
|
||||
if service_id:
|
||||
return Service.query.filter_by(id=service_id).one()
|
||||
elif user_id:
|
||||
return Service.query.filter(Service.users.any(id=user_id)).all()
|
||||
return Service.query.all()
|
||||
@@ -1,20 +0,0 @@
|
||||
from datetime import datetime
|
||||
|
||||
from sqlalchemy.orm import load_only
|
||||
|
||||
from app import db
|
||||
from app.models import User
|
||||
|
||||
|
||||
def create_user(email_address):
|
||||
user = User(email_address=email_address,
|
||||
created_at=datetime.now())
|
||||
db.session.add(user)
|
||||
db.session.commit()
|
||||
return user.id
|
||||
|
||||
|
||||
def get_users(user_id=None):
|
||||
if user_id:
|
||||
return User.query.filter_by(id=user_id).one()
|
||||
return User.query.filter_by().all()
|
||||
@@ -1,7 +0,0 @@
|
||||
from flask import jsonify
|
||||
from .. import main
|
||||
|
||||
|
||||
@main.route('/', methods=['GET'])
|
||||
def get_index():
|
||||
return jsonify(result="hello world"), 200
|
||||
@@ -1,17 +1,2 @@
|
||||
from flask import jsonify
|
||||
from .. import main
|
||||
|
||||
|
||||
# TODO need for health check url
|
||||
|
||||
|
||||
# TODO remove
|
||||
@main.route('/', methods=['GET'])
|
||||
def get_index():
|
||||
return jsonify(result="hello world"), 200
|
||||
|
||||
|
||||
# TODO remove
|
||||
@main.route('/', methods=['POST'])
|
||||
def post_index():
|
||||
return jsonify(result="hello world"), 200
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
from flask import jsonify
|
||||
from .. import main
|
||||
|
||||
|
||||
@main.route('/notification', methods=['POST'])
|
||||
def create_notification():
|
||||
return jsonify(result="created"), 201
|
||||
@@ -1,38 +0,0 @@
|
||||
from flask import jsonify
|
||||
from app.main.dao.services_dao import (create_new_service, get_services)
|
||||
from app.main.dao.users_dao import (get_users)
|
||||
from .. import main
|
||||
|
||||
|
||||
# TODO auth to be added.
|
||||
@main.route('/service', methods=['POST'])
|
||||
def create_service():
|
||||
return jsonify(result="created"), 201
|
||||
|
||||
|
||||
# TODO auth to be added
|
||||
@main.route('/service/<int:service_id>', method=['PUT'])
|
||||
def update_service(service_id):
|
||||
return jsonify(result="updated")
|
||||
|
||||
|
||||
# TODO auth to be added.
|
||||
# Should be restricted by user, user id
|
||||
# is pulled from the token
|
||||
@main.route('/service/<int:service_id>', method=['GET'])
|
||||
@main.route('/service', methods=['GET'])
|
||||
def get_service(service_id=None):
|
||||
services = get_services
|
||||
return jsonify(
|
||||
data=services
|
||||
)
|
||||
|
||||
|
||||
# TODO auth to be added
|
||||
# auth should be allow for admin tokens only
|
||||
@main.route('/user/<int:user_id>/service', method=['GET'])
|
||||
@main.route('/user/<int:user_id>/service/<int:service_id>', method=['GET'])
|
||||
def get_service_by_user_id(user_id, service_id=None):
|
||||
user = get_users(user_id=user_id)
|
||||
services = get_services(user, service_id=service_id)
|
||||
return jsonify(data=services)
|
||||
Reference in New Issue
Block a user