Class JobService
java.lang.Object
me.josephsf.jobportaljosephsfeir.service.JobService
Service class for managing job data and operations in the Job Portal system.
This service provides methods for creating, retrieving, updating, and deleting job postings, as well as searching and filtering jobs based on various criteria. It interacts with the MongoDB database through the JobRepository and handles related business logic.
- Since:
- 2025-05-15
-
Constructor Summary
ConstructorsConstructorDescriptionJobService(JobRepository jobRepository) Constructs a new JobService with required dependencies. -
Method Summary
Modifier and TypeMethodDescriptionlongcountJobsByRecruiter(String recruiterId) Counts the number of active jobs posted by a specific recruiter.Creates a new job posting.booleanDeletes a job posting.Retrieves all jobs that are marked as active.org.springframework.data.domain.Page<Job> getAllJobs(org.springframework.data.domain.Pageable pageable) Retrieves all jobs with pagination support.getJobById(String id) Retrieves a job by its ID.getJobsByCategory(String category) Finds jobs by category.getJobsByCompany(String companyName) Finds jobs by company name.getJobsByLocation(String location) Finds jobs by location.getJobsByRecruiter(String recruiterId) Finds jobs posted by a specific recruiter.getJobsBySalaryRange(Double minSalary, Double maxSalary) Finds jobs within a specified salary range.org.springframework.data.domain.Page<Job> searchJobs(String keyword, org.springframework.data.domain.Pageable pageable) Searches for jobs based on a keyword.Toggles the active status of a job posting.Updates an existing job posting.
-
Constructor Details
-
JobService
Constructs a new JobService with required dependencies.- Parameters:
jobRepository- Repository for job data operations
-
-
Method Details
-
getAllJobs
public org.springframework.data.domain.Page<Job> getAllJobs(org.springframework.data.domain.Pageable pageable) Retrieves all jobs with pagination support.- Parameters:
pageable- Pagination and sorting parameters- Returns:
- A page of job postings
-
getJobById
Retrieves a job by its ID.- Parameters:
id- The unique identifier of the job- Returns:
- The job if found, null otherwise
-
createJob
Creates a new job posting.- Parameters:
jobDto- The data transfer object containing job information- Returns:
- The created job posting
-
updateJob
Updates an existing job posting.- Parameters:
id- The unique identifier of the job to updatejobDto- The data transfer object containing updated job information- Returns:
- The updated job posting or null if the job is not found
-
deleteJob
Deletes a job posting.- Parameters:
id- The unique identifier of the job to delete- Returns:
- true if the job was successfully deleted, false otherwise
-
searchJobs
public org.springframework.data.domain.Page<Job> searchJobs(String keyword, org.springframework.data.domain.Pageable pageable) Searches for jobs based on a keyword.- Parameters:
keyword- The search keyword to match against job title, description, or company namepageable- Pagination and sorting parameters- Returns:
- A page of jobs matching the search criteria
-
getJobsByCategory
Finds jobs by category.- Parameters:
category- The job category to filter by- Returns:
- List of jobs in the specified category
-
getJobsByLocation
Finds jobs by location.- Parameters:
location- The location to filter by- Returns:
- List of jobs in the specified location
-
getJobsByRecruiter
Finds jobs posted by a specific recruiter.- Parameters:
recruiterId- The ID of the recruiter- Returns:
- List of jobs posted by the specified recruiter
-
getJobsByCompany
Finds jobs by company name.- Parameters:
companyName- The company name to search for- Returns:
- List of jobs posted by the specified company
-
getJobsBySalaryRange
Finds jobs within a specified salary range.- Parameters:
minSalary- The minimum salarymaxSalary- The maximum salary- Returns:
- List of jobs with salaries within the specified range
-
toggleJobActive
Toggles the active status of a job posting.- Parameters:
id- The unique identifier of the job- Returns:
- The updated job with toggled active status or null if the job is not found
-
getActiveJobs
Retrieves all jobs that are marked as active.- Returns:
- List of active job postings
-
countJobsByRecruiter
Counts the number of active jobs posted by a specific recruiter.- Parameters:
recruiterId- The ID of the recruiter- Returns:
- The count of active jobs posted by the specified recruiter
-