Skip to content

Commit ce0aa84

Browse files
committed
add endpoints to get a users' resume/profile_picture by user id
Signed-off-by: longfight123 <[email protected]>
1 parent 495e90a commit ce0aa84

File tree

1 file changed

+100
-0
lines changed

1 file changed

+100
-0
lines changed

backend/routers/user_profile_router.py

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,58 @@ def get_user_profile_picture_me(
117117
filename={current_user.username}_profile_picture.jpg"
118118
}
119119
)
120+
121+
@router.get(
122+
"/users/profile/{user_id}/profile_picture",
123+
status_code=status.HTTP_200_OK,
124+
tags=["UserProfile"],
125+
summary="Retrieve the profile picture of the user with id == user_id from the database.",
126+
description="Retrieve the specified users' profile picture from the database as a jpg file.",
127+
response_description="The specified users' profile picture."
128+
)
129+
def get_user_profile_picture(db: Session = Depends(dependencies.get_db),
130+
user_id: int = Path()):
131+
132+
"""
133+
GET route to obtain a user's profile picture by user_id.
134+
135+
Parameters
136+
----------
137+
db: Session
138+
a database session
139+
user_id: int
140+
the user's unique identifier
141+
142+
Returns
143+
-------
144+
fastapi.Response
145+
a response with the profile picture
146+
"""
147+
148+
# Check that the user has a profile
149+
dependencies.user_profile_exists(db, user_id)
150+
151+
user_profile = user_profile_crud.get_user_profile_by_id(db, user_id)
152+
153+
# Check that the user has a profile picture
154+
if user_profile is not None:
155+
file = user_profile.profile_picture
156+
157+
if file is None:
158+
raise HTTPException(
159+
status_code=status.HTTP_404_NOT_FOUND,
160+
detail=f"User {user_id} does not have a profile picture in the database."
161+
)
162+
163+
return Response(
164+
content=file,
165+
media_type="image/jpg",
166+
headers={
167+
"content-disposition": f"attachment; \
168+
filename={user_profile.first_name}_profile_picture.jpg"
169+
}
170+
)
171+
120172

121173
@router.get(
122174
"/users/profile/me/resume",
@@ -166,6 +218,54 @@ def get_user_resume_me(
166218
filename={current_user.username}_resume.pdf"
167219
}
168220
)
221+
222+
@router.get(
223+
"/users/profile/{user_id}/resume",
224+
status_code=status.HTTP_200_OK,
225+
tags=["UserProfile"],
226+
summary="Retrieve the resume of the user with id == user_id from the database.",
227+
description="Retrieve the specified users' resume from the database as a pdf file.",
228+
response_description="The specified users' resume."
229+
)
230+
def get_user_resume(db: Session = Depends(dependencies.get_db),
231+
user_id: int = Path()):
232+
"""
233+
GET route to obtain the resume of the user with id == user_id.
234+
235+
Parameters
236+
----------
237+
db: Session
238+
a database session
239+
user_id: int
240+
the unique identifier of the user
241+
242+
Returns
243+
-------
244+
fastapi.Response
245+
a response with the resume
246+
"""
247+
248+
dependencies.user_profile_exists(db, user_id)
249+
250+
user_profile = user_profile_crud.get_user_profile_by_id(db, user_id)
251+
252+
if user_profile is not None:
253+
file = user_profile.resume
254+
255+
if file is None:
256+
raise HTTPException(
257+
status_code=status.HTTP_404_NOT_FOUND,
258+
detail=f"User {user_id} does not have a resume in the database."
259+
)
260+
261+
return Response(
262+
content=file,
263+
media_type="application/pdf",
264+
headers={
265+
"content-disposition": f"attachment; \
266+
filename={user_profile.first_name}_resume.pdf"
267+
}
268+
)
169269

170270
@router.get(
171271
"/users/profile/{username}",

0 commit comments

Comments
 (0)