-
-
Notifications
You must be signed in to change notification settings - Fork 141
feat: Implement of profile page and necessary frontend and backend services #248
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
Open
PinJinx
wants to merge
2
commits into
AOSSIE-Org:main
Choose a base branch
from
PinJinx:profile-page
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| import logging | ||
| from fastapi import APIRouter, HTTPException, Depends,status | ||
| from app.database.supabase.services import get_user_details, validate_user,update_user_details | ||
| from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials | ||
| from app.models.database.supabase import UserProfileEdit | ||
|
|
||
|
|
||
| router = APIRouter() | ||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| security = HTTPBearer() | ||
|
|
||
|
|
||
| async def get_user( | ||
| credentials: HTTPAuthorizationCredentials = Depends(security), | ||
| ): | ||
| token = credentials.credentials | ||
| result = await validate_user(token) | ||
| if not result: | ||
| raise HTTPException( | ||
| status_code=status.HTTP_401_UNAUTHORIZED, | ||
| detail="Invalid or expired token"+token, | ||
| ) | ||
| return result | ||
|
|
||
|
|
||
| @router.get("/") | ||
| async def fetch_details(user=Depends(get_user),): | ||
| """Fetch user profile details.""" | ||
| try: | ||
| (id, name) = user | ||
| if not id: | ||
| raise HTTPException(status_code=401, detail="Unauthorized") | ||
| user_details = await get_user_details(id) | ||
| if not user_details: | ||
| raise HTTPException(status_code=404, detail="User not found") | ||
| return {"user": { | ||
| "id": user_details.get("id"), | ||
| "email": user_details.get("email"), | ||
| "display_name": user_details.get("display_name"), | ||
| "avatar_url": user_details.get("avatar_url"), | ||
| "avatar_path": user_details.get("avatar_path"), | ||
| "bio": user_details.get("bio"), | ||
| "discord":user_details.get("discord_username"), | ||
| "github":user_details.get("github_username"), | ||
| "slack":user_details.get("slack_username"), | ||
| "skills": user_details.get("skills") or {"languages": [], "frameworks": []}, | ||
| }} | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| except HTTPException as he: | ||
| raise he | ||
| except Exception as e: | ||
| logger.error(f"Fetching profile details failed: {e}") | ||
| raise HTTPException( | ||
| status_code=503, | ||
| detail={ | ||
| "service": "frontend_services", | ||
| "status": "http exception", | ||
| "error": str(e) | ||
| } | ||
| ) from e | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| @router.patch("/edit") | ||
| async def edit_details( | ||
| profile_data: UserProfileEdit, | ||
| user=Depends(get_user) | ||
| ): | ||
| """ | ||
| Edit user profile details. | ||
| Only updates the fields provided in the request body. | ||
| """ | ||
| try: | ||
| (user_id, _) = user | ||
| if not user_id: | ||
| raise HTTPException(status_code=401, detail="Unauthorized") | ||
| update_data = profile_data.model_dump(exclude_unset=True) | ||
|
|
||
| if not update_data: | ||
| raise HTTPException( | ||
| status_code=400, | ||
| detail="No valid fields provided for update" | ||
| ) | ||
|
|
||
| updated_user = await update_user_details(user_id, update_data) | ||
|
|
||
| if not updated_user: | ||
| raise HTTPException(status_code=404, detail="User not found or update failed") | ||
|
|
||
|
|
||
| return {"user": { | ||
| "id": updated_user.get("id"), | ||
| "email": updated_user.get("email"), | ||
| "display_name": updated_user.get("display_name"), | ||
| "avatar_url": updated_user.get("avatar_url"), | ||
| "avatar_path": updated_user.get("avatar_path"), | ||
| "bio": updated_user.get("bio"), | ||
| "discord": updated_user.get("discord_username"), | ||
| "github": updated_user.get("github_username"), | ||
| "slack": updated_user.get("slack_username"), | ||
| "skills": updated_user.get("skills") or [], | ||
| }} | ||
|
|
||
| except HTTPException as he: | ||
| raise he | ||
| except Exception as e: | ||
| logger.error(f"Updating profile details failed: {e}") | ||
| raise HTTPException( | ||
| status_code=503, | ||
| detail={ | ||
| "service": "frontend_services", | ||
| "status": "http exception", | ||
| "error": str(e) | ||
| } | ||
| ) from e | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.