naturerobots / HSOS-SEP-PlantMap-2022

PlantMap Digital Logbook: A tool to support sustainable micro farming :link: https://naturerobots.github.io/HSOS-SEP-PlantMap-2022/
BSD 3-Clause "New" or "Revised" License
4 stars 5 forks source link

API endpoints for user settings #199

Closed pbrozi closed 2 years ago

pbrozi commented 2 years ago

I would suggest the following endpoints for user settings:

Method: GET; Path: user Returns all information from the requesting (authenticated) user as JSON.

Example output:

{
  "id": 1,
  "username": "name",
  "email": "email",
  "first_name": "name",
  "last_name": "name",
  "date_joined": "2022-08-03T10:25:36.901821Z",
  "last_login": "2022-08-03T10:29:05.575935Z"
}

Method: PUT; Path: user Endpoint to edit user information. New values can be submitted by sending JSON with the request body. Allowed keys are: username, password, email, first_name and last_name. At least one key needs to be present. The user needs to be authenticated to access this endpoint.

Example input:

{
  "username": "newuser",
  "password": "newpass",
  "email": "newemail",
  "first_name": "newname",
  "last_name": "newname"
}

Output: HTTP-200 if changes were successful or HTTP-400 if not.

Method: GET; Path: companies/{company_id}/gardens/{garden_id}/widgets Returns settings for saved widgets as JSON.

Method: POST; Path: companies/{company_id}/gardens/{garden_id}/widgets Any JSON content can be send to the backend and will be saved in the database. It can be retrieved using a GET request.

Method: DELETE; Path: companies/{company_id}/gardens/{garden_id} Deletes the garden specified in the URL, if it exists and the requesting user has admin permissions on it.

Method: DELETE; Path: companies/{company_id} Deletes the company specified in the URL, if it exists and the requesting user has admin permissions on it.

The functionality to add users to a company or garden is provided by the permission system. Endpoints createPermission and removePermission exist for companies and gardens.

@dobro929 please tell me if this matches your requirements.

dobro929 commented 2 years ago

@pbrozi Looks good but for user edit we should use PUT or PATCH instead of POST and please make sure that all gardens, permissions, etc. are deleted when we delete the company or a garden. 👍🏼

dobro929 commented 2 years ago

@pbrozi Can we move ../widgets to /user/widgets ? It makes more sense for a user to have their own widgets.

pbrozi commented 2 years ago

Okay. I initially thought that the user can save the settings for each garden. Should this still be possible?

dobro929 commented 2 years ago

We should kept that in mind for the future but for now i think it's enough to have only user dependent widgets.

jarkenau commented 2 years ago

@dobro929 @pbrozi could this issue be closed?