Interface CandidateRepository

All Superinterfaces:
org.springframework.data.repository.CrudRepository<Candidate,String>, org.springframework.data.repository.ListCrudRepository<Candidate,String>, org.springframework.data.repository.ListPagingAndSortingRepository<Candidate,String>, org.springframework.data.mongodb.repository.MongoRepository<Candidate,String>, org.springframework.data.repository.PagingAndSortingRepository<Candidate,String>, org.springframework.data.repository.query.QueryByExampleExecutor<Candidate>, org.springframework.data.repository.Repository<Candidate,String>

@Repository public interface CandidateRepository extends org.springframework.data.mongodb.repository.MongoRepository<Candidate,String>
Repository interface for accessing and manipulating Candidate documents in MongoDB.

This repository provides methods for CRUD operations on Candidate entities, as well as custom queries for retrieving candidates based on various criteria such as user ID, skills, experience level, location, education, and work history. It leverages Spring Data MongoDB's query method naming conventions and the @Query annotation for more complex queries.

As a Spring Data repository, it automatically provides standard operations like:

  • Saving and updating candidate profiles
  • Deleting candidate profiles
  • Finding candidate profiles by ID
  • Retrieving all candidate profiles

The interface also defines custom queries for candidate searching and filtering, which are essential for job matching and recruiter search functionalities.

Since:
2025-05-15
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Checks if a candidate profile exists for a specific user.
    Finds candidates with a specific job title in their work experience.
    Finds candidates with a specific degree in their education history.
    findByExperienceLevel(String experienceLevel)
    Finds candidates with a specific experience level.
    Finds candidates by partial location (case-insensitive).
    Finds candidates who have any of the specified skills.
    Finds a candidate profile by its associated user ID.
    Finds candidates within a specific range of years of experience.
    searchCandidates(List<String> skills, Integer minExperience, String location)
    Searches for candidates matching multiple criteria: skills, minimum experience, and location.

    Methods inherited from interface org.springframework.data.repository.CrudRepository

    count, delete, deleteAll, deleteAll, deleteAllById, deleteById, existsById, findById, save

    Methods inherited from interface org.springframework.data.repository.ListCrudRepository

    findAll, findAllById, saveAll

    Methods inherited from interface org.springframework.data.repository.ListPagingAndSortingRepository

    findAll

    Methods inherited from interface org.springframework.data.mongodb.repository.MongoRepository

    findAll, findAll, insert, insert

    Methods inherited from interface org.springframework.data.repository.PagingAndSortingRepository

    findAll

    Methods inherited from interface org.springframework.data.repository.query.QueryByExampleExecutor

    count, exists, findAll, findBy, findOne
  • Method Details

    • findByUserId

      Optional<Candidate> findByUserId(String userId)
      Finds a candidate profile by its associated user ID. This method is used to retrieve the profile for a specific user account.
      Parameters:
      userId - the ID of the user account
      Returns:
      an Optional containing the candidate profile if found, or empty if not
    • existsByUserId

      boolean existsByUserId(String userId)
      Checks if a candidate profile exists for a specific user. This is useful during profile creation to prevent duplicates.
      Parameters:
      userId - the ID of the user account
      Returns:
      true if a profile exists, false otherwise
    • findBySkills

      @Query("{ \'skills\': { $in: ?0 } }") List<Candidate> findBySkills(List<String> skills)
      Finds candidates who have any of the specified skills. Uses MongoDB's $in operator to match against an array of skills.
      Parameters:
      skills - a list of skills to search for
      Returns:
      a list of candidates matching the skills criteria
    • findByExperienceLevel

      @Query("{ \'experienceLevel\': ?0 }") List<Candidate> findByExperienceLevel(String experienceLevel)
      Finds candidates with a specific experience level.
      Parameters:
      experienceLevel - the experience level to match (e.g., ENTRY, JUNIOR, MID, SENIOR, EXECUTIVE)
      Returns:
      a list of candidates with the specified experience level
    • findByLocationContainingIgnoreCase

      List<Candidate> findByLocationContainingIgnoreCase(String location)
      Finds candidates by partial location (case-insensitive). This is useful for geographic filtering of candidates.
      Parameters:
      location - the partial location to search for
      Returns:
      a list of candidates matching the location search
    • findByYearsOfExperienceRange

      @Query("{ \'yearsOfExperience\': { $gte: ?0, $lte: ?1 } }") List<Candidate> findByYearsOfExperienceRange(Integer minYears, Integer maxYears)
      Finds candidates within a specific range of years of experience. Uses MongoDB's $gte (greater than or equal) and $lte (less than or equal) operators.
      Parameters:
      minYears - the minimum years of experience
      maxYears - the maximum years of experience
      Returns:
      a list of candidates with experience within the specified range
    • findByEducationDegree

      @Query("{ \'education.degree\': ?0 }") List<Candidate> findByEducationDegree(String degree)
      Finds candidates with a specific degree in their education history. This query searches within the embedded education array for matching degrees.
      Parameters:
      degree - the degree to search for
      Returns:
      a list of candidates with the specified degree
    • findByCurrentTitle

      @Query("{ \'experience.title\': { $regex: ?0, $options: \'i\' } }") List<Candidate> findByCurrentTitle(String title)
      Finds candidates with a specific job title in their work experience. This query searches within the embedded experience array for matching titles. Uses a case-insensitive regular expression match.
      Parameters:
      title - the job title to search for
      Returns:
      a list of candidates with the specified title in their work history
    • searchCandidates

      @Query("{ $and: [ { \'skills\': { $in: ?0 } }, { \'yearsOfExperience\': { $gte: ?1 } }, { \'location\': { $regex: ?2, $options: \'i\' } } ] }") List<Candidate> searchCandidates(List<String> skills, Integer minExperience, String location)
      Searches for candidates matching multiple criteria: skills, minimum experience, and location. This complex query combines multiple conditions using MongoDB's $and operator.
      Parameters:
      skills - a list of skills to search for
      minExperience - the minimum years of experience
      location - the location to search for
      Returns:
      a list of candidates matching all the specified criteria