Closed MarisiaS closed 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?
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.
This PR addresses issue #19
Implementation
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.
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.backend/api/CustomField.py Created a custom IntegerField that allows blank values called
BlankableIntegerField
. Django by default doesn't allow blank for IntergerFields.backend/api/serializers/GroupSerializer.py Developed a Model serializer for the Group model, using the
BlankableIntegerFiel
d for bothmin_age
andmax_age
.Incorporated the following validations:
validate_age
: Ensures correctness of the age range at the Serializer level. This approach allows for the handling of exceptions as Validation Errors with a Bad Request status code. Without this validation, errors might occur at the model level, leading to Internal Server Errors. -validate_unique_group
: to return a Bad request status code when the group already exists.validate
method override: Included to add custom validators.backend/api/views/GroupView.py Created a basic Model View set for Group.
backend/api/urls.py Added a router to generate the endpoints for Group.
backend/api/fixtures/setup_data.json
Added data for 7 group objects.
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:
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.