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 | @CrossOrigin(origins = "http://localhost:3000")
|
---|
18 | @RequestMapping("/api/edit/work")
|
---|
19 | public class WorkEditController {
|
---|
20 |
|
---|
21 | WorkService workService;
|
---|
22 |
|
---|
23 | public WorkEditController(WorkService workService) {
|
---|
24 | this.workService = workService;
|
---|
25 | }
|
---|
26 |
|
---|
27 | @PostMapping("/job/{id}")
|
---|
28 | public JobResponseDTO editJob(@PathVariable Long id,
|
---|
29 | @RequestBody JobRegisterDTO body){
|
---|
30 |
|
---|
31 | if(body.getAccountId().equals(this.workService.getJobById(id).getAccount().getId())) {
|
---|
32 | Job k = this.workService.editJob(id, body.getTitle(), body.getDescription(), body.getSalary());
|
---|
33 | return new JobResponseDTO(k);
|
---|
34 | }
|
---|
35 | return null;
|
---|
36 | }
|
---|
37 |
|
---|
38 | @PostMapping("/internship/{id}")
|
---|
39 | public InternshipResponseDTO editInternship(@PathVariable Long id,
|
---|
40 | @RequestBody InternshipRegisterDTO body){
|
---|
41 |
|
---|
42 | if(body.getAccountId().equals(this.workService.getJobById(id).getAccount().getId())){
|
---|
43 | Internship k = this.workService.editInternship(id, body.getTitle(), body.getDescription(), body.getSalary(), body.getOpenSpots());
|
---|
44 | return new InternshipResponseDTO(k);
|
---|
45 | }
|
---|
46 | return null;
|
---|
47 | }
|
---|
48 |
|
---|
49 | @PostMapping("/project/{id}")
|
---|
50 | public ProjectResponseDTO editProject(@PathVariable Long id,
|
---|
51 | @RequestBody ProjectRegisterDTO body){
|
---|
52 |
|
---|
53 | if(body.getAccountId().equals(this.workService.getJobById(id).getAccount().getId())) {
|
---|
54 | Project k = this.workService.editProject(id, body.getTitle(), body.getDescription(), body.getSalary());
|
---|
55 | return new ProjectResponseDTO(k);
|
---|
56 | }
|
---|
57 | return null;
|
---|
58 | }
|
---|
59 | }
|
---|