Ignore:
Timestamp:
06/20/24 11:57:13 (5 months ago)
Author:
223021 <daniel.ilievski.2@…>
Branches:
main
Children:
0f0add0
Parents:
befb988
Message:

Did more refactoring

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

Legend:

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

    rbefb988 r08f82ec  
    3131        http.csrf(AbstractHttpConfigurer::disable)
    3232                .authorizeHttpRequests(request -> request
    33                         // TO DO: FIX PERMISSIONS
    34                         .requestMatchers("/api/job-advertisements/**",
    35                                 "/api/job-advertisements/view/**",
     33                        .requestMatchers(
     34                                "/api/auth/**",
     35                                "/api/job-advertisements/**",
     36                                "/api/applications/**",
    3637                                "/api/recruiter/**",
    37                                 "/api/job-seeker/**",
    38                                 "/api/recruiter/{id}/info",
    39                                 "/api/recruiter/{id}/edit-info",
    40                                 "/api/job-advertisements/apply/**",
    41                                 "/api/auth/**",
    42                                 "/api/resume/**",
    43                                 "/api/my-applications/**",
    44                                 "/api/applications/{id}/update",
    45                                 "/api/admin/**").permitAll()
    46 //                        .requestMatchers("/api/recruiter").hasAnyAuthority(Role.ROLE_RECRUITER.name())
     38                                "/api/job-seeker/**"
     39                        ).permitAll()
     40                        .requestMatchers("/api/admin/**").hasAnyAuthority(Role.ROLE_ADMIN.name())
     41                        .requestMatchers("/api/recruiter/{id}/edit-info").hasAnyAuthority(Role.ROLE_RECRUITER.name())
     42                        .requestMatchers("/api/recruiter/submit-logo").hasAnyAuthority(Role.ROLE_RECRUITER.name())
     43                        .requestMatchers("/api/job-seeker/{id}/edit-info").hasAnyAuthority(Role.ROLE_RECRUITER.name())
     44                        .requestMatchers("/api/job-seeker/submit-profile-pic").hasAnyAuthority(Role.ROLE_JOBSEEKER.name())
     45                        .requestMatchers("/api/job-advertisements/add").hasAnyAuthority(Role.ROLE_RECRUITER.name())
     46                        .requestMatchers("/api/job-advertisements/edit/{id}").hasAnyAuthority(Role.ROLE_RECRUITER.name())
     47                        .requestMatchers("/api/job-advertisements/delete/{id}").hasAnyAuthority(Role.ROLE_RECRUITER.name())
     48                        .requestMatchers("/api/applications/{id}/update").hasAnyAuthority(Role.ROLE_RECRUITER.name())
     49                        .requestMatchers("/api/job-advertisements/{advertisement_id}/applications").hasAnyAuthority(Role.ROLE_RECRUITER.name())
     50                        .requestMatchers("/api/applications/submit").hasAnyAuthority(Role.ROLE_JOBSEEKER.name())
     51                        .requestMatchers("/api/my-applications/{id}").hasAnyAuthority(Role.ROLE_JOBSEEKER.name())
    4752                        .anyRequest().authenticated())
    4853                .sessionManagement(manager -> manager.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
  • jobvista-backend/src/main/java/mk/ukim/finki/predmeti/internettehnologii/jobvistabackend/controllers/ApplicationController.java

    rbefb988 r08f82ec  
    4242    }
    4343
    44     @GetMapping("/resume/{fileName:.+}")
    45     public ResponseEntity<Resource> downloadResume(@PathVariable("fileName") String fileName) {
    46         Resource resource = applicationService.loadResumeAsResource(fileName);
     44    @GetMapping("/applications/{id}/download-resume")
     45    public ResponseEntity<Resource> downloadResume(@PathVariable("id") Long applicationId) {
     46        Resource resource = applicationService.loadResumeAsResource(applicationId);
    4747        return ResponseEntity.ok()
    4848                .contentType(MediaType.APPLICATION_PDF)
     
    5151    }
    5252
    53     @PostMapping("/job-advertisements/apply")
     53    @PostMapping("/applications/submit")
    5454    public ResponseEntity<ApplicationDetailsDTO> submitApplication(
    5555            @RequestParam("jobSeekerId") Long jobSeekerId,
     
    6161            @RequestParam("messageToRecruiter") String messageToRecruiter) {
    6262
    63         ApplicationDTO applicationDTO = new ApplicationDTO(jobSeekerId, jobAdId, resumeFile, answerOne, answerTwo, answerThree, messageToRecruiter);
     63        ApplicationDTO applicationDTO = new ApplicationDTO(jobSeekerId, jobAdId,
     64                resumeFile, answerOne, answerTwo, answerThree, messageToRecruiter);
    6465        ApplicationDetailsDTO applicationDetailsDTO = applicationService.submitApplication(applicationDTO);
    6566        return new ResponseEntity<>(applicationDetailsDTO, HttpStatus.OK);
    6667    }
    67 
    6868}
  • jobvista-backend/src/main/java/mk/ukim/finki/predmeti/internettehnologii/jobvistabackend/controllers/JobAdvertisementController.java

    rbefb988 r08f82ec  
    4646
    4747    @GetMapping("/recruiter/{id}")
    48     public ResponseEntity<?> findALlJobAdvertisementsByRecruiterId(@PathVariable Long id) {
     48    public ResponseEntity<?> findAllJobAdvertisementsByRecruiterId(@PathVariable Long id) {
    4949        List<JobAdDetailsDTO> jobAdDetailsDTOS = jobAdvertisementService.findAllJobAdvertisementsByRecruiterId(id);
    5050        return new ResponseEntity<>(jobAdDetailsDTOS, HttpStatus.OK);
  • jobvista-backend/src/main/java/mk/ukim/finki/predmeti/internettehnologii/jobvistabackend/models/applications/Application.java

    rbefb988 r08f82ec  
    3232    private JobAdvertisement jobAdvertisement;
    3333
    34     @Column(name = "resume_file_name", nullable = false)
    35     private String resumeFileName;
     34    @Column(name = "resume_file_name", nullable = true)
     35    private String resumeFilePath;
    3636
    3737    @ElementCollection
     
    4545    private ApplicationStatus status;
    4646
    47     public Application(JobSeeker jobSeeker, JobAdvertisement jobAdvertisement, String resumeFileName, List<String> answers, String message) {
     47    public Application(JobSeeker jobSeeker, JobAdvertisement jobAdvertisement, List<String> answers, String message) {
    4848        this.jobSeeker = jobSeeker;
    4949        this.jobAdvertisement = jobAdvertisement;
    50         this.resumeFileName = resumeFileName;
     50        this.resumeFilePath = "";
    5151        this.questionAnswers = answers;
    5252        this.message = message;
     
    6969                application.getJobAdvertisement().getTitle(),
    7070                application.getQuestionAnswers(),
    71                 application.getResumeFileName(),
     71                application.getResumeFilePath(),
    7272                application.getMessage(),
    7373                application.getSubmittedOn(),
  • jobvista-backend/src/main/java/mk/ukim/finki/predmeti/internettehnologii/jobvistabackend/service/impl/ApplicationServiceImpl.java

    rbefb988 r08f82ec  
    4141    public ApplicationServiceImpl(@Value("${file.upload-dir}") String uploadDir, UserRepository userRepository, ApplicationRepository applicationRepository, JobAdvertisementRepository jobAdvertisementRepository,
    4242                                  JobSeekerRepository jobSeekerRepository) {
    43         this.fileStorageLocation = Paths.get(uploadDir).toAbsolutePath().normalize();
     43        this.fileStorageLocation = Paths.get(uploadDir + "/applications").toAbsolutePath().normalize();
    4444
    4545        try {
     
    5858    public ApplicationDetailsDTO submitApplication(ApplicationDTO applicationDTO) {
    5959
     60        JobSeeker jobSeeker = jobSeekerRepository.findById(applicationDTO.getJobSeekerId())
     61                .orElseThrow(() -> new IllegalArgumentException("User not found."));
     62        JobAdvertisement jobAdvertisement = jobAdvertisementRepository.findById(applicationDTO.getJobAdId())
     63                .orElseThrow(() -> new IllegalArgumentException("Job advertisement not found."));
     64
    6065        if (applicationDTO.getResumeFile().isEmpty()) {
    6166            throw new RuntimeException("Failed to store empty file.");
    6267        }
    63 
    64         Path targetLocation = this.fileStorageLocation.resolve(applicationDTO.getResumeFile().getOriginalFilename());
    65         try {
    66             Files.copy(applicationDTO.getResumeFile().getInputStream(), targetLocation, StandardCopyOption.REPLACE_EXISTING);
    67         } catch (IOException e) {
    68             throw new RuntimeException(e);
    69         }
    70 
    71         JobSeeker jobSeeker = jobSeekerRepository.findById(applicationDTO.getJobSeekerId()).orElseThrow(() -> new IllegalArgumentException("User not found"));
    72         JobAdvertisement jobAdvertisement = jobAdvertisementRepository.findById(applicationDTO.getJobAdId()).orElseThrow(() -> new IllegalArgumentException("Job Ad not found"));
    7368
    7469        List<String> answers = new ArrayList<>();
     
    7772        answers.add(applicationDTO.getAnswerThree());
    7873
    79         Application application = new Application(jobSeeker, jobAdvertisement, applicationDTO.getResumeFile().getOriginalFilename(), answers, applicationDTO.getMessageToRecruiter());
    80         applicationRepository.save(application);
     74        Application application = new Application(jobSeeker, jobAdvertisement,
     75                answers,applicationDTO.getMessageToRecruiter());
     76        application = applicationRepository.save(application);
     77
     78        Path filePath = this.fileStorageLocation.resolve(String.valueOf(application.getId())).resolve("resume");
     79        Path targetLocation = filePath.resolve(applicationDTO.getResumeFile().getOriginalFilename());
     80
     81        try {
     82            Files.createDirectories(filePath);
     83            Files.copy(applicationDTO.getResumeFile().getInputStream(), targetLocation);
     84        } catch (IOException e) {
     85            throw new RuntimeException(e);
     86        }
     87
     88        String relativePath = Paths.get("uploads","applications",String.valueOf(application.getId()),
     89                "resume", applicationDTO.getResumeFile().getOriginalFilename()).toString();
     90        application.setResumeFilePath(relativePath);
     91        application = applicationRepository.save(application);
     92
    8193        return Application.mapToApplicationDetailsDTO(application);
    8294    }
     
    95107
    96108    @Override
    97     public Resource loadResumeAsResource(String fileName) {
     109    public Resource loadResumeAsResource(Long applicationId) {
     110        Application application = applicationRepository.findById(applicationId).
     111                orElseThrow(() -> new IllegalArgumentException("Application not found"));
     112
     113        String relativeFilePath = application.getResumeFilePath();
     114        Path filePath = fileStorageLocation.getParent().getParent().resolve(relativeFilePath).normalize();
     115
    98116        try {
    99             Path filePath = fileStorageLocation.resolve(fileName).normalize();
    100117            Resource resource = new UrlResource(filePath.toUri());
    101118            if (resource.exists()) {
    102119                return resource;
    103120            } else {
    104                 throw new RuntimeException("File not found " + fileName);
     121                throw new RuntimeException("File not found: " + relativeFilePath);
    105122            }
    106123        } catch (IOException ex) {
    107             throw new RuntimeException("File not found " + fileName, ex);
     124            throw new RuntimeException("File path is invalid: " + relativeFilePath, ex);
    108125        }
    109126    }
  • jobvista-backend/src/main/java/mk/ukim/finki/predmeti/internettehnologii/jobvistabackend/service/impl/JobAdvertisementServiceImpl.java

    rbefb988 r08f82ec  
    1717
    1818import java.time.LocalDate;
    19 import java.time.LocalDateTime;
    2019import java.util.Comparator;
    2120import java.util.List;
     
    2423@RequiredArgsConstructor
    2524public class JobAdvertisementServiceImpl implements JobAdvertisementService {
    26     private final UserRepository userRepository;
    2725    private final JobAdvertisementRepository jobAdvertisementRepository;
    2826    private final RecruiterRepository recruiterRepository;
     
    3028    @Override
    3129    public JobAdDetailsDTO addJobAdvertisement(JobAdvertisementDTO jobAdvertisementDTO) {
    32         Recruiter recruiter = recruiterRepository.findById(jobAdvertisementDTO.getId()).orElseThrow(() -> new IllegalArgumentException("User not found"));
     30        Recruiter recruiter = recruiterRepository.findById(jobAdvertisementDTO.getId())
     31                .orElseThrow(() -> new IllegalArgumentException("User not found"));
    3332        JobAdvertisement jobAdvertisement = new JobAdvertisement(
    3433                recruiter,
     
    4746    @Override
    4847    public JobAdDetailsDTO editJobAdvertisement(Long id, JobAdvertisementDTO jobAdvertisementDTO) {
    49         JobAdvertisement jobAdvertisement = jobAdvertisementRepository.findById(id).orElseThrow(() -> new IllegalArgumentException("Job Advertisement not found"));
     48        JobAdvertisement jobAdvertisement = jobAdvertisementRepository.findById(id)
     49                .orElseThrow(() -> new IllegalArgumentException("Job Advertisement not found"));
    5050        jobAdvertisement.setTitle(jobAdvertisementDTO.getTitle());
    5151        jobAdvertisement.setDescription(jobAdvertisementDTO.getDescription());
  • jobvista-backend/src/main/java/mk/ukim/finki/predmeti/internettehnologii/jobvistabackend/service/impl/RecruiterServiceImpl.java

    rbefb988 r08f82ec  
    3232        this.recruiterRepository = recruiterRepository;
    3333
    34         this.logoStorageLocation = Paths.get(uploadDir + "/logo").toAbsolutePath().normalize();
     34        this.logoStorageLocation = Paths.get(uploadDir + "/recruiters").toAbsolutePath().normalize();
    3535        try {
    3636            Files.createDirectories(this.logoStorageLocation);
     
    7070    public void submitLogo(Long recruiterId, MultipartFile logoFile) {
    7171
    72         Path recruiterLogoDir = this.logoStorageLocation.resolve(String.valueOf(recruiterId));
     72        Path recruiterLogoDir = this.logoStorageLocation.resolve(String.valueOf(recruiterId)).resolve("logos");
    7373        try {
    7474            Files.createDirectories(recruiterLogoDir);
     
    8282                Recruiter recruiter = recruiterRepository.findById(recruiterId)
    8383                        .orElseThrow(() -> new RuntimeException("Recruiter not found"));
    84                 String relativePath = Paths.get("uploads", "logo", String.valueOf(recruiterId), originalFilename).toString();
     84                String relativePath = Paths.get("uploads","recruiters", String.valueOf(recruiterId), "logos", originalFilename).toString();
    8585                recruiter.setLogoFilePath(relativePath);
    8686                recruiterRepository.save(recruiter);
  • jobvista-backend/src/main/java/mk/ukim/finki/predmeti/internettehnologii/jobvistabackend/service/intef/ApplicationService.java

    rbefb988 r08f82ec  
    1414    List<ApplicationDetailsDTO> findAllByJobAdvertisementId(Long jobId);
    1515    List<ApplicationDetailsDTO> findAllByJobSeekerId(Long jobSeekerId);
    16     Resource loadResumeAsResource(String fileName);
     16    Resource loadResumeAsResource(Long applicationId);
    1717    ApplicationStatusDTO updateApplicationStatus(Long id, String status);
    1818}
Note: See TracChangeset for help on using the changeset viewer.