MarisiaS / SMM

0 stars 0 forks source link

BE- Improve Site implementation #45

Closed viriponce closed 6 months ago

viriponce commented 6 months ago

This PR addresses issue #44

Implementation

  1. *backend/api/serializers/SiteSerializer.py Add the serializer method validate_name to check if the site name is unique. It throws a Validation Error if there is an existing site with the same name.

  2. backend/api/views/SiteView.py Added the patch method to the http_method_names in the site view. In the list method, used the LimitOffsetPagination (setup in the settings) to return the serialized data paginated.

Swagger

Patch endpoint:

The patch endpoint for Site is now available in Swagger:

Screenshot 2024-02-12 at 11 31 19 AM

I updated the information for a site using this endpoint and confirmed the new site information is saved.

List endpoint:

The list(Get) endpoint is including the pagination information in the response: Before

Screenshot 2024-02-12 at 11 06 20 AM

After

Screenshot 2024-02-12 at 11 07 31 AM

Duplicate site name:

When trying to post or patch a Site using an existing name, the response is now a Bad Request error (400 status code) with the appropriate message:

Screenshot 2024-02-12 at 11 23 46 AM