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

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

refactoring controllers

  • Property mode set to 100644
File size: 2.4 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/{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}
Note: See TracBrowser for help on using the repository browser.