API Documentation

Welcome to the LRCY Project API Documentation

This documentation provides you with information about the various APIs available in our system. We have organized the APIs into five main categories:

  • User API (19): These APIs handle user-related tasks such as registration, login, updating profiles, and stats about the user.
  • Event API (5): These APIs deal with event-related tasks like creating, updating, deleting, and retrieving event details.
  • Post API (19): These APIs handle post-related tasks such as creating, updating, deleting, and fetching posts, comments, and more.
  • Admin API (22): These APIs are responsible for administrative tasks such as managing users, events, and posts, as well as handling system settings.
  • Download API (1): This API allows users to download files or resources from the system.

Please click on the respective tabs above to explore the available APIs and their respective documentation. The documentation includes information about each API's functionality, parameters, return values, and possible errors.

Unit Testing

All of the unit tests for the User, Event, Post, and Admin controllers have been generated by Laravel and have passed Laravel's testing suite. These tests were specifically made in Laravel and are a part of the LRCY Project API Documentation. The purpose of unit testing is to verify that each unit of code works as expected and to catch any bugs or errors early in the development process. These tests were created to ensure that the APIs are functioning as intended and to catch any issues before they can affect users.

User Controller (Tests\Unit\UserController)

  • Signup api
  • Register api
  • Login api
  • Recover request api
  • Change password api
  • Check request status api
  • Get user info api
  • Logout api
  • Edit profile api
  • Get trainings info api
  • Get events organized api
  • Get events organized count api
  • Get total volunteering time api
  • Get completed trainings count api
  • Get posts count api
  • Get comments count api
  • Get total likes received api
  • Get own posts api
  • Get branch info api

Event Controller (Tests\Unit\EventController)

  • Get yearly goals api
  • Get event info api
  • Get announcements api
  • Get event pictures api
  • Get training info api

Post Controller (Tests\Unit\PostController)

  • Create post api
  • Edit post api
  • Delete post api
  • Get post api
  • Get posts api
  • Like post api
  • Unlike post api
  • Comment post api
  • Reply comment api
  • Like comment api
  • Unlike comment api
  • Delete comment api
  • Delete reply api
  • Edit comment api
  • Edit reply api
  • Get comments api
  • Get replies api
  • Get post likes api
  • Get comment likes api

Admin Controller (Tests\Unit\AdminController)

  • Admin login api
  • Logout api
  • Add user api
  • Edit user api
  • Delete user api
  • Get requests api
  • Accept request api
  • Decline request api
  • Send announcement api
  • Delete announcement api
  • Edit announcement api
  • Add event api
  • Edit event api
  • Delete event api
  • Set yearly goal api
  • Edit yearly goal api
  • Delete yearly goal api
  • Add training for user api
  • Delete training for user api
  • Add image to event api
  • Remove image from event api

User Controller

1.1 signup

POST

http://example.com/api/v0.1/auth/signup

Description:

The signup(Request $credentials) function takes a Request object as input, which includes the 'organization_id' input parameter. The function retrieves a volunteer user record from the database based on the 'organization_id' input parameter. If the record exists, the function determines the status message based on the registration status of the volunteer user. If the user is already registered, the status message will be "Organization ID found, user already registered". If the user is not registered, the status message will be "Organization ID found, user not registered". If the record does not exist, the status message will be "Organization ID not found"

Parameters:

Name Type Description
$credentials Request A Request object containing the ‘organization_id’ input parameter.

Returns:

Type Description
JSON A JSON response containing the status message based on the existence and registration status of the volunteer user. The response has a single key-value pair, where the key is 'status' and the value is the status message.

Errors:

Error Description
Organization ID found, user already registered If the user exists and is already registered
Organization ID not found If the user does not exist

1.2 register

POST

http://example.com/api/v0.1/auth/register

Description:

The register(Request $request) function takes a Request object as input, which includes the 'organization_id', 'username', 'password', and 'confirm_password' input parameters. The function validates the input parameters and checks for password validity using the validatePassword() function. If the input is valid and the password meets the requirements, the function retrieves a volunteer user record from the database based on the 'organization_id' input parameter. If the user record exists and the user is not registered, it updates the user's registration status, username, and password, and saves the changes to the database. The function then returns a JSON response containing the status message, "Organization ID found, user registered successfully", and an authentication token.

Parameters:

Name Type Description
$request Request A Request object containing the 'organization_id', 'username', 'password', and 'confirm_password' input parameters.

Returns:

Type Description
JSON A JSON response containing the status message based on the existence, registration status, and input validation of the volunteer user. The response includes the 'status' key with the status message, and the 'token' key with the authentication token if the user registration is successful.

Errors:

Error Description
Invalid input Invalid input' with the associated validation errors
Invalid password Invalid password' with the associated validation errors
Organization ID not found If the user does not exist
User already registered Organization ID found, user already registered

1.3 login

POST

http://example.com/api/v0.1/auth/login

Description:

The login(Request $credentials) function takes a Request object as input, which includes the 'organization_id' and 'password' input parameters. The function checks if the volunteer user exists in the database, is registered, and is active. It also verifies if the user has exceeded the maximum number of login attempts. If the user is allowed to log in and the password is correct, the function resets the user's login attempts, generates a new token, and returns a JSON response containing the status message, "Login successful", and the user information. If the password is incorrect, the function adds a failed login attempt to the database and returns a JSON response with the status message "Invalid credentials".

Parameters:

Name Type Description
$credentials Request A Request object containing the 'organization_id' and 'password' input parameters.

Returns:

Type Description
JSON A JSON response containing the status message and user information if the login is successful. The response includes the 'status' key with the status message, and other keys with user information such as 'token', 'user_id', 'username', 'user_profile_pic', 'branch_id', and 'full_name'.

Errors:

Error Description
Invalid credentials The user credentials provided in the request are invalid.
The user credentials provided in the request are invalid. The user has exceeded the maximum number of login attempts allowed.

1.4 recoverRequest

POST

http://example.com/api/v0.1/auth/recover_request

Description:

The recoverRequest(Request $request) function takes a Request object as input, which includes the 'organization_id' input parameter. The function retrieves a volunteer user record from the database based on the `organization_id` input parameter, and checks whether the user exists and is registered. If the user exists and is registered, the function checks whether the user has already submitted a recovery request. If the user has not already submitted a recovery request, the function creates a new recovery request and returns a JSON response containing the status message "Recovery request sent successfully!". If the user has already submitted a recovery request, the function returns a JSON response with the status message "User has already submitted a request." If the user does not exist or is not registered, the function returns a JSON response with the relevant error message.

Parameters:

Name Type Description
$request Request A Request object containing the 'organization_id' input parameter.

Returns:

Type Description
JSON A JSON response containing the status message if the recovery request is successful. The response includes the 'status' key with the status message.

Errors:

Error Description
Organization ID not found The organization ID provided in the request does not exist in the database.
User is not registered The user with the provided organization ID is not registered.
User has already submitted a request. The user with the provided organization ID has already submitted a recovery request.

