1 | package it.finki.tinki.web.controller;
|
---|
2 |
|
---|
3 | import it.finki.tinki.model.Work.Internship;
|
---|
4 | import it.finki.tinki.model.Work.Job;
|
---|
5 | import it.finki.tinki.model.Work.Project;
|
---|
6 | import it.finki.tinki.model.dto.register.work.InternshipRegisterDTO;
|
---|
7 | import it.finki.tinki.model.dto.register.work.JobRegisterDTO;
|
---|
8 | import it.finki.tinki.model.dto.register.work.ProjectRegisterDTO;
|
---|
9 | import it.finki.tinki.model.dto.response.work.InternshipResponseDTO;
|
---|
10 | import it.finki.tinki.model.dto.response.work.JobResponseDTO;
|
---|
11 | import it.finki.tinki.model.dto.response.work.ProjectResponseDTO;
|
---|
12 | import it.finki.tinki.service.WorkService;
|
---|
13 | import org.springframework.stereotype.Controller;
|
---|
14 | import org.springframework.web.bind.annotation.*;
|
---|
15 |
|
---|
16 | @RestController
|
---|
17 | @RequestMapping("/api/edit/work")
|
---|
18 | public class WorkEditController {
|
---|
19 |
|
---|
20 | WorkService workService;
|
---|
21 |
|
---|
22 | public WorkEditController(WorkService workService) {
|
---|
23 | this.workService = workService;
|
---|
24 | }
|
---|
25 |
|
---|
26 | @PostMapping("/job/{userId}/{id}")
|
---|
27 | public JobResponseDTO editJob(@PathVariable Long userId,
|
---|
28 | @PathVariable Long id,
|
---|
29 | @RequestBody JobRegisterDTO body){
|
---|
30 |
|
---|
31 | if(userId.equals(this.workService.getJobById(id).getAccount().getId())) {
|
---|
32 | Job k = this.workService.editJob(id, body.getTitle(), body.getDescription(), body.getSalary());
|
---|
33 |
|
---|
34 | return new JobResponseDTO(k);
|
---|
35 | }
|
---|
36 |
|
---|
37 | return null;
|
---|
38 | }
|
---|
39 |
|
---|
40 | @PostMapping("/internship/{userId}/{id}")
|
---|
41 | public InternshipResponseDTO editInternship(@PathVariable Long userId,
|
---|
42 | @PathVariable Long id,
|
---|
43 | @RequestBody InternshipRegisterDTO body){
|
---|
44 |
|
---|
45 | if(userId.equals(this.workService.getJobById(id).getAccount().getId())){
|
---|
46 | Internship k = this.workService.editInternship(id, body.getTitle(), body.getDescription(), body.getSalary(), body.getOpenSpots());
|
---|
47 |
|
---|
48 | return new InternshipResponseDTO(k);
|
---|
49 | }
|
---|
50 |
|
---|
51 | return null;
|
---|
52 | }
|
---|
53 |
|
---|
54 | @PostMapping("/project/{userId}/{id}")
|
---|
55 | public ProjectResponseDTO editProject(@PathVariable Long userId,
|
---|
56 | @PathVariable Long id,
|
---|
57 | @RequestBody ProjectRegisterDTO body){
|
---|
58 |
|
---|
59 | if(userId.equals(this.workService.getJobById(id).getAccount().getId())) {
|
---|
60 | Project k = this.workService.editProject(id, body.getTitle(), body.getDescription(), body.getSalary());
|
---|
61 |
|
---|
62 | return new ProjectResponseDTO(k);
|
---|
63 | }
|
---|
64 |
|
---|
65 | return null;
|
---|
66 | }
|
---|
67 | }
|
---|