@@ -67,6 +67,106 @@ def get_user_profile_me(db: Session = Depends(dependencies.get_db),
6767 # Ignore the type error from pylance
6868 return user_profile_crud .get_user_profile_by_id (db , current_user .id )
6969
70+ @router .get (
71+ "/users/profile/me/profile_picture" ,
72+ status_code = status .HTTP_200_OK ,
73+ tags = ["UserProfile" ],
74+ summary = "Retrieve the current user's profile picture from the database." ,
75+ description = "Retrieve the current user's profile picture from the database as a jpg file." ,
76+ response_description = "The current user's profile picture."
77+ )
78+ def get_user_profile_picture_me (
79+ db : Session = Depends (dependencies .get_db ),
80+ current_user : user_model .User = Depends (dependencies .get_current_user )
81+ ):
82+ """
83+ A GET route to obtain the current authenticated user's profile picture.
84+
85+ Parameters
86+ ----------
87+ db: Session
88+ a database session
89+ current_user: models.user_model.User
90+ a sqlalchemy pbject representing the current authenticated user
91+
92+ Returns
93+ -------
94+ fastapi.Response
95+ a response with the profile picture
96+ """
97+ dependencies .user_profile_exists (db , current_user .id )
98+ database_user_profile : user_profile_model .UserProfile = user_profile_crud .get_user_profile_by_id (
99+ db ,
100+ current_user .id
101+ )
102+
103+ if database_user_profile is not None :
104+ file = database_user_profile .profile_picture
105+
106+ if file is None :
107+ raise HTTPException (
108+ status_code = status .HTTP_404_NOT_FOUND ,
109+ detail = f"User { current_user .id } does not have a profile picture in the database."
110+ )
111+
112+ return Response (
113+ content = file ,
114+ media_type = "image/jpg" ,
115+ headers = {
116+ "content-disposition" : f"attachment; \
117+ filename={ current_user .username } _profile_picture.jpg"
118+ }
119+ )
120+
121+ @router .get (
122+ "/users/profile/me/resume" ,
123+ status_code = status .HTTP_200_OK ,
124+ tags = ["UserProfile" ],
125+ summary = "Retrieve the current user's resume from the database." ,
126+ description = "Retrieve the current user's resume from the database as a pdf file." ,
127+ response_description = "The current user's resume."
128+ )
129+ def get_user_resume_me (
130+ db : Session = Depends (dependencies .get_db ),
131+ current_user : user_model .User = Depends (dependencies .get_current_user )
132+ ):
133+ """
134+ A GET route to obtain the current authenticated user's resume.
135+
136+ Parameters
137+ ----------
138+ db: Session
139+ a database session
140+ current_user: models.user_model.User
141+ a sqlalchemy pbject representing the current authenticated user
142+
143+ Returns
144+ -------
145+ fastapi.Response
146+ a response with the resume
147+ """
148+ dependencies .user_profile_exists (db , current_user .id )
149+ database_user_profile : user_profile_model .UserProfile = user_profile_crud .get_user_profile_by_id (
150+ db ,
151+ current_user .id
152+ )
153+
154+ if database_user_profile is not None :
155+ file = database_user_profile .resume
156+
157+ if file is None :
158+ raise HTTPException (
159+ status_code = status .HTTP_404_NOT_FOUND ,
160+ detail = f"User { current_user .id } does not have a resume in the database."
161+ )
162+
163+ return Response (content = file , media_type = "application/pdf" ,
164+ headers = {
165+ "content-disposition" : f"attachment; \
166+ filename={ current_user .username } _resume.pdf"
167+ }
168+ )
169+
70170@router .get (
71171 "/users/profile/{username}" ,
72172 response_model = user_profile_schema .UserProfile | None ,
@@ -114,7 +214,7 @@ def create_user_profile(*, db: Session = Depends(dependencies.get_db),
114214 ):
115215 """
116216 A POST route to create a new user profile for the current authenticated user.
117-
217+
118218 Parameters
119219 ----------
120220 db: Session
@@ -123,7 +223,7 @@ def create_user_profile(*, db: Session = Depends(dependencies.get_db),
123223 a sqlalchemy User object representing the current authenticated user
124224 user_profile: schemas.user_profile_schema.UserProfileCreate
125225 a pydantic model representing the current authenticated user's profile information
126-
226+
127227 Returns
128228 -------
129229 schemas.user_profile_schema.UserProfile
@@ -158,7 +258,7 @@ def delete_user_profile_me(db: Session = Depends(dependencies.get_db),
158258 a database session
159259 current_user:models.user_model.User
160260 a sqlalchemy User object representing the current authenticated user
161-
261+
162262 Returns
163263 -------
164264 schemas.user_profile_schema.UserProfile
0 commit comments