1.5 changePassword

POST

http://example.com/api/v0.1/auth/change_password

Description:

The changePassword(Request $request) function takes a Request object as input, which includes the 'organization_id', 'password', and 'confirm_password' input parameters. The function first validates the input parameters. Then, it retrieves the user ID from the organization ID of the request, and checks the user's recover request status. If the status is false(0), it returns an error response stating that the password recovery request has not been accepted. If the status is null, it returns an error response stating that the user has not submitted a password recovery request. If the status is true(1), the function proceeds with changing the user's password. It updates the password field in the volunteer_user table and returns a JSON response containing the status message, "Password changed successfully!"

Parameters:

Name Type Description
$request Request A Request object containing the 'organization_id', 'password', and 'confirm_password' input parameters.

Returns:

Type Description
JSON A JSON response containing the status message, "Password changed successfully!"

Errors:

Error Description
User has not submitted a password recovery request The user has not submitted a password recovery request.
Password recovery request has not been accepted The user's password recovery request has not been accepted.

1.6 checkRequestStatus

POST

http://example.com/api/v0.1/auth/check_request_status

Description:

The checkRequestStatus(Request $request) function takes a Request object as input, which includes the 'organization_id' input parameter. The function retrieves the volunteer user record from the database based on the 'organization_id', and checks if the user has already submitted a password recovery request. If the user has submitted a request, the function returns a JSON response indicating whether the request has been accepted or not. If the user has not submitted a request, the function returns a JSON response with an error message.

Parameters:

Name Type Description
$request Request A Request object containing the 'organization_id' input parameter.

Returns:

Type Description
JSON A JSON response containing the status message indicating whether the password recovery request has been accepted or not.

Errors:

Error Description
User has not submitted a request. The user has not submitted a password recovery request yet.
Request not yet accepted The password recovery request has been submitted but not yet accepted by the administrator.

1.7 logout

POST

http://example.com/api/v0.1/user/logout

Description:

The logout(Request $request) function takes a Request object as input and deletes the user's token from the database, effectively logging the user out of the application. The function then returns a JSON response with the status message "Logged out".

Parameters:

Name Type Description
$request Request A Request object

Returns:

Type Description
JSON A JSON response containing the status message "Logged out".

Errors:

Error Description
Unauthorized The user is not authorized to access this endpoint.

1.8 editProfile

POST

http://example.com/api/v0.1/user/edit_profile

Description:

The editProfile function takes a Request object as input, which includes the user profile information to be updated, such as the user's profile picture, username, and bio. The function first checks if the user exists in the database, and if not, returns an error response. If the user exists, the function validates the input data and updates the user's profile picture, username, and bio if provided. The updated profile picture file is saved to the storage and the hash name is stored in the database. Finally, the function returns a success response with the updated profile picture hash name.

Parameters:

Name Type Description
$request Request A Request object containing the user profile information to be updated.

Parameters:

Type Description
JSON A JSON response containing the status message and updated profile picture hash name if the profile is updated successfully. The response includes the 'status' key with the status message, 'message' key with the success message, and 'new_pic' key with the updated profile picture hash name.

Errors:

Error Description
User not found The user does not exist in the database.
Validation errors The input data provided does not pass validation. The response includes the 'errors' key with the validation errors.

1.9 getUserInfo

GET

http://example.com/api/v0.1/user/get_user_info/{branch_id}/{user_id?}

Description:

The getUserInfo function retrieves user information from the database based on the provided branch_id and user_id (optional) parameters. If no user is found, it returns an error response. If user_id is not provided, it returns an array of user objects, otherwise it returns a single user object. Password, field1, field2, created_at, and updated_at fields are removed from the user object(s), and a 'user_type' field is added, indicating whether the user is an admin or volunteer.

Parameters:

Name Type Description
branch_id int The ID of the branch to retrieve users for.
user_id int The ID of the user to retrieve information for (optional). If not provided, returns information for all users in the branch.

Returns:

Type Description
JSON A JSON response containing either an array of user objects or a single user object, depending on whether user_id is provided. The response includes the 'status' key with the status message and other keys with user information, such as 'user_id', 'full_name', 'username', 'user_bio', and 'user_type'.

Errors:

Error Description
No user(s) found No user(s) were found in the database based on the provided branch_id and user_id parameters.

1.10 getTrainingsInfo

GET

http://example.com/api/v0.1/user/get_trainings_info/{user_id}

Description:

The getTrainingsInfo function retrieves information about a user's trainings based on their user_id. If the user is not found, it returns an error response. The function returns an array of trainings the user has taken, as well as an array of trainings they have not taken. Trainings are sorted by program ID and each training object includes an ID, name, description, and program ID. The function also returns the count of trainings the user has not taken and the count of trainings in each program.

Parameters:

Name Type Description
user_id int The ID of the user to retrieve training information for.

Returns:

Type Description
JSON A JSON response containing an array of trainings the user has taken, an array of trainings they have not taken, the count of trainings they have not taken, and the count of trainings in each program. The response includes the 'status' key with the status message and other keys with training information.

Errors:

Error Description
User not found The user ID provided does not match any user in the database.

1.11 getEventsOrganized

GET

http://example.com/api/v0.1/user/get_events_organized/{user_id}

Description:

The getEventsOrganized function retrieves a list of events organized by the user with the provided user_id. It returns an error response if the user is not found, or a message indicating no events were found if the user did not organize any events. The response includes the 'status' key with the status message and an array of events organized by the user, sorted by date from newest to oldest. Each event includes the 'id', 'event_date', 'event_title', 'program_id', 'event_type_id', and 'role_name' fields.

Parameters:

Name Type Description
user_id int The ID of the user to retrieve events for.

Returns:

Type Description
JSON A JSON response containing an array of events organized by the user, sorted by date from newest to oldest. The response includes the 'status' key with the status message and an array of events organized by the user, sorted by date from newest to oldest. Each event includes the 'id', 'event_date', 'event_title', 'program_id', 'event_type_id', and 'role_name' fields.

Errors:

Error Description
User not found No user was found in the database based on the provided user_id parameter.
No events found for this user No events were found for the user with the provided user_id parameter.

1.12 getEventsOrganizedCount

GET

http://example.com/api/v0.1/user/get_events_organized_count/{user_id}

Description:

The getEventsOrganizedCount function retrieves the total number of events organized by a user based on the provided user_id parameter. If no user is found, it returns an error response. If the user has not organized any events, it returns a response with a message indicating that no events were found.

Parameters:

Name Type Description
user_id int The ID of the user to retrieve information for.

Returns:

Type Description
JSON A JSON response containing the total number of events organized by the user. The response includes the 'status' key with the status message and 'total_events' key with the count of events.

Errors:

Error Description
No user found No user was found in the database based on the provided user_id parameter.
No events found for this user The user has not organized any events.

1.13 getTotalVolunteeringTime

GET

http://example.com/api/v0.1/user/get_total_volunteering_time/{user_id}

Description:

