Class CandidateController
This controller handles HTTP requests related to candidate profiles, including creating, retrieving, updating, and deleting candidate information. It also provides endpoints for searching candidates based on various criteria such as skills and experience levels, which are primarily used by recruiters. Candidate-specific operations like updating resume and availability status are also supported.
Different endpoints have different authorization requirements based on user roles.
- Since:
- 2025-05-14
-
Constructor Summary
ConstructorsConstructorDescriptionCandidateController(CandidateService candidateService) Constructs a CandidateController with the specified service. -
Method Summary
Modifier and TypeMethodDescriptioncreateCandidateProfile(@Valid CandidateDto candidateDto) Creates a new candidate profile.Deletes a candidate profile.Retrieves all candidates who are currently available for job opportunities.Retrieves a candidate profile by its ID.getCandidateByUserId(String userId) Retrieves a candidate profile by the associated user ID.Retrieves candidates with a specific experience level.getCandidatesBySkill(String skill) Retrieves candidates who have a specific skill.Retrieves statistics about a candidate's profile and job applications.searchCandidates(List<String> skills, Integer minExperience, String location, String experienceLevel) Searches for candidates based on multiple criteria.updateAvailability(String id, Boolean isAvailable) Updates a candidate's availability status.updateCandidateProfile(String id, @Valid CandidateDto candidateDto) Updates an existing candidate profile.updateResume(String id, String resumeUrl) Updates a candidate's resume URL.
-
Constructor Details
-
CandidateController
Constructs a CandidateController with the specified service.- Parameters:
candidateService- The service for candidate-related operations
-
-
Method Details
-
getCandidateById
@GetMapping("/{id}") @PreAuthorize("hasAnyRole(\'CANDIDATE\', \'RECRUITER\', \'ADMIN\')") public ResponseEntity<?> getCandidateById(@PathVariable String id) Retrieves a candidate profile by its ID.This endpoint is accessible to candidates, recruiters, and administrators. It returns the candidate's profile information if found.
- Parameters:
id- The ID of the candidate profile to retrieve- Returns:
- ResponseEntity with the candidate profile or a not-found status
-
getCandidateByUserId
@GetMapping("/user/{userId}") @PreAuthorize("hasRole(\'CANDIDATE\')") public ResponseEntity<?> getCandidateByUserId(@PathVariable String userId) Retrieves a candidate profile by the associated user ID.This endpoint allows candidates to access their own profile by their user ID. It is primarily used for profile setup and management.
- Parameters:
userId- The ID of the user associated with the candidate profile- Returns:
- ResponseEntity with the candidate profile or a not-found status
-
createCandidateProfile
@PostMapping @PreAuthorize("hasRole(\'CANDIDATE\')") public ResponseEntity<?> createCandidateProfile(@Valid @RequestBody @Valid CandidateDto candidateDto) Creates a new candidate profile.This endpoint allows users with the CANDIDATE role to create their profile by providing their personal and professional information. A user can only have one candidate profile.
- Parameters:
candidateDto- The DTO containing candidate profile information- Returns:
- ResponseEntity with the created profile or an error response
-
updateCandidateProfile
@PutMapping("/{id}") @PreAuthorize("hasRole(\'CANDIDATE\')") public ResponseEntity<?> updateCandidateProfile(@PathVariable String id, @Valid @RequestBody @Valid CandidateDto candidateDto) Updates an existing candidate profile.This endpoint allows candidates to update their profile information such as personal details, skills, experience, and education.
- Parameters:
id- The ID of the candidate profile to updatecandidateDto- The DTO containing updated profile information- Returns:
- ResponseEntity with the updated profile or a not-found status
-
deleteCandidateProfile
@DeleteMapping("/{id}") @PreAuthorize("hasAnyRole(\'CANDIDATE\', \'ADMIN\')") public ResponseEntity<?> deleteCandidateProfile(@PathVariable String id) Deletes a candidate profile.This endpoint allows candidates to delete their own profile or administrators to delete any candidate profile.
- Parameters:
id- The ID of the candidate profile to delete- Returns:
- ResponseEntity with a success response or a not-found status
-
searchCandidates
@GetMapping("/search") @PreAuthorize("hasRole(\'RECRUITER\')") public ResponseEntity<?> searchCandidates(@RequestParam(required=false) List<String> skills, @RequestParam(required=false) Integer minExperience, @RequestParam(required=false) String location, @RequestParam(required=false) String experienceLevel) Searches for candidates based on multiple criteria.This endpoint allows recruiters to search for candidates based on skills, minimum experience, location, and experience level. All parameters are optional and can be combined for more specific searches.
- Parameters:
skills- The list of skills to search forminExperience- The minimum years of experience requiredlocation- The preferred location of candidatesexperienceLevel- The experience level category (e.g., ENTRY, JUNIOR, MID, SENIOR)- Returns:
- ResponseEntity with a list of matching candidates
-
getCandidatesBySkill
@GetMapping("/skills/{skill}") @PreAuthorize("hasRole(\'RECRUITER\')") public ResponseEntity<?> getCandidatesBySkill(@PathVariable String skill) Retrieves candidates who have a specific skill.This endpoint allows recruiters to find candidates with a particular skill.
- Parameters:
skill- The skill to search for- Returns:
- ResponseEntity with a list of candidates having the specified skill
-
getCandidatesByExperienceLevel
@GetMapping("/experience/{level}") @PreAuthorize("hasRole(\'RECRUITER\')") public ResponseEntity<?> getCandidatesByExperienceLevel(@PathVariable String level) Retrieves candidates with a specific experience level.This endpoint allows recruiters to find candidates based on their experience level category (e.g., ENTRY, JUNIOR, MID, SENIOR, EXECUTIVE).
- Parameters:
level- The experience level to search for- Returns:
- ResponseEntity with a list of candidates at the specified experience level
-
updateResume
@PutMapping("/{id}/resume") @PreAuthorize("hasRole(\'CANDIDATE\')") public ResponseEntity<?> updateResume(@PathVariable String id, @RequestParam String resumeUrl) Updates a candidate's resume URL.This endpoint allows candidates to update the URL to their resume without changing other profile information.
- Parameters:
id- The ID of the candidate profileresumeUrl- The new resume URL- Returns:
- ResponseEntity with the updated candidate profile or a not-found status
-
updateAvailability
@PutMapping("/{id}/availability") @PreAuthorize("hasRole(\'CANDIDATE\')") public ResponseEntity<?> updateAvailability(@PathVariable String id, @RequestParam Boolean isAvailable) Updates a candidate's availability status.This endpoint allows candidates to indicate whether they are currently available for job opportunities.
- Parameters:
id- The ID of the candidate profileisAvailable- The availability status (true if available, false if not)- Returns:
- ResponseEntity with the updated candidate profile or a not-found status
-
getAvailableCandidates
@GetMapping("/available") @PreAuthorize("hasRole(\'RECRUITER\')") public ResponseEntity<?> getAvailableCandidates()Retrieves all candidates who are currently available for job opportunities.This endpoint allows recruiters to find candidates who have indicated they are actively looking for job opportunities.
- Returns:
- ResponseEntity with a list of available candidates
-
getCandidateStats
@GetMapping("/{id}/stats") @PreAuthorize("hasRole(\'CANDIDATE\')") public ResponseEntity<?> getCandidateStats(@PathVariable String id) Retrieves statistics about a candidate's profile and job applications.This endpoint provides statistical information about a candidate's job application history, including counts of applications by status, skills, experience, and education details.
- Parameters:
id- The ID of the candidate profile- Returns:
- ResponseEntity with statistical information about the candidate
-