Closed viriponce closed 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.
![]()
For me, the distance had a different default value:
I'm trying to explicitly created the example for those methods but I'm not getting the expected result yet.
This PR addresses issue #23
Implementation
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
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.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.
Incorporated the following validations:
validate_distance
: Field validator to return a bad request when the value provided for distance is negative or equal to 0. -validate_unique_event_type
: to return a bad request status code when the combinatios of the values for distance, stroke and type already exists.validate
method override: call the validate_unique_event_type validator.backend/api/views/EventTypeView.py Created a basic Model View set for EventType.
backend/api/urls.py Added a router to generate the endpoints for Event Type.
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 withloaddata
command.Swagger
The endpoints are accessible through Swagger:
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.