Skip to content

Commit

Permalink
Merge pull request #25 from jadmsaadaot/handle-returning-users
Browse files Browse the repository at this point in the history
Handle returning users to EPIC.submit
  • Loading branch information
jadmsaadaot authored Aug 7, 2024
2 parents 5760575 + ad5966d commit aceaa57
Show file tree
Hide file tree
Showing 18 changed files with 8,079 additions and 2,861 deletions.
20 changes: 20 additions & 0 deletions submit-api/src/submit_api/resources/account.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from submit_api.utils.util import cors_preflight
from submit_api.schemas.account import AccountSchema, AccountCreateSchema
from .apihelper import Api as ApiHelper
from ..exceptions import ResourceNotFoundError

API = Namespace("accounts", description="Endpoints for Account Management")
"""Custom exception messages
Expand Down Expand Up @@ -58,3 +59,22 @@ def post():
account_data = AccountCreateSchema().load(API.payload)
created_account = AccountService.create_account(account_data)
return AccountSchema().dump(created_account), HTTPStatus.CREATED


@cors_preflight("GET, OPTIONS")
@API.route("/proponent/<proponent_id>", methods=["GET", "OPTIONS"])
@API.doc(params={"proponent_id": "The account identifier"})
class User(Resource):
"""Resource for managing a single account"""

@staticmethod
@ApiHelper.swagger_decorators(API, endpoint_description="Fetch a account by proponent id")
@API.response(code=200, model=account_list_model, description="Success")
@API.response(404, "Not Found")
@cors.crossdomain(origin="*")
def get(proponent_id):
"""Fetch an account by id."""
account = AccountService.get_account_by_proponent_id(proponent_id)
if not account:
return ResourceNotFoundError(f"Account with proponent {proponent_id} not found")
return AccountSchema().dump(account), HTTPStatus.OK
6 changes: 6 additions & 0 deletions submit-api/src/submit_api/services/account_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ def get_account_by_id(cls, _account_id):
db_account = AccountModel.find_by_id(_account_id)
return db_account

@classmethod
def get_account_by_proponent_id(cls, _proponent_id):
"""Get account by id."""
db_account = AccountModel.get_by_proponent_id(_proponent_id)
return db_account

@classmethod
def get_all_accounts(cls):
"""Get all accounts."""
Expand Down
Loading

0 comments on commit aceaa57

Please sign in to comment.