-
Notifications
You must be signed in to change notification settings - Fork 219
Open
Labels
Description
Description
Add an endpoint to allow user to report another user for any code of conduct violation.
Acceptance Criteria
- It should be an authenticated endpoint, accessible users.
- It should be a
POSTrequest at/api/v1/report/. - The system should create a new entry in the report table in the database.
- The response should return a structured JSON format with a success message.
- The response
statusshould201 - If the requesting user is unauthorized, the request should return an appropriate error message.
Purpose
To allow users to report users that is violating the code of conduct in which admins and super admins can look into.
Requirements
- Develop server-side logic to handle creation of new row in the report table.
- Ensure the endpoint is secured and accessible only to authorized users.
- Write unit tests to validate the functionality of the endpoint.
Expected Outcome
users should be able to report another user.
Tasks
- Create an endpoint (
POST: /api/v1/reports/) to handle report creation. - Implement authentication and authorization to restrict access to authorized and authenticated user.
- Develop logic to add new entry in the report table.
- Ensure proper error handling for unauthorized access.
- Write comprehensive unit tests for the endpoint.
Example Request
curl -X POST {rootdomain}/api/v1/report \
-H "Authorization: Bearer <YOUR_ACCESS_TOKEN>" \
-d '{ "reported_userId": "string", "reason": "string"}' Response [Success]
{
"status_code": 201,
"reported_by": "userid",
"reported_user": "userid",
"reason": "reason of been reported",
"status": "pending",
"created_at": "2025-02-22"
} Response [Errors]
- Unauthorized Request
{
"status_code": 403,
"error": "User not authorized"
}- User trying to report itself
{
"status": 400,
"error": "User cannot report yourself"
}- Input validation
- invalid userId
{
"status": 404,
"error": "user to be reported not found"
}- empty reason
{
"status": 400,
"error": "reason of been reported cannot be empty"
}Testing
Test proper authentication and authorization mechanisms.
Test edge cases like invalid userId, empty reason and user reporting itself