Skip to content

Commit

Permalink
add endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
tonlls committed Sep 23, 2024
1 parent 3008dea commit 280640b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/impl/Event/router_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from src.configuration.Configuration import Configuration
from src.error.AuthenticationException import AuthenticationException
from src.impl.Company.schema import CompanyGet
from src.impl.Event.schema import EventCreate, HackerEventRegistration
from src.impl.Event.schema import EventCreate, HackerEventRegistration, HackerEventRegistrationUpdate
from src.impl.Event.schema import EventGet
from src.impl.Event.schema import EventGetAll
from src.impl.Event.schema import EventUpdate
Expand Down Expand Up @@ -142,6 +142,15 @@ def register_hacker(id: int,
return {'success': True, 'event_id': event.id, 'user_id': hacker_id}


@router.put("/{id}/update-register/{hacker_id}")
def register_hacker(id: int,
hacker_id: int,
payload: HackerEventRegistrationUpdate,
token: BaseToken = Depends(JWTBearer())):
event = event_service.update_register(id, hacker_id, payload, token)
return {'success': True, 'event_id': event.id, 'user_id': hacker_id}


# @router.delete("/{id}/participants/{hacker_id}")
# def remove_event_participant(id: int,
# hacker_id: int,
Expand Down
24 changes: 24 additions & 0 deletions src/impl/Event/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,30 @@ def add_hacker(self, event_id: int, hacker_id: int,
db.session.commit()
db.session.refresh(event)
return event

@BaseService.needs_service(UserService)
def update_register(self, event_id: int, hacker_id: int,
payload: HackerEventRegistration, data: BaseToken):
if not data.check([UserType.LLEIDAHACKER]) and not data.check(
[UserType.HACKER], hacker_id):
raise AuthenticationException("Not authorized")
event = self.get_by_id(event_id)
if event.archived:
raise InvalidDataException(
"Unable to operate with an archived event, unarchive it first")
if not data.is_admin:
if event.max_participants <= len(event.registered_hackers):
raise InvalidDataException("Event is full")
hacker = self.user_service.get_by_id(hacker_id)
if hacker not in event.registered_hackers:
raise InvalidDataException('Hacker is not registered')
reg = db.session.query(HackerEventRegistration).filter(HackerRegistration.user_id == hacker_id, HackerRegistration.event_id == event_id).first()
if reg is None:
raise InvalidDataException('Hacker is not registered')
set_existing_data(reg, payload)
db.session.commit()
db.session.refresh(event)
return event

@BaseService.needs_service('HackerGroupService')
def add_hacker_group(self, id: int, hacker_group_id: int, data: BaseToken):
Expand Down

0 comments on commit 280640b

Please sign in to comment.