Ignore:
Timestamp:
06/17/24 21:59:14 (5 months ago)
Author:
223021 <daniel.ilievski.2@…>
Branches:
main
Children:
08f82ec
Parents:
b248810
Message:

Added an edit profile page for both job seekers and recruiters, where they can upload profile pictures/company logos and edit their profile data. Added profile page specifically for recruiters. Refactored existing code.

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

Legend:

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

    rb248810 rbefb988  
    22
    33import lombok.RequiredArgsConstructor;
     4import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.models.enumerations.Role;
    45import org.springframework.context.annotation.Bean;
    56import org.springframework.context.annotation.Configuration;
     
    3132                .authorizeHttpRequests(request -> request
    3233                        // 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", "/api/admin/**").permitAll()
    35                         //.requestMatchers("/api/job-advertisements/**").hasAnyAuthority(Role.ROLE_RECRUITER.name())
     34                        .requestMatchers("/api/job-advertisements/**",
     35                                "/api/job-advertisements/view/**",
     36                                "/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())
    3647                        .anyRequest().authenticated())
    3748                .sessionManagement(manager -> manager.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
  • jobvista-backend/src/main/java/mk/ukim/finki/predmeti/internettehnologii/jobvistabackend/controllers/AdminController.java

    rb248810 rbefb988  
    22
    33import lombok.RequiredArgsConstructor;
     4import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.models.users.DTO.RecruiterAdminDetailsDTO;
    45import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.models.users.DTO.RecruiterDetailsDTO;
    56import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.service.intef.AdminService;
     
    2021    @PostMapping("/change-access/{recruiter_id}")
    2122    public ResponseEntity<?> changeAccess(@PathVariable("recruiter_id") Long recruiterId, @RequestBody boolean access) {
    22         RecruiterDetailsDTO recruiterDetailsDTO = adminService.changeAccess(recruiterId, access);
    23         return new ResponseEntity<>(recruiterDetailsDTO, HttpStatus.OK);
     23        RecruiterAdminDetailsDTO recruiterAdminDetailsDTO = adminService.changeAccess(recruiterId, access);
     24        return new ResponseEntity<>(recruiterAdminDetailsDTO, HttpStatus.OK);
    2425    }
    2526
    2627    @GetMapping("/recruiters")
    2728    public ResponseEntity<?> findAllRecruiters() {
    28         List<RecruiterDetailsDTO> recruiterDetailsDTOList = adminService.findAllRecruiters();
    29         return new ResponseEntity<>(recruiterDetailsDTOList, HttpStatus.OK);
     29        List<RecruiterAdminDetailsDTO> recruiterAdminDetailsDTOList = adminService.findAllRecruiters();
     30        return new ResponseEntity<>(recruiterAdminDetailsDTOList, HttpStatus.OK);
    3031    }
    3132}
  • jobvista-backend/src/main/java/mk/ukim/finki/predmeti/internettehnologii/jobvistabackend/controllers/JobSeekerController.java

    rb248810 rbefb988  
    33
    44import lombok.AllArgsConstructor;
    5 import org.springframework.web.bind.annotation.CrossOrigin;
    6 import org.springframework.web.bind.annotation.RequestMapping;
    7 import org.springframework.web.bind.annotation.RestController;
     5import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.models.users.DTO.JobSeekerEditDetailsDTO;
     6import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.models.users.DTO.RecruiterEditDetailsDTO;
     7import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.service.intef.JobSeekerService;
     8import org.springframework.core.io.Resource;
     9import org.springframework.http.HttpHeaders;
     10import org.springframework.http.HttpStatus;
     11import org.springframework.http.MediaType;
     12import org.springframework.http.ResponseEntity;
     13import org.springframework.web.bind.annotation.*;
     14import org.springframework.web.multipart.MultipartFile;
    815
    916@RestController
     
    1219@CrossOrigin(origins = "*")
    1320public class JobSeekerController {
     21    private final JobSeekerService jobSeekerService;
     22
     23    @GetMapping("/{id}/edit-info")
     24    public ResponseEntity<?> getJobSeekerEditDetailsById(@PathVariable("id") Long id) {
     25        JobSeekerEditDetailsDTO jobSeekerEditDetailsDTO = jobSeekerService.getJobSeekerEditDetailsById(id);
     26        return new ResponseEntity<>(jobSeekerEditDetailsDTO, HttpStatus.OK);
     27    }
     28
     29    @PostMapping("/{id}/edit-info")
     30    public ResponseEntity<?> editRecruiterDetailsById(@PathVariable("id") Long id, @RequestBody JobSeekerEditDetailsDTO jobSeekerEditDetailsDTO) {
     31        JobSeekerEditDetailsDTO jobSeekerEditDetailsDTOresp = jobSeekerService.editJobSeekerDetailsById(id, jobSeekerEditDetailsDTO);
     32        return new ResponseEntity<>(jobSeekerEditDetailsDTOresp, HttpStatus.OK);
     33    }
     34
     35    @PostMapping("/submit-profile-pic")
     36    public ResponseEntity<?> submitJobSeekerProfilePic(
     37            @RequestParam("jobSeekerId") Long jobSeekerId,
     38            @RequestParam("profilePicFile") MultipartFile profilePicFile) {
     39        jobSeekerService.submitProfilePic(jobSeekerId, profilePicFile);
     40        return new ResponseEntity<>(HttpStatus.OK);
     41    }
     42
     43    @GetMapping("/{id}/download-profile-pic")
     44    public ResponseEntity<?> downloadJobSeekerProfilePic(@PathVariable("id") Long id) {
     45        Resource resource = jobSeekerService.loadProfilePicAsResource(id);
     46        return ResponseEntity.ok()
     47                .contentType(MediaType.IMAGE_JPEG)
     48                .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + resource.getFilename() + "\"")
     49                .body(resource);
     50    }
    1451}
  • jobvista-backend/src/main/java/mk/ukim/finki/predmeti/internettehnologii/jobvistabackend/controllers/RecruiterController.java

    rb248810 rbefb988  
    33import lombok.AllArgsConstructor;
    44import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.models.users.DTO.RecruiterDetailsDTO;
     5import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.models.users.DTO.RecruiterEditDetailsDTO;
    56import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.service.intef.RecruiterService;
     7import org.springframework.core.io.Resource;
     8import org.springframework.http.HttpHeaders;
    69import org.springframework.http.HttpStatus;
     10import org.springframework.http.MediaType;
    711import org.springframework.http.ResponseEntity;
    812import org.springframework.web.bind.annotation.*;
     13import org.springframework.web.multipart.MultipartFile;
    914
    1015@RestController
     
    1621    private final RecruiterService recruiterService;
    1722
    18     @GetMapping("/info/{id}")
     23    @GetMapping("/{id}/info")
    1924    public ResponseEntity<?> getRecruiterDetailsById(@PathVariable("id") Long id) {
    2025        RecruiterDetailsDTO recruiterDetailsDTO = recruiterService.getRecruiterDetailsById(id);
    2126        return new ResponseEntity<>(recruiterDetailsDTO, HttpStatus.OK);
    2227    }
     28
     29    @GetMapping("/{id}/edit-info")
     30    public ResponseEntity<?> getRecruiterEditDetailsById(@PathVariable("id") Long id) {
     31        RecruiterEditDetailsDTO recruiterEditDetailsDTO = recruiterService.getRecruiterEditDetailsById(id);
     32        return new ResponseEntity<>(recruiterEditDetailsDTO, HttpStatus.OK);
     33    }
     34
     35    @PostMapping("/{id}/edit-info")
     36    public ResponseEntity<?> editRecruiterDetailsById(@PathVariable("id") Long id, @RequestBody RecruiterEditDetailsDTO recruiterEditDetailsDTO) {
     37        RecruiterEditDetailsDTO recruiterEditDetailsDTOresp = recruiterService.editRecruiterDetailsById(id, recruiterEditDetailsDTO);
     38        return new ResponseEntity<>(recruiterEditDetailsDTOresp, HttpStatus.OK);
     39    }
     40
     41    @PostMapping("/submit-logo")
     42    public ResponseEntity<?> submitRecruiterLogo(
     43            @RequestParam("recruiterId") Long recruiterId,
     44            @RequestParam("logoFile") MultipartFile logoFile) {
     45        recruiterService.submitLogo(recruiterId, logoFile);
     46        return new ResponseEntity<>(HttpStatus.OK);
     47    }
     48
     49    @GetMapping("/{id}/download-logo")
     50    public ResponseEntity<?> downloadRecruiterLogo(@PathVariable("id") Long id) {
     51        Resource resource = recruiterService.loadLogoAsResource(id);
     52        return ResponseEntity.ok()
     53                .contentType(MediaType.IMAGE_JPEG)
     54                .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + resource.getFilename() + "\"")
     55                .body(resource);
     56    }
    2357}
  • jobvista-backend/src/main/java/mk/ukim/finki/predmeti/internettehnologii/jobvistabackend/models/applications/Application.java

    rb248810 rbefb988  
    6262                application.getJobSeeker().getEmail(),
    6363                application.getJobSeeker().getPhoneNumber(),
     64                application.getJobAdvertisement().getRecruiter().getId(),
    6465                application.getJobAdvertisement().getRecruiter().getName(),
    65                 application.getJobAdvertisement().getRecruiter().getEmail(),
    66                 application.getJobAdvertisement().getRecruiter().getPhoneNumber(),
     66                application.getJobAdvertisement().getRecruiter().getContactEmailAddress(),
     67                application.getJobAdvertisement().getRecruiter().getContactPhoneNumber(),
    6768                application.getJobAdvertisement().getId(),
    6869                application.getJobAdvertisement().getTitle(),
  • jobvista-backend/src/main/java/mk/ukim/finki/predmeti/internettehnologii/jobvistabackend/models/applications/DTO/ApplicationDetailsDTO.java

    rb248810 rbefb988  
    1818    private String jobSeekerEmail;
    1919    private String jobSeekerPhoneNumber;
     20    private Long recruiterId;
    2021    private String recruiterName;
    2122    private String recruiterEmail;
  • jobvista-backend/src/main/java/mk/ukim/finki/predmeti/internettehnologii/jobvistabackend/models/job_advertisements/DTO/JobAdvertisementDTO.java

    rb248810 rbefb988  
    1111@NoArgsConstructor
    1212public class JobAdvertisementDTO {
    13     private String email;
     13    private Long id;
    1414    private String title;
    1515    private String description;
  • jobvista-backend/src/main/java/mk/ukim/finki/predmeti/internettehnologii/jobvistabackend/models/users/DTO/RecruiterDetailsDTO.java

    rb248810 rbefb988  
    1111@NoArgsConstructor
    1212public class RecruiterDetailsDTO {
    13     private Long id;
    14     private String email;
    1513    private String companyName;
    1614    private String companyDescription;
    17     private String phoneNumber;
    18     private boolean hasAccess;
    19     private LocalDateTime registeredOn;
     15    private String contactEmail;
     16    private String contactPhoneNumber;
     17    private String receptionist;
    2018}
  • jobvista-backend/src/main/java/mk/ukim/finki/predmeti/internettehnologii/jobvistabackend/models/users/JobSeeker.java

    rb248810 rbefb988  
    88import lombok.NoArgsConstructor;
    99import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.models.enumerations.Role;
     10
     11import java.nio.file.Paths;
    1012
    1113@Entity
     
    2224        this.lastName = lastName;
    2325        this.phoneNumber = phoneNumber;
     26
     27        String relativeProfilePicFilePath = Paths.get("uploads", "job-seekers", "profile-pics", "default-profile-pic.png").toString();
     28        this.profilePicFilePath = relativeProfilePicFilePath;
     29
    2430        this.role = Role.ROLE_JOBSEEKER;
    2531    }
     
    3440    private String phoneNumber;
    3541
     42    private String profilePicFilePath;
     43
    3644    @Override
    3745    public String getName() {
  • jobvista-backend/src/main/java/mk/ukim/finki/predmeti/internettehnologii/jobvistabackend/models/users/Recruiter.java

    rb248810 rbefb988  
    99import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.models.enumerations.Role;
    1010
     11import java.nio.file.Paths;
     12
    1113@Entity
    1214@Data
    1315@NoArgsConstructor
    14 @AllArgsConstructor
    1516@Table(name = "recruiters")
    1617public class Recruiter extends User {
     
    2122        this.companyName = companyName;
    2223        this.companyDescription = "";
    23         this.phoneNumber = phoneNumber;
     24        this.contactEmailAddress = email;
     25        this.contactPhoneNumber = phoneNumber;
     26        this.receptionist = "";
     27
     28        String relativeLogoFilePath = Paths.get("uploads", "logo", "default-company-logo.png").toString();
     29        this.logoFilePath = relativeLogoFilePath;
    2430        this.role = Role.ROLE_RECRUITER;
    2531    }
     
    3137    private String companyDescription;
    3238
    33     @Column(name = "phone_number")
    34     private String phoneNumber;
     39    private String contactEmailAddress;
     40
     41    private String contactPhoneNumber;
     42
     43    private String receptionist;
     44
     45    private String logoFilePath;
    3546
    3647    @Override
  • jobvista-backend/src/main/java/mk/ukim/finki/predmeti/internettehnologii/jobvistabackend/models/users/mappers/JobSeekerMapper.java

    rb248810 rbefb988  
    22
    33import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.models.users.DTO.JobSeekerDTO;
     4import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.models.users.DTO.JobSeekerEditDetailsDTO;
     5import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.models.users.DTO.RecruiterEditDetailsDTO;
    46import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.models.users.JobSeeker;
     7import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.models.users.Recruiter;
    58
    69public class JobSeekerMapper {
     
    2629    }
    2730
     31    public static JobSeekerEditDetailsDTO mapToJobSeekerEditDetailsDTO(JobSeeker jobSeeker) {
     32        return new JobSeekerEditDetailsDTO(
     33                jobSeeker.getEmail(),
     34                jobSeeker.getFirstName(),
     35                jobSeeker.getLastName(),
     36                jobSeeker.getPhoneNumber()
     37        );
     38    }
     39
    2840}
  • jobvista-backend/src/main/java/mk/ukim/finki/predmeti/internettehnologii/jobvistabackend/models/users/mappers/RecruiterMapper.java

    rb248810 rbefb988  
    11package mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.models.users.mappers;
    22
     3import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.models.users.DTO.RecruiterAdminDetailsDTO;
    34import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.models.users.DTO.RecruiterDTO;
    45import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.models.users.DTO.RecruiterDetailsDTO;
     6import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.models.users.DTO.RecruiterEditDetailsDTO;
    57import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.models.users.Recruiter;
    68
     
    1214                recruiter.getPassword(),
    1315                recruiter.getCompanyName(),
    14                 recruiter.getPhoneNumber()
     16                recruiter.getContactPhoneNumber()
    1517        );
    1618    }
     
    1820    public static RecruiterDetailsDTO mapToRecruiterDetailsDTO(Recruiter recruiter) {
    1921        return new RecruiterDetailsDTO(
     22                recruiter.getCompanyName(),
     23                recruiter.getCompanyDescription(),
     24                recruiter.getContactEmailAddress(),
     25                recruiter.getContactPhoneNumber(),
     26                recruiter.getReceptionist()
     27        );
     28    }
     29    public static RecruiterEditDetailsDTO mapToRecruiterEditDetailsDTO(Recruiter recruiter) {
     30        return new RecruiterEditDetailsDTO(
     31                recruiter.getEmail(),
     32                recruiter.getCompanyName(),
     33                recruiter.getCompanyDescription(),
     34                recruiter.getContactEmailAddress(),
     35                recruiter.getContactPhoneNumber(),
     36                recruiter.getReceptionist()
     37        );
     38    }
     39
     40    public static RecruiterAdminDetailsDTO mapToRecruiterAdminDetailsDTO(Recruiter recruiter) {
     41        return new RecruiterAdminDetailsDTO(
    2042                recruiter.getId(),
    2143                recruiter.getEmail(),
    2244                recruiter.getCompanyName(),
    2345                recruiter.getCompanyDescription(),
    24                 recruiter.getPhoneNumber(),
     46                recruiter.getContactEmailAddress(),
     47                recruiter.getContactPhoneNumber(),
     48                recruiter.getReceptionist(),
    2549                recruiter.isHasAccess(),
    2650                recruiter.getRegisteredOn()
     
    3660        );
    3761    }
     62
    3863//    Using MapStruct:
    3964//    RecruiterMapper INSTANCE = Mappers.getMapper(RecruiterMapper.class);
  • jobvista-backend/src/main/java/mk/ukim/finki/predmeti/internettehnologii/jobvistabackend/service/impl/AdminServiceImpl.java

    rb248810 rbefb988  
    33import lombok.AllArgsConstructor;
    44import lombok.RequiredArgsConstructor;
     5import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.models.users.DTO.RecruiterAdminDetailsDTO;
    56import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.models.users.DTO.RecruiterDetailsDTO;
    67import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.models.users.Recruiter;
     
    2021
    2122    @Override
    22     public RecruiterDetailsDTO changeAccess(long recruiterId, boolean access) {
     23    public RecruiterAdminDetailsDTO changeAccess(long recruiterId, boolean access) {
    2324        Recruiter recruiter = recruiterRepository.findById(recruiterId).orElse(null);
    2425        if (recruiter != null) {
    2526            recruiter.setHasAccess(access);
    2627            recruiterRepository.save(recruiter);
    27             return RecruiterMapper.mapToRecruiterDetailsDTO(recruiter);
     28            return RecruiterMapper.mapToRecruiterAdminDetailsDTO(recruiter);
    2829        }
    2930        return null;
     
    3233
    3334    @Override
    34     public List<RecruiterDetailsDTO> findAllRecruiters() {
     35    public List<RecruiterAdminDetailsDTO> findAllRecruiters() {
    3536        List<Recruiter> recruiterList = recruiterRepository.findAll();
    36         return recruiterList.stream().map(RecruiterMapper::mapToRecruiterDetailsDTO).toList();
     37        return recruiterList.stream().map(RecruiterMapper::mapToRecruiterAdminDetailsDTO).toList();
    3738    }
    3839}
  • jobvista-backend/src/main/java/mk/ukim/finki/predmeti/internettehnologii/jobvistabackend/service/impl/JobAdvertisementServiceImpl.java

    rb248810 rbefb988  
    3030    @Override
    3131    public JobAdDetailsDTO addJobAdvertisement(JobAdvertisementDTO jobAdvertisementDTO) {
    32         Recruiter recruiter = recruiterRepository.findRecruiterByEmail(jobAdvertisementDTO.getEmail()).orElseThrow(() -> new IllegalArgumentException("User not found"));
     32        Recruiter recruiter = recruiterRepository.findById(jobAdvertisementDTO.getId()).orElseThrow(() -> new IllegalArgumentException("User not found"));
    3333        JobAdvertisement jobAdvertisement = new JobAdvertisement(
    3434                recruiter,
  • jobvista-backend/src/main/java/mk/ukim/finki/predmeti/internettehnologii/jobvistabackend/service/impl/JwtServiceImpl.java

    rb248810 rbefb988  
    2525                .claim("role", user.getRole())
    2626                .claim("access", user.isHasAccess())
     27                .claim("id", user.getId())
    2728                .setIssuedAt(new Date())
    2829                .setExpiration(new Date(System.currentTimeMillis() + 1000 * 60 * 60 * 24))
  • jobvista-backend/src/main/java/mk/ukim/finki/predmeti/internettehnologii/jobvistabackend/service/impl/RecruiterServiceImpl.java

    rb248810 rbefb988  
    33import lombok.RequiredArgsConstructor;
    44import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.models.users.DTO.RecruiterDetailsDTO;
     5import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.models.users.DTO.RecruiterEditDetailsDTO;
    56import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.models.users.Recruiter;
    67import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.models.users.mappers.RecruiterMapper;
    78import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.repositories.RecruiterRepository;
    89import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.service.intef.RecruiterService;
     10import org.springframework.beans.factory.annotation.Autowired;
     11import org.springframework.beans.factory.annotation.Value;
     12import org.springframework.core.io.Resource;
     13import org.springframework.core.io.UrlResource;
    914import org.springframework.stereotype.Service;
     15import org.springframework.web.multipart.MultipartFile;
     16
     17import java.io.IOException;
     18import java.nio.file.Files;
     19import java.nio.file.Path;
     20import java.nio.file.Paths;
     21import java.nio.file.StandardCopyOption;
    1022
    1123@Service
     
    1426
    1527    private final RecruiterRepository recruiterRepository;
     28    private final Path logoStorageLocation;
     29
     30    @Autowired
     31    RecruiterServiceImpl(@Value("./uploads") String uploadDir, RecruiterRepository recruiterRepository) {
     32        this.recruiterRepository = recruiterRepository;
     33
     34        this.logoStorageLocation = Paths.get(uploadDir + "/logo").toAbsolutePath().normalize();
     35        try {
     36            Files.createDirectories(this.logoStorageLocation);
     37        } catch (IOException ex) {
     38            throw new RuntimeException("Could not create the directory where the uploaded files will be stored.", ex);
     39        }
     40    }
     41
     42
     43    @Override
     44    public RecruiterEditDetailsDTO editRecruiterDetailsById(Long recruiterId, RecruiterEditDetailsDTO recruiterEditDetailsDTO) {
     45        Recruiter recruiter = recruiterRepository.findById(recruiterId).orElse(null);
     46        recruiter.setEmail(recruiterEditDetailsDTO.getEmail());
     47        recruiter.setCompanyName(recruiterEditDetailsDTO.getCompanyName());
     48        recruiter.setCompanyDescription(recruiterEditDetailsDTO.getCompanyDescription());
     49        recruiter.setContactEmailAddress(recruiterEditDetailsDTO.getContactEmail());
     50        recruiter.setContactPhoneNumber(recruiterEditDetailsDTO.getContactPhoneNumber());
     51        recruiter.setReceptionist(recruiterEditDetailsDTO.getReceptionist());
     52        recruiterRepository.save(recruiter);
     53        return RecruiterMapper.mapToRecruiterEditDetailsDTO(recruiter);
     54    }
     55
     56    @Override
     57    public RecruiterEditDetailsDTO getRecruiterEditDetailsById(Long recruiterId) {
     58        Recruiter recruiter = recruiterRepository.findById(recruiterId).orElse(null);
     59        return RecruiterMapper.mapToRecruiterEditDetailsDTO(recruiter);
     60    }
     61
    1662
    1763    @Override
     
    2066        return RecruiterMapper.mapToRecruiterDetailsDTO(recruiter);
    2167    }
     68
     69    @Override
     70    public void submitLogo(Long recruiterId, MultipartFile logoFile) {
     71
     72        Path recruiterLogoDir = this.logoStorageLocation.resolve(String.valueOf(recruiterId));
     73        try {
     74            Files.createDirectories(recruiterLogoDir);
     75            String originalFilename = logoFile.getOriginalFilename();
     76
     77            if (originalFilename != null) {
     78                Path targetLocation = recruiterLogoDir.resolve(originalFilename);
     79
     80                Files.copy(logoFile.getInputStream(), targetLocation, StandardCopyOption.REPLACE_EXISTING);
     81
     82                Recruiter recruiter = recruiterRepository.findById(recruiterId)
     83                        .orElseThrow(() -> new RuntimeException("Recruiter not found"));
     84                String relativePath = Paths.get("uploads", "logo", String.valueOf(recruiterId), originalFilename).toString();
     85                recruiter.setLogoFilePath(relativePath);
     86                recruiterRepository.save(recruiter);
     87            }
     88
     89        } catch (IOException ex) {
     90            throw new RuntimeException("Could not store file. Please try again!", ex);
     91        }
     92
     93     
     94    }
     95
     96    public Resource loadLogoAsResource(Long recruiterId) {
     97        Recruiter recruiter = recruiterRepository.findById(recruiterId)
     98                .orElseThrow(() -> new RuntimeException("Recruiter not found"));
     99
     100        try {
     101            String relativeLogoPath = recruiter.getLogoFilePath();
     102            Path logoPath = this.logoStorageLocation.getParent().getParent().resolve(relativeLogoPath);
     103            Resource resource = new UrlResource(logoPath.toUri());
     104            if (resource.exists()) {
     105                return resource;
     106            } else {
     107                throw new RuntimeException("File not found " + logoPath);
     108            }
     109        } catch (IOException ex) {
     110            throw new RuntimeException("File not found " + ex);
     111        }
     112
     113    }
     114
    22115}
  • jobvista-backend/src/main/java/mk/ukim/finki/predmeti/internettehnologii/jobvistabackend/service/intef/AdminService.java

    rb248810 rbefb988  
    11package mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.service.intef;
    22
     3import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.models.users.DTO.RecruiterAdminDetailsDTO;
    34import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.models.users.DTO.RecruiterDetailsDTO;
    45
     
    67
    78public interface AdminService {
    8     RecruiterDetailsDTO changeAccess(long recruiterId, boolean access);
    9     List<RecruiterDetailsDTO> findAllRecruiters();
     9    RecruiterAdminDetailsDTO changeAccess(long recruiterId, boolean access);
     10    List<RecruiterAdminDetailsDTO> findAllRecruiters();
    1011}
  • jobvista-backend/src/main/java/mk/ukim/finki/predmeti/internettehnologii/jobvistabackend/service/intef/RecruiterService.java

    rb248810 rbefb988  
    22
    33import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.models.users.DTO.RecruiterDetailsDTO;
    4 import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.models.users.Recruiter;
     4import mk.ukim.finki.predmeti.internettehnologii.jobvistabackend.models.users.DTO.RecruiterEditDetailsDTO;
     5import org.springframework.core.io.Resource;
     6import org.springframework.web.multipart.MultipartFile;
    57
    68public interface RecruiterService {
    79    RecruiterDetailsDTO getRecruiterDetailsById(Long recruiterId);
     10    RecruiterEditDetailsDTO editRecruiterDetailsById(Long recruiterId, RecruiterEditDetailsDTO recruiterEditDetailsDTO);
     11    RecruiterEditDetailsDTO getRecruiterEditDetailsById(Long recruiterId);
     12
     13    void submitLogo(Long recruiterId, MultipartFile logoFile);
     14    Resource loadLogoAsResource(Long recruiterId);
    815}
Note: See TracChangeset for help on using the changeset viewer.