-
Notifications
You must be signed in to change notification settings - Fork 7
feat: added admin filtering and tracking added for all admin related functionality #13
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
base: master
Are you sure you want to change the base?
Changes from all commits
d9242c4
3c45aac
7c8fddb
123015b
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 |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |
| import json | ||
| from typing import List, Optional | ||
| from app.core.database import db | ||
| from app.core.auth import AuthenticatedUser | ||
| from app.schemas.event import ( | ||
| EventCreate, | ||
| EventUpdate, | ||
|
|
@@ -14,16 +15,16 @@ class EventService: | |
| """Service for event management""" | ||
|
|
||
| @staticmethod | ||
| async def create_event(event_data: EventCreate) -> EventResponse: | ||
| async def create_event(event_data: EventCreate, auth: AuthenticatedUser) -> EventResponse: | ||
| """Create a new event""" | ||
| event_id = str(uuid.uuid4()) | ||
|
|
||
| # Insert event | ||
| await db.execute( | ||
| """ | ||
| INSERT INTO events (id, name, description, date, time, venue, | ||
| venue_address, venue_map_link, is_active) | ||
| VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) | ||
| venue_address, venue_map_link, is_active, admin_user_id) | ||
| VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?) | ||
| """, | ||
| [ | ||
| event_id, | ||
|
|
@@ -35,6 +36,7 @@ async def create_event(event_data: EventCreate) -> EventResponse: | |
| event_data.venue_address, | ||
| event_data.venue_map_link, | ||
| 1 if event_data.is_active else 0, | ||
| auth.user_id, | ||
| ], | ||
| ) | ||
|
|
||
|
|
@@ -44,8 +46,8 @@ async def create_event(event_data: EventCreate) -> EventResponse: | |
| await db.execute( | ||
| """ | ||
| INSERT INTO event_fields (id, event_id, field_name, field_type, | ||
| field_label, is_required, field_options, field_order) | ||
| VALUES (?, ?, ?, ?, ?, ?, ?, ?) | ||
| field_label, is_required, field_options, field_order, admin_user_id) | ||
| VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) | ||
| """, | ||
| [ | ||
| field_id, | ||
|
|
@@ -56,6 +58,7 @@ async def create_event(event_data: EventCreate) -> EventResponse: | |
| 1 if field.is_required else 0, | ||
| field.field_options, | ||
| field.field_order, | ||
| auth.user_id, | ||
| ], | ||
| ) | ||
|
|
||
|
|
@@ -84,6 +87,7 @@ async def get_event(event_id: str) -> Optional[EventResponse]: | |
| is_required=bool(row["is_required"]), | ||
| field_options=row["field_options"], | ||
| field_order=row["field_order"], | ||
| admin_user_id=row["admin_user_id"], | ||
| ) | ||
| for row in fields_rows | ||
| ] | ||
|
|
@@ -98,31 +102,49 @@ async def get_event(event_id: str) -> Optional[EventResponse]: | |
| venue_address=event["venue_address"], | ||
| venue_map_link=event["venue_map_link"], | ||
| is_active=bool(event["is_active"]), | ||
| admin_user_id=event["admin_user_id"], | ||
| created_at=event["created_at"], | ||
| updated_at=event["updated_at"], | ||
| fields=fields, | ||
| ) | ||
|
|
||
|
|
||
| @staticmethod | ||
| async def get_all_events() -> List[EventResponse]: | ||
| """Get all events""" | ||
| events = await db.fetch_all("SELECT * FROM events ORDER BY created_at DESC") | ||
| events = await db.fetch_all( | ||
| "SELECT * FROM events ORDER BY created_at DESC" | ||
| ) | ||
| result = [] | ||
| for event in events: | ||
| event_response = await EventService.get_event(event["id"]) | ||
| if event_response: | ||
| result.append(event_response) | ||
| return result | ||
|
|
||
|
|
||
|
|
||
| @staticmethod | ||
| async def get_active_event() -> List[EventResponse]: | ||
| """Get active event. at this point only 1 event can be active""" | ||
| event = await db.fetch_all( | ||
| "SELECT * FROM events WHERE is_active = 1 ORDER BY created_at DESC LIMIT 1", | ||
| ) | ||
| if not event: | ||
| return None | ||
| return await EventService.get_event(event[0]["id"]) | ||
|
|
||
| # we are not using now but will come handy | ||
| @staticmethod | ||
| async def get_active_event() -> Optional[EventResponse]: | ||
| """Get currently active event""" | ||
| event = await db.fetch_one( | ||
| "SELECT * FROM events WHERE is_active = 1 ORDER BY created_at DESC LIMIT 1" | ||
| async def get_active_events_by_admin_id(auth: AuthenticatedUser) -> List[EventResponse]: | ||
| """Get all active events for a specific admin""" | ||
| event = await db.fetch_all( | ||
| "SELECT * FROM events WHERE admin_user_id = ? AND is_active = 1 ORDER BY created_at DESC LIMIT 1", | ||
| [auth.user_id] | ||
| ) | ||
| if not event: | ||
| return None | ||
| return await EventService.get_event(event["id"]) | ||
| return await EventService.get_event(event[0]["id"]) | ||
|
|
||
| @staticmethod | ||
| async def update_event(event_id: str, event_data: EventUpdate) -> Optional[EventResponse]: | ||
|
|
@@ -188,7 +210,7 @@ async def delete_event(event_id: str) -> bool: | |
| return True | ||
|
|
||
| @staticmethod | ||
| async def clone_event(event_id: str, new_name: str) -> Optional[EventResponse]: | ||
| async def clone_event(event_id: str, new_name: str, auth: AuthenticatedUser) -> Optional[EventResponse]: | ||
| """Clone an existing event""" | ||
| source_event = await EventService.get_event(event_id) | ||
| if not source_event: | ||
|
|
@@ -217,11 +239,16 @@ async def clone_event(event_id: str, new_name: str) -> Optional[EventResponse]: | |
| ], | ||
| ) | ||
|
|
||
| return await EventService.create_event(new_event_data) | ||
| return await EventService.create_event(new_event_data, auth) | ||
|
|
||
| @staticmethod | ||
| async def get_event_registrations(event_id: str) -> List[dict]: | ||
| """Get all registrations for an event""" | ||
| # First verify the event exists | ||
| event = await db.fetch_one("SELECT id FROM events WHERE id = ?", [event_id]) | ||
| if not event: | ||
| return [] | ||
|
|
||
| registrations = await db.fetch_all( | ||
| "SELECT * FROM registrations WHERE event_id = ? ORDER BY created_at DESC", | ||
| [event_id], | ||
|
|
@@ -241,8 +268,8 @@ async def get_event_registrations(event_id: str) -> List[dict]: | |
| ] | ||
|
|
||
| @staticmethod | ||
| async def update_event_fields(event_id: str, fields: List) -> Optional[List[EventFieldResponse]]: | ||
| """Replace all fields for an event""" | ||
| async def update_event_fields(event_id: str, fields: List, auth: AuthenticatedUser) -> Optional[List[EventFieldResponse]]: | ||
| """Replace fields for an event""" | ||
| event = await db.fetch_one("SELECT id FROM events WHERE id = ?", [event_id]) | ||
| if not event: | ||
| return None | ||
|
|
@@ -256,8 +283,8 @@ async def update_event_fields(event_id: str, fields: List) -> Optional[List[Even | |
| await db.execute( | ||
| """ | ||
| INSERT INTO event_fields (id, event_id, field_name, field_type, | ||
| field_label, is_required, field_options, field_order) | ||
| VALUES (?, ?, ?, ?, ?, ?, ?, ?) | ||
| field_label, is_required, field_options, field_order, admin_user_id) | ||
| VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) | ||
| """, | ||
| [ | ||
| field_id, | ||
|
|
@@ -268,6 +295,7 @@ async def update_event_fields(event_id: str, fields: List) -> Optional[List[Even | |
| 1 if field.is_required else 0, | ||
| field.field_options, | ||
| field.field_order, | ||
| auth.user_id, | ||
| ], | ||
| ) | ||
|
|
||
|
|
@@ -294,8 +322,8 @@ async def add_event_field(event_id: str, field) -> Optional[EventFieldResponse]: | |
| await db.execute( | ||
| """ | ||
| INSERT INTO event_fields (id, event_id, field_name, field_type, | ||
| field_label, is_required, field_options, field_order) | ||
| VALUES (?, ?, ?, ?, ?, ?, ?, ?) | ||
| field_label, is_required, field_options, field_order, admin_user_id) | ||
|
PandaWhoCodes marked this conversation as resolved.
|
||
| VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) | ||
| """, | ||
| [ | ||
| field_id, | ||
|
|
@@ -306,6 +334,7 @@ async def add_event_field(event_id: str, field) -> Optional[EventFieldResponse]: | |
| 1 if field.is_required else 0, | ||
| field.field_options, | ||
| next_order, | ||
| auth.user_id, | ||
| ], | ||
| ) | ||
|
|
||
|
|
@@ -318,13 +347,14 @@ async def add_event_field(event_id: str, field) -> Optional[EventFieldResponse]: | |
| is_required=field.is_required, | ||
| field_options=field.field_options, | ||
| field_order=next_order, | ||
| admin_user_id=auth.user_id, | ||
| ) | ||
|
|
||
| @staticmethod | ||
| async def delete_event_field(event_id: str, field_id: str) -> bool: | ||
| async def delete_event_field(event_id: str, field_id: str, auth: AuthenticatedUser) -> bool: | ||
| """Delete a field from an event""" | ||
| result = await db.execute( | ||
| "DELETE FROM event_fields WHERE id = ? AND event_id = ?", | ||
| [field_id, event_id] | ||
| "DELETE FROM event_fields WHERE id = ? AND event_id = ? AND admin_user_id = ?", | ||
| [field_id, event_id, auth.user_id] | ||
|
Owner
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 this lockin that only I can delete my content.
Contributor
Author
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. @PandaWhoCodes so any admin can view,edit or delete anything wrt event? I will make these changes then
Owner
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. yes sir
Owner
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 resolve these comments |
||
| ) | ||
| return True | ||
Uh oh!
There was an error while loading. Please reload this page.