Skip to content

Implemented homework-4#243

Open
alexx5039-bot wants to merge 3 commits intomate-academy:mainfrom
alexx5039-bot:main
Open

Implemented homework-4#243
alexx5039-bot wants to merge 3 commits intomate-academy:mainfrom
alexx5039-bot:main

Conversation

@alexx5039-bot
Copy link

No description provided.

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Summary

Excellent work on implementing the email notifications using BackgroundTasks and setting up the core logic for profile creation. Your code is well-structured, but there are two critical requirements that need to be addressed before this can be approved.

  1. Validation Logic Location: The validation for profile fields (name, gender, birth date, etc.) is currently implemented in the route handler at src/routes/profiles.py. The task requires this logic to be centralized within the Pydantic schema in src/schemas/profiles.py using @field_validator decorators.
  2. Avatar URL Format: The API response for a successful profile creation returns the S3 object key for the avatar (e.g., avatars/1_avatar.jpg) instead of a full URL. The response must provide a complete, usable URL (e.g., http://minio-theater/avatars/1_avatar.jpg) as specified in the requirements.

Please move the validation logic and correct the avatar URL format. I'm looking forward to seeing your updated submission!


✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨

Important

Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.

Tip

If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.

Caution

Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.

Footnotes

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

Comment on lines 100 to 115
try:
validate_name(data.first_name)
validate_name(data.last_name)
validate_gender(data.gender)
validate_birth_date(data.date_of_birth)

if not data.info.strip():
raise ValueError("Info field cannot be empty or contain only spaces.")

validate_image(data.avatar)

except ValueError as e:
raise HTTPException(
status_code=422,
detail=str(e)
)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the task description, the validation for profile creation fields should be implemented within the ProfileCreateSchema in schemas/profiles.py, likely using Pydantic's @field_validator decorators. While your validation logic here is correct, moving it to the schema will centralize validation rules and keep the route handler focused on business logic.

avatar_url=avatar_key,
)

return profile

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The task requirements specify that the response should contain the full URL for the user's avatar, not just the S3 object key. You are currently storing and returning the key (avatars/{user_id}_avatar.jpg). You'll need to construct the full URL (e.g., by combining the S3 endpoint/bucket from settings with this key) before sending the response.

Comment on lines +15 to +21
class ProfileCreateSchema(BaseModel):
first_name: str
last_name: str
gender: str
date_of_birth: date
info: str
avatar: UploadFile

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This schema is missing the required validation logic. According to the task description, validation for fields like first_name, last_name, gender, date_of_birth, info, and avatar should be implemented within this class. Consider using Pydantic's @field_validator decorator along with the imported validation functions to enforce the rules specified in the requirements.

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Summary

Excellent progress on this! You've successfully moved most of the validation logic into the Pydantic schema, which is a great improvement. I'm requesting one change to fully meet the task requirements.

The validation for the avatar image is still located in the route handler (src/routes/profiles.py). For consistency and to meet the requirements, all profile validation, including the avatar, must be centralized in src/schemas/profiles.py.

Please create a @field_validator for the avatar field within the ProfileCreateSchema and call validate_image from there. Once that's done, this will be ready for approval. Great work so far!


✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨

Important

Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.

Tip

If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.

Caution

Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.

Footnotes

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

from config import get_jwt_auth_manager
from storages.interfaces import S3StorageInterface
from config.dependencies import get_s3_storage_client
from validation import validate_image, validate_name, validate_gender, validate_birth_date

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These validation functions are no longer used in this file since the logic has been moved to the Pydantic schema. It's good practice to remove unused imports to keep the code clean.

avatar_key = f"avatars/{user_id}_avatar.jpg"

try:
validate_image(data.avatar)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the task requirements, all validation for the profile creation, including the avatar image, should be handled within the ProfileCreateSchema in src/schemas/profiles.py. While this works, please move the image validation into the schema using a @field_validator to centralize all the validation logic as required.

gender: str
date_of_birth: date
info: str
avatar: UploadFile

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent work on adding validators for the profile fields! However, the validation for the avatar is missing from this schema. The task requires using the validate_image function within a @field_validator here to ensure the file type and size are correct, just as you've done for the other fields.

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Summary

Excellent work on this task! You've done a fantastic job moving all the validation logic into the Pydantic schema, which was the main goal here. I am approving your solution so you can move forward, but I have a couple of minor suggestions for cleanup in src/routes/profiles.py.

  • You can remove the unused validation imports, as that logic is now correctly handled in the schema.
  • The try...except ValueError block is now redundant. Your Pydantic model validation will catch any ValueError and raise a single HTTPException, so that except block is unreachable.

These are just small cleanups to keep the code tidy. Overall, this is a very strong submission. Great job!


✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨

Footnotes

  1. Rate AI review example

from config import get_jwt_auth_manager
from storages.interfaces import S3StorageInterface
from config.dependencies import get_s3_storage_client
from validation import validate_image, validate_name, validate_gender, validate_birth_date

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These validation imports are no longer needed in this file, as all validation logic has been correctly moved to src/schemas/profiles.py. It's good practice to remove unused imports to keep the code clean.

Comment on lines +110 to +111
except ValueError as e:
raise HTTPException(status_code=422, detail=str(e))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This except ValueError block appears to be unreachable. The validation is now handled within the ProfileCreateSchema, which catches any ValueError from the validators and raises a single HTTPException with a 422 status code. This block can be safely removed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants