lucoenergia / conluz

Conluz is an API-driven application designed for the efficient management of an energy community,enabling the administration of community members and their corresponding supply points and the retrieval of consumption, production data.
Apache License 2.0
0 stars 0 forks source link

Implement endpoint to update a user #36

Closed viktorKhan closed 9 months ago

viktorKhan commented 9 months ago

Endpoint URL:

The API endpoint for updating a user should be accessible at /api/v1/users/{userId}, where {userId} is the identifier of the user to be updated.

HTTP Method:

The API should use the HTTP PUT method for updating a user.

Request Body:

The endpoint should accept a JSON request body with these fields to be updated:

{
  "number": 0,
  "fullName": "string",
  "address": "string",
  "email": "string",
  "phoneNumber": "string",
  "role": "PARTNER"
}

The request should include the JWT token in the Authorization header for authentication.

Authentication:

The API should require a valid JWT token in the Authorization header for authentication. If the token is missing or invalid, the API should respond with a 401 Unauthorized status.

User Existence:

The API should check if the specified user exists before attempting to update. If the user does not exist, the API should respond with a 404 Not Found status.

Validation:

The API should validate the incoming data to ensure it meets the required format and constraints. If the data is invalid, the API should respond with a 400 Bad Request status, along with details about the validation errors.

User Update:

If authentication, authorization, and validation are successful, the API should update the specified user with the provided information. The API should respond with a 200 OK status upon successful user update.

Response Body:

The API response should include:

{
  "id": "1bba9d48-a0c8-4dac-bf81-e06106ad7b4a",
  "personalId": "12345678Z",
  "number": 2,
  "fullName": "Alice Smith",
  "address": "Fake Street 666",
  "email": "alicesmith@email.com",
  "phoneNumber": "+34666555111",
  "enabled": true,
  "role": "PARTNER"
}

Error Handling:

The API should handle unexpected errors gracefully and provide meaningful error messages in the response.

Security:

The API should employ secure practices to prevent unauthorized access or data leakage during the update process.

Logging:

The API should log relevant information, such as successful user updates or any errors encountered during the process.

Testing:

Unit tests and integration tests should be in place to verify the functionality of the endpoint under various scenarios, including valid and invalid input.