[a3d2b0d] | 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
|
---|
[17abe5e] | 17 | @CrossOrigin(origins = "http://localhost:3000")
|
---|
[a3d2b0d] | 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/{userId}/{id}")
|
---|
| 28 | public JobResponseDTO editJob(@PathVariable Long userId,
|
---|
| 29 | @PathVariable Long id,
|
---|
| 30 | @RequestBody JobRegisterDTO body){
|
---|
| 31 |
|
---|
| 32 | if(userId.equals(this.workService.getJobById(id).getAccount().getId())) {
|
---|
| 33 | Job k = this.workService.editJob(id, body.getTitle(), body.getDescription(), body.getSalary());
|
---|
| 34 |
|
---|
| 35 | return new JobResponseDTO(k);
|
---|
| 36 | }
|
---|
| 37 |
|
---|
| 38 | return null;
|
---|
| 39 | }
|
---|
| 40 |
|
---|
| 41 | @PostMapping("/internship/{userId}/{id}")
|
---|
| 42 | public InternshipResponseDTO editInternship(@PathVariable Long userId,
|
---|
| 43 | @PathVariable Long id,
|
---|
| 44 | @RequestBody InternshipRegisterDTO body){
|
---|
| 45 |
|
---|
| 46 | if(userId.equals(this.workService.getJobById(id).getAccount().getId())){
|
---|
| 47 | Internship k = this.workService.editInternship(id, body.getTitle(), body.getDescription(), body.getSalary(), body.getOpenSpots());
|
---|
| 48 |
|
---|
| 49 | return new InternshipResponseDTO(k);
|
---|
| 50 | }
|
---|
| 51 |
|
---|
| 52 | return null;
|
---|
| 53 | }
|
---|
| 54 |
|
---|
| 55 | @PostMapping("/project/{userId}/{id}")
|
---|
| 56 | public ProjectResponseDTO editProject(@PathVariable Long userId,
|
---|
| 57 | @PathVariable Long id,
|
---|
| 58 | @RequestBody ProjectRegisterDTO body){
|
---|
| 59 |
|
---|
| 60 | if(userId.equals(this.workService.getJobById(id).getAccount().getId())) {
|
---|
| 61 | Project k = this.workService.editProject(id, body.getTitle(), body.getDescription(), body.getSalary());
|
---|
| 62 |
|
---|
| 63 | return new ProjectResponseDTO(k);
|
---|
| 64 | }
|
---|
| 65 |
|
---|
| 66 | return null;
|
---|
| 67 | }
|
---|
| 68 | }
|
---|