The getTotalVolunteeringTime function calculates and returns the total amount of time the specified user has volunteered, based on their user_start_date and user_end_date (if provided) fields in the database. It returns a response in JSON format, including a 'status' key with the status message and a 'total_time' key with the total volunteering time in the format of "[years] Y [months] M".

Parameters:

Name Type Description
user_id int The ID of the user to retrieve volunteering time for.

Returns:

Type Description
JSON A JSON response containing a 'status' key with the status message and a 'total_time' key with the total volunteering time in the format of "[years] Y [months] M".

Errors:

Error Description
User not found The specified user_id parameter does not correspond to a valid user in the database.

1.14 getCompletedTrainingsCount

GET

http://example.com/api/v0.1/user/get_completed_trainings_count/{user_id}

Description:

The getCompletedTrainingsCount function retrieves the total count of completed trainings for a given user based on the provided user_id parameter. If no user is found, it returns an error response. It returns the total count of completed trainings as a JSON response.

Parameters:

Name Type Description
user_id int The ID of the user to retrieve the completed trainings count for.

Returns:

Type Description
JSON A JSON response containing the total count of completed trainings for the given user. The response includes the 'total_trainings' key with the total count of completed trainings.

Errors:

Error Description
User not found No user was found in the database based on the provided user_id parameter.

1.15 getPostsCount

GET

http://example.com/api/v0.1/user/get_posts_count/{user_id}

Description:

The getPostsCount function returns the total count of posts for the given user_id.

Parameters:

Name Type Description
user_id int The ID of the user to retrieve post count for.

Returns:

Type Description
JSON A JSON response containing the 'total_posts' key with the total count of posts for the given user_id.

Errors:

Error Description
User not found No user was found in the database based on the provided user_id parameter.

1.16 getCommentsCount

GET

http://example.com/api/v0.1/user/get_comments_count/{user_id}

Description:

The getCommentsCount function retrieves the total number of comments made by the user with the provided user_id parameter. If no user is found, it returns an error response.

Parameters:

Name Type Description
user_id int The ID of the user to retrieve the total number of comments for.

Returns:

Type Description
JSON A JSON response containing the total number of comments made by the user with the provided user_id parameter. The response includes the 'total_comments' key with the count of comments.

Errors:

Error Description
User not found No user was found in the database with the provided user_id parameter.

1.17 getTotalLikesReceived

GET

http://example.com/api/v0.1/user/get_total_likes_received/{user_id}

Description:

The getTotalLikesReceived function returns the total number of likes received by the given user_id, which includes the sum of likes on posts and comments.

Parameters:

Name Type Description
user_id int The ID of the user to retrieve the total number of likes received for.

Returns:

Type Description
JSON A JSON response containing the 'total_likes_received' key with the total number of likes received by the given user_id.

Errors:

Error Description
User not found No user was found in the database based on the provided user_id parameter.

1.18 getOwnPosts

GET

http://example.com/api/v0.1/user/get_own_posts/{user_id}

Description:

The getOwnPosts function returns all the posts created by the user with the given user_id.

Parameters:

Name Type Description
user_id int The ID of the user to retrieve the posts for.

Returns:

Type Description
JSON A JSON response containing an array of posts that the user with the given user_id has created. Each post includes the following fields: id, post_title, post_body, post_date, full_name (full name of the user who created the post).

Errors:

Error Description
User not found No user was found in the database based on the provided user_id parameter.
No posts found for this user The user with the given user_id did not create any posts.

1.19 getBranchInfo

GET

http://example.com/api/v0.1/user/get_branch_info/{user_id}

Description:

The getBranchInfo function retrieves the branch information of a given user_id by matching the user's branch_id with the id in the branch table.

Parameters:

Name Type Description
user_id int The ID of the user to retrieve the branch information for.

Returns:

Type Description
JSON A JSON response containing the 'branch_name' key with the name of the branch and the 'branch_location' key with the location of the branch matching the user's branch_id.

Errors:

Error Description
User not found No user was found in the database based on the provided user_id parameter.
Branch not found No branch was found in the database based on the user's branch_id.

Event Controller

2.1 getYearlyGoals

GET

http://example.com/api/v0.1/event/get_yearly_goals/{branch_id}

Description:

The getYearlyGoals function returns the yearly goals for a given branch_id. The goals are grouped based on the program_id.

Parameters:

Name Type Description
branch_id int The ID of the branch to retrieve yearly goals for.

Returns:

Type Description
JSON A JSON response containing the yearly goals grouped by program_id.

Errors:

Error Description
No goals found No goals were found in the database based on the provided branch_id parameter and the current year.

2.2 getEventInfo(branch_id, event_id)

GET

http://example.com/api/v0.1/event/get_event_info/{branch_id}/{event_id?}

Description:

The getEventInfo function returns information about events in the given branch, grouped by program name. If an event_id is provided, only the information for that event is returned.

Parameters:

Name Type Description
branch_id int The ID of the branch to retrieve events for.
event_id int Optional. The ID of the event to retrieve information for.

Returns:

Type Description
JSON If event_id is provided, returns a JSON response containing the event information including program name and a list of users responsible for the event. If event_id is not provided, returns a JSON response containing an array of events information grouped by program name, including program name and a list of users responsible for each event.

Errors:

Error Description
Event not found No event(s) were found in the database based on the provided branch_id and event_id parameters.

2.3 getAnnouncements

GET

http://example.com/api/v0.1/event/get_announcements/{branch_id}

Description:

The getAnnouncements function returns a list of announcements for a given branch. The function includes information about the announcer's name, profile picture, and the importance level of the announcement.

Parameters:

Name Type Description
branch_id int The ID of the branch to retrieve announcements for.

Returns:

Type Description
JSON A JSON response containing an array of announcement objects for the given branch. Each announcement object contains the announcement's information, the announcer's name and profile picture, and the importance level of the announcement.

Errors:

Error Description
No announcements found No announcements were found in the database based on the provided branch_id parameter.

2.4 getEventPictures

GET

http://example.com/api/v0.1/event/get_event_pictures/{event_id}

Description:

The getEventPictures function returns the pictures of a specific event. The pictures are ordered by date.

Parameters:

Name Type Description
event_id int The ID of the event to retrieve pictures for.

Returns:

Type Description
JSON A JSON response containing the pictures of the event ordered by date.

Errors:

Error Description
Event not found No event was found in the database based on the provided event_id parameter.
Pictures not found No pictures were found in the database based on the provided event_id parameter.

2.5 getTrainingInfo

GET

http://example.com/api/v0.1/training/get_training_info/{training_id?}

Description:

The getTrainingInfo function returns information about a specific training or all trainings. The function returns the training(s) information including the program name.

Parameters:

Name Type Description
training_id int (optional) The ID of the training to retrieve. If not provided, all trainings will be returned.

Returns:

Type Description
JSON A JSON response containing the training(s) information including the program name.

Errors:

Error Description
Training not found No training was found in the database based on the provided training_id parameter.

