MarisiaS / SMM

0 stars 0 forks source link

BE- Register record times #66

Closed viriponce closed 6 months ago

viriponce commented 6 months ago

This PR addresses issue #25

Implementation

  1. backend/api/models.py

Implemented the TimeRecord model with the following fields:

For the Athlete model, the property full_name was added.

  1. backend/api/migrations/0013_timerecord.py

Migration file generated with command makemigrations for TimeRecord model.

  1. backend/api/serializers/TimeRecordSerializer.py

Created TimeRecordSerializer based on ModelSerializer to display almost all the information about an the time record and added the event_type_name and athlete_full_name fields.

In this file, created the validation method validate_time to ensure the format for this field is valid [M:]S.mm.

  1. backend/api/views/TimeRecordView.py

Created a ModelViewSet named TimeRecordViewSet. Overrode the list method to add the parameters athlete_name and event_type_id in order to use them as filters. Overrode the get_queryset method to implement the filter logic in case athlete_name or event_type_id were provided.

  1. backend/api/urls.py

Added the following endpoint:

Added a router to generate the endpoints for TimeRecord.

  1. backend/api/fixtures/time_record.json

A fixture file called time_record.json was created with multiple time record objects.

  1. backend/project/settings.py Add SWAGGER_UI_DIST to SPECTACULAR_SETTINGS because there is a known bug in Swagger causing the schema not being rendered correctly: https://github.com/tfranzel/drf-spectacular/issues/1186

Swagger

All new endpoints are accessible through Swagger. Each endpoint has been tested successfully, including listing all Time Records which shows all the record information and includes the athlete full name and event type name associated with the record. For listing, the records can be filtered by athlete_name and event_type_id. When athlete_name parameter is provided, the time records for the athletes whose first name or last name start with the provided value are displayed. When event_type_id parameter is provided, the time records for the that specific event type are displayed.

Screenshot 2024-03-01 at 10 09 36 PM