Changeset 08f82ec for jobvista-backend/src/main/java/mk/ukim/finki/predmeti/internettehnologii/jobvistabackend/service/impl
- Timestamp:
- 06/20/24 11:57:13 (2 weeks ago)
- Branches:
- main
- Children:
- 0f0add0
- Parents:
- befb988
- Location:
- jobvista-backend/src/main/java/mk/ukim/finki/predmeti/internettehnologii/jobvistabackend/service/impl
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
jobvista-backend/src/main/java/mk/ukim/finki/predmeti/internettehnologii/jobvistabackend/service/impl/ApplicationServiceImpl.java
rbefb988 r08f82ec 41 41 public ApplicationServiceImpl(@Value("${file.upload-dir}") String uploadDir, UserRepository userRepository, ApplicationRepository applicationRepository, JobAdvertisementRepository jobAdvertisementRepository, 42 42 JobSeekerRepository jobSeekerRepository) { 43 this.fileStorageLocation = Paths.get(uploadDir ).toAbsolutePath().normalize();43 this.fileStorageLocation = Paths.get(uploadDir + "/applications").toAbsolutePath().normalize(); 44 44 45 45 try { … … 58 58 public ApplicationDetailsDTO submitApplication(ApplicationDTO applicationDTO) { 59 59 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 60 65 if (applicationDTO.getResumeFile().isEmpty()) { 61 66 throw new RuntimeException("Failed to store empty file."); 62 67 } 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"));73 68 74 69 List<String> answers = new ArrayList<>(); … … 77 72 answers.add(applicationDTO.getAnswerThree()); 78 73 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 81 93 return Application.mapToApplicationDetailsDTO(application); 82 94 } … … 95 107 96 108 @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 98 116 try { 99 Path filePath = fileStorageLocation.resolve(fileName).normalize();100 117 Resource resource = new UrlResource(filePath.toUri()); 101 118 if (resource.exists()) { 102 119 return resource; 103 120 } else { 104 throw new RuntimeException("File not found " + fileName);121 throw new RuntimeException("File not found: " + relativeFilePath); 105 122 } 106 123 } catch (IOException ex) { 107 throw new RuntimeException("File not found " + fileName, ex);124 throw new RuntimeException("File path is invalid: " + relativeFilePath, ex); 108 125 } 109 126 } -
jobvista-backend/src/main/java/mk/ukim/finki/predmeti/internettehnologii/jobvistabackend/service/impl/JobAdvertisementServiceImpl.java
rbefb988 r08f82ec 17 17 18 18 import java.time.LocalDate; 19 import java.time.LocalDateTime;20 19 import java.util.Comparator; 21 20 import java.util.List; … … 24 23 @RequiredArgsConstructor 25 24 public class JobAdvertisementServiceImpl implements JobAdvertisementService { 26 private final UserRepository userRepository;27 25 private final JobAdvertisementRepository jobAdvertisementRepository; 28 26 private final RecruiterRepository recruiterRepository; … … 30 28 @Override 31 29 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")); 33 32 JobAdvertisement jobAdvertisement = new JobAdvertisement( 34 33 recruiter, … … 47 46 @Override 48 47 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")); 50 50 jobAdvertisement.setTitle(jobAdvertisementDTO.getTitle()); 51 51 jobAdvertisement.setDescription(jobAdvertisementDTO.getDescription()); -
jobvista-backend/src/main/java/mk/ukim/finki/predmeti/internettehnologii/jobvistabackend/service/impl/RecruiterServiceImpl.java
rbefb988 r08f82ec 32 32 this.recruiterRepository = recruiterRepository; 33 33 34 this.logoStorageLocation = Paths.get(uploadDir + "/ logo").toAbsolutePath().normalize();34 this.logoStorageLocation = Paths.get(uploadDir + "/recruiters").toAbsolutePath().normalize(); 35 35 try { 36 36 Files.createDirectories(this.logoStorageLocation); … … 70 70 public void submitLogo(Long recruiterId, MultipartFile logoFile) { 71 71 72 Path recruiterLogoDir = this.logoStorageLocation.resolve(String.valueOf(recruiterId)) ;72 Path recruiterLogoDir = this.logoStorageLocation.resolve(String.valueOf(recruiterId)).resolve("logos"); 73 73 try { 74 74 Files.createDirectories(recruiterLogoDir); … … 82 82 Recruiter recruiter = recruiterRepository.findById(recruiterId) 83 83 .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(); 85 85 recruiter.setLogoFilePath(relativePath); 86 86 recruiterRepository.save(recruiter);
Note:
See TracChangeset
for help on using the changeset viewer.