Changeset 28b3398 for jobvista-backend/src/main/java/mk/ukim/finki/predmeti
- Timestamp:
- 06/09/24 14:24:03 (6 months ago)
- Branches:
- main
- Children:
- b248810
- Parents:
- 19398ad
- 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 30 30 http.csrf(AbstractHttpConfigurer::disable) 31 31 .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() 33 35 //.requestMatchers("/api/job-advertisements/**").hasAnyAuthority(Role.ROLE_RECRUITER.name()) 34 36 .anyRequest().authenticated()) -
jobvista-backend/src/main/java/mk/ukim/finki/predmeti/internettehnologii/jobvistabackend/controllers/JobAdvertisementController.java
r19398ad r28b3398 3 3 4 4 import lombok.AllArgsConstructor; 5 import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.models.applications.Application; 6 import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.models.applications.DTO.ApplicationDTO; 7 import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.models.job_advertisements.DTO.JobAdFilterDTO; 5 8 import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.models.job_advertisements.DTO.JobAdvertisementDTO; 6 9 import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.models.job_advertisements.DTO.JobAdDetailsDTO; 7 10 import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.models.job_advertisements.JobAdvertisement; 11 import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.service.intef.ApplicationService; 8 12 import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.service.intef.JobAdvertisementService; 9 13 import org.springframework.http.HttpStatus; 10 14 import org.springframework.http.ResponseEntity; 11 15 import org.springframework.web.bind.annotation.*; 16 import org.springframework.web.multipart.MultipartFile; 12 17 13 18 import java.util.List; … … 20 25 21 26 private final JobAdvertisementService jobAdvertisementService; 27 private final ApplicationService applicationService; 22 28 23 29 @PostMapping("/add") … … 45 51 } 46 52 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 47 59 @GetMapping("/all") 48 60 public ResponseEntity<?> findAllJobAdvertisements() { … … 51 63 } 52 64 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}") 54 72 public ResponseEntity<?> findJobAdvertisementById(@PathVariable Long id) { 55 73 JobAdDetailsDTO jobAdDetailsDTO = jobAdvertisementService.findJobAdvertisementById(id); 56 74 return new ResponseEntity<>(jobAdDetailsDTO, HttpStatus.OK); 57 75 } 76 77 78 58 79 } -
jobvista-backend/src/main/java/mk/ukim/finki/predmeti/internettehnologii/jobvistabackend/models/job_advertisements/JobAdvertisement.java
r19398ad r28b3398 8 8 import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.models.enumerations.JobType; 9 9 import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.models.job_advertisements.DTO.JobAdDetailsDTO; 10 import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.models.users.Recruiter; 10 11 import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.models.users.User; 11 12 … … 20 21 public class JobAdvertisement { 21 22 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) { 23 24 this.recruiter = recruiter; 24 25 this.title = title; … … 38 39 39 40 @ManyToOne 40 private User recruiter;41 private Recruiter recruiter; 41 42 42 43 private String title; -
jobvista-backend/src/main/java/mk/ukim/finki/predmeti/internettehnologii/jobvistabackend/repositories/RecruiterRepository.java
r19398ad r28b3398 5 5 import org.springframework.data.jpa.repository.JpaRepository; 6 6 7 import java.util.Optional; 8 7 9 public interface RecruiterRepository extends JpaRepository<Recruiter, Long> { 8 RecruiterfindRecruiterByEmail(String email);10 Optional<Recruiter> findRecruiterByEmail(String email); 9 11 } -
jobvista-backend/src/main/java/mk/ukim/finki/predmeti/internettehnologii/jobvistabackend/service/impl/JobAdvertisementServiceImpl.java
r19398ad r28b3398 5 5 import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.models.enumerations.JobType; 6 6 import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.models.job_advertisements.DTO.JobAdDetailsDTO; 7 import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.models.job_advertisements.DTO.JobAdFilterDTO; 7 8 import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.models.job_advertisements.DTO.JobAdvertisementDTO; 8 9 import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.models.job_advertisements.JobAdvertisement; 10 import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.models.users.Recruiter; 9 11 import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.models.users.User; 10 12 import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.repositories.JobAdvertisementRepository; 13 import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.repositories.RecruiterRepository; 11 14 import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.repositories.UserRepository; 12 15 import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.service.intef.JobAdvertisementService; … … 15 18 import java.time.LocalDate; 16 19 import java.time.LocalDateTime; 20 import java.util.Comparator; 17 21 import java.util.List; 18 22 … … 22 26 private final UserRepository userRepository; 23 27 private final JobAdvertisementRepository jobAdvertisementRepository; 28 private final RecruiterRepository recruiterRepository; 24 29 25 30 @Override 26 31 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")); 28 33 JobAdvertisement jobAdvertisement = new JobAdvertisement( 29 34 recruiter, … … 35 40 JobType.valueOf(jobAdvertisementDTO.getJobType()), 36 41 EmploymentStatus.valueOf(jobAdvertisementDTO.getEmploymentStatus()) 37 42 ); 38 43 jobAdvertisementRepository.save(jobAdvertisement); 39 44 return JobAdvertisement.mapToJobAdDetailsDTO(jobAdvertisement); … … 79 84 80 85 @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 81 115 public List<JobAdDetailsDTO> findAllJobAdvertisementsByRecruiterId(Long recruiterId) { 82 116 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 // });92 117 93 118 return jobAdvertisementList.stream() … … 95 120 .toList(); 96 121 } 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 97 132 @Override 98 133 public JobAdDetailsDTO findJobAdvertisementById(Long id) { -
jobvista-backend/src/main/java/mk/ukim/finki/predmeti/internettehnologii/jobvistabackend/service/intef/JobAdvertisementService.java
r19398ad r28b3398 2 2 3 3 import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.models.job_advertisements.DTO.JobAdDetailsDTO; 4 import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.models.job_advertisements.DTO.JobAdFilterDTO; 4 5 import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.models.job_advertisements.DTO.JobAdvertisementDTO; 5 6 import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.models.job_advertisements.JobAdvertisement; … … 14 15 15 16 List<JobAdDetailsDTO> findAllJobAdvertisements(); 17 List<JobAdDetailsDTO> filterJobAdvertisements(JobAdFilterDTO jobAdFilterDTO); 16 18 List<JobAdDetailsDTO> findAllJobAdvertisementsByRecruiterId(Long recruiterId); 19 List<JobAdDetailsDTO> filterJobAdvertisementsByRecruiterId(Long recruiterId, JobAdFilterDTO jobAdFilterDTO); 17 20 JobAdDetailsDTO findJobAdvertisementById(Long id); 18 21
Note:
See TracChangeset
for help on using the changeset viewer.