Skip to content
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

Open
wants to merge 7 commits into
base: stage
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions backend/model/events/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@
from datetime import datetime
from typing import Optional

from model.events.events_constants import EventStatus
from model.events.events_constants import EventStatus, RegistrationType
from pydantic import BaseModel, EmailStr, Extra, Field
from pynamodb.attributes import BooleanAttribute, NumberAttribute, UnicodeAttribute
from pynamodb.attributes import (
BooleanAttribute,
EnumAttribute,
NumberAttribute,
UnicodeAttribute,
)
from pynamodb.indexes import AllProjection, LocalSecondaryIndex
from pynamodb.models import Model

Expand Down Expand Up @@ -43,6 +48,8 @@ class Meta:
name = UnicodeAttribute(null=True)
description = UnicodeAttribute(null=True)
status = UnicodeAttribute(null=True)
registrationType = EnumAttribute(choices=RegistrationType)
redirectRegisterUrl = UnicodeAttribute(null=True)
email = UnicodeAttribute(null=True)
startDate = UnicodeAttribute(null=True)
endDate = UnicodeAttribute(null=True)
Expand All @@ -67,6 +74,8 @@ class Config:

name: str = Field(None, title='Name')
description: str = Field(None, title='Description')
registrationType: RegistrationType = Field(RegistrationType.TECHTIX, title='Registration Type')
redirectRegisterUrl: str = Field(None, title='Redirect Register URL')
email: EmailStr = Field(None, title='Email')
startDate: datetime = Field(None, title='Date')
endDate: datetime = Field(None, title='Date')
Expand Down
5 changes: 5 additions & 0 deletions backend/model/events/events_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,8 @@ class EventUploadField(str, Enum):
BANNER = 'bannerLink'
LOGO = 'logoLink'
CERTIFICATE_TEMPLATE = 'certificateTemplate'


class RegistrationType(str, Enum):
TECHTIX = 'TechTix'
REDIRECT = 'redirect'
23 changes: 23 additions & 0 deletions backend/usecase/discount_usecase.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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})
Copy link
Member

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


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})
Expand All @@ -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})
Copy link
Member

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


status, discounts, message = self.__discounts_repository.query_discounts(
event_id=event_id,
)
Expand Down Expand Up @@ -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})
Copy link
Member

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


status, discount_entry, message = self.__discounts_repository.query_discounts(
discount_id=entry_id, event_id=event_id
)
Expand Down Expand Up @@ -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'})

Expand Down
33 changes: 33 additions & 0 deletions backend/usecase/evaluation_usecase.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Copy link
Member

Choose a reason for hiding this comment

The 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?
Copy link
Member

Choose a reason for hiding this comment

The 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})
Expand Down Expand Up @@ -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})
Expand Down Expand Up @@ -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})
Copy link
Member

Choose a reason for hiding this comment

The 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})
Expand All @@ -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})
Expand Down Expand Up @@ -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})
Expand Down
34 changes: 33 additions & 1 deletion backend/usecase/registration_usecase.py
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add guards to create_registration_approval_flow also

Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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


Expand Down Expand Up @@ -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)
Copy link
Member

Choose a reason for hiding this comment

The 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})
Expand Down Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Use self.__events_repository for accessing the entry not the usecase
  2. Check if event exists first before accessing the registrationType attribute so do if event and event.registrationType
  3. Utilize existing event queries if possible

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})
Expand Down Expand Up @@ -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:
Copy link
Member

Choose a reason for hiding this comment

The 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})
Expand All @@ -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:
Copy link
Member

Choose a reason for hiding this comment

The 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})

Expand All @@ -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
Copy link
Member

Choose a reason for hiding this comment

The 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})
Expand Down Expand Up @@ -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})
Expand Down
Loading