MarisiaS / SMM

0 stars 0 forks source link

BE- Add Event Type endpoints: #49

Closed viriponce closed 6 months ago

viriponce commented 6 months ago

This PR addresses issue #23

Implementation

  1. backend/api/models.py Implemented the EventType model with the following fields:

Introduced a name property to dynamically generate the event type name based on the three fields mentioned above.

Create an unique constraint for the combinations of those three fields

  1. backend/api/migrations/0009_eventtype_eventtype_unique_event_type.py After creating the model, I ran the makemigrations command and the migration for the EventType model was created.

  2. backend/api/serializers/EventTypeSerializer.py Created a Model serializer for the EventType model. Included all the fields plus the name. Defined stroke and type as ChoiceField in order to validate the values passed for these against the choices defined in the model for them.

    stroke = serializers.ChoiceField(choices=EventType.Stroke.choices,required=True)
    type = serializers.ChoiceField(choices=EventType.Type.choices, required=True)

Incorporated the following validations:

  1. backend/api/views/EventTypeView.py Created a basic Model View set for EventType.

  2. backend/api/urls.py Added a router to generate the endpoints for Event Type.

  3. backend/api/fixtures/setup_data.json

Added data for 9 event type objects.

I applied the migration with migrate command, then loaded the fixture data with loaddata command.

Swagger

The endpoints are accessible through Swagger:

Screenshot 2024-02-15 at 1 41 49 PM

I tried each of the new endpoints successfully. I was able to create, delete, patch and get an event type. When posting and patching, I got the expected error for entering invalid data.

viriponce commented 6 months ago

We've observed that the requirement states 'Distance must be greater than 0,' yet the examples in both the request and response show the distance being set to 0. It might be beneficial to update the examples accordingly. image

image

For me, the distance had a different default value:

Screenshot 2024-02-16 at 9 07 55 AM Screenshot 2024-02-16 at 9 07 23 AM

I'm trying to explicitly created the example for those methods but I'm not getting the expected result yet.