Interface JobRepository

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

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

This repository provides methods for CRUD operations on Job entities, as well as custom queries for retrieving jobs based on various criteria such as title, category, location, company, salary range, and recruiter. 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 jobs
  • Deleting jobs
  • Finding jobs by ID
  • Retrieving all jobs

The interface also defines custom queries for job searching and filtering capabilities needed by the application.

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

    Modifier and Type
    Method
    Description
    long
    Counts the number of active jobs posted by a specific recruiter.
    org.springframework.data.domain.Page<Job>
    findAll(org.springframework.data.domain.Pageable pageable)
    Retrieves all jobs with pagination and sorting support.
    Finds jobs in a specific category.
    Finds jobs from companies with names containing the specified keyword (case-insensitive).
    Finds jobs based on their active status.
    Finds jobs in a specific location.
    Finds jobs posted by a specific recruiter.
    findBySalaryRange(Double minSalary, Double maxSalary)
    Finds jobs within a specified salary range.
    Finds jobs with titles containing the specified keyword (case-insensitive).
    org.springframework.data.domain.Page<Job>
    searchJobs(String keyword, org.springframework.data.domain.Pageable pageable)
    Searches for active jobs matching a keyword in title, description, or company name.

    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.query.QueryByExampleExecutor

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

    • findByTitleContainingIgnoreCase

      List<Job> findByTitleContainingIgnoreCase(String title)
      Finds jobs with titles containing the specified keyword (case-insensitive).
      Parameters:
      title - the keyword to search for in job titles
      Returns:
      a list of jobs matching the search criteria
    • findByCategory

      List<Job> findByCategory(String category)
      Finds jobs in a specific category.
      Parameters:
      category - the job category
      Returns:
      a list of jobs in the specified category
    • findByLocation

      List<Job> findByLocation(String location)
      Finds jobs in a specific location.
      Parameters:
      location - the job location
      Returns:
      a list of jobs in the specified location
    • findByCompanyNameContainingIgnoreCase

      List<Job> findByCompanyNameContainingIgnoreCase(String companyName)
      Finds jobs from companies with names containing the specified keyword (case-insensitive).
      Parameters:
      companyName - the keyword to search for in company names
      Returns:
      a list of jobs matching the search criteria
    • findBySalaryRange

      @Query("{ \'salary\' : { $gte : ?0, $lte : ?1 } }") List<Job> findBySalaryRange(Double minSalary, Double maxSalary)
      Finds jobs within a specified salary range.
      Parameters:
      minSalary - the minimum salary
      maxSalary - the maximum salary
      Returns:
      a list of jobs with salaries within the specified range
    • findByRecruiterId

      List<Job> findByRecruiterId(String recruiterId)
      Finds jobs posted by a specific recruiter.
      Parameters:
      recruiterId - the ID of the recruiter
      Returns:
      a list of jobs posted by the specified recruiter
    • findByIsActive

      List<Job> findByIsActive(Boolean isActive)
      Finds jobs based on their active status.
      Parameters:
      isActive - true to find active jobs, false to find inactive jobs
      Returns:
      a list of jobs with the specified active status
    • findAll

      org.springframework.data.domain.Page<Job> findAll(org.springframework.data.domain.Pageable pageable)
      Retrieves all jobs with pagination and sorting support. Overrides the standard findAll method to explicitly support pagination.
      Specified by:
      findAll in interface org.springframework.data.repository.PagingAndSortingRepository<Job,String>
      Parameters:
      pageable - pagination and sorting information
      Returns:
      a page of jobs
    • searchJobs

      @Query("{ $and: [ { $or: [ { \'title\': { $regex: ?0, $options: \'i\' } }, { \'description\': { $regex: ?0, $options: \'i\' } }, { \'companyName\': { $regex: ?0, $options: \'i\' } } ] }, { \'isActive\': true } ] }") org.springframework.data.domain.Page<Job> searchJobs(String keyword, org.springframework.data.domain.Pageable pageable)
      Searches for active jobs matching a keyword in title, description, or company name. This is a complex query that uses MongoDB's $and and $or operators to perform a search across multiple fields while filtering for active jobs only.
      Parameters:
      keyword - the search keyword
      pageable - pagination and sorting information
      Returns:
      a page of jobs matching the search criteria
    • countByRecruiterIdAndIsActive

      long countByRecruiterIdAndIsActive(String recruiterId, Boolean isActive)
      Counts the number of active jobs posted by a specific recruiter.
      Parameters:
      recruiterId - the ID of the recruiter
      isActive - the active status to filter by
      Returns:
      the count of jobs matching the criteria