This is a server side part of my fund raising project. Written in JavaScript using Node.js, and Express.js framework, includes various endpoints for managing ideas, users, donations, login, and logout functionality. The template for this documentation has been generated with the help of ChatGPT.
- π οΈ Server Setup
- π‘ Ideas Endpoints
- π₯ GET /ideas
- π€ POST /ideas
- π§ PUT /ideas
- π§ PUT /ideas/status
- ποΈ DELETE /ideas
- π₯ Users Endpoints
- π₯ GET /users
- π€ POST /users
- π§ PUT /users
- ποΈ DELETE /users
- π° Donations Endpoints
- π₯ GET /donations
- π€ POST /donations
- π Login and Logout Endpoints
- π€ POST /login
- π₯ GET /login
- π€ POST /logout
The server is set up using Node.js, Express.js framework and includes necessary middleware and configurations. Here are the important details regarding server setup:
- The server listens on port 3003.
- CORS (Cross-Origin Resource Sharing) is enabled to allow requests from http://localhost:3000.
- Body parsing middleware is used for handling JSON and URL-encoded data.
- The server uses cookies for session management.
-
Retrieves a list of ideas based on optional query parameters.
-
Query Parameters:
-
sortBy
(optional): Sorts the ideas based on specific criteria. Accepted values:totalDonationSum
,status
-
status
(optional): Filters ideas based on thestatus
. Accepted values:accepted
,pending
,rejected
-
-
Response:
- Status Code: 200 (OK)
- Body: An array of ideas in the requested order and filter criteria.
-
JSON
example:[ { "id": "70c8e131-ac49-453f-85f6-d18160b7be19", "picture": "./img/default_idea.png", "header": "Idea 1", "description": "Idea 1 Description 1 ", "askedSum": 100, "userId": "6fba75be-1f13-449e-b8ee-0d9287d70208", "status": "accepted", "donations": [ { "id": "d6667fd3-0182-4730-9f20-866602f87ff8", "sum": 20, "userId": "6fba75be-1f13-449e-b8ee-0d9287d70208", "ideaId": "70c8e131-ac49-453f-85f6-d18160b7be19" }, { "id": "7a739df1-7629-4743-8387-0334af332692", "sum": 10, "userId": "6fba75be-1f13-449e-b8ee-0d9287d70208", "ideaId": "70c8e131-ac49-453f-85f6-d18160b7be19" } ], "totalDonationSum": 30 } ]
-
Creates a new idea.
-
Request Body:
header
: Idea's header/title.description
: Idea's description.askedSum
: The requested sum for the idea.userId
: ID of the user associated with the idea.
-
JSON
example:{ "header": "Header For Example", "description": "Description for example", "askedSum": 10000, "userId": "6fba75be-1f13-449e-b8ee-0d9287d70208" }
-
Response:
-
Status Code: 200 (OK)
-
Body: Success message indicating that the idea was created successfully.
- Message example:
Idea created successfully.
-
-
Updates an existing idea.
-
Request Body:
ideaId
: ID of the idea to be updated.key
: The property/key to be updated.value
: The new value for the specified property/key.
-
JSON
example:{ "ideaId": "b8f40262-d265-419d-a769-e0299901b73b", "key": "description", "value": "UPDATED Description Example" }
-
Response:
- Status Code: 200 (OK)
- Body: Success message indicating that the idea was updated successfully.
- Message example:
Idea updated successfully.
-
Updates the status (approval) of an existing idea.
-
Request Body:
ideaId
: ID of the idea to update the status.isApproved
: Boolean value representing the new status (true for approved, false for rejected).
-
JSON
example:{ "ideaId": "b8f40262-d265-419d-a769-e0299901b73b", "key": "isApproved", "value": "true" }
-
Response:
- Status Code: 200 (OK)
- Body: Success message indicating that the idea'sstatus was updated successfully.
- Message example:
Ideas status updated successfully.
-
Deletes an existing idea.
-
Request Body:
ideaId
: ID of the idea to be deleted.
-
JSON
example:{ "ideaId": "b8f40262-d265-419d-a769-e0299901b73b" }
-
Response:
- Status Code: 200 (OK)
- Body: Success message indicating that the idea was deleted successfully.
- Message example:
Ideas successfully deleted.
-
Retrieves a list of all users.
-
Response:
- Status Code: 200 (OK)
- Body: An array of user objects representing all the users.
-
JSON
example:[ { "id": "6fba75be-1f13-449e-b8ee-0d9287d70208", "picture": "./img/default_userpic.webp", "username": "DVader", "password": "202cb962ac59075b964b07152d234b70", "firstName": "Darth", "lastName": "Vader", "session": "542a7bf888c911a06bd2966cf87931d2", "role": "user" } ]
-
Creates a new user.
-
Request Body:
username
: User's username.password
: User's password.firstName
: User's first name.lastName
: User's last name.
-
JSON
example:{ "username": "GreateJedi", "password": "UltraStronPassword123", "firstName": "The Greatest", "lastName": "Jedi" }
-
Response:
- Status Code: 200 (OK)
- Body: Success message indicating that the user was created successfully.
- Message example:
User created successfully.
-
Updates an existing user.
-
Request Body:
userId
: ID of the user to be updated.key
: The property/key to be updated.value
: The new value for the specified property/key.
-
JSON
example:{ "userId": "4429f767-ce48-4b4a-b1be-975aca7313c9", "key": "firstName", "value": "Jimmy" }
-
Response:
-
Status Code: 200 (OK)
-
Body: Success message indicating that the user was updated successfully.
- Message example:
User successfully update.
-
-
JSON
example:[ { "id": "4e97bd2a-b0ec-41fc-92bd-a286360f8be1", "picture": "./img/default_userpic.webp", "username": "GreateJedi", "password": "8051013a166f52c8a71d886353ec528e", "firstName": "The Greatest", "lastName": "Jedi", "session": null, "role": "user" } ]
-
Deletes an existing user.
-
Request Body:
userId
: ID of the user to be deleted.
-
JSON
example:{ "userId": "4429f767-ce48-4b4a-b1be-975aca7313c9" }
-
Response:
- Status Code: 200 (OK)
- Body: Success message indicating that the user was deleted successfully.
- Message example:
User successfully deleted.
-
Retrieves the total sum donated for a specific idea.
-
Query Parameters:
ideaId
: ID of the idea to get the total sum donated for.
-
JSON
example:{ "ideaId": "70c8e131-ac49-453f-85f6-d18160b7be19" }
-
Response:
- Status Code: 200 (OK)
- Body: The total sum donated for the specified idea.
- Message example:
30
-
Creates a new donation for an idea, either by a registered or an unregistered user.
-
Request Body:
ideaId
: ID of the idea for which the donation is made.userId
(optional): ID of the registered user making the donation.firstName
(optional): First name of the unregistered user making the donation.sum
: The amount being donated.
-
JSON
example:{ "ideaId": "55b27a57-394b-4df4-87f3-ea47dccb040e", "userId": "a9670cd0-85fa-4847-966b-ab10d58e7a67", "sum": 250 }
-
Response:
- Status Code: 200 (OK)
- Body: Success message indicating that the donation was created successfully.
- Message example:
Donation created successfully.
-
JSON
example:[ { "id": "91dfc9ea-14fa-4f1b-b3c3-740ac1ce729d", "sum": 250, "userId": "a9670cd0-85fa-4847-966b-ab10d58e7a67", "ideaId": "55b27a57-394b-4df4-87f3-ea47dccb040e" } ]
-
Logs in a user and creates a session.
-
Request Body:
username
: User's username.password
: User's password.
-
JSON
example:{ "username": "DVader", "password": "123" }
-
Response:
- Status Code: 200 (OK)
- Body: Success message indicating that the user was logged in successfully.
- Message example:
Successfully logged in.
-
Retrieves the information of the logged-in user.
-
Query Parameters:
userLoginSession
: Session ID of the logged-in user.
-
JSON
example:{ "userLoginSession": "000e1fb3a675b7094b5836b85217015d" }
-
Response:
- Status Code: 200 (OK)
- Body:
JSON
object containing information about the logged-in user, including name and role.
-
JSON
example:{ "status": "OK", "message": "You are Logged in.", "name": "Master", "role": "user" }
-
Logs out the user and clears the session.
-
Request Body:
userLoginSession
: Session ID of the user to be logged out.
-
JSON
example:{ "userLoginSession": "000e1fb3a675b7094b5836b85217015d" }
-
Response:
- Status Code: 200 (OK)
- Body: Success message indicating that the user was logged out successfully.
- Message example:
You have successfully logged out.
π This concludes the documentation for the Fund Raising Project Server Side. The provided code includes various endpoints for managing ideas, users, donations, login, and logout functionality. Each endpoint is described with its purpose, request/response details, and any required parameters or bodies.
π Please note that this documentation assumes familiarity with the Node.js and Express.js framework and the usage of the provided code within a larger application or system. Make sure to adapt and integrate the code as needed based on your specific requirements and project structure.