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:
-
Method Summary
Modifier and TypeMethodDescriptionlongcountByRecruiterIdAndIsActive(String recruiterId, Boolean isActive) 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.findByCategory(String category) Finds jobs in a specific category.findByCompanyNameContainingIgnoreCase(String companyName) Finds jobs from companies with names containing the specified keyword (case-insensitive).findByIsActive(Boolean isActive) Finds jobs based on their active status.findByLocation(String location) Finds jobs in a specific location.findByRecruiterId(String recruiterId) 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, saveMethods inherited from interface org.springframework.data.repository.ListCrudRepository
findAll, findAllById, saveAllMethods inherited from interface org.springframework.data.repository.ListPagingAndSortingRepository
findAllMethods inherited from interface org.springframework.data.mongodb.repository.MongoRepository
findAll, findAll, insert, insertMethods inherited from interface org.springframework.data.repository.query.QueryByExampleExecutor
count, exists, findAll, findBy, findOne
-
Method Details
-
findByTitleContainingIgnoreCase
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
Finds jobs in a specific category.- Parameters:
category- the job category- Returns:
- a list of jobs in the specified category
-
findByLocation
Finds jobs in a specific location.- Parameters:
location- the job location- Returns:
- a list of jobs in the specified location
-
findByCompanyNameContainingIgnoreCase
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 salarymaxSalary- the maximum salary- Returns:
- a list of jobs with salaries within the specified range
-
findByRecruiterId
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
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. -
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 keywordpageable- pagination and sorting information- Returns:
- a page of jobs matching the search criteria
-
countByRecruiterIdAndIsActive
Counts the number of active jobs posted by a specific recruiter.- Parameters:
recruiterId- the ID of the recruiterisActive- the active status to filter by- Returns:
- the count of jobs matching the criteria
-