1 | package it.finki.tinki.service.impl;
|
---|
2 |
|
---|
3 | import it.finki.tinki.model.Jobs.Internship;
|
---|
4 | import it.finki.tinki.model.Jobs.Job;
|
---|
5 | import it.finki.tinki.model.Jobs.Project;
|
---|
6 | import it.finki.tinki.model.Skill;
|
---|
7 | import it.finki.tinki.model.Users.Account;
|
---|
8 | import it.finki.tinki.model.enumerator.AccountType;
|
---|
9 | import it.finki.tinki.repository.InternshipRepository;
|
---|
10 | import it.finki.tinki.repository.JobRepository;
|
---|
11 | import it.finki.tinki.repository.MatchRepository;
|
---|
12 | import it.finki.tinki.repository.ProjectRepository;
|
---|
13 | import it.finki.tinki.service.AccountService;
|
---|
14 | import it.finki.tinki.service.SkillService;
|
---|
15 | import it.finki.tinki.service.WorkService;
|
---|
16 | import org.springframework.stereotype.Service;
|
---|
17 |
|
---|
18 | import java.util.Date;
|
---|
19 | import java.util.List;
|
---|
20 |
|
---|
21 | @Service
|
---|
22 | public class WorkServiceImpl implements WorkService {
|
---|
23 |
|
---|
24 | JobRepository jobRepository;
|
---|
25 | InternshipRepository internshipRepository;
|
---|
26 | ProjectRepository projectRepository;
|
---|
27 | MatchRepository matchRepository;
|
---|
28 | SkillService skillService;
|
---|
29 | AccountService accountService;
|
---|
30 |
|
---|
31 | public WorkServiceImpl(JobRepository jobRepository,
|
---|
32 | InternshipRepository internshipRepository,
|
---|
33 | ProjectRepository projectRepository,
|
---|
34 | MatchRepository matchRepository,
|
---|
35 | SkillService skillService,
|
---|
36 | AccountService accountService) {
|
---|
37 | this.jobRepository = jobRepository;
|
---|
38 | this.internshipRepository = internshipRepository;
|
---|
39 | this.projectRepository = projectRepository;
|
---|
40 | this.matchRepository = matchRepository;
|
---|
41 | this.skillService = skillService;
|
---|
42 | this.accountService = accountService;
|
---|
43 | }
|
---|
44 |
|
---|
45 | @Override
|
---|
46 | public List<Job> getAllJobsByAccount(Long accId) {
|
---|
47 | return this.jobRepository.findAllByAccount_Id(accId);
|
---|
48 | }
|
---|
49 |
|
---|
50 | @Override
|
---|
51 | public List<Internship> getAllInternshipsByAccount(Long accId) {
|
---|
52 | return this.internshipRepository.findAllByAccount_Id(accId);
|
---|
53 | }
|
---|
54 |
|
---|
55 | @Override
|
---|
56 | public List<Project> getAllProjectsByAccount(Long accId) {
|
---|
57 | return this.projectRepository.findAllByAccount_Id(accId);
|
---|
58 | }
|
---|
59 |
|
---|
60 | @Override
|
---|
61 | public List<Job> getAllJobs() {
|
---|
62 | return this.jobRepository.findAll();
|
---|
63 | }
|
---|
64 |
|
---|
65 | @Override
|
---|
66 | public List<Internship> getAllInternships() {
|
---|
67 | return this.internshipRepository.findAll();
|
---|
68 | }
|
---|
69 |
|
---|
70 | @Override
|
---|
71 | public List<Project> getAllProjects() {
|
---|
72 | return this.projectRepository.findAll();
|
---|
73 | }
|
---|
74 |
|
---|
75 | @Override
|
---|
76 | public Job insertJob(String title, String description, Long adccId, int salary, List<Long> skillsRequired, AccountType type) {
|
---|
77 | List<Skill> skills = this.skillService.returnSkillsBasedOnId(skillsRequired);
|
---|
78 | Account account = this.accountService.findByIdAndType(adccId, type);
|
---|
79 | Job j = new Job(title, description, account, salary, skills);
|
---|
80 | return this.jobRepository.save(j);
|
---|
81 | }
|
---|
82 |
|
---|
83 | @Override
|
---|
84 | public Internship insertInternship(String title, String description, Long adccId, int salary, List<Long> skillsTrained, int openSpots, AccountType type) {
|
---|
85 | List<Skill> skills = this.skillService.returnSkillsBasedOnId(skillsTrained);
|
---|
86 | Account account = this.accountService.findByIdAndType(adccId, type);
|
---|
87 | Internship j = new Internship(title, description, account, salary, skills, openSpots);
|
---|
88 | return this.internshipRepository.save(j);
|
---|
89 | }
|
---|
90 |
|
---|
91 | @Override
|
---|
92 | public Project insertProject(String title, String description, Long adccId, int salary, List<Long> skillsRequired, Date validUntil, AccountType type) {
|
---|
93 | List<Skill> skills = this.skillService.returnSkillsBasedOnId(skillsRequired);
|
---|
94 | Account account = this.accountService.findByIdAndType(adccId, type);
|
---|
95 | Project j = new Project(title, description, account, salary, skills, validUntil);
|
---|
96 | return this.projectRepository.save(j);
|
---|
97 | }
|
---|
98 | }
|
---|