MarisiaS / SMM

0 stars 0 forks source link

BE- Session model, serializer and view #50

Closed MarisiaS closed 6 months ago

MarisiaS commented 6 months ago

This PR addresses issue #41

Implementation

  1. backend/api/models.py

Implemented Session model with the following fields:

Introduced a name property to dynamically generate the session name based on days of the week and time

  1. backend/api/migrations/0009_session.py

After creating the model, I ran the makemigrations command, resulting in the migration for the Session model.

  1. backend/api/serializers/SessionSerializer.py

Developed a Model serializer for the Session model, incorporating validations for days_of_week:

Added a extend_schema_serializer decorator to the serializer to provide examples of response and request data.

  1. backend/api/views/SessionView.py

Created a basic Model ViewSet for Session model.

  1. backend/api/urls.py

Added a router to generate the endpoints for Session

  1. backend/api/fixtures/setup_data.json

Added data for 2 session objects.

I applied the migrations running the migrate command. Then load the fixture data with loaddata 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 session.

Posting a session without a coach and/or school is posible but days_of_week and time is required.

MarisiaS commented 6 months ago

@viriponce I have introduced a 'label' field to the model. However, I'm uncertain about the optimal approach. I'm considering three options:

  1. Leave it as is right now: Retain the existing structure with both 'name' and 'label'.

  2. Eliminate the name: Remove the 'name' function, keeping only the 'label' field.

  3. Change name for label and label for name: Swap the names of the 'name' and 'label' .

What are your thoughts on these options?

viriponce commented 6 months ago

@viriponce I have introduced a 'label' field to the model. However, I'm uncertain about the optimal approach. I'm considering three options:

  1. Leave it as is right now: Retain the existing structure with both 'name' and 'label'.
  2. Eliminate the name: Remove the 'name' function, keeping only the 'label' field.
  3. Change name for label and label for name: Swap the names of the 'name' and 'label' .

What are your thoughts on these options?

For future reference, We discussed the options and decided to eliminate name function, make coach_id and school_id required. The user will provide a name for the session.