-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add registration attributes and guards #171
base: stage
Are you sure you want to change the base?
Changes from 3 commits
6ba24eb
682e587
4ea512c
c56174f
dbf036e
ca6dcce
06095a1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,10 +10,12 @@ | |
DiscountOrganization, | ||
DiscountOut, | ||
) | ||
from model.events.events_constants import RegistrationType | ||
from repository.discount_repository import DiscountsRepository | ||
from repository.events_repository import EventsRepository | ||
from repository.registrations_repository import RegistrationsRepository | ||
from starlette.responses import JSONResponse | ||
from usecase.event_usecase import EventUsecase | ||
from utils.utils import Utils | ||
|
||
|
||
|
@@ -24,6 +26,11 @@ def __init__(self): | |
self.__registrations_repository = RegistrationsRepository() | ||
|
||
def get_discount(self, event_id: str, entry_id: str) -> DiscountOut: | ||
event = EventUsecase.get_event(event_id) | ||
if event.registrationType == RegistrationType.REDIRECT: | ||
message = 'Error: No discounts for REDIRECT registrationType' | ||
return JSONResponse(status_code=HTTPStatus.BAD_REQUEST, content={'message': message}) | ||
|
||
status, discount, message = self.__discounts_repository.query_discounts(event_id=event_id, discount_id=entry_id) | ||
if status != HTTPStatus.OK: | ||
return JSONResponse(status_code=status, content={'message': message}) | ||
|
@@ -48,6 +55,11 @@ def get_discount(self, event_id: str, entry_id: str) -> DiscountOut: | |
return discount_out | ||
|
||
def get_discount_list(self, event_id: str) -> List[DiscountOrganization]: | ||
event = EventUsecase.get_event(event_id) | ||
if event.registrationType == RegistrationType.REDIRECT: | ||
message = 'Error: No discounts for REDIRECT registrationType' | ||
return JSONResponse(status_code=HTTPStatus.BAD_REQUEST, content={'message': message}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be error NOT_FOUND |
||
|
||
status, discounts, message = self.__discounts_repository.query_discounts( | ||
event_id=event_id, | ||
) | ||
|
@@ -84,6 +96,11 @@ def get_discount_list(self, event_id: str) -> List[DiscountOrganization]: | |
] | ||
|
||
def claim_discount(self, event_id: str, entry_id: str, registration_id: str): | ||
event = EventUsecase.get_event(event_id) | ||
if event.registrationType == RegistrationType.REDIRECT: | ||
message = 'Error: No discounts for REDIRECT registrationType' | ||
return JSONResponse(status_code=HTTPStatus.BAD_REQUEST, content={'message': message}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be error NOT_FOUND |
||
|
||
status, discount_entry, message = self.__discounts_repository.query_discounts( | ||
discount_id=entry_id, event_id=event_id | ||
) | ||
|
@@ -116,7 +133,13 @@ def claim_discount(self, event_id: str, entry_id: str, registration_id: str): | |
return DiscountOut(**discount_data) | ||
|
||
def create_discounts(self, discount_in: DiscountIn) -> Union[JSONResponse, List[DiscountOut]]: | ||
event = EventUsecase.get_event(DiscountIn.eventId) | ||
if event.registrationType == RegistrationType.REDIRECT: | ||
message = 'Error: Discounts should not be created for REDIRECT registrationType' | ||
return JSONResponse(status_code=HTTPStatus.BAD_REQUEST, content={'message': message}) | ||
|
||
status, _, __ = self.__events_repository.query_events(discount_in.eventId) | ||
|
||
if status != HTTPStatus.OK: | ||
return JSONResponse(status_code=status, content={'message': 'Event does not exist'}) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,11 +8,13 @@ | |
EvaluationOut, | ||
EvaluationPatch, | ||
) | ||
from model.events.events_constants import RegistrationType | ||
from model.registrations.registration import RegistrationPatch, RegistrationPreviewOut | ||
from repository.evaluations_repository import EvaluationRepository | ||
from repository.events_repository import EventsRepository | ||
from repository.registrations_repository import RegistrationsRepository | ||
from starlette.responses import JSONResponse | ||
from usecase.event_usecase import EventUsecase | ||
|
||
|
||
class EvaluationUsecase: | ||
|
@@ -24,6 +26,15 @@ def __init__(self): | |
def create_evaluation(self, evaluation_list_in: EvaluationListIn) -> Union[JSONResponse, List[EvaluationOut]]: | ||
event_id = evaluation_list_in.eventId | ||
registration_id = evaluation_list_in.registrationId | ||
|
||
# NOTE: next three lines copy pasted a lot, should this be a helper or nah kay mubo ra | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remove comment |
||
event = EventUsecase.get_event( | ||
event_id | ||
) # NOTE: am i doing this right, i don't wanna add another param but di pud ko sure if fetching the whole thing is the best move? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use the EventRepository for this. |
||
if event.registrationType == RegistrationType.REDIRECT: | ||
message = 'Error: Evaluation should not be created for REDIRECT registrationType' | ||
return JSONResponse(status_code=HTTPStatus.BAD_REQUEST, content={'message': message}) | ||
|
||
status, _, message = self.__events_repository.query_events(event_id=event_id) | ||
if status != HTTPStatus.OK: | ||
return JSONResponse(status_code=status, content={'message': message}) | ||
|
@@ -58,6 +69,11 @@ def update_evaluation( | |
question: str, | ||
evaluation_in: EvaluationPatch, | ||
) -> Union[JSONResponse, EvaluationOut]: | ||
event = EventUsecase.get_event(event_id) | ||
if event.registrationType == RegistrationType.REDIRECT: | ||
message = 'Error: No evaluation to update for REDIRECT registrationType' | ||
return JSONResponse(status_code=HTTPStatus.BAD_REQUEST, content={'message': message}) | ||
|
||
status, _, message = self.__events_repository.query_events(event_id=event_id) | ||
if status != HTTPStatus.OK: | ||
return JSONResponse(status_code=status, content={'message': message}) | ||
|
@@ -86,6 +102,11 @@ def update_evaluation( | |
return EvaluationOut(**evaluation_data) | ||
|
||
def get_evaluation(self, event_id: str, registration_id: str, question: str) -> Union[JSONResponse, EvaluationOut]: | ||
event = EventUsecase.get_event(event_id) | ||
if event.registrationType == RegistrationType.REDIRECT: | ||
message = 'Error: No evaluations for REDIRECT registrationType' | ||
return JSONResponse(status_code=HTTPStatus.BAD_REQUEST, content={'message': message}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be NOT_FOUND |
||
|
||
status, _, message = self.__events_repository.query_events(event_id=event_id) | ||
if status != HTTPStatus.OK: | ||
return JSONResponse(status_code=status, content={'message': message}) | ||
|
@@ -103,6 +124,11 @@ def get_evaluations( | |
self, event_id: str = None, registration_id: str = None, question: str = None | ||
) -> Union[JSONResponse, List[EvaluationListOut]]: | ||
if event_id: | ||
event = EventUsecase.get_event(event_id) | ||
if event.registrationType == RegistrationType.REDIRECT: | ||
message = 'Error: No evaluations for REDIRECT registrationType' | ||
return JSONResponse(status_code=HTTPStatus.BAD_REQUEST, content={'message': message}) | ||
|
||
status, _, message = self.__events_repository.query_events(event_id=event_id) | ||
if status != HTTPStatus.OK: | ||
return JSONResponse(status_code=status, content={'message': message}) | ||
|
@@ -138,6 +164,13 @@ def get_evaluations( | |
return evaluations_return | ||
|
||
def get_evaluations_by_question(self, event_id: str, question: str) -> Union[JSONResponse, List[EvaluationOut]]: | ||
event = EventUsecase.get_event(event_id) | ||
if event.registrationType == RegistrationType.REDIRECT: | ||
return JSONResponse( | ||
status_code=HTTPStatus.BAD_REQUEST, | ||
content={'message': 'Error: No evaluations for REDIRECT registrationType'}, | ||
ArJSarmiento marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) | ||
|
||
status, _, message = self.__events_repository.query_events(event_id=event_id) | ||
if status != HTTPStatus.OK: | ||
return JSONResponse(status_code=status, content={'message': message}) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add guards to |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
from typing import List, Union | ||
|
||
import ulid | ||
from model.events.events_constants import EventStatus | ||
from model.events.events_constants import EventStatus, RegistrationType | ||
from model.registrations.registration import ( | ||
RegistrationIn, | ||
RegistrationOut, | ||
|
@@ -14,6 +14,7 @@ | |
from starlette.responses import JSONResponse | ||
from usecase.discount_usecase import DiscountUsecase | ||
from usecase.email_usecase import EmailUsecase | ||
from usecase.event_usecase import EventUsecase | ||
from usecase.file_s3_usecase import FileS3Usecase | ||
|
||
|
||
|
@@ -45,6 +46,12 @@ def create_registration(self, registration_in: RegistrationIn) -> Union[JSONResp | |
Union[JSONResponse, RegistrationOut]: If successful, returns the created registration entry. | ||
If unsuccessful, returns a JSONResponse with an error message. | ||
""" | ||
|
||
event = EventUsecase.get_event(registration_in.eventId) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use EventRepository for this. Apply for all instances. Use cases should call repositories for data fetching. |
||
if event.registrationType == RegistrationType.REDIRECT: | ||
message = 'Registrations should not be created for REDIRECT registration type' | ||
return JSONResponse(status_code=HTTPStatus.BAD_REQUEST, content={'message': message}) | ||
|
||
status, event, message = self.__events_repository.query_events(event_id=registration_in.eventId) | ||
if status != HTTPStatus.OK: | ||
return JSONResponse(status_code=status, content={'message': message}) | ||
|
@@ -113,6 +120,11 @@ def update_registration( | |
Union[JSONResponse, RegistrationOut]: If successful, returns the updated registration entry. | ||
If unsuccessful, returns a JSONResponse with an error message. | ||
""" | ||
event = EventUsecase.get_event(event_id) | ||
if event.registrationType == RegistrationType.REDIRECT: | ||
message = 'No registrations for REDIRECT registration type' | ||
return JSONResponse(status_code=HTTPStatus.BAD_REQUEST, content={'message': message}) | ||
Comment on lines
+196
to
+199
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
APPLY FOR ALL INSTANCES |
||
|
||
status, _, message = self.__events_repository.query_events(event_id=event_id) | ||
if status != HTTPStatus.OK: | ||
return JSONResponse(status_code=status, content={'message': message}) | ||
|
@@ -161,6 +173,11 @@ def get_registration(self, event_id: str, registration_id: str) -> Union[JSONRes | |
If not found, returns a JSONResponse with an error message. | ||
""" | ||
|
||
event = EventUsecase.get_event(event_id) | ||
if event.registrationType == RegistrationType.REDIRECT: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should NOT_FOUND. Should be BAD_REQUEST for CUD operations and NOT_FOUND for READ operations |
||
message = 'No registrations for REDIRECT registration type' | ||
return JSONResponse(status_code=HTTPStatus.BAD_REQUEST, content={'message': message}) | ||
|
||
status, _, message = self.__events_repository.query_events(event_id=event_id) | ||
if status != HTTPStatus.OK: | ||
return JSONResponse(status_code=status, content={'message': message}) | ||
|
@@ -183,6 +200,11 @@ def get_registration_by_email(self, event_id: str, email: str) -> RegistrationOu | |
registrations, | ||
message, | ||
) = self.__registrations_repository.query_registrations_with_email(event_id=event_id, email=email) | ||
event = EventUsecase.get_event(event_id) | ||
if event.registrationType == RegistrationType.REDIRECT: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should NOT_FOUND. Should be BAD_REQUEST for CUD operations and NOT_FOUND for READ operations |
||
message = 'No registrations for REDIRECT registration type' | ||
return JSONResponse(status_code=HTTPStatus.BAD_REQUEST, content={'message': message}) | ||
|
||
if status != HTTPStatus.OK or not registrations: | ||
return JSONResponse(status_code=status, content={'message': message}) | ||
|
||
|
@@ -204,6 +226,11 @@ def get_registrations(self, event_id: str = None) -> Union[JSONResponse, List[Re | |
Union[JSONResponse, List[RegistrationOut]]: If successful, returns a list of registration entries. | ||
If unsuccessful, returns a JSONResponse with an error message. | ||
""" | ||
event = EventUsecase.get_event(event_id) | ||
if event.registrationType == RegistrationType.REDIRECT: | ||
message = 'No registrations for REDIRECT registration type' | ||
return JSONResponse(status_code=HTTPStatus.BAD_REQUEST, content={'message': message}) | ||
Comment on lines
+308
to
+311
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should NOT_FOUND. Should be BAD_REQUEST for CUD operations and NOT_FOUND for READ operations |
||
|
||
status, _, message = self.__events_repository.query_events(event_id=event_id) | ||
if status != HTTPStatus.OK: | ||
return JSONResponse(status_code=status, content={'message': message}) | ||
|
@@ -233,6 +260,11 @@ def delete_registration(self, event_id: str, registration_id: str) -> Union[None | |
Union[None, JSONResponse]: If deleted successfully, returns None. | ||
If unsuccessful, returns a JSONResponse with an error message. | ||
""" | ||
event = EventUsecase.get_event(event_id) | ||
if event.registrationType == RegistrationType.REDIRECT: | ||
message = 'No registrations for REDIRECT registration type' | ||
return JSONResponse(status_code=HTTPStatus.BAD_REQUEST, content={'message': message}) | ||
|
||
status, _, message = self.__events_repository.query_events(event_id=event_id) | ||
if status != HTTPStatus.OK: | ||
return JSONResponse(status_code=status, content={'message': message}) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be error NOT_FOUND