Post Controller

3.1 createPost

POST

http://example.com/api/v0.1/post/create_post

Description:

The createPost() function creates a new post in the database with the specified user ID, post type, and caption.

If the post type is "image", the function requires an uploaded file as "post_media".

Parameters:

Name Type Description
user_id int The ID of the user creating the post.
post_type string The type of the post. Must be one of "text" or "image".
post_caption string The caption for the post. Required if the post type is "text".
post_media file The file to upload for the post media. Required if the post type is "image.

Returns:

Type Description
JSON A JSON response indicating whether the post was created successfully, and including the post ID if successful.

Errors:

Error Description
User not found The user ID provided in the request does not exist in the database.
Invalid post type The post_type field in the request must be one of: text or image.
Invalid file type If the post_type is 'image', the post_media field must be an image file (JPEG, BMP, PNG, or JPG).
Missing required fields The user_id and post_type fields are required in the request. If the post_type is 'text', the post_caption field is also required.

3.2 editPost

POST

http://example.com/api/v0.1/post/edit_post

Description:

The editPost(Request $request) function takes a Request object as input, which includes the post ID and the new caption for the post. The function checks if the post exists in the database based on the post ID. If the post exists, the function updates the post's caption to the new value. If the update is successful, the function returns a JSON response with a "Post updated successfully" message. If the update fails, the function returns a JSON response with a "Post could not be updated" message.

Parameters:

Name Type Description
Request Request object A Request object containing the following input parameters:
post_id Integer The ID of the post to be edited.
post_caption String The new caption for the post.

Returns:

Type Description
JSON A JSON response containing a status message. The response has two key-value pairs, where the keys are 'status' and 'message', and the values are the status message.

Errors:

Error Description
Post not found If the post with the specified ID does not exist in the database.
Post could not be updated If the post caption could not be updated in the database.

3.3 deletePost

POST

http://example.com/api/v0.1/post/delete_post

Description:

The deletePost(Request $request) function takes a Request object as input, which includes the post ID and the ID of the user who wants to delete the post. The function checks if the post exists in the database based on the post ID. If the post exists, the function checks if the user ID from the request matches the user ID of the post. If the user ID matches, the function deletes the post, as well as all associated likes, comments, and replies from the database. If the delete is successful, the function returns a JSON response with a "Post deleted successfully" message. If the delete fails, the function returns a JSON response with a "Post could not be deleted" message.

Parameters:

Name Type Description
Request Request object A Request object containing the following input parameters:
post_id Integer The ID of the post to be deleted.
user_id Integer The ID of the user who wants to delete the post.

Returns:

Type Description
JSON A JSON response containing a status message. The response has two key-value pairs, where the keys are 'status' and 'message', and the values are the status message.

Errors:

Error Description
Post not found If the post with the specified ID does not exist in the database.
You are not authorized to delete this post If the user ID from the request does not match the user ID of the post.
Post could not be deleted If the post could not be deleted from the database.

3.4 getPosts

GET

http://example.com/api/v0.1/post/get_posts/{user_id?}

Description:

The getPosts($user_id = null) function retrieves posts from the database based on the user ID. If a user ID is provided, the function checks if the user exists in the database. If the user does not exist, the function returns an error response. If no user ID is provided, the function retrieves all posts from the database. The retrieved posts are sorted in descending order based on the post date. The function removes unwanted fields from each post and retrieves the name, profile picture, and username of the post owner based on the user ID. If no user is found for a post, the function returns null. The function returns a JSON response containing a status message, and an array of post objects, each containing the post details and the user details.

Parameters:

Name Type Description
user_id Integer The ID of the user whose posts will be retrieved. If not provided, all posts will be retrieved.

Returns:

Type Description
JSON A JSON response containing a status message, and an array of post objects, each containing the post details and the user details. The response has three key-value pairs, where the keys are 'status', 'message', and 'posts', and the values are the status message, the message explaining the result of the API request, and the array of post objects respectively.

Errors:

Error Description
User not found If the user with the specified ID does not exist in the database.
No posts found If no posts were found in the database.

3.5 getPost

GET

http://example.com/api/v0.1/post/get_post/{post_id}

Description:

The getPost() function retrieves a single post from the database based on the post ID provided in the URL parameter. If the post is found, the function returns the post data along with the name of the user who posted the post. If the post is not found, the function returns an error response.

Parameters:

Name Type Description
post_id integer The ID of the post to retrieve from the database.

Returns:

Type Description
JSON A JSON response containing the post data and name of the user who posted the post. The response has three key-value pairs:
  • 'status': A string indicating the status of the response, either "success" or "error".
  • 'message': A string containing a message describing the status of the response.
  • 'post': An object containing the post data and name of the user who posted the post.

Errors:

Error Description
Post not found If the post with the specified ID does not exist in the database.

3.6 likePost

POST

http://example.com/api/v0.1/post/like_post

Description:

The likePost() function is used to like a post. The function takes in the post ID and user ID as parameters and checks if both the post and the user exist in the database. If either the post or the user is not found, the function returns an error response. If the user has already liked the post, the function returns an error response. If the user has not liked the post yet, a new like instance is created with the post ID, user ID, and the current date, and is saved to the database. If the like is saved successfully, the function increments the post like count and returns a success response. If the like cannot be saved, the function returns an error response. If the post like count cannot be updated, the function returns an error response.

Parameters:

Name Type Description
post_id integer The ID of the post to like
user_id integer The ID of the user liking the post

Returns:

Type Description
JSON A JSON response indicating whether the like was successful or not. The response has two key-value pairs, where 'status' indicates the status of the operation and 'message' provides additional information about the operation.

Errors:

Error Description
Post not found If the post with the specified ID does not exist in the database.
User not found If the user with the specified ID does not exist in the database.
You have already liked this post If the user has already liked the post.
error If the post could not be liked or the like count could not be updated.

3.7 unlikePost

POST

http://example.com/api/v0.1/post/unlike_post

Description:

The unlikePost API function unlikes a post by a user. The function takes in two parameters: the post ID and the user ID. If the post and user exist in the database, the function checks if the user has already liked the post. If the user has not liked the post, the function returns an error response. If the user has liked the post, the function deletes the like from the database, decrements the post like count, and returns a success response. If the like could not be deleted or the post like count could not be updated, the function returns an error response.

Parameters:

Name Type Description
post_id int The ID of the post to unlike
user_id int The ID of the user unliking the post

Returns:

Type Description
JSON A JSON response containing the status of the unlike operation and a message. The response has two key-value pairs: 'status' and 'message'.

Errors:

Error Description
Post not found If the post with the specified ID does not exist in the database.
User not found If the user with the specified ID does not exist in the database.
You have not liked this post If the user has not liked the post.
Post could not be unliked If the like instance could not be deleted from the database.
Post like count could not be updated If the like instance was successfully deleted from the database but the post like count could not be decremented.

3.8 commentPost

POST

http://example.com/api/v0.1/post/comment_post

Description:

