Skip to content

Solution#272

Open
illia3124124 wants to merge 3 commits intomate-academy:mainfrom
illia3124124:my-branch
Open

Solution#272
illia3124124 wants to merge 3 commits intomate-academy:mainfrom
illia3124124:my-branch

Conversation

@illia3124124
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

Great work on implementing the email notifications and profile schemas! The overall structure is solid. However, changes are needed to fully meet the task requirements.

The most critical issue is in src/routes/profiles.py. The endpoint for creating a profile correctly authenticates the user making the request, but it doesn't check if the target user (identified by user_id in the URL) exists and is active. Please add a check to query for the target user and raise an error if they are not found or inactive before attempting to create the profile.

Additionally, in src/storages/s3.py, the ContentType for file uploads is hardcoded as image/jpeg. To properly support other image formats like PNG, you should pass the content_type from the UploadFile object in your route and use it in the S3 client.

Once these two points are addressed, your solution will be ready. Keep up the great effort!


✨ 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

status_code=status.HTTP_403_FORBIDDEN,
detail="You don't have permission to edit this profile."
)

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, you need to verify that the user for whom the profile is being created (identified by user_id from the path) exists and is active. The current implementation only validates the authenticated user making the request via the auth_user helper function. You should add a query here to fetch the target user and raise a 401 Unauthorized error if they are not found or not active.

Bucket=self._bucket_name,
Key=file_name,
Body=file_data,
ContentType="image/jpeg",

Choose a reason for hiding this comment

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

The ContentType is hardcoded to image/jpeg. While this works for the test case, the requirements state that PNG files should also be supported. Storing a PNG file with a JPEG content type is not ideal and may cause rendering issues in some browsers.

Consider modifying this method to accept a content_type argument and pass the actual content type from the UploadFile object in routes/profiles.py.

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 iteration! I am approving your solution as you've successfully addressed all the critical feedback from the previous review and met all the task requirements. The profile creation endpoint is now robust and handles user validation and file uploads correctly.

I have a few minor suggestions for you to consider for future improvements:

  • In src/routes/profiles.py, the manual validation for the info field is redundant since the ProfileRequestSchema already handles it. You can remove that check for cleaner code.
  • The docstring for upload_file in src/storages/interfaces.py could be updated to match the None return type hint.
  • There's a leftover print statement in src/tests/test_e2e/test_storage.py that can be removed to keep the test output clean.

These are just small refinements, and your implementation is solid. 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

Comment on lines +97 to +101
if info_raw is None or not str(info_raw).strip():
raise HTTPException(
status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
detail="Info field cannot be empty or contain only spaces.",
)

Choose a reason for hiding this comment

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

This manual validation for the info field is redundant. The ProfileRequestSchema on line 104 already performs this check with its own validator. It's a good practice to centralize all input validation within the Pydantic schema for consistency. You can safely remove these lines and let the schema handle it.

:param file_name: The name of the file to be stored.
:param file_data: The file data in bytes.
:param content_type: The content type of the file. Defaults to "application/octet-stream".
:return: URL of the uploaded file.

Choose a reason for hiding this comment

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

The docstring indicates that this method returns the URL of the uploaded file, but the type hint correctly specifies None. Since the get_file_url method is responsible for generating the URL, this docstring should be updated to reflect that the method does not return anything.

}

profile_response = await e2e_client.post(profile_url, headers=headers, files=files)
print("Profile creation response:", profile_response.status_code, profile_response.text)

Choose a reason for hiding this comment

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

This print statement appears to be for debugging purposes. It's a good practice to remove debugging statements like this from the final code to keep test logs clean and focused on test results.

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.

3 participants