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

Last change on this file since 17abe5e was 17abe5e, checked in by i-ina <76742075+i-ina@…>, 3 years ago

react components for details and bugfix

  • 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@CrossOrigin(origins = "http://localhost:3000")
18@RequestMapping("/api/edit/work")
19public 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}
Note: See TracBrowser for help on using the repository browser.