The commentPost() function is used to create a new comment on a post. The function takes in the post ID, user ID, and comment content as parameters and validates them. If any of the parameters are missing, the function returns an error response. If both the post and the user exist in the database, the function creates a new comment instance with the post ID, user ID, comment content, current date, and default values for the comment like count and reply count. The comment is then saved to the database. If the comment is saved successfully, the function increments the post comment count and returns a success response. If the comment cannot be saved, the function returns an error response. If the post comment count cannot be updated, the function returns an error response.

Parameters:

Name Type Description
post_id integer The ID of the post to comment on
user_id integer The ID of the user making the comment
comment_content string The content of the comment

Returns:

Type Description
JSON A JSON response indicating whether the comment was posted successfully or not. The response has two key-value pairs, where 'status' indicates the status of the operation and 'message' provides additional information about the operation.

Errors:

Error Description
Post not found If the post with the specified ID does not exist in the database.
User not found If the user with the specified ID does not exist in the database.
Comment could not be posted If the comment instance could not be saved to the database.
Post comment count could not be updated If the comment instance was successfully saved to the database but the post comment count could not be incremented.

3.9 replyComment

POST

http://example.com/api/v0.1/post/reply_comment

Description:

The replyComment API function is used to reply to a comment. The function takes in the comment ID, user ID, and reply content as parameters and checks if both the comment and the user exist in the database. If either the comment or the user is not found, the function returns an error response. If the user has not replied to the comment yet, a new reply instance is created with the comment ID, user ID, and the current date, and is saved to the database. If the reply is saved successfully, the function increments the comment reply count and returns a success response. If the reply cannot be saved, the function returns an error response. If the comment reply count cannot be updated, the function returns an error response.

Parameters:

Name Type Description
comment_id int The ID of the comment to reply to
user_id int The ID of the user replying to the comment
reply_content string The content of the reply

Returns:

Type Description
JSON A JSON response indicating whether the reply was successful or not. The response has two key-value pairs, where 'status' indicates the status of the operation and 'message' provides additional information about the operation.

Errors:

Error Description
Comment not found If the comment with the specified ID does not exist in the database.
User not found If the user with the specified ID does not exist in the database.
error If the reply could not be posted or the comment reply count could not beupdated.

3.10 likeComment

POST

http://example.com/api/v0.1/post/like_comment

Description:

The likeComment() function is used to like a comment. The function takes in the comment ID and user ID as parameters and checks if both the comment and the user exist in the database. If either the comment or the user is not found, the function returns an error response. If the user has already liked the comment, the function returns an error response. If the user has not liked the comment yet, a new Comment_like instance is created with the comment ID, user ID, and the current date, and is saved to the database. If the like is saved successfully, the function increments the comment like count and returns a success response. If the like cannot be saved, the function returns an error response. If the comment like count cannot be updated, the function returns an error response.

Parameters:

Name Type Description
comment_id integer The ID of the comment to like
user_id integer The ID of the user liking the comment

Returns:

Type Description
JSON A JSON response indicating whether the like was successful or not. The response has two key-value pairs, where 'status' indicates the status of the operation and 'message' provides additional information about the operation.

Errors:

Error Description
Comment not found If the comment with the specified ID does not exist in the database.
User not found If the user with the specified ID does not exist in the database.
You have already liked this comment If the user has already liked the comment.

3.11 unlikeComment

POST

http://example.com/api/v0.1/post/unlike_comment

Description:

The unlikeComment() function is used to unlike a comment. The function takes in the comment ID and user ID as parameters and checks if both the comment and the user exist in the database. If either the comment or the user is not found, the function returns an error response. If the user has not already liked the comment, the function returns an error response. If the user has already liked the comment, the corresponding Comment_like instance is deleted from the database. If the like is deleted successfully, the function decrements the comment like count and returns a success response. If the like cannot be deleted, the function returns an error response. If the comment like count cannot be updated, the function returns an error response.

Parameters:

Name Type Description
comment_id integer The ID of the comment to unlike
user_id integer The ID of the user unliking the comment

Returns:

Type Description
JSON A JSON response indicating whether the unlike was successful or not. The response has two key-value pairs, where 'status' indicates the status of the operation and 'message' provides additional information about the operation.

Errors:

Error Description
Comment not found If the comment with the specified ID does not exist in the database.
User not found If the user with the specified ID does not exist in the database.
You have not liked this comment If the user has not liked the comment yet and tries to unlike it.

3.12 deleteComment

POST

http://example.com/api/v0.1/post/delete_comment

Description:

The deleteComment() function is used to delete a comment. The function takes in the comment ID and user ID as parameters and checks if both the comment and the user exist in the database. If either the comment or the user is not found, the function returns an error response. If the user is not the owner of the comment, the function returns an error response. The function deletes the comment and all associated likes and replies from the database. If the comment is deleted successfully, the function decrements the comment count of the post associated with the comment and returns a success response. If the comment cannot be deleted, the function returns an error response. If the post comment count cannot be updated, the function returns an error response.

Parameters:

Name Type Description
comment_id integer The ID of the comment to delete
user_id integer The ID of the user deleting the comment

Returns:

Type Description
JSON A JSON response indicating whether the comment was deleted successfully or not. The response has two key-value pairs, where 'status' indicates the status of the operation and 'message' provides additional information about the operation.

Errors:

Error Description
Comment not found If the comment with the specified ID does not exist in the database.
User not found If the user with the specified ID does not exist in the database.
You are not the owner of this comment If the user trying to delete the comment is not the owner of the comment.

3.13 deleteReply

POST

http://example.com/api/v0.1/post/delete_reply

Description:

The deleteReply() function is used to delete a reply. The function takes in the reply ID and user ID as parameters and checks if both the reply and the user exist in the database. If either the reply or the user is not found, the function returns an error response. If the user is not the owner of the reply, the function returns an error response. If the user is the owner of the reply, the corresponding Reply instance is deleted from the database. If the reply is deleted successfully, the function decrements the comment reply count and returns a success response. If the comment reply count cannot be updated, the function returns an error response.

Parameters:

Name Type Description
reply_id integer The ID of the reply to delete
user_id integer The ID of the user deleting the reply

Returns:

Type Description
JSON A JSON response indicating whether the deletion was successful or not. The response has two key-value pairs, where 'status' indicates the status of the operation and 'message' provides additional information about the operation.

Errors:

Error Description
Reply not found If the reply with the specified ID does not exist in the database.
User not found If the user with the specified ID does not exist in the database.
You are not the owner of this reply If the user trying to delete the reply is not the owner of the reply.

3.14 editComment

POST

http://example.com/api/v0.1/post/edit_comment

Description:

The editComment() function is used to edit a comment. The function takes in the comment ID, user ID, and new comment content as parameters and checks if both the comment and the user exist in the database. If either the comment or the user is not found, the function returns an error response. If the user is not the owner of the comment, the function returns an error response. If the user is the owner of the comment, the corresponding Comment instance is updated with the new content. If the update is successful, the function returns a success response. If the update cannot be performed, the function returns an error response.

