[5f9d25a] | 1 | package it.finki.tinki.service.impl;
|
---|
| 2 |
|
---|
| 3 | import it.finki.tinki.model.Users.Account;
|
---|
| 4 | import it.finki.tinki.model.Users.Company;
|
---|
| 5 | import it.finki.tinki.model.Users.Team;
|
---|
| 6 | import it.finki.tinki.model.Users.User;
|
---|
| 7 | import it.finki.tinki.model.Work.Internship;
|
---|
| 8 | import it.finki.tinki.model.Work.Job;
|
---|
| 9 | import it.finki.tinki.model.Work.Project;
|
---|
| 10 | import it.finki.tinki.model.dto.response.account.CompanyResponseDTO;
|
---|
| 11 | import it.finki.tinki.model.dto.response.account.TeamResponseDTO;
|
---|
| 12 | import it.finki.tinki.model.dto.response.account.UserResponseDTO;
|
---|
| 13 | import it.finki.tinki.model.dto.response.work.InternshipResponseDTO;
|
---|
| 14 | import it.finki.tinki.model.dto.response.work.JobResponseDTO;
|
---|
| 15 | import it.finki.tinki.model.dto.response.work.ProjectResponseDTO;
|
---|
| 16 | import it.finki.tinki.model.enumerator.AccountType;
|
---|
| 17 | import it.finki.tinki.service.BuilderService;
|
---|
| 18 | import it.finki.tinki.service.MatchmakerService;
|
---|
| 19 | import it.finki.tinki.service.WorkService;
|
---|
| 20 | import org.springframework.stereotype.Service;
|
---|
| 21 |
|
---|
| 22 | import java.util.List;
|
---|
| 23 |
|
---|
| 24 | @Service
|
---|
| 25 | public class BuilderServiceImpl implements BuilderService {
|
---|
| 26 |
|
---|
| 27 | MatchmakerService matchmakerService;
|
---|
| 28 | WorkService workService;
|
---|
| 29 |
|
---|
| 30 | public BuilderServiceImpl(MatchmakerService matchmakerService, WorkService workService) {
|
---|
| 31 | this.matchmakerService = matchmakerService;
|
---|
| 32 | this.workService = workService;
|
---|
| 33 | }
|
---|
| 34 |
|
---|
| 35 | @Override
|
---|
| 36 | public UserResponseDTO buildUserResponseDTO(Account a1) {
|
---|
| 37 | UserResponseDTO uDto = new UserResponseDTO();
|
---|
| 38 |
|
---|
| 39 | uDto.setError(null);
|
---|
| 40 |
|
---|
| 41 | uDto.setId(a1.getId());
|
---|
| 42 | uDto.setEmail(a1.getEmail());
|
---|
| 43 | uDto.setName(a1.getName());
|
---|
| 44 | uDto.setType(AccountType.USER);
|
---|
| 45 | uDto.setSurname(((User) a1).getSurname());
|
---|
| 46 |
|
---|
| 47 | uDto.setRetained(((User) a1).getRetainedSkills());
|
---|
| 48 | uDto.setToLearn(((User) a1).getSkillsToLearn());
|
---|
| 49 |
|
---|
| 50 | List<Job> matchedJobs = this.matchmakerService.getMatchingJobsForUser((User) a1);
|
---|
| 51 | List<Project> matchedProjects = this.matchmakerService.getMatchingProjectsForUser((User) a1);
|
---|
| 52 | List<Internship> matchedInternships = this.matchmakerService.getMatchingInternshipsForUser((User) a1);
|
---|
| 53 |
|
---|
| 54 | matchedJobs.forEach(job -> {
|
---|
| 55 | JobResponseDTO dto = new JobResponseDTO(job);
|
---|
| 56 | uDto.getJobs().add(dto);
|
---|
| 57 | });
|
---|
| 58 |
|
---|
| 59 | matchedProjects.forEach(project -> {
|
---|
| 60 | ProjectResponseDTO dto = new ProjectResponseDTO(project);
|
---|
| 61 | uDto.getProjects().add(dto);
|
---|
| 62 | });
|
---|
| 63 |
|
---|
| 64 | matchedInternships.forEach(internship -> {
|
---|
| 65 | InternshipResponseDTO dto = new InternshipResponseDTO(internship);
|
---|
| 66 | uDto.getInternships().add(dto);
|
---|
| 67 | });
|
---|
| 68 |
|
---|
| 69 | return uDto;
|
---|
| 70 | }
|
---|
| 71 |
|
---|
| 72 | @Override
|
---|
| 73 | public CompanyResponseDTO buildCompanyResponseDTO(Account a1) {
|
---|
| 74 | CompanyResponseDTO cDto = new CompanyResponseDTO();
|
---|
| 75 |
|
---|
| 76 | cDto.setError(null);
|
---|
| 77 |
|
---|
| 78 | cDto.setId(a1.getId());
|
---|
| 79 | cDto.setEmail(a1.getEmail());
|
---|
| 80 | cDto.setName(a1.getName());
|
---|
| 81 | cDto.setType(AccountType.COMPANY);
|
---|
| 82 | cDto.setAddress(((Company) a1).getAddress());
|
---|
| 83 |
|
---|
| 84 | List<Job> jobs = this.workService.getAllJobsByAccount(a1.getId());
|
---|
| 85 | List<Internship> internships = this.workService.getAllInternshipsByAccount(a1.getId());
|
---|
| 86 |
|
---|
| 87 | jobs.forEach(job -> {
|
---|
| 88 | JobResponseDTO dto = new JobResponseDTO(job);
|
---|
| 89 | cDto.getJobs().add(dto);
|
---|
| 90 | });
|
---|
| 91 |
|
---|
| 92 | internships.forEach(internship -> {
|
---|
| 93 | InternshipResponseDTO dto = new InternshipResponseDTO(internship);
|
---|
| 94 | cDto.getInternships().add(dto);
|
---|
| 95 | });
|
---|
| 96 |
|
---|
| 97 | return cDto;
|
---|
| 98 | }
|
---|
| 99 |
|
---|
| 100 | @Override
|
---|
| 101 | public TeamResponseDTO buildTeamResponseDTO(Account a1) {
|
---|
| 102 | TeamResponseDTO tDto = new TeamResponseDTO();
|
---|
| 103 |
|
---|
| 104 | tDto.setError(null);
|
---|
| 105 |
|
---|
| 106 | tDto.setId(a1.getId());
|
---|
| 107 | tDto.setEmail(a1.getEmail());
|
---|
| 108 | tDto.setName(a1.getName());
|
---|
| 109 | tDto.setType(AccountType.TEAM);
|
---|
| 110 | tDto.setMembers(((Team) a1).getMembers());
|
---|
| 111 |
|
---|
| 112 | List<Job> jobs = this.workService.getAllJobsByAccount(a1.getId());
|
---|
| 113 | List<Project> projects = this.workService.getAllProjectsByAccount(a1.getId());
|
---|
| 114 |
|
---|
| 115 | jobs.forEach(job -> {
|
---|
| 116 | JobResponseDTO dto = new JobResponseDTO(job);
|
---|
| 117 | tDto.getJobs().add(dto);
|
---|
| 118 | });
|
---|
| 119 |
|
---|
| 120 | projects.forEach(project -> {
|
---|
| 121 | ProjectResponseDTO dto = new ProjectResponseDTO(project);
|
---|
| 122 | tDto.getProjects().add(dto);
|
---|
| 123 | });
|
---|
| 124 |
|
---|
| 125 | return tDto;
|
---|
| 126 | }
|
---|
| 127 | }
|
---|