Ignore:
Timestamp:
06/09/24 14:24:03 (5 months ago)
Author:
223021 <daniel.ilievski.2@…>
Branches:
main
Children:
b248810
Parents:
19398ad
Message:

Implemented job application functionality, added job advertisement filtering and replaced text areas with editors

Location:
jobvista-backend/src/main/java/mk/ukim/finki/predmeti/internettehnologii/jobvistabackend
Files:
10 added
6 edited

Legend:

Unmodified
Added
Removed
  • jobvista-backend/src/main/java/mk/ukim/finki/predmeti/internettehnologii/jobvistabackend/config/SecurityConfiguration.java

    r19398ad r28b3398  
    3030        http.csrf(AbstractHttpConfigurer::disable)
    3131                .authorizeHttpRequests(request -> request
    32                         .requestMatchers("/api/job-advertisements/all","/api/job-advertisements/view/**","/api/recruiter/info/**", "/api/auth/**").permitAll()
     32                        // TO DO: FIX PERMISSIONS
     33                        .requestMatchers("/api/job-advertisements/**","/api/job-advertisements/view/**","/api/recruiter/info/**",
     34                                "/api/job-advertisements/apply/**","/api/auth/**", "/api/resume/**", "/api/my-applications/**", "/api/applications/{id}/update").permitAll()
    3335                        //.requestMatchers("/api/job-advertisements/**").hasAnyAuthority(Role.ROLE_RECRUITER.name())
    3436                        .anyRequest().authenticated())
  • jobvista-backend/src/main/java/mk/ukim/finki/predmeti/internettehnologii/jobvistabackend/controllers/JobAdvertisementController.java

    r19398ad r28b3398  
    33
    44import lombok.AllArgsConstructor;
     5import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.models.applications.Application;
     6import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.models.applications.DTO.ApplicationDTO;
     7import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.models.job_advertisements.DTO.JobAdFilterDTO;
    58import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.models.job_advertisements.DTO.JobAdvertisementDTO;
    69import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.models.job_advertisements.DTO.JobAdDetailsDTO;
    710import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.models.job_advertisements.JobAdvertisement;
     11import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.service.intef.ApplicationService;
    812import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.service.intef.JobAdvertisementService;
    913import org.springframework.http.HttpStatus;
    1014import org.springframework.http.ResponseEntity;
    1115import org.springframework.web.bind.annotation.*;
     16import org.springframework.web.multipart.MultipartFile;
    1217
    1318import java.util.List;
     
    2025
    2126    private final JobAdvertisementService jobAdvertisementService;
     27    private final ApplicationService applicationService;
    2228
    2329    @PostMapping("/add")
     
    4551    }
    4652
     53    @PostMapping("/recruiter/{id}/filtered")
     54    public ResponseEntity<?> filterJobAdvertisementsByRecruiterId(@PathVariable Long id, @RequestBody JobAdFilterDTO jobAdFilterDTO) {
     55        List<JobAdDetailsDTO> jobAdDetailsDTOS = jobAdvertisementService.filterJobAdvertisementsByRecruiterId(id, jobAdFilterDTO);
     56        return new ResponseEntity<>(jobAdDetailsDTOS, HttpStatus.OK);
     57    }
     58
    4759    @GetMapping("/all")
    4860    public ResponseEntity<?> findAllJobAdvertisements() {
     
    5163    }
    5264
    53     @GetMapping("/view/{id}")
     65    @PostMapping("/filtered")
     66    public ResponseEntity<?> filterJobAdvertisements(@RequestBody JobAdFilterDTO jobAdFilterDTO) {
     67        List<JobAdDetailsDTO> jobAdDetailsDTOS = jobAdvertisementService.filterJobAdvertisements(jobAdFilterDTO);
     68        return new ResponseEntity<>(jobAdDetailsDTOS, HttpStatus.OK);
     69    }
     70
     71    @GetMapping("/{id}")
    5472    public ResponseEntity<?> findJobAdvertisementById(@PathVariable Long id) {
    5573        JobAdDetailsDTO jobAdDetailsDTO = jobAdvertisementService.findJobAdvertisementById(id);
    5674        return new ResponseEntity<>(jobAdDetailsDTO, HttpStatus.OK);
    5775    }
     76
     77
     78
    5879}
  • jobvista-backend/src/main/java/mk/ukim/finki/predmeti/internettehnologii/jobvistabackend/models/job_advertisements/JobAdvertisement.java

    r19398ad r28b3398  
    88import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.models.enumerations.JobType;
    99import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.models.job_advertisements.DTO.JobAdDetailsDTO;
     10import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.models.users.Recruiter;
    1011import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.models.users.User;
    1112
     
    2021public class JobAdvertisement {
    2122
    22     public JobAdvertisement(User recruiter, String title, String description, String industry, int startingSalary, LocalDate activeUntil, JobType jobType, EmploymentStatus employmentStatus) {
     23    public JobAdvertisement(Recruiter recruiter, String title, String description, String industry, int startingSalary, LocalDate activeUntil, JobType jobType, EmploymentStatus employmentStatus) {
    2324        this.recruiter = recruiter;
    2425        this.title = title;
     
    3839
    3940    @ManyToOne
    40     private User recruiter;
     41    private Recruiter recruiter;
    4142
    4243    private String title;
  • jobvista-backend/src/main/java/mk/ukim/finki/predmeti/internettehnologii/jobvistabackend/repositories/RecruiterRepository.java

    r19398ad r28b3398  
    55import org.springframework.data.jpa.repository.JpaRepository;
    66
     7import java.util.Optional;
     8
    79public interface RecruiterRepository extends JpaRepository<Recruiter, Long> {
    8     Recruiter findRecruiterByEmail(String email);
     10    Optional<Recruiter> findRecruiterByEmail(String email);
    911}
  • jobvista-backend/src/main/java/mk/ukim/finki/predmeti/internettehnologii/jobvistabackend/service/impl/JobAdvertisementServiceImpl.java

    r19398ad r28b3398  
    55import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.models.enumerations.JobType;
    66import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.models.job_advertisements.DTO.JobAdDetailsDTO;
     7import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.models.job_advertisements.DTO.JobAdFilterDTO;
    78import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.models.job_advertisements.DTO.JobAdvertisementDTO;
    89import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.models.job_advertisements.JobAdvertisement;
     10import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.models.users.Recruiter;
    911import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.models.users.User;
    1012import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.repositories.JobAdvertisementRepository;
     13import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.repositories.RecruiterRepository;
    1114import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.repositories.UserRepository;
    1215import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.service.intef.JobAdvertisementService;
     
    1518import java.time.LocalDate;
    1619import java.time.LocalDateTime;
     20import java.util.Comparator;
    1721import java.util.List;
    1822
     
    2226    private final UserRepository userRepository;
    2327    private final JobAdvertisementRepository jobAdvertisementRepository;
     28    private final RecruiterRepository recruiterRepository;
    2429
    2530    @Override
    2631    public JobAdDetailsDTO addJobAdvertisement(JobAdvertisementDTO jobAdvertisementDTO) {
    27         User recruiter = userRepository.findByEmail(jobAdvertisementDTO.getEmail()).orElseThrow(() -> new IllegalArgumentException("User not found"));
     32        Recruiter recruiter = recruiterRepository.findRecruiterByEmail(jobAdvertisementDTO.getEmail()).orElseThrow(() -> new IllegalArgumentException("User not found"));
    2833        JobAdvertisement jobAdvertisement = new JobAdvertisement(
    2934                recruiter,
     
    3540                JobType.valueOf(jobAdvertisementDTO.getJobType()),
    3641                EmploymentStatus.valueOf(jobAdvertisementDTO.getEmploymentStatus())
    37                 );
     42        );
    3843        jobAdvertisementRepository.save(jobAdvertisement);
    3944        return JobAdvertisement.mapToJobAdDetailsDTO(jobAdvertisement);
     
    7984
    8085    @Override
     86    public List<JobAdDetailsDTO> filterJobAdvertisements(JobAdFilterDTO jobAdFilterDTO) {
     87        List<JobAdvertisement> filteredJobAds = jobAdvertisementRepository.findAll();
     88        filteredJobAds = filter(filteredJobAds, jobAdFilterDTO);
     89
     90        return filteredJobAds.stream()
     91                .map(JobAdvertisement::mapToJobAdDetailsDTO)
     92                .toList();
     93    }
     94
     95    private List<JobAdvertisement> filter(List<JobAdvertisement> filteredJobAdvertisements, JobAdFilterDTO jobAdFilterDTO) {
     96        return filteredJobAdvertisements.stream()
     97                .filter(jobAd -> jobAd.getTitle().toLowerCase().contains(jobAdFilterDTO.getSearchTerm().toLowerCase()))
     98                .filter(jobAd -> jobAdFilterDTO.getIndustry().equals("all") || jobAd.getIndustry().equals(jobAdFilterDTO.getIndustry()))
     99                .sorted(getComparator(jobAdFilterDTO.getSortOrder()))
     100                .toList();
     101    }
     102
     103    private Comparator<JobAdvertisement> getComparator(String sortOrder) {
     104        return switch (sortOrder) {
     105            case "date_newest" -> Comparator.comparing(JobAdvertisement::getPostedOn).reversed();
     106            case "date_oldest" -> Comparator.comparing(JobAdvertisement::getPostedOn);
     107            case "salary_highest" -> Comparator.comparing(JobAdvertisement::getStartingSalary).reversed();
     108            case "salary_lowest" -> Comparator.comparing(JobAdvertisement::getStartingSalary);
     109            default -> Comparator.comparing(JobAdvertisement::getPostedOn); // Default sorting order
     110        };
     111    }
     112
     113
     114    @Override
    81115    public List<JobAdDetailsDTO> findAllJobAdvertisementsByRecruiterId(Long recruiterId) {
    82116        List<JobAdvertisement> jobAdvertisementList = jobAdvertisementRepository.findAllByRecruiterId(recruiterId);
    83 //        jobAdvertisementList.forEach(jobAdvertisement -> {
    84 //            if (!jobAdvertisement.isJobAdActive() && jobAdvertisement.isActive()) {
    85 //                jobAdvertisement.setActive(false);
    86 //                jobAdvertisementRepository.save(jobAdvertisement);
    87 //            } else if (jobAdvertisement.isJobAdActive() && !jobAdvertisement.isActive()) {
    88 //                jobAdvertisement.setActive(true);
    89 //                jobAdvertisementRepository.save(jobAdvertisement);
    90 //            }
    91 //        });
    92117
    93118        return jobAdvertisementList.stream()
     
    95120                .toList();
    96121    }
     122
     123    @Override
     124    public List<JobAdDetailsDTO> filterJobAdvertisementsByRecruiterId(Long recruiterId, JobAdFilterDTO jobAdFilterDTO) {
     125        List<JobAdvertisement> filteredJobAds = jobAdvertisementRepository.findAllByRecruiterId(recruiterId);
     126        filteredJobAds = filter(filteredJobAds, jobAdFilterDTO);
     127        return filteredJobAds.stream()
     128                .map(JobAdvertisement::mapToJobAdDetailsDTO)
     129                .toList();
     130    }
     131
    97132    @Override
    98133    public JobAdDetailsDTO findJobAdvertisementById(Long id) {
  • jobvista-backend/src/main/java/mk/ukim/finki/predmeti/internettehnologii/jobvistabackend/service/intef/JobAdvertisementService.java

    r19398ad r28b3398  
    22
    33import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.models.job_advertisements.DTO.JobAdDetailsDTO;
     4import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.models.job_advertisements.DTO.JobAdFilterDTO;
    45import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.models.job_advertisements.DTO.JobAdvertisementDTO;
    56import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.models.job_advertisements.JobAdvertisement;
     
    1415
    1516    List<JobAdDetailsDTO> findAllJobAdvertisements();
     17    List<JobAdDetailsDTO> filterJobAdvertisements(JobAdFilterDTO jobAdFilterDTO);
    1618    List<JobAdDetailsDTO> findAllJobAdvertisementsByRecruiterId(Long recruiterId);
     19    List<JobAdDetailsDTO> filterJobAdvertisementsByRecruiterId(Long recruiterId, JobAdFilterDTO jobAdFilterDTO);
    1720    JobAdDetailsDTO findJobAdvertisementById(Long id);
    1821
Note: See TracChangeset for help on using the changeset viewer.