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 | import java.util.HashMap;
|
---|
17 | import java.util.Map;
|
---|
18 |
|
---|
19 | @RestController
|
---|
20 | @CrossOrigin(origins = "http://localhost:3000")
|
---|
21 | @RequestMapping("/api/edit/work")
|
---|
22 | public 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 | }
|
---|