Parameters:

Name Type Description
comment_id integer The ID of the comment to edit
user_id integer The ID of the user editing the comment
comment_content string The new content of the comment

Returns:

Type Description
JSON A JSON response indicating whether the edit was successful or not. The response has two key-value pairs, where 'status' indicates the status of the operation and 'message' provides additional information about the operation.

Errors:

Error Description
Comment not found If the comment with the specified ID does not exist in the database.
User not found If the user with the specified ID does not exist in the database.
You are not the owner of this comment If the user trying to edit the comment is not the owner of the comment.

3.15 editReply

POST

http://example.com/api/v0.1/post/edit_reply

Description:

The editReply() function is used to edit a reply. The function takes in the reply ID, user ID, and new content as parameters and checks if both the reply and the user exist in the database. If either the reply or the user is not found, the function returns an error response. If the user is not the owner of the reply, the function returns an error response. If the reply is found and the user is the owner, the reply content is updated with the new content and the function returns a success response. If the reply cannot be updated, the function returns an error response.

Parameters:

Name Type Description
reply_id integer The ID of the reply to edit
user_id integer The ID of the user editing the reply
reply_content string The new content of the reply

Returns:

Type Description
JSON A JSON response indicating whether the edit was successful or not. The response has two key-value pairs, where 'status' indicates the status of the operation and 'message' provides additional information about the operation.

Errors:

Error Description
Reply not found If the reply with the specified ID does not exist in the database.
User not found If the user with the specified ID does not exist in the database.
You are not the owner of this reply If the user trying to edit the reply is not the owner of the reply.

3.16 getComments

GET

http://example.com/api/v0.1/post/get_comments/{post_id}

Description:

The getComments() function is used to retrieve all comments associated with a given post. The function takes in a post ID as a parameter and checks if the post exists in the database. If the post is found, the function retrieves all comments associated with the post, removes any unnecessary fields, and retrieves the user who made the comment. If no comments are found, the function returns an error response. Otherwise, the function returns a success response along with the comments.

Parameters:

Name Type Description
post_id integer The ID of the post to retrieve comments for

Returns:

Type Description
JSON A JSON response indicating whether the operation was successful or not. The response has two key-value pairs, where 'status' indicates the status of the operation and 'comments' provides the list of comments associated with the post.

Errors:

Error Description
Post not found If the post with the specified ID does not exist in the database.
No comments found for this post If no comments are associated with the post.

3.17 getReplies

GET

http://example.com/api/v0.1/post/get_replies/{comment_id}

Description:

The getReplies() function is used to retrieve all replies for a given comment. The function takes in the comment ID as a parameter and checks if the comment exists in the database. If the comment is found, the function retrieves all the replies associated with it, removes unwanted fields, and gets user information for each reply. The function then returns a JSON response containing the replies or an error message if no replies were found for the comment.

Parameters:

Name Type Description
comment_id integer The ID of the comment to retrieve replies for

Returns:

Type Description
JSON A JSON response indicating whether the operation was successful or not. The response has two key-value pairs, where 'status' indicates the status of the operation and 'replies' provides an array of replies if any are found.

Errors:

Error Description
Comment not found If the comment with the specified ID does not exist in the database.
No replies found for this comment If there are no replies associated with the comment in the database.

3.18 getPostLikes

GET

http://example.com/api/v0.1/post/get_post_likes/{post_id}

Description:

The getPostLikes() function is used to retrieve the likes associated with a post. The function takes in the post ID as a parameter and checks if the post exists in the database. If the post is found, the likes associated with the post are retrieved and returned. If no likes are found, the function returns an error response.

Parameters:

Name Type Description
post_id integer The ID of the post to retrieve likes for.

Returns:

Type Description
JSON A JSON response indicating whether the likes were retrieved successfully or not. The response has three key-value pairs, where 'status' indicates the status of the operation, 'likes' provides the retrieved likes, and 'total_likes' provides the total number of likes. The 'likes' key contains an array of like objects with the 'field1', 'field2', 'created_at', 'updated_at', and 'like_date' fields removed.

Errors:

Error Description
Post not found If the post with the specified ID does not exist in the database.
No likes found for this post If no likes are found for the post.

3.19 getCommentLikes

GET

http://example.com/api/v0.1/post/get_comment_likes/{comment_id}

Description:

The getCommentLikes() function is used to get the likes for a specific comment. The function takes in the comment ID as a parameter and checks if the comment exists in the database. If the comment is found, the function retrieves the likes associated with the comment and removes unwanted fields. The function then returns the likes and the total like count. If no likes are found for the comment, the function returns an error response.

Parameters:

Name Type Description
comment_id integer The ID of the comment to get likes for

Returns:

Type Description
JSON A JSON response indicating whether the operation was successful or not. The response has two key-value pairs, where 'status' indicates the status of the operation and 'likes' provides an array of likes associated with the comment, and 'total_likes' gives the total number of likes for the comment.

Errors:

Error Description
Comment not found If the comment with the specified ID does not exist in the database.
No likes found for this comment If no likes are found for the comment.

Admin Controller

4.1 adminLogin

POST

http://example.com/api/v0.1/admin/admin_login

Description:

The adminLogin function allows an admin user to log in to the system and obtain a token for authentication.

Parameters:

Name Type Description
organization_id string The ID of the admin user's organization.
password string The admin user's password.

Returns:

Type Description
JSON A JSON response containing the status of the login attempt, user information, and a token for authentication.

Errors:

Error Description
User not found The user with the provided organization_id was not found in the database.
Permission denied The user with the provided organization_id is not an admin user and is not authorized to log in as an admin.
Too many failed login attempts The user with the provided organization_id has exceeded the maximum number of login attempts and is temporarily locked out of the system.
Invalid credentials The password provided does not match the password on file for the user with the provided organization_id.

4.2 logout

POST

http://example.com/api/v0.1/admin/logout

Description:

The logout function logs out the authenticated admin user by revoking all their personal access tokens.

Returns:

Type Description
JSON A JSON response confirming the user has been logged out.

Errors:

Error Description
Unauthorized The user is not authenticated and therefore cannot log out.

4.3 addUser

POST

http://example.com/api/v0.1/admin/add_user

Description:

The addUser function adds a new user to the system.

Parameters:

Name Type Description
branch_id int The ID of the branch to which the user belongs.
first_name string The first name of the user.
last_name string The last name of the user.
organization_id int The ID of the user in the organization's database.
user_dob date The date of birth of the user.
user_position string The position of the user in the organization.
gender int The gender of the user. 0 for female, 1 for male, 2 for non-binary, and 3 for other.
user_type_id int The ID of the user's type. 0 for volunteer and 1 for admin.
is_active int Whether the user is active or not. 0 for inactive and 1 for active.
user_start_date date The date when the user started working in the organization.
user_end_date date (optional) The date when the user stopped working in the organization.

Returns:

Type Description
JSON A JSON response containing the status, message, and the added user's information.

