boolean-uk / team-dev-frontend-client

1 stars 11 forks source link

API-Issue: Add API endpoint to update (PUT/PATCH) the infos of user by id #36

Closed mbalabanov closed 2 years ago

mbalabanov commented 2 years ago

At present the user endpoint of the API only provides PATCH for changing the cohort a user is assigned to.

As a developer using the API, I would want my users to be able to update their personal information (first name, last name, etc.). For this I would like to kindly request the addition of a PATCH or PUT endpoint to update the infos of user by id

glowkeeper commented 2 years ago

I'll look into this, but I'm imagining it isn't super high priority, right?

mbalabanov commented 2 years ago

Thank you. We'd need to talk to the project manager regarding the priorization of features.

mbalabanov commented 2 years ago

Dear project manager, what is the priority of this feature? Do we want users to be able to edit their profile?

glowkeeper commented 2 years ago

There is an endpoint for updating profile information - I'll update the docs to reflect this...watch this space...

mbalabanov commented 2 years ago

Thank you for updating the docs. There seem to some inaccuracies. Please read below or see image with details: Please see image here: https://imgur.com/a/zbjVjtQ

According to the API documentation, the payload for the PATCH request should be structured as follows:

{
  "email": "string",
  "password": "string",
  "cohortId": 0,
  "role": "string",
  "profile": {
    "update": {
      "firstName": "string",
      "lastName": "string",
      "bio": "string",
      "githubUrl": "string",
      "profileUrl": "string"
    }
  }
}

This is incorrect. A PATCH request sent using this payload does not make any changes. Please also note that the API expects the key biography instead of bio

The correct format of the payload for a PATCH request is as follows (same as for create user):

{
  "email": "string",
  "password": "string",
  "cohortId": 0,
  "role": "string",
  "firstName": "string",
  "lastName": "string",
  "biography": "string",
  "githubUrl": "string",
  "profileUrl": "string"
}

There still is an issue that the cohortId gets replaced with null. Might be a typo in the API sourcecode instead of cohortId something else like cohort or similar.

mbalabanov commented 2 years ago

This is the request for the cohortId that gets reset to null: https://imgur.com/a/vINVNxJ (see response in image)


### PATCH - Update existing user
PATCH https://team-dev-frontend-server.herokuapp.com/user/update/1 HTTP/1.1
content-type: application/json
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VySWQiOjEsImlhdCI6MTY2NTY1NDI4MCwiZXhwIjoxNjY1NzQwNjgwfQ.0uhUy8-QXjWwz4dNDpaEcywy-8bRGDCKQ6M0g9-xMh4

{
  "email": "teacher@teacher.com",
  "password": "t3ach3r",
  "cohortId": 5,
  "role": "TEACHER",
  "firstName": "Third Changed first name",
  "lastName": "Third Changed last name",
  "biography": "The quick brown fox jumps over the lazy dog.",
  "githubUrl": "http://github.com/test",
  "profileUrl": "https://images.unsplash.com/photo-1614027164847-1b28cfe1df60?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=972&q=80"
}

Result: cohortId gets set to null Expected result: Updating a user should not set the cohortId to null

glowkeeper commented 2 years ago

fixed, I reckon - the cohortId wasn't being assigned from the json destructuring and therefore, wasn't being passed to the user constructor...

Please confirm

mbalabanov commented 2 years ago

I can confirm that the cohortId no longer gets set to null when a user is updated. (It is also not being updated to a different cohortId if the request provides one, but I guess that is why we have a different API endpoint for updating the cohortId.)