source: src/main/java/it/finki/tinki/service/impl/WorkServiceImpl.java@ fc8421e

Last change on this file since fc8421e was a3d2b0d, checked in by Vzdra <vladko.zdravkovski@…>, 3 years ago

added work edit routes

  • Property mode set to 100644
File size: 8.0 KB
Line 
1package it.finki.tinki.service.impl;
2
3import it.finki.tinki.model.Users.User;
4import it.finki.tinki.model.Work.Internship;
5import it.finki.tinki.model.Work.Job;
6import it.finki.tinki.model.Work.Project;
7import it.finki.tinki.model.Skill;
8import it.finki.tinki.model.Users.Account;
9import it.finki.tinki.model.Work.Work;
10import it.finki.tinki.model.dto.response.work.InternshipResponseDTO;
11import it.finki.tinki.model.dto.response.work.JobResponseDTO;
12import it.finki.tinki.model.dto.response.work.ProjectResponseDTO;
13import it.finki.tinki.model.dto.response.work.WorkResponseDTO;
14import it.finki.tinki.model.enumerator.AccountType;
15import it.finki.tinki.repository.*;
16import it.finki.tinki.service.AccountService;
17import it.finki.tinki.service.MatchmakerService;
18import it.finki.tinki.service.SkillService;
19import it.finki.tinki.service.WorkService;
20import org.springframework.stereotype.Service;
21
22import java.util.*;
23
24@Service
25public class WorkServiceImpl implements WorkService {
26
27 JobRepository jobRepository;
28 InternshipRepository internshipRepository;
29 ProjectRepository projectRepository;
30 MatchRepository matchRepository;
31 MatchmakerService matchmakerService;
32 SkillService skillService;
33 AccountService accountService;
34 UserRepository userRepository;
35
36 public WorkServiceImpl(JobRepository jobRepository,
37 InternshipRepository internshipRepository,
38 ProjectRepository projectRepository,
39 MatchRepository matchRepository,
40 SkillService skillService,
41 AccountService accountService,
42 UserRepository userRepository,
43 MatchmakerService matchmakerService) {
44 this.jobRepository = jobRepository;
45 this.internshipRepository = internshipRepository;
46 this.projectRepository = projectRepository;
47 this.matchRepository = matchRepository;
48 this.skillService = skillService;
49 this.accountService = accountService;
50 this.userRepository = userRepository;
51 this.matchmakerService = matchmakerService;
52 }
53
54 @Override
55 public List<Job> getAllJobsByAccount(Long accId) {
56 return this.jobRepository.findAllByAccount_Id(accId);
57 }
58
59 @Override
60 public List<Internship> getAllInternshipsByAccount(Long accId) {
61 return this.internshipRepository.findAllByAccount_Id(accId);
62 }
63
64 @Override
65 public List<Project> getAllProjectsByAccount(Long accId) {
66 return this.projectRepository.findAllByAccount_Id(accId);
67 }
68
69 @Override
70 public Job insertJob(String title, String description, Long adccId, int salary, List<Long> skillsRequired, AccountType type) {
71 List<Skill> skills = this.skillService.returnSkillsBasedOnId(skillsRequired);
72 Account account = this.accountService.findByIdAndType(adccId, type);
73 Job j = new Job(title, description, account, salary, skills);
74 Job jb = this.jobRepository.save(j);
75
76 List<User> users = this.userRepository.findAll();
77
78 users.forEach(user -> {
79 this.matchmakerService.setUpUserJobMatches(jb, user);
80 });
81
82 return jb;
83 }
84
85 @Override
86 public Internship insertInternship(String title, String description, Long adccId, int salary, List<Long> skillsTrained, int openSpots, AccountType type) {
87 List<Skill> skills = this.skillService.returnSkillsBasedOnId(skillsTrained);
88 Account account = this.accountService.findByIdAndType(adccId, type);
89 Internship j = new Internship(title, description, account, salary, skills, openSpots);
90 Internship jb = this.internshipRepository.save(j);
91
92 List<User> users = this.userRepository.findAll();
93
94 users.forEach(user -> {
95 this.matchmakerService.setUpUserInternshipMatches(jb, user);
96 });
97
98 return jb;
99 }
100
101 @Override
102 public Project insertProject(String title, String description, Long adccId, int salary, List<Long> skillsRequired, Date validUntil, AccountType type) {
103 List<Skill> skills = this.skillService.returnSkillsBasedOnId(skillsRequired);
104 Account account = this.accountService.findByIdAndType(adccId, type);
105 Project j = new Project(title, description, account, salary, skills, validUntil);
106 Project jb = this.projectRepository.save(j);
107
108 List<User> users = this.userRepository.findAll();
109
110 users.forEach(user -> {
111 this.matchmakerService.setUpUserProjectMatches(jb, user);
112 });
113
114 return jb;
115 }
116
117 @Override
118 public Job editJob(Long id, String title, String description, int salary) {
119 Job j = this.jobRepository.findById(id).get();
120
121 j.setTitle(title);
122 j.setDescription(description);
123 j.setSalary(salary);
124
125 return this.jobRepository.save(j);
126 }
127
128 @Override
129 public Internship editInternship(Long id, String title, String description, int salary, int openSpots) {
130 Internship j = this.internshipRepository.findById(id).get();
131
132 j.setTitle(title);
133 j.setDescription(description);
134 j.setSalary(salary);
135
136 return this.internshipRepository.save(j);
137 }
138
139 @Override
140 public Project editProject(Long id, String title, String description, int salary) {
141 Project j = this.projectRepository.findById(id).get();
142
143 j.setTitle(title);
144 j.setDescription(description);
145 j.setSalary(salary);
146
147 return this.projectRepository.save(j);
148 }
149
150 @Override
151 public List<JobResponseDTO> fullTextJobSearch(String text) {
152 List<Skill> skills = this.skillService.returnBasedOnText(text);
153
154 List<Job> jobs = this.jobRepository.findAllByTitleContainsOrDescriptionContains(text,text);
155 List<Job> sjob = new ArrayList<>();
156
157 skills.forEach(skill -> {
158 sjob.addAll(this.jobRepository.findAllBySkillsRequiredContaining(skill));
159 });
160
161 sjob.forEach(job -> {
162 if(!jobs.contains(job)){
163 jobs.add(job);
164 }
165 });
166
167 List<JobResponseDTO> jobs2 = new ArrayList<>();
168
169 jobs.forEach(job -> {
170 jobs2.add(new JobResponseDTO(job));
171 });
172
173 return jobs2;
174 }
175
176 @Override
177 public List<InternshipResponseDTO> fullTextInternshipSearch(String text) {
178 List<Skill> skills = this.skillService.returnBasedOnText(text);
179
180 List<Internship> jobs = this.internshipRepository.findAllByTitleContainsOrDescriptionContains(text,text);
181 List<Internship> sjob = new ArrayList<>();
182
183 skills.forEach(skill -> {
184 sjob.addAll(this.internshipRepository.findAllBySkillsTrainedContaining(skill));
185 });
186
187 sjob.forEach(job -> {
188 if(!jobs.contains(job)){
189 jobs.add(job);
190 }
191 });
192
193 List<InternshipResponseDTO> jobs2 = new ArrayList<>();
194
195 jobs.forEach(job -> {
196 jobs2.add(new InternshipResponseDTO(job));
197 });
198
199 return jobs2;
200 }
201
202 @Override
203 public List<ProjectResponseDTO> fullTextProjectSearch(String text) {
204 List<Skill> skills = this.skillService.returnBasedOnText(text);
205
206 List<Project> jobs = this.projectRepository.findAllByTitleContainsOrDescriptionContains(text,text);
207 List<Project> sjob = new ArrayList<>();
208
209 skills.forEach(skill -> {
210 sjob.addAll(this.projectRepository.findAllBySkillsRequiredContaining(skill));
211 });
212
213 sjob.forEach(job -> {
214 if(!jobs.contains(job)){
215 jobs.add(job);
216 }
217 });
218
219 List<ProjectResponseDTO> jobs2 = new ArrayList<>();
220
221 jobs.forEach(job -> {
222 jobs2.add(new ProjectResponseDTO(job));
223 });
224
225 return jobs2;
226 }
227
228 @Override
229 public Job getJobById(Long id) {
230 return this.jobRepository.findById(id).get();
231 }
232
233 @Override
234 public Internship getInternshipById(Long id) {
235 return this.internshipRepository.findById(id).get();
236 }
237
238 @Override
239 public Project getProjectById(Long id) {
240 return this.projectRepository.findById(id).get();
241 }
242}
Note: See TracBrowser for help on using the repository browser.