Song commited on
Commit
54072de
·
1 Parent(s): d181edf
Files changed (1) hide show
  1. app.py +41 -1
app.py CHANGED
@@ -38,7 +38,7 @@ from dependencies import get_current_user, get_optional_user, require_roles, Use
38
  from exceptions import SilverTableException, PaymentException
39
  from exceptions import handle_payment_error
40
  from crud import (
41
- get_profiles_by_user, create_profile, update_profile, delete_profile,
42
  create_order, get_orders_by_profile,
43
  create_donation, update_donation_status,
44
  get_menu_items, get_dashboard_stats
@@ -160,6 +160,46 @@ async def get_profiles(
160
  )
161
 
162
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
163
  @app.post("/api/profiles", response_model=ProfileRead, status_code=status.HTTP_201_CREATED)
164
  async def create_user_profile(
165
  profile_data: ProfileCreate,
 
38
  from exceptions import SilverTableException, PaymentException
39
  from exceptions import handle_payment_error
40
  from crud import (
41
+ get_profile, get_profiles_by_user, create_profile, update_profile, delete_profile,
42
  create_order, get_orders_by_profile,
43
  create_donation, update_donation_status,
44
  get_menu_items, get_dashboard_stats
 
160
  )
161
 
162
 
163
+ @app.get("/api/profiles/{profile_id}", response_model=ProfileRead)
164
+ async def get_profile_by_id(
165
+ profile_id: str,
166
+ current_user: User = Depends(get_current_user),
167
+ db: AsyncSession = Depends(get_session)
168
+ ):
169
+ """
170
+ Get a specific profile by ID.
171
+ Requires authentication.
172
+ """
173
+ try:
174
+ # Validate profile_id format
175
+ try:
176
+ profile_uuid = UUID(profile_id)
177
+ except ValueError:
178
+ raise HTTPException(
179
+ status_code=status.HTTP_400_BAD_REQUEST,
180
+ detail="Invalid profile ID format"
181
+ )
182
+
183
+ # Get the profile
184
+ profile = await get_profile(db, profile_uuid)
185
+
186
+ if not profile:
187
+ raise HTTPException(
188
+ status_code=status.HTTP_404_NOT_FOUND,
189
+ detail="Profile not found"
190
+ )
191
+
192
+ return profile
193
+ except HTTPException:
194
+ raise
195
+ except Exception as e:
196
+ logger.error(f"Error fetching profile {profile_id}: {str(e)}")
197
+ raise HTTPException(
198
+ status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
199
+ detail="Failed to fetch profile"
200
+ )
201
+
202
+
203
  @app.post("/api/profiles", response_model=ProfileRead, status_code=status.HTTP_201_CREATED)
204
  async def create_user_profile(
205
  profile_data: ProfileCreate,