Skip to content

Commit 1ea8ff9

Browse files
authored
Merge pull request #303 from SPARCS-UP-Mindanao/297-be-make-preregistrationpatch-extraignore
fix: bugs in konfhubID
2 parents ed933ef + 29b2782 commit 1ea8ff9

7 files changed

Lines changed: 120 additions & 76 deletions

File tree

backend/controller/event_router.py

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from constants.common_constants import CommonConstants
66
from fastapi import APIRouter, Depends, Path, Query
77
from model.common import Message
8-
from model.events.event import EventIn, EventOut
8+
from model.events.event import EventAdminOut, EventIn, EventOut
99
from model.events.events_constants import EventUploadType
1010
from model.file_uploads.file_upload import FileUploadIn, FileUploadOut
1111
from model.file_uploads.file_upload_constants import FileUploadConstants
@@ -40,7 +40,7 @@ def get_events(
4040
:type admin_id: str, optional
4141
4242
:return: List of EventOut objects.
43-
:rtype: List[EventOut]
43+
:rtype: List[Union[EventOut, EventAdminOut]]
4444
4545
"""
4646
events_uc = EventUsecase()
@@ -49,7 +49,7 @@ def get_events(
4949

5050
@event_router.get(
5151
'/admin',
52-
response_model=List[EventOut],
52+
response_model=List[EventAdminOut],
5353
responses={
5454
404: {'model': Message, 'description': 'Event not found'},
5555
500: {'model': Message, 'description': 'Internal server error'},
@@ -58,7 +58,7 @@ def get_events(
5858
)
5959
@event_router.get(
6060
'/admin/',
61-
response_model=List[EventOut],
61+
response_model=List[EventAdminOut],
6262
response_model_exclude_none=True,
6363
response_model_exclude_unset=True,
6464
include_in_schema=False,
@@ -75,8 +75,8 @@ def get_admin_events(
7575
:param current_user: The current user, defaults to Depends(get_current_user).
7676
:type current_user: AccessUser, optional
7777
78-
:return: List of EventOut objects.
79-
:rtype: List[EventOut]
78+
:return: List of EventOut, EventAdminOut objects.
79+
:rtype: List[EventAdminOut]
8080
8181
"""
8282
_ = current_user
@@ -116,9 +116,43 @@ def get_event(
116116
return events_uc.get_event(entry_id)
117117

118118

119+
@event_router.get(
120+
'/admin/{entryId}',
121+
response_model=EventAdminOut,
122+
responses={
123+
404: {'model': Message, 'description': 'Event not found'},
124+
500: {'model': Message, 'description': 'Internal server error'},
125+
},
126+
summary='Get event',
127+
)
128+
@event_router.get(
129+
'admin/{entryId}/',
130+
response_model=EventAdminOut,
131+
response_model_exclude_none=True,
132+
response_model_exclude_unset=True,
133+
include_in_schema=False,
134+
)
135+
def get_admin_event(
136+
entry_id: str = Path(..., title='Event Id', alias=CommonConstants.ENTRY_ID),
137+
current_user: AccessUser = Depends(get_current_user),
138+
):
139+
"""Get event
140+
141+
:param entry_id: The event with admin permission.
142+
:type entry_id: str, optional
143+
144+
:return: EventOut object.
145+
:rtype: EventOut
146+
147+
"""
148+
_ = current_user
149+
events_uc = EventUsecase()
150+
return events_uc.get_event(entry_id)
151+
152+
119153
@event_router.post(
120154
'',
121-
response_model=EventOut,
155+
response_model=EventAdminOut,
122156
responses={
123157
400: {'model': Message, 'description': 'Bad request'},
124158
500: {'model': Message, 'description': 'Internal server error'},
@@ -127,7 +161,7 @@ def get_event(
127161
)
128162
@event_router.post(
129163
'/',
130-
response_model=EventOut,
164+
response_model=EventAdminOut,
131165
response_model_exclude_none=True,
132166
response_model_exclude_unset=True,
133167
include_in_schema=False,
@@ -155,7 +189,7 @@ def create_event(
155189

156190
@event_router.put(
157191
'/{entryId}',
158-
response_model=EventOut,
192+
response_model=EventAdminOut,
159193
responses={
160194
400: {'model': Message, 'description': 'Bad request'},
161195
404: {'model': Message, 'description': 'Event not found'},
@@ -165,7 +199,7 @@ def create_event(
165199
)
166200
@event_router.put(
167201
'/{entryId}/',
168-
response_model=EventOut,
202+
response_model=EventAdminOut,
169203
response_model_exclude_none=True,
170204
response_model_exclude_unset=True,
171205
include_in_schema=False,

backend/external_gateway/konfhub_gateway.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,11 @@ def capture_registration(
2828
raise Exception(f'Failed to capture registration: {response.status_code} - {response.text}')
2929

3030
except requests.exceptions.SSLError as ssl_err:
31-
logger.error(f'SSL certificate verification failed: {ssl_err}')
32-
return HTTPStatus.BAD_GATEWAY, None, str(ssl_err)
31+
error_message = f'SSL certificate verification failed: {ssl_err}'
32+
logger.error(error_message)
33+
return HTTPStatus.BAD_GATEWAY, None, error_message
34+
3335
except Exception as e:
34-
logger.error(f'Failed to capture registration: {e}')
35-
return HTTPStatus.INTERNAL_SERVER_ERROR, None, str(e)
36+
error_message = f'Failed to capture registration: {e}'
37+
logger.error(error_message)
38+
return HTTPStatus.INTERNAL_SERVER_ERROR, None, error_message

backend/model/events/event.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ class Config:
124124
lastEmailSent: datetime = Field(None, title='Last Email Sent')
125125

126126

127-
class EventOut(EventDataIn):
127+
class EventAdminOut(EventDataIn):
128128
class Config:
129129
extra = Extra.ignore
130130

@@ -137,3 +137,11 @@ class Config:
137137
logoUrl: Optional[str] = Field(None, title='Logo Pre-signed URL')
138138
certificateTemplateUrl: Optional[str] = Field(None, title='Certificate Template Pre-signed URL')
139139
ticketTypes: Optional[List[TicketTypeOut]] = Field(None, title='Ticket Types')
140+
141+
142+
class EventOut(EventAdminOut):
143+
class Config:
144+
extra = Extra.ignore
145+
146+
konfhubId: Optional[str] = Field(None, title='Konfhub ID', exclude=True)
147+
konfhubApiKey: Optional[str] = Field(None, title='Konfhub API Key', exclude=True)

backend/usecase/event_usecase.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from urllib.parse import unquote_plus
88

99
from constants.common_constants import CommonConstants
10-
from model.events.event import EventIn, EventOut
10+
from model.events.event import EventAdminOut, EventIn, EventOut
1111
from model.events.events_constants import EventStatus
1212
from model.ticket_types.ticket_types import TicketTypeOut
1313
from repository.events_repository import EventsRepository
@@ -165,22 +165,24 @@ def update_event(self, event_id: str, event_in: EventIn) -> Union[JSONResponse,
165165

166166
return self.collect_pre_signed_url(event_out)
167167

168-
def get_event(self, event_id: str) -> Union[JSONResponse, EventOut]:
168+
def get_event(self, event_id: str) -> Union[JSONResponse, EventOut, EventAdminOut]:
169169
"""Get an event by its ID
170170
171171
:param event_id: The ID of the event to get.
172172
:type event_id: str
173173
174174
:return: The requested event or an error message.
175-
:rtype: Union[JSONResponse, EventOut]
175+
:rtype: Union[JSONResponse, EventOut, EventAdminOut]
176176
177177
"""
178+
current_user = os.getenv('CURRENT_USER')
178179
status, event, message = self.__events_repository.query_events(event_id=event_id)
179180
if status != HTTPStatus.OK:
180181
return JSONResponse(status_code=status, content={'message': message})
181182

182183
event_data = self.__convert_data_entry_to_dict(event)
183-
event_out = EventOut(**event_data)
184+
event_model = EventAdminOut if current_user else EventOut
185+
event_out = event_model(**event_data)
184186

185187
if event.hasMultipleTicketTypes:
186188
_, ticket_types, _ = self.__ticket_type_repository.query_ticket_types(event_id=event_id)
@@ -202,6 +204,8 @@ def get_events(self, admin_id: str = None) -> Union[JSONResponse, List[EventOut]
202204
:rtype: Union[JSONResponse, List[EventOut]]
203205
204206
"""
207+
current_user = os.getenv('CURRENT_USER')
208+
205209
if admin_id:
206210
status, events, message = self.__events_repository.query_events_by_admin_id(admin_id)
207211
else:
@@ -211,7 +215,8 @@ def get_events(self, admin_id: str = None) -> Union[JSONResponse, List[EventOut]
211215
return JSONResponse(status_code=status, content={'message': message})
212216

213217
events_data = [self.__convert_data_entry_to_dict(event) for event in events]
214-
return [self.collect_pre_signed_url(EventOut(**event_data)) for event_data in events_data]
218+
event_model = EventAdminOut if current_user else EventOut
219+
return [self.collect_pre_signed_url(event_model(**event_data)) for event_data in events_data]
215220

216221
def delete_event(self, event_id: str) -> Union[None, JSONResponse]:
217222
"""Delete an event by its ID

backend/usecase/registration_usecase.py

Lines changed: 40 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -172,30 +172,9 @@ def create_registration(self, registration_in: RegistrationIn) -> Union[JSONResp
172172

173173
# Capture registration to KonfHub
174174
if event.konfhubId:
175-
phone_number_with_no_zero = registration_in.contactNumber.lstrip('0')
176-
konfhub_registration_details = RegistrationDetail(
177-
name=f'{registration_in.firstName} {registration_in.lastName}',
178-
email_id=registration_in.email,
179-
quantity=1,
180-
designation=registration_in.title,
181-
organisation=registration_in.organization,
182-
t_shirt_size=registration_in.shirtSize,
183-
phone_number=phone_number_with_no_zero,
184-
dial_code=CommonConstants.PH_DIAL_CODE,
185-
country_code=CommonConstants.PH_COUNTRY_CODE,
186-
)
187-
konfhub_capture_registration_in = KonfHubCaptureRegistrationIn(
188-
event_id=event.konfhubId,
189-
registration_tz=CommonConstants.PH_TIMEZONE,
190-
registration_details={
191-
registration_in.ticketTypeId: [konfhub_registration_details],
192-
},
193-
)
194-
status, _, message = self.__konfhub_gateway.capture_registration(
195-
konfhub_capture_registration_in, event.konfhubApiKey
196-
)
197-
if status != HTTPStatus.OK:
198-
return JSONResponse(status_code=status, content={'message': message})
175+
konfhub_response = self.register_konfhub(registration_in=registration_in, event_id=event_id, event=event)
176+
if konfhub_response != HTTPStatus.OK:
177+
return konfhub_response
199178

200179
registration_data = self.__convert_data_entry_to_dict(registration)
201180

@@ -252,36 +231,9 @@ def create_registration_approval_flow(
252231
return JSONResponse(status_code=status, content={'message': message})
253232

254233
if event.konfhubId:
255-
ticket_type_id = registration_in.ticketTypeId
256-
if not ticket_type_id:
257-
_, ticket_types_entries, _ = self.__ticket_type_repository.query_ticket_types(event_id=event_id)
258-
ticket_types_list = [ticket_type.konfhubId for ticket_type in ticket_types_entries or []]
259-
ticket_type_id = ticket_types_list[0]
260-
261-
phone_number_with_no_zero = registration_in.contactNumber.lstrip('0')
262-
konfhub_registration_details = RegistrationDetail(
263-
name=f'{registration_in.firstName} {registration_in.lastName}',
264-
email_id=registration_in.email,
265-
quantity=1,
266-
designation=registration_in.title,
267-
organisation=registration_in.organization,
268-
t_shirt_size=registration_in.shirtSize,
269-
phone_number=phone_number_with_no_zero,
270-
dial_code=CommonConstants.PH_DIAL_CODE,
271-
country_code=CommonConstants.PH_COUNTRY_CODE,
272-
)
273-
konfhub_capture_registration_in = KonfHubCaptureRegistrationIn(
274-
event_id=event.konfhubId,
275-
registration_tz=CommonConstants.PH_TIMEZONE,
276-
registration_details={
277-
ticket_type_id: [konfhub_registration_details],
278-
},
279-
)
280-
status, _, message = self.__konfhub_gateway.capture_registration(
281-
konfhub_capture_registration_in, event.konfhubApiKey
282-
)
283-
if status != HTTPStatus.OK:
284-
return JSONResponse(status_code=status, content={'message': message})
234+
konfhub_response = self.register_konfhub(registration_in=registration_in, event_id=event_id, event=event)
235+
if konfhub_response != HTTPStatus.OK:
236+
return konfhub_response
285237

286238
registration_data = self.__convert_data_entry_to_dict(registration)
287239

@@ -510,6 +462,40 @@ def collect_pre_signed_url(self, registration: RegistrationOut):
510462

511463
return registration
512464

465+
def register_konfhub(self, registration_in: RegistrationIn, event_id: str, event: Event):
466+
ticket_type_id = registration_in.ticketTypeId
467+
if not ticket_type_id:
468+
_, ticket_types_entries, _ = self.__ticket_type_repository.query_ticket_types(event_id=event_id)
469+
ticket_types_list = [ticket_type.konfhubId for ticket_type in ticket_types_entries or []]
470+
ticket_type_id = ticket_types_list[0]
471+
472+
phone_number_with_no_zero = registration_in.contactNumber.lstrip('0')
473+
konfhub_registration_details = RegistrationDetail(
474+
name=f'{registration_in.firstName} {registration_in.lastName}',
475+
email_id=registration_in.email,
476+
quantity=1,
477+
designation=registration_in.title,
478+
organisation=registration_in.organization,
479+
t_shirt_size=registration_in.shirtSize,
480+
phone_number=phone_number_with_no_zero,
481+
dial_code=CommonConstants.PH_DIAL_CODE,
482+
country_code=CommonConstants.PH_COUNTRY_CODE,
483+
)
484+
konfhub_capture_registration_in = KonfHubCaptureRegistrationIn(
485+
event_id=event.konfhubId,
486+
registration_tz=CommonConstants.PH_TIMEZONE,
487+
registration_details={
488+
ticket_type_id: [konfhub_registration_details],
489+
},
490+
)
491+
status, _, message = self.__konfhub_gateway.capture_registration(
492+
konfhub_capture_registration_in, event.konfhubApiKey
493+
)
494+
if status != HTTPStatus.OK:
495+
return JSONResponse(status_code=status, content={'message': message})
496+
497+
return status
498+
513499
@staticmethod
514500
def __convert_data_entry_to_dict(data_entry):
515501
"""Converts a data entry to a dictionary.

frontend/src/api/events.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,14 @@ export const getEvent = (entryId: string) =>
136136
output: mapEventDtoToEvent
137137
});
138138

139+
export const getAdminEvent = (entryId: string) =>
140+
createApi<EventDto, Event>({
141+
method: 'get',
142+
authorize: true,
143+
url: `/events/admin/${entryId}`,
144+
output: mapEventDtoToEvent
145+
});
146+
139147
export const updateEvent = (entryId: string, event: OptionalEvent) =>
140148
createApi<EventDto, Event>({
141149
method: 'put',

frontend/src/pages/admin/event/AdminEventPage.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { Outlet as AdminEventRoute, useParams } from 'react-router-dom';
22
import { TECHTIX_72 } from '@/assets/techtix';
3-
import { getEvent } from '@/api/events';
3+
import { getAdminEvent } from '@/api/events';
44
import { useApiQuery } from '@/hooks/useApi';
55

66
const AdminEventPageContent = () => {
77
const { eventId } = useParams();
88

9-
const { data: response, isFetching, refetch: refetchEvent } = useApiQuery(getEvent(eventId!));
9+
const { data: response, isFetching, refetch: refetchEvent } = useApiQuery(getAdminEvent(eventId!));
1010

1111
if (isFetching) {
1212
return (

0 commit comments

Comments
 (0)