Kaadan commited on
Commit
3bc61a5
·
1 Parent(s): b67657a

addinf my application endpoint

Browse files
backend/api/application_routes.py CHANGED
@@ -5,7 +5,7 @@ import json
5
 
6
  from database.database import get_db
7
  from schemas import ApplicationCreate, ApplicationUpdate, ApplicationResponse, ApplicationListResponse, ApplicationDetailedResponse, ApplicationDetailedListResponse, MyApplicationsListResponse, MyApplicationResponse, MyApplicationsJob, MyApplicationsAssessment, ApplicationAssessment
8
- from services import create_application, get_application, get_applications_by_job_and_assessment, calculate_application_score, get_applications_by_user
9
  from services.assessment_service import get_assessment
10
  from services.job_service import get_job
11
  from utils.dependencies import get_current_user
@@ -260,7 +260,7 @@ def create_new_application(jid: str, aid: str, application: ApplicationCreate, d
260
  def get_my_applications(page: int = 1, limit: int = 10, db: Session = Depends(get_db), current_user: User = Depends(get_current_user)):
261
  """Get list of applications for the current logged-in user"""
262
  logger.info(f"Retrieving applications for user ID: {current_user.id}, page: {page}, limit: {limit}")
263
-
264
  skip = (page - 1) * limit
265
  applications = get_applications_by_user(db, current_user.id, skip=skip, limit=limit)
266
 
@@ -275,7 +275,7 @@ def get_my_applications(page: int = 1, limit: int = 10, db: Session = Depends(ge
275
 
276
  # Get assessment to retrieve passing score
277
  assessment = get_assessment(db, application.assessment_id)
278
-
279
  # Get job details
280
  job = get_job(db, application.job_id)
281
 
@@ -304,4 +304,49 @@ def get_my_applications(page: int = 1, limit: int = 10, db: Session = Depends(ge
304
  count=len(applications),
305
  total=total,
306
  data=application_responses
307
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
  from database.database import get_db
7
  from schemas import ApplicationCreate, ApplicationUpdate, ApplicationResponse, ApplicationListResponse, ApplicationDetailedResponse, ApplicationDetailedListResponse, MyApplicationsListResponse, MyApplicationResponse, MyApplicationsJob, MyApplicationsAssessment, ApplicationAssessment
8
+ from services import create_application, get_application, get_applications_by_job_and_assessment, calculate_application_score, get_applications_by_user, get_application_by_user
9
  from services.assessment_service import get_assessment
10
  from services.job_service import get_job
11
  from utils.dependencies import get_current_user
 
260
  def get_my_applications(page: int = 1, limit: int = 10, db: Session = Depends(get_db), current_user: User = Depends(get_current_user)):
261
  """Get list of applications for the current logged-in user"""
262
  logger.info(f"Retrieving applications for user ID: {current_user.id}, page: {page}, limit: {limit}")
263
+
264
  skip = (page - 1) * limit
265
  applications = get_applications_by_user(db, current_user.id, skip=skip, limit=limit)
266
 
 
275
 
276
  # Get assessment to retrieve passing score
277
  assessment = get_assessment(db, application.assessment_id)
278
+
279
  # Get job details
280
  job = get_job(db, application.job_id)
281
 
 
304
  count=len(applications),
305
  total=total,
306
  data=application_responses
307
+ )
308
+
309
+
310
+ @router.get("/my-applications/{id}", response_model=MyApplicationResponse)
311
+ def get_my_application(id: str, db: Session = Depends(get_db), current_user: User = Depends(get_current_user)):
312
+ """Get a specific application by ID for the current logged-in user"""
313
+ logger.info(f"Retrieving application with ID: {id} for user ID: {current_user.id}")
314
+
315
+ # Get the application for the current user
316
+ application = get_application_by_user(db, id, current_user.id)
317
+ if not application:
318
+ logger.warning(f"Application not found for ID: {id} and user ID: {current_user.id}")
319
+ raise HTTPException(
320
+ status_code=status.HTTP_404_NOT_FOUND,
321
+ detail="Application not found or does not belong to the current user"
322
+ )
323
+
324
+ # Calculate score
325
+ score = calculate_application_score(db, application.id)
326
+
327
+ # Get assessment to retrieve passing score
328
+ assessment = get_assessment(db, application.assessment_id)
329
+
330
+ # Get job details
331
+ job = get_job(db, application.job_id)
332
+
333
+ # Create response object that matches technical requirements exactly
334
+ application_response = MyApplicationResponse(
335
+ id=application.id,
336
+ job=MyApplicationsJob(
337
+ id=job.id if job else "",
338
+ title=job.title if job else "",
339
+ seniority=job.seniority if job else "",
340
+ description=job.description if job else ""
341
+ ) if job else None,
342
+ assessment=MyApplicationsAssessment(
343
+ id=assessment.id if assessment else "",
344
+ title=assessment.title if assessment else "",
345
+ passing_score=assessment.passing_score if assessment else 0.0
346
+ ) if assessment else None,
347
+ score=score,
348
+ created_at=application.created_at.isoformat() if application.created_at else None
349
+ )
350
+
351
+ logger.info(f"Successfully retrieved application with ID: {id} for user ID: {current_user.id}")
352
+ return application_response
backend/services/__init__.py CHANGED
@@ -36,6 +36,7 @@ from .application_service import (
36
  get_application,
37
  get_applications_by_job_and_assessment,
38
  get_applications_by_user,
 
39
  create_application,
40
  update_application,
41
  delete_application,
@@ -72,6 +73,7 @@ __all__ = [
72
  "get_application",
73
  "get_applications_by_job_and_assessment",
74
  "get_applications_by_user",
 
75
  "create_application",
76
  "update_application",
77
  "delete_application",
 
36
  get_application,
37
  get_applications_by_job_and_assessment,
38
  get_applications_by_user,
39
+ get_application_by_user,
40
  create_application,
41
  update_application,
42
  delete_application,
 
73
  "get_application",
74
  "get_applications_by_job_and_assessment",
75
  "get_applications_by_user",
76
+ "get_application_by_user",
77
  "create_application",
78
  "update_application",
79
  "delete_application",
backend/services/application_service.py CHANGED
@@ -20,6 +20,19 @@ def get_application(db: Session, application_id: str) -> Optional[Application]:
20
  logger.debug(f"Application not found for ID: {application_id}")
21
  return application
22
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
  def get_applications_by_job_and_assessment(db: Session, job_id: str, assessment_id: str, skip: int = 0, limit: int = 100) -> List[Application]:
24
  """Get list of applications by job and assessment IDs"""
25
  logger.debug(f"Retrieving applications for job ID: {job_id}, assessment ID: {assessment_id}, skip={skip}, limit={limit}")
 
20
  logger.debug(f"Application not found for ID: {application_id}")
21
  return application
22
 
23
+ def get_application_by_user(db: Session, application_id: str, user_id: str) -> Optional[Application]:
24
+ """Get application by ID and user ID"""
25
+ logger.debug(f"Retrieving application with ID: {application_id} for user ID: {user_id}")
26
+ application = db.query(Application).filter(
27
+ Application.id == application_id,
28
+ Application.user_id == user_id
29
+ ).first()
30
+ if application:
31
+ logger.debug(f"Found application: {application.id} for user: {user_id}")
32
+ else:
33
+ logger.debug(f"Application not found for ID: {application_id} and user ID: {user_id}")
34
+ return application
35
+
36
  def get_applications_by_job_and_assessment(db: Session, job_id: str, assessment_id: str, skip: int = 0, limit: int = 100) -> List[Application]:
37
  """Get list of applications by job and assessment IDs"""
38
  logger.debug(f"Retrieving applications for job ID: {job_id}, assessment ID: {assessment_id}, skip={skip}, limit={limit}")