MarisiaS / SMM

0 stars 0 forks source link

Add Group model, serializer and view #48

Closed MarisiaS closed 6 months ago

MarisiaS commented 6 months ago

This PR addresses issue #19

Implementation

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

Introduced a name property to dynamically generate the group name based on gender and age range.

To ensure uniqueness among groups based on gender and age range, the following functions were employed:

Coalesce: Utilized to return the first non-NULL expression among its arguments. ExpressionWrapper: Employed to create a database expression applicable in various contexts such as annotations or filters. output_field: Specified to denote the expected output type of the expression.

Unique constraints were added to enforce the uniqueness of groups based on gender and age range.

  1. backend/api/migrations/0008_group_group_unique_group.py After creating the model, I ran the makemigrations command and the migration for the Group model was created.

  2. backend/api/CustomField.py Created a custom IntegerField that allows blank values called BlankableIntegerField. Django by default doesn't allow blank for IntergerFields.

  3. backend/api/serializers/GroupSerializer.py Developed a Model serializer for the Group model, using the BlankableIntegerField for both min_age and max_age.

Incorporated the following validations:

  1. backend/api/views/GroupView.py Created a basic Model View set for Group.

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

  3. backend/api/fixtures/setup_data.json

Added data for 7 group objects.

  1. backend/project/urls.py

Fixed lint error.

I applied the migrations running the migrate command. Then load the fixture data with loaddata command.

Swagger

The endpoints are accessible through Swagger:

image

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

viriponce commented 6 months ago

Regarding the values for min_age and max_age be the same, how will be handling this scenario?? Should we allow the user to enter the same values ? From user perspective, it could be confusing not allowing me entering the same value to indicate that it's just for that age, what do you think? Or are we will be providing clarification on the FE about this?

MarisiaS commented 6 months ago

Regarding the values for min_age and max_age be the same, how will be handling this scenario?? Should we allow the user to enter the same values ? From user perspective, it could be confusing not allowing me entering the same value to indicate that it's just for that age, what do you think? Or are we will be providing clarification on the FE about this?

Great points! It makes sense to permit users to input the same value for both min_age and max_age when specifying a single age. We should include a message on the front end to clarify this aspect. On the BE, we will treat the age range as a closed interval.