Class JobService

java.lang.Object
me.josephsf.jobportaljosephsfeir.service.JobService

@Service public class JobService extends Object
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 Details

    • JobService

      public JobService(JobRepository jobRepository)
      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

      public Job getJobById(String id)
      Retrieves a job by its ID.
      Parameters:
      id - The unique identifier of the job
      Returns:
      The job if found, null otherwise
    • createJob

      public Job createJob(JobDto jobDto)
      Creates a new job posting.
      Parameters:
      jobDto - The data transfer object containing job information
      Returns:
      The created job posting
    • updateJob

      public Job updateJob(String id, JobDto jobDto)
      Updates an existing job posting.
      Parameters:
      id - The unique identifier of the job to update
      jobDto - The data transfer object containing updated job information
      Returns:
      The updated job posting or null if the job is not found
    • deleteJob

      public boolean deleteJob(String id)
      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 name
      pageable - Pagination and sorting parameters
      Returns:
      A page of jobs matching the search criteria
    • getJobsByCategory

      public List<Job> getJobsByCategory(String category)
      Finds jobs by category.
      Parameters:
      category - The job category to filter by
      Returns:
      List of jobs in the specified category
    • getJobsByLocation

      public List<Job> getJobsByLocation(String location)
      Finds jobs by location.
      Parameters:
      location - The location to filter by
      Returns:
      List of jobs in the specified location
    • getJobsByRecruiter

      public List<Job> getJobsByRecruiter(String recruiterId)
      Finds jobs posted by a specific recruiter.
      Parameters:
      recruiterId - The ID of the recruiter
      Returns:
      List of jobs posted by the specified recruiter
    • getJobsByCompany

      public List<Job> getJobsByCompany(String companyName)
      Finds jobs by company name.
      Parameters:
      companyName - The company name to search for
      Returns:
      List of jobs posted by the specified company
    • getJobsBySalaryRange

      public List<Job> getJobsBySalaryRange(Double minSalary, Double maxSalary)
      Finds jobs within a specified salary range.
      Parameters:
      minSalary - The minimum salary
      maxSalary - The maximum salary
      Returns:
      List of jobs with salaries within the specified range
    • toggleJobActive

      public Job toggleJobActive(String id)
      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

      public List<Job> getActiveJobs()
      Retrieves all jobs that are marked as active.
      Returns:
      List of active job postings
    • countJobsByRecruiter

      public long countJobsByRecruiter(String recruiterId)
      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