source: src/main/java/it/finki/tinki/web/controller/WorkEditController.java@ a3d2b0d

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

added work edit routes

  • Property mode set to 100644
File size: 2.5 KB
Line 
1package it.finki.tinki.web.controller;
2
3import it.finki.tinki.model.Work.Internship;
4import it.finki.tinki.model.Work.Job;
5import it.finki.tinki.model.Work.Project;
6import it.finki.tinki.model.dto.register.work.InternshipRegisterDTO;
7import it.finki.tinki.model.dto.register.work.JobRegisterDTO;
8import it.finki.tinki.model.dto.register.work.ProjectRegisterDTO;
9import it.finki.tinki.model.dto.response.work.InternshipResponseDTO;
10import it.finki.tinki.model.dto.response.work.JobResponseDTO;
11import it.finki.tinki.model.dto.response.work.ProjectResponseDTO;
12import it.finki.tinki.service.WorkService;
13import org.springframework.stereotype.Controller;
14import org.springframework.web.bind.annotation.*;
15
16@RestController
17@RequestMapping("/api/edit/work")
18public 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}
Note: See TracBrowser for help on using the repository browser.