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

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

bugfixes and refactoring

  • Property mode set to 100644
File size: 3.1 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
16import java.util.HashMap;
17import java.util.Map;
18
19@RestController
20@CrossOrigin(origins = "http://localhost:3000")
21@RequestMapping("/api/edit/work")
22public class WorkEditController {
23
24 WorkService workService;
25
26 public WorkEditController(WorkService workService) {
27 this.workService = workService;
28 }
29
30 @PostMapping("/job/{id}")
31 public Map<String, String> editJob(@PathVariable Long id,
32 @RequestBody JobRegisterDTO body){
33
34 Map<String, String> response = new HashMap<>();
35
36 if(body.getAccountId().equals(this.workService.getJobById(id).getAccount().getId())) {
37 Job k = this.workService.editJob(id, body.getTitle(), body.getDescription(), body.getSalary());
38 if(k!=null){
39 response.put("success", "Job edited successfully!");
40 return response;
41 }
42 }
43
44 response.put("error", "Internship edit failed!");
45 return response;
46 }
47
48 @PostMapping("/internship/{id}")
49 public Map<String, String> editInternship(@PathVariable Long id,
50 @RequestBody InternshipRegisterDTO body){
51
52 Map<String, String> response = new HashMap<>();
53
54 if(body.getAccountId().equals(this.workService.getInternshipById(id).getAccount().getId())){
55 Internship k = this.workService.editInternship(id, body.getTitle(), body.getDescription(), body.getSalary(), body.getOpenSpots());
56 if(k!=null){
57 response.put("success", "Internship edited successfully!");
58 return response;
59 }
60 }
61
62 response.put("error", "Internship edit failed!");
63 return response;
64 }
65
66 @PostMapping("/project/{id}")
67 public Map<String, String> editProject(@PathVariable Long id,
68 @RequestBody ProjectRegisterDTO body){
69
70 Map<String, String> response = new HashMap<>();
71
72 if(body.getAccountId().equals(this.workService.getProjectById(id).getAccount().getId())) {
73 Project k = this.workService.editProject(id, body.getTitle(), body.getDescription(), body.getSalary());
74 if(k!=null){
75 response.put("success", "Project edited successfully!");
76 return response;
77 }
78 }
79
80 response.put("error", "Project edit failed!");
81 return response;
82 }
83}
Note: See TracBrowser for help on using the repository browser.