-
Notifications
You must be signed in to change notification settings - Fork 0
[InProgress] DEV #54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[InProgress] DEV #54
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,6 +1,7 @@ | ||||||||||||
| from typing import Literal | ||||||||||||
| from uuid import UUID | ||||||||||||
|
|
||||||||||||
| from fastapi import APIRouter, Depends, HTTPException | ||||||||||||
| from fastapi import APIRouter, Depends, HTTPException, Path | ||||||||||||
| from sqlalchemy.ext.asyncio import AsyncSession | ||||||||||||
| from starlette import status | ||||||||||||
|
|
||||||||||||
|
|
@@ -83,6 +84,20 @@ async def check_username_availability( | |||||||||||
| return {"message": "Username is available"} | ||||||||||||
|
|
||||||||||||
|
|
||||||||||||
| @router.get( | ||||||||||||
| "/{user_id}", | ||||||||||||
| response_model=schemas.UserResponse, | ||||||||||||
| summary="Delete user account", | ||||||||||||
| description="Delete a user account by username. Returns the deleted user information.", | ||||||||||||
|
Comment on lines
+90
to
+91
|
||||||||||||
| summary="Delete user account", | |
| description="Delete a user account by username. Returns the deleted user information.", | |
| summary="Get user by ID", | |
| description="Retrieve user information by their unique user ID.", |
Copilot
AI
Feb 5, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This endpoint lacks error handling when the user is not found. The function can return None (as specified in the service function return type), but there's no check to raise a 404 HTTPException when the user doesn't exist. Other similar endpoints in this file (like delete_account on line 109, read_user on line 184) properly check for None and raise appropriate exceptions. This should follow the same pattern.
| return await service.get_user_by_user_id(user_id, db) | |
| user = await service.get_user_by_user_id(user_id, db) | |
| if not user: | |
| raise HTTPException(status_code=404, detail="User not found") | |
| return user |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -6,7 +6,7 @@ | |||||
| from sqlalchemy.exc import NoResultFound | ||||||
| from sqlalchemy.ext.asyncio import AsyncSession | ||||||
|
|
||||||
| from core import storage | ||||||
| from core import models, storage | ||||||
| from core.authflow.service import hash_password | ||||||
| from core.models import User | ||||||
| from core.types import FileContentType | ||||||
|
|
@@ -25,6 +25,13 @@ async def get_user(db: AsyncSession, username: str): | |||||
| return None | ||||||
|
|
||||||
|
|
||||||
| async def get_user_by_user_id( | ||||||
| user_id: uuid.UUID, db: AsyncSession | ||||||
|
Comment on lines
+28
to
+29
|
||||||
| ) -> models.User | None: | ||||||
| query = select(models.User).filter(models.User.id == str(user_id)) | ||||||
|
Comment on lines
+28
to
+31
|
||||||
| query = select(models.User).filter(models.User.id == str(user_id)) | |
| query = select(models.User).filter(models.User.id == user_id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This endpoint path "/{user_id}" conflicts with the existing "/{username}" GET endpoint on line 178. FastAPI will route requests to the first matching pattern, which means this new endpoint will intercept all requests intended for the username endpoint. When a client requests "/users/john", FastAPI will try to parse "john" as a UUID for this endpoint instead of treating it as a username. Consider using a more specific path like "/by-id/{user_id}" or "/user-id/{user_id}" to avoid this ambiguity.