Errors:

Error Description
Validation failed One or more input parameters failed validation. The specific error message will be included in the response.
User could not be added The function was unable to add the new user to the database. The specific error message will be included in the response.

4.4 editUser

POST

http://example.com/api/v0.1/admin/edit_user

Description:

The editUser function updates the information of a specific user.

Parameters:

Name Type Description
user_id int The ID of the user to be edited.
first_name string The user's first name.
last_name string The user's last name.
user_dob date The user's date of birth.
user_position string The user's position.
gender int The user's gender. (0 = Female, 1 = Male, 2 = Other)
user_type_id int The user's type. (0 = Volunteer, 1 = Admin)
is_active int Whether the user is currently active. (0 = Inactive, 1 = Active)
user_start_date date The user's start date with the organization.
user_end_date date (optional) The user's end date with the organization, if applicable.

Returns:

Type Description
JSON A JSON response containing the status of the operation and a message.

Errors:

Error Description
Validation failed The request parameters failed validation.
User not found The specified user was not found in the database.
Error An error occurred while updating the user information.

4.5 deleteUser

POST

http://example.com/api/v0.1/admin/delete_user

Description:

The deleteUser function deletes the specified user from the database.

Parameters:

Name Type Description
user_id integer The unique identifier of the user to be deleted.

Returns:

Type Description
JSON A JSON response confirming the user has been deleted successfully.

Errors:

Error Description
User not found The specified user could not be found in the database.
General error An error occurred while deleting the user from the database.

4.6 getRequests

GET

http://example.com/api/v0.1/admin/get_requests/{branch_id}

Description:

The getRequests function retrieves all the recover requests made by users in the specified branch, if any.

Parameters:

Name Type Description
branch_id integer The ID of the branch whose recover requests are being retrieved.

Returns:

Type Description
JSON A JSON response containing the recover requests made by users in the specified branch, if any.

Errors:

Error Description
Not Found The specified branch does not exist or has no recover requests made by its users.

4.7 acceptRequest

POST

http://example.com/api/v0.1/admin/accept_request

Description:

The acceptRequest function accepts a recover request by updating the request status to accepted.

Parameters:

Parameter Description
request_id The ID of the recover request to accept.

Returns:

Type Description
JSON A JSON response confirming that the recover request has been accepted.

Errors:

Error Description
Validation failed The required parameter request_id was not provided or is not an integer.
Recover request not found The provided request_iddoes not correspond to a recover request in the database.
Recover request has already been accepted The provided request_id corresponds to a recover request that has already been accepted.

4.9 declineRequest

POST

http://example.com/api/v0.1/admin/decline_request

Description:

The declineRequest function declines a recover request based on the provided request ID.

Parameters:

Name Description
request_id The ID of the recover request to decline.

Returns:

Type Description
JSON A JSON response confirming the recover request has been declined.

Errors:

Error Description
Validation failed The request_id parameter is missing or not an integer.
Error The recover request with the provided ID was not found.

4.10 sendAnnouncement

POST

http://example.com/api/v0.1/admin/send_announcement

Description:

The sendAnnouncement function creates a new announcement.

Parameters:

Name Type Description
announcement_title string The title of the announcement
announcement_content string The content of the announcement
admin_id integer The ID of the admin user sending the announcement
importance_level integer The level of importance of the announcement (0 = low, 1 = medium, 2 = high)

Returns:

Type Description
JSON A JSON response confirming the announcement has been sent.

Errors:

Error Description
Invalid admin user The admin user does not exist or is not an admin.
The importance level field is required The importance level field is missing or has an invalid value.
Validation error The request parameters failed validation. The error message will contain details about the validation failure.

4.11 deleteAnnouncement

POST

http://example.com/api/v0.1/admin/delete_announcement

Description:

The deleteAnnouncement function deletes the announcement with the provided ID, but only if the admin user who created the announcement and the admin user who sent the delete request are the same.

Parameters:

Parameter Description
announcement_id The ID of the announcement to be deleted.
admin_id The ID of the admin user who sent the delete request.

Returns:

Type Description
JSON A JSON response confirming whether the announcement was deleted successfully or if an error occurred.

Errors:

Error Description
Announcement not found The announcement with the provided ID could not be found.
User not found The admin user with the provided ID could not be found.
User is not an admin The admin user with the provided ID is not an admin and does not have permission to delete announcements.
User is not the one who sent the announcement The admin user with the provided ID did not send the announcement with the provided ID and therefore cannot delete it.

4.12 editAnnouncement

POST

http://example.com/api/v0.1/admin/edit_announcement

Description:

The editAnnouncement function edits an existing announcement sent by an admin user.

Parameters:

Parameter Type Description
announcement_id integer The ID of the announcement to be edited
announcement_title string The new title of the announcement
announcement_content string The new content of the announcement
admin_id integer The ID of the admin user who sent the announcement
importance_level integer The new importance level of the announcement (0, 1, or 2)

Returns:

Type Description
JSON A JSON response confirming the announcement has been edited.

Errors:

Error Description
Unauthorized The user is not authorized to access this resource.
Validation Error The request did not pass validation rules. The error message will contain the details.
Not Found The requested resource was not found.
Internal Server Error An unexpected error occurred while processing the request.

4.13 addEvent

POST

http://example.com/api/v1/admin/add_event

Description:

The addEvent function creates a new event and adds it to the database. It also adds responsible people for the event and increments the goals table for goals that have the same program ID and event type ID as the event

Parameters:

Name Type Description
program_id integer The ID of the program associated with the event.
event_main_picture file An image file to be associated with the event. (optional)
event_description string A description of the event.
event_location string The location of the event.
event_date date The date of the event.
event_title string The title of the event.
event_type_id integer The ID of the type of event.
budget_sheet file An image file of the event's budget sheet. (optional)
proposal file An image file of the event's proposal. (optional)
meeting_minute file An image file of the event's meeting minute. (optional)
branch_id integer The ID of the branch associated with the event.
responsibles array An array of objects representing the people responsible for the event. Each object must contain a user ID and role name.

Returns:

Type Description
JSON A JSON response indicating whether the event was created successfully or not.

Errors:

Error Description
Invalid request parameters The request parameters failed validation. The error message will contain details about the validation failure.
Error creating event An error occurred while creating the event. The error message will contain details about the error.
Error adding responsibilities An error occurred while adding responsibilities for the event. The error message will contain details about the error.

4.14 editEvent

POST

http://example.com/api/v0.1/admin/edit_event

Description:

The editEvent function updates an existing event with new information.

Parameters:

Name Type Description
event_id integer The ID of the event to be updated
program_id integer The ID of the program the event is associated with
event_main_picture file The main picture for the event
event_description string The description of the event
event_location string The location of the event
event_date date The date of the event
event_title string The title of the event
event_type_id integer The ID of the event type
budget_sheet file The budget sheet for the event
proposal file The proposal for the event
meeting_minute file The meeting minutes for the event (optional)
responsibles array An array of responsible people, each with a user_id and role_name
event_images array An array of event images to be added to the event

