-
Notifications
You must be signed in to change notification settings - Fork 1
Sprint3
During Sprint 3, the backend team implemented the event management system. An event denotes a sport event that any user can create, and other users can join. This includes endpoints for creating, updating, joining, and deleting sports events, along with database schema enhancements.
| Issue Number | Title | Objective | Status |
|---|---|---|---|
| 34 | Create Event API | Implement API to create new events. | Completed |
| 47 | Update Event API | Implement API to update existing events. | Completed |
| 48 | Fetch All Events API | Develop API to retrieve event list. | Completed |
| 49 | Get Event by ID API | Implement API to fetch event details by ID. | Completed |
| 50 | Join Event API | Develop API to allow users to join events. | Completed |
| 51 | Leave Event API | Implement API to allow users to leave events. | Completed |
| 52 | Delete Event API | Create API to delete existing events. | Completed |
-
Database Schema Additions:
-
eventstableCREATE TABLE events ( id SERIAL PRIMARY KEY, event_owner INT REFERENCES users(id) ON DELETE CASCADE, sport TEXT NOT NULL, event_datetime TIMESTAMP NOT NULL, max_players INT NOT NULL CHECK (max_players > 0), location_name TEXT NOT NULL, latitude DECIMAL(9,6) NOT NULL, longitude DECIMAL(9,6) NOT NULL, description TEXT, title TEXT, is_full BOOLEAN, created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP );
-
event_participantstableCREATE TABLE event_participants ( id SERIAL PRIMARY KEY, event_id INT REFERENCES events(id) ON DELETE CASCADE, user_id INT REFERENCES users(id) ON DELETE CASCADE, joined_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP );
-
-
New Event Endpoints:
-
POST /events: Create a new event. -
GET /events: Retrieve all events with optional filters. -
GET /events/:id: Retrieve a single event by ID. -
PUT /events/:id: Update an event. -
POST /events/:id/join: Join an event. -
DELETE /events/:id/leave: Leave an event. -
DELETE /events/:id: Delete an event.
-
-
Example Request/Response:
-
POST
/eventsRequest:{ "sport": "Football", "event_date": "2025-03-25T15:00:00Z", "max_players": 20, "location_name": "Central Park, NY", "latitude": 40.785091, "longitude": -73.968285, "description": "Need players for a friendly football match", "title": "Lets football!" } -
POST
/eventsResponse:{ "id": 1, "event_owner": 1, "sport": "Football", "event_datetime": "2025-03-25T15:00:00Z", "max_players": 20, "location_name": "Central Park, NY", "latitude": 40.785091, "longitude": -73.968285, "description": "Friendly football match", "title": "Lets football!", "created_at": "2025-03-25T10:00:00Z", "updated_at": "2025-03-25T10:00:00Z", "is_full": false, "registered_count": 0 }
-
-
Business Logic:
- Event capacity is updated automatically when users join or leave.
- Events are marked as full (
is_full=true) whenregistered_count >= max_players.
-
cmd/api/events_test:
-
createEventHandler_test
- Should allow creation of a valid event via the
/eventsroute and return201 Created. - Should reject event creation with invalid/missing fields via the
/eventsroute and return400 Bad Request. - Should reject unauthorized event creation via the
/eventsroute and return401 Unauthorized.
- Should allow creation of a valid event via the
-
getEventHandler_test
- Should return event details successfully via the
/events/{id}route and return200 OK. - Should reject request with invalid event ID via the
/events/{id}route and return400 Bad Request. - Should reject unauthorized access to event via the
/events/{id}route and return401 Unauthorized.
- Should return event details successfully via the
-
updateEventHandler_test
- Should allow valid updates to an event via the
/events/{id}route and return200 OK. - Should reject unauthorized update requests via the
/events/{id}route and return401 Unauthorized. - Should reject update attempts by non-owners via the
/events/{id}route and return403 Forbidden.
- Should allow valid updates to an event via the
-
deleteEventHandler_test
- Should allow event deletion by owner via the
/events/{id}route and return200 OK. - Should reject unauthorized delete requests via the
/events/{id}route and return401 Unauthorized. - Should reject delete attempts by non-owners via the
/events/{id}route and return403 Forbidden.
- Should allow event deletion by owner via the
-
-
internal/store/events_test:
-
eventStore_Create_test
- Should create a valid event in the database and return success.
- Should return an error when creating an event with missing required fields.
-
eventStore_GetByID_test
- Should retrieve an existing event by ID and return correct event details.
- Should return
ErrEventNotFoundfor a non-existent event ID.
-
eventStore_Delete_test
- Should delete an existing event and confirm it no longer exists in the database.
- Should return
ErrEventNotFoundwhen attempting to delete a non-existent event.
-
eventStore_Join_test
- Should allow a valid user to join an existing event and update participant list.
- Should return
ErrAlreadyJoinedif the same user attempts to join the event again. - Should return an error when attempting to join a non-existent event.
-
All backend endpoints are documented using Swagger UI at:
http://localhost:8080/v1/swagger/index.html#/
- Description: Creates a new event.
-
Headers:
Authorization: Bearer JWT_TOKEN_HERE Content-Type: application/json -
Request Body:
{ "sport": "Football", "event_date": "2025-03-25T15:00:00Z", "max_players": 20, "location_name": "Central Park, NY", "latitude": 40.785091, "longitude": -73.968285, "description": "Need players for a friendly football match", "title": "Lets football!" } -
Response (200 OK):
{ "id": 1, "event_owner": 1, "sport": "Football", "event_datetime": "2025-03-25T15:00:00Z", "max_players": 20, "location_name": "Central Park, NY", "latitude": 40.785091, "longitude": -73.968285, "description": "Friendly football match", "title": "Lets football!", "created_at": "2025-03-25T10:00:00Z", "updated_at": "2025-03-25T10:00:00Z", "is_full": false, "registered_count": 0 }
- Description: Retrieves a list of events with optional filters.
-
Headers:
Authorization: Bearer JWT_TOKEN_HERE Content-Type: application/json -
Response (200 OK):
[ { "id": 1, "event_owner": 1, "sport": "Football", "event_datetime": "2025-03-25T15:00:00Z", "max_players": 20, "location_name": "Central Park, NY", "latitude": 40.785091, "longitude": -73.968285, "description": "Friendly football match", "title": "Lets football!", "created_at": "2025-03-25T10:00:00Z", "updated_at": "2025-03-25T10:00:00Z", "is_full": false, "registered_count": 2, "event_participants": [ { "id": 2, "name": "John Doe", "email": "johndoe@gmail.com" }, { "id": 3, "name": "John Does", "email": "johndoes@gmail.com" } ] } ]
- Description: Retrieves details of a single event by ID.
-
Headers:
Authorization: Bearer JWT_TOKEN_HERE - Response (200 OK): Same structure as above.
- Description: Updates the given fields of an event.
-
Headers:
Authorization: Bearer JWT_TOKEN_HERE Content-Type: application/json - Request Body: Any subset of event fields.
-
Response (200 OK):
{ "message": "Event updated successfully." }
- Description: User joins an event.
-
Headers:
Authorization: Bearer JWT_TOKEN_HERE -
Response (200 OK):
{ "message": "You have successfully joined the event!" }
- Description: User leaves an event.
-
Headers:
Authorization: Bearer JWT_TOKEN_HERE -
Response (200 OK):
{ "message": "You have successfully left the event!" }
- Description: Deletes an event.
-
Headers:
Authorization: Bearer JWT_TOKEN_HERE -
Response (200 OK):
{ "message": "You have successfully deleted the event!" }
Here's our Github Repository for Sportify - Sportify Repo
Here's our Github Project Board - Sportify Project Board
This document is also available in our Github Wiki Page
Along with this, we also added our design documentation (originally or Atlassian Confluence) onto our Github Repo