# Events App API Documentation - Team Vikings ## Introduction Welcome to the Events App API documentation. This API is designed to provide functionalities for managing events within your mobile application. It is built using Node.js, Express.js, MySQL, and Sequelize. ## Base URL The base URL for all API endpoints is: ``` http://13.51.241.113:5000/ ``` <!-- ## Authentication All API endpoints require authentication using JSON Web Tokens (JWT). To authenticate, include the JWT token in the Authorization header of your requests: ``` Authorization: Bearer <your_token_here> ``` To obtain a JWT token, your mobile app users must log in using their credentials and then use the token for subsequent requests. ## Error Handling In case of an error, the API will respond with a JSON object containing an error field. Example: ```json { "error": "Invalid API key." } ``` --> ## Endpoints ### User Management #### 1. Authentication - Endpoint: `/api/v1/auth` - Method: **POST** - Description: _Authenticate a user_. - Request Body: - googleId- Google Id of user to be authenticated - email- Email of use to be authenticated - picture- URL of user avatar (profile picture) - name - Full name of user to be authenticated * Example Request: ```json POST http://13.51.241.113:5000/api/v1/auth { "googleId": "erhiogererieket", "email": "not.found@gmail.com", "picture": "mypicture.png", "name": "Not Found" } ``` * Example Response: ```json { "message": "Authentication successful", "user": { "id": "erhiogererieket", "name": "Not Found", "email": "not.found@gmail.com", "avatar": "mypicture.png" }, "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6ImVyaGlvZ2VyZXJpZWtldCIsImVtYWlsIjoibm90LmZvdW5kQGdtYWlsLmNvbSIsImlhdCI6MTY5NTU1NDgxOCwiZXhwIjoyMTI3NTU0ODE4fQ.8Uz8EZLgGwXn1iEx9J1oFx1ybcm5SepKbHK3JqAT2MQ" } ``` ### Event Management #### 1. Create Event ✅ - Endpoint: `/api/v1/events` - Method: **POST** - Description: _Create an event_. * Example Request: ```json curl --location 'http://13.51.241.113:5000/api/v1/events' \ --form 'title="Football"' \ --form 'images=@"uHDl6_3kP/event.jpeg"' \ --form 'description="Let me confirm"' \ --form 'location="my house"' \ --form 'start_date="2023-09-15"' \ --form 'end_date="2023-09-15"' \ --form 'start_time="14:30:00"' \ --form 'end_time="16:30:00"' ``` * Example Response: ```json { "id": 4, "title": "Football", "description": "Let me confirm", "location": "my house", "creator_id": "erhiogererieker", "start_date": "2023-09-15T00:00:00.000Z", "end_date": "2023-09-15T00:00:00.000Z", "start_time": "14:30:00", "end_time": "16:30:00", "urls": [ "https://res.cloudinary.com/ol4juwon/image/upload/v1695397281/test/w2yst4j34mhu6lipsgez.jpg" ] } ``` #### 2. Get all events ✅ - Endpoint: `/api/v1/events` - Method: **GET** - Description: _Get a list of all events_. * Example Request: ```json GET http://13.51.241.113:5000/api/v1/events ``` * Example Response: ```json { "events": { "nowEvents": [], "upcomingEvents": [ { "id": "f717ea79-3e5f-4ffe-a313-36c2b9bf39f2", "title": "HNGx Finalist Hangout", "description": "Hangout of the souls that survived HNGx", "location": "New Location", "creator_id": "0965a1c3-a465-4141-8e5a-6e434151d724", "start_date": "2023-09-23", "end_date": "2023-09-23", "start_time": "00:36:00", "end_time": "00:36:00", "image": null }, { "id": "e250c857-23f3-4077-b163-779459d298c1", "title": "rrrr", "description": "ffff", ... ] } } ``` #### 3. Get event details ✅ - Endpoint: `/api/v1/events/<event_id>` - Method: **GET** - Description: _Get details of an event_. - Request Body: - Empty * Example Request: ```json GET http://13.51.241.113:5000/api/v1/events/4025146c-f5e7-4311-8268-aef6e1554fb3 ``` * Example Response: ```json { "event": { "id": "4025146c-f5e7-4311-8268-aef6e1554fb3", "title": "bbbb", "description": "hvhhh", "location": "hhh", "creator_id": "0965a1c3-a465-4141-8e5a-6e434151d724", "start_date": "2023-09-23", "end_date": "2023-09-23", "start_time": "00:46:00", "end_time": "00:46:00" } } ``` #### 4. Update event details ✅ - Endpoint: `/api/v1/events/<event_id>` - Method: **PUT** - Description: _Update details of an event_. - Request Body: - JSON containing fields to update * Example Request: ```json POST http://13.51.241.113:5000/api/v1/events/1b369ca8-75cb-4c09-92c7-ed33d101d53a { "location": "Unknown", "title": "Submission day" } ``` * Example Response: ```json { "message": "Event updated successfully" } ``` #### 5. Delete event - Endpoint: `/api/v1/events/<event_id>` - Method: **DELETE** - Description: _Delete an event_. - Request Body: - Empty * Example Request: ```json DELETE http://13.51.241.113:5000/api/v1/events/1b369ca8-75cb-4c09-92c7-ed33d101d53a ``` * Example Response: ```json { "message": "Event deleted successfully" } ``` #### 6. Add comment to event ✅ - Endpoint: `/api/v1/events/<event_id>/comments` - Method: **POST** - Description: _Add comment to an event_. - Request Body: { "body": comment text } * Example Request: ```json POST http://13.51.241.113:5000/api/v1/events/b46ebd67-18b2-4980-87a5-b8da9624524a/comments { "body": "Comment from new endpoint" } ``` * Example Response: ```json { "message": "Comment created successfully", "comment": { "id": "fdfeb319-eb11-4074-9a68-764e7a4eec8c", "body": "Comment from new endpoint", "user_id": "erhiogererieket", "event_id": "b46ebd67-18b2-4980-87a5-b8da9624524a" }, "images": null } ``` #### 7. Get event comments ✅ - Endpoint: `/api/v1/events/<event_id>/comments` - Method: **GET** - Description: _Get comments for an event_. - Request Body: - Empty * Example Request: ```json POST http://13.51.241.113:5000/api/v1/events/b46ebd67-18b2-4980-87a5-b8da9624524a/comments ``` * Example Response: ```json { "comments": [ { "id": "547a2c7a-8c20-4824-aef6-40f0b20624b5", "body": "first to comment", "user_id": "erhiogererieket", "event_id": "b46ebd67-18b2-4980-87a5-b8da9624524a", "likesCount": 0, "User": { "id": "erhiogererieket", "name": "Not Found", "email": "not.found@gmail.com", "avatar": "mypicture.png" }, "Images": [], "Event": { "id": "b46ebd67-18b2-4980-87a5-b8da9624524a", "title": "Testing 1", "description": "An unknown event", "location": "Unknown", "creator_id": "erhiogererieket", "start_date": "2023-09-23", "end_date": "2023-09-24", "start_time": "18:51:00", "end_time": "18:52:00" } }, { "id": "85bd881e-6268-4df2-8844-eb0b3812a52b", "body": "first to comment", "user_id": "erhiogererieket", "event_id": "b46ebd67-18b2-4980-87a5-b8da9624524a", "likesCount": 0, "User": { "id": "erhiogererieket", "name": "Not Found", "email": "not.found@gmail.com", "avatar": "mypicture.png" }, "Images": [], "Event": { "id": "b46ebd67-18b2-4980-87a5-b8da9624524a", "title": "Testing 1", "description": "An unknown event", "location": "Unknown", "creator_id": "erhiogererieket", "start_date": "2023-09-23", "end_date": "2023-09-24", "start_time": "18:51:00", "end_time": "18:52:00" } }, ... ] } ``` #### 8. Like comment ✅ - Endpoint: `/api/v1/comments/<comment_id>/likes/<user_id>` - Method: **POST** - Description: _Add like to a comment_. - Request Body: - Empty * Example Request: ```json POST http://13.51.241.113:5000/api/v1/comments/547a2c7a-8c20-4824-aef6-40f0b20624b5/members/erhiogererieket/like ``` * Example Response: ```json { "comment": { "id": "547a2c7a-8c20-4824-aef6-40f0b20624b5", "likesCount": 1 }, "message": "Comment liked", "status": "success" } ``` #### 9. Un-like comment ✅ - Endpoint: `/api/v1/comments/<comment_id>/likes/<user_id>` - Method: **DELETE** - Description: _Remove like from a comment_. - Request Body: - Empty * Example Request: ```json DELETE http://13.51.241.113:5000/api/v1/comments/547a2c7a-8c20-4824-aef6-40f0b20624b5/members/erhiogererieket/unlike ``` * Example Response: ```json { "comment": { "id": "547a2c7a-8c20-4824-aef6-40f0b20624b5", "likesCount": 0 }, "message": "Comment unliked", "status": "success" } ``` ### User Interractions #### 1. Express interest in an event ✅ - Endpoint: `/api/users/<user_id>/interests/<event_id>` - Method: **POST** - Description: _Express interest in an event_. - Request Body: - Empty * Example Request: ```json POST http://13.51.241.113:5000/api/v1/users/erhiogererieket/interests/b46ebd67-18b2-4980-87a5-b8da9624524a ``` * Example Response: ```json { "user_id": "erhiogererieket", "event_id": "b46ebd67-18b2-4980-87a5-b8da9624524a" } ``` #### 2. Remove interest from event ✅ - Endpoint: `/api/users/<user_id>/interests/<event_id>:` - Method: **DELETE** - Description: _Remove interest from an event_. - Request Body: - Empty * Example Request: ```json DELETE http://13.51.241.113:5000/api/v1/users/erhiogererieket/interests/b46ebd67-18b2-4980-87a5-b8da9624524a ``` * Example Response: ```json { "message": "You are no longer interested in this event" } ``` #### 3. Create group ✅ - Endpoint: `/api/groups` - Method: **POST** - Description: _Create a new group_. - * Example Request: ```json POST /api/events FORM DATA title="princeibs group" name="my group" ``` * Example Response: ```json { "id": "0ec55219-c0a1-4e20-9e68-f085cf7fde8a", "title": "princeibs group", "url": [] } ``` #### 4. Get group details - Endpoint: `/api/v1/groups/<group_id>` - Method: **GET** - Description: _Get details of a group with the specified group id_. * Example Request: ```json GET http://13.51.241.113:5000/api/v1/groups/79f62d89-9f70-40b6-8353-d9f5d3e7b99a ``` #### 5. Update group - Endpoint: `/api/v1/groups/<group_id>` - Method: **PUT** - Description: _Update group details with the specified group id_. #### 6. Delete group - Endpoint: `/api/groups/<group_id>` - Method: **DELETE** - Description: _Delete a group_. #### 7. Add user to group ✅ - Endpoint: `/api/groups/<group_id>/members/<user_id>` - Method: **POST** - Description: _Add user to a group_. - Request Body: - Empty * Example Request: ```json POST http://13.51.241.113:5000/api/v1/groups/79f62d89-9f70-40b6-8353-d9f5d3e7b99a/members/erhiogererieket ``` * Example Response: ```json { "message": "User successfully added to group" } ``` #### 8. Remove user from group ✅ - Endpoint: `/api/groups/<group_id>/members/<user_id>` - Method: **DELETE** - Description: _Remove user from a group_. - Request Body: - EMPTY * Example Request: ```json DELETE http://13.51.241.113:5000/api/v1/groups/79f62d89-9f70-40b6-8353-d9f5d3e7b99a/members/erhiogererieket ``` * Example Response: ```json { "error": "User is not a member of the group" } ```