Returns:

Type Description
JSON A JSON response confirming the event has been updated.

Errors:

Error Description
Event not found The event with the specified event_id does not exist.
Validation error The request parameters failed validation. The error message will contain details about the validation failure.
File type error One or more of the uploaded files are not in the supported file formats (jpeg, bmp, png, jpg).

4.15 deleteEvent

POST

http://example.com/api/v0.1/admin/delete_event

Description:

The deleteEvent function deletes an existing event.

Parameters:

Name Type Description
event_id integer The ID of the event to be deleted

Returns:

Type Description
JSON A JSON response confirming the event has been deleted.

Errors:

Error Description
Event not found The event with the specified event_id does not exist.
An error occurred while deleting the event An unexpected error occurred during the event deletion process.

4.16 addImageToEvent

POST

http://example.com/api/v0.1/admin/add_event_photo

Description:

The addImageToEvent function adds an image to an existing event.

Parameters:

Name Type Description
event_id integer The ID of the event to which the image will be added
image file The image file to be added to the event (JPEG, BMP, PNG, or JPG format)

Returns:

Type Description
JSON A JSON response confirming the image has been added to the event.

Errors:

Error Description
Validation failed The request parameters failed validation. The error message will contain details about the validation failure.
Event not found The event with the specified event_id does not exist.

4.17 removeImageFromEvent

POST

http://example.com/api/v0.1/admin/remove_image

Description:

The removeImageFromEvent function removes an image from an existing event.

Parameters:

Name Type Description
id integer The ID of the image to be removed

Returns:

Type Description
JSON A JSON response confirming the image has been removed from the event.

Errors:

Error Description
Validation failed The request parameters failed validation. The error message will contain details about the validation failure.
Image not found The image with the specified ID does not exist.
Failed to delete the image An error occurred while attempting to delete the image.

4.18 setYearlyGoal

POST

http://example.com/api/v0.1/admin/set_yearly_goal

Description:

The setYearlyGoal function sets a yearly goal for a specific program and event type.

Parameters:

Name Type Description
goal_name string The name of the goal
goal_description string The description of the goal
program_id integer The ID of the program for which the goal is being set
number_to_complete integer The number of events to complete the goal
goal_year integer The year for which the goal is being set
event_type_id integer The ID of the event type associated with the goal
goal_deadline date The deadline for completing the goal
start_date date The start date for the goal
branch_id integer The ID of the branch associated with the goal

Returns:

Type Description
JSON A JSON response indicating the success of the goal creation.

Errors:

Error Description
Validation failed The request parameters failed validation. The error message will contain details about the validation failure.
Error creating goal There was an issue creating the goal in the database. The error message will provide more details on the specific issue.

4.19 editYearlyGoal

POST

http://example.com/api/v0.1/admin/edit_yearly_goal

Description:

The editYearlyGoal function allows you to edit an existing yearly goal by providing its ID and the updated details. The goal will be updated with the new information provided in the request. If the number of completed goals is greater than or equal to the number to complete, the goal status will be marked as completed (1). Otherwise, the goal status will be marked as incomplete (0). The API will also update the goal counter for events in the same year as the goal.

Parameters:

Parameter Type Description
goal_id integer The ID of the goal to be edited.
goal_name string The new name of the goal.
goal_description string The new description of the goal.
program_id integer The ID of the program the goal is associated with.
number_to_complete integer The new number of events required to complete the goal.
goal_year integer The new year the goal is set for.
event_type_id integer The ID of the event type associated with the goal.
goal_deadline date The new deadline for the goal.
start_date date The new start date for the goal.
branch_id integer The ID of the branch the goal is associated with.
number_completed integer The updated number of events completed for the goal.

Return:

Returns a JSON object with status and message properties, indicating the success or failure of the operation.

Errors:

Error Description
Validation failed The request parameters failed validation. The error message will contain details about the validation failure.
Goal not found The goal with the specified ID does not exist.
An error occurred while updating the goal An error occurred while attempting to update the goal. The error message will contain more information.

4.20 deleteYearlyGoal

POST

http://example.com/api/v0.1/admin/delete_yearly_goal

Description:

The deleteYearlyGoal function deletes an existing yearly goal by providing its ID.

Parameters:

Name Type Description
goal_id integer The ID of the yearly goal to be deleted

Returns:

Type Description
JSON A JSON response confirming the yearly goal has been deleted.

Errors:

Error Description
Goal not found The yearly goal with the specified goal_id does not exist.
An error occurred while deleting the yearly goal An unexpected error occurred during the yearly goal deletion process.

4.21 addTrainingForUser

POST

http://example.com/api/v0.1/admin/add_training_for_user

Description:

The addTrainingForUser function adds one or more trainings to one or more users by providing the training and user IDs.

Parameters:

Name Type Description
training_ids array An array of training IDs to be added
user_ids array An array of user IDs to receive the trainings

Returns:

Type Description
JSON A JSON response confirming the trainings have been added to the users successfully or an error message if an error occurs.

Errors:

Error Description
Validation failed The request parameters failed validation. The error message will contain details about the validation failure.
One or more trainings do not exist The trainings with the specified training_ids do not exist or are incorrect.
One or more users do not exist The users with the specified user_ids do not exist or are incorrect.
Error adding trainings An unexpected error occurred during the process of adding trainings to the users.

4.22 deleteTrainingForUser

POST

http://example.com/api/v0.1/admin/delete_training_for_user

Description:

The deleteTrainingForUser function removes one or more trainings from one or more users by providing the training and user IDs.

Parameters:

Name Type Description
training_ids array An array of training IDs to be removed
user_ids array An array of user IDs to remove the trainings from

Returns:

Type Description
JSON A JSON response confirming the trainings have been removed from the users successfully or an error message if an error occurs.

Errors:

Error Description
Validation failed The request parameters failed validation. The error message will contain details about the validation failure.
One or more trainings do not exist The trainings with the specified training_ids do not exist or are incorrect.
One or more users do not exist The users with the specified user_ids do not exist or are incorrect.
Error removing trainings An unexpected error occurred during the process of removing trainings from the users.

Download Controller

5.1 downloadPictureByURL

GET

http://example.com/api/v0.1/event/download_picture_url/{pictureUrl}

Description:

The downloadPictureByUrl($pictureUrl) function takes a URL string as input, which includes the location of the picture to be downloaded. The function checks if the picture exists in the specified location on the server. If the picture exists, the function retrieves the picture, converts it to base64 format, and returns a JSON response containing the base64-encoded content. If the picture does not exist, the function returns a JSON response with a "Image not found" message.

Parameters:

Name Type Description
pictureUrl String The URL of the picture to be downloaded.

Returns:

Type Description
JSON A JSON response containing the base64-encoded content of the picture. The response has a single key-value pair, where the key is 'data' and the value is the base64-encoded content of the picture.

Errors:

Error Description
Image not found If the picture does not exist in the specified location on the server.