[a3d2b0d] | 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 |
|
---|
[33d4f5d] | 16 | import java.util.HashMap;
|
---|
| 17 | import java.util.Map;
|
---|
| 18 |
|
---|
[a3d2b0d] | 19 | @RestController
|
---|
[17abe5e] | 20 | @CrossOrigin(origins = "http://localhost:3000")
|
---|
[a3d2b0d] | 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 |
|
---|
[5f9d25a] | 30 | @PostMapping("/job/{id}")
|
---|
[33d4f5d] | 31 | public Map<String, String> editJob(@PathVariable Long id,
|
---|
| 32 | @RequestBody JobRegisterDTO body){
|
---|
| 33 |
|
---|
| 34 | Map<String, String> response = new HashMap<>();
|
---|
[a3d2b0d] | 35 |
|
---|
[5f9d25a] | 36 | if(body.getAccountId().equals(this.workService.getJobById(id).getAccount().getId())) {
|
---|
[a3d2b0d] | 37 | Job k = this.workService.editJob(id, body.getTitle(), body.getDescription(), body.getSalary());
|
---|
[33d4f5d] | 38 | if(k!=null){
|
---|
| 39 | response.put("success", "Job edited successfully!");
|
---|
| 40 | return response;
|
---|
| 41 | }
|
---|
[a3d2b0d] | 42 | }
|
---|
[33d4f5d] | 43 |
|
---|
| 44 | response.put("error", "Internship edit failed!");
|
---|
| 45 | return response;
|
---|
[a3d2b0d] | 46 | }
|
---|
| 47 |
|
---|
[5f9d25a] | 48 | @PostMapping("/internship/{id}")
|
---|
[33d4f5d] | 49 | public Map<String, String> editInternship(@PathVariable Long id,
|
---|
[a3d2b0d] | 50 | @RequestBody InternshipRegisterDTO body){
|
---|
| 51 |
|
---|
[33d4f5d] | 52 | Map<String, String> response = new HashMap<>();
|
---|
| 53 |
|
---|
[8f1f460] | 54 | if(body.getAccountId().equals(this.workService.getInternshipById(id).getAccount().getId())){
|
---|
[a3d2b0d] | 55 | Internship k = this.workService.editInternship(id, body.getTitle(), body.getDescription(), body.getSalary(), body.getOpenSpots());
|
---|
[33d4f5d] | 56 | if(k!=null){
|
---|
| 57 | response.put("success", "Internship edited successfully!");
|
---|
| 58 | return response;
|
---|
| 59 | }
|
---|
[a3d2b0d] | 60 | }
|
---|
[33d4f5d] | 61 |
|
---|
| 62 | response.put("error", "Internship edit failed!");
|
---|
| 63 | return response;
|
---|
[a3d2b0d] | 64 | }
|
---|
| 65 |
|
---|
[5f9d25a] | 66 | @PostMapping("/project/{id}")
|
---|
[33d4f5d] | 67 | public Map<String, String> editProject(@PathVariable Long id,
|
---|
[a3d2b0d] | 68 | @RequestBody ProjectRegisterDTO body){
|
---|
| 69 |
|
---|
[33d4f5d] | 70 | Map<String, String> response = new HashMap<>();
|
---|
| 71 |
|
---|
[8f1f460] | 72 | if(body.getAccountId().equals(this.workService.getProjectById(id).getAccount().getId())) {
|
---|
[a3d2b0d] | 73 | Project k = this.workService.editProject(id, body.getTitle(), body.getDescription(), body.getSalary());
|
---|
[33d4f5d] | 74 | if(k!=null){
|
---|
| 75 | response.put("success", "Project edited successfully!");
|
---|
| 76 | return response;
|
---|
| 77 | }
|
---|
[a3d2b0d] | 78 | }
|
---|
[33d4f5d] | 79 |
|
---|
| 80 | response.put("error", "Project edit failed!");
|
---|
| 81 | return response;
|
---|
[a3d2b0d] | 82 | }
|
---|
| 83 | }
|
---|