Ignore:
Timestamp:
01/12/21 02:42:18 (4 years ago)
Author:
Vzdra <vladko.zdravkovski@…>
Branches:
master
Children:
a70db1a
Parents:
8f1f460
Message:

bugfixes and refactoring

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/main/java/it/finki/tinki/web/controller/WorkEditController.java

    r8f1f460 r33d4f5d  
    1414import org.springframework.web.bind.annotation.*;
    1515
     16import java.util.HashMap;
     17import java.util.Map;
     18
    1619@RestController
    1720@CrossOrigin(origins = "http://localhost:3000")
     
    2629
    2730    @PostMapping("/job/{id}")
    28     public JobResponseDTO editJob(@PathVariable Long id,
    29                                   @RequestBody JobRegisterDTO body){
     31    public Map<String, String> editJob(@PathVariable Long id,
     32                                       @RequestBody JobRegisterDTO body){
     33
     34        Map<String, String> response = new HashMap<>();
    3035
    3136        if(body.getAccountId().equals(this.workService.getJobById(id).getAccount().getId())) {
    3237            Job k = this.workService.editJob(id, body.getTitle(), body.getDescription(), body.getSalary());
    33             return new JobResponseDTO(k);
     38            if(k!=null){
     39                response.put("success", "Job edited successfully!");
     40                return response;
     41            }
    3442        }
    35         return null;
     43
     44        response.put("error", "Internship edit failed!");
     45        return response;
    3646    }
    3747
    3848    @PostMapping("/internship/{id}")
    39     public InternshipResponseDTO editInternship(@PathVariable Long id,
     49    public Map<String, String> editInternship(@PathVariable Long id,
    4050                                                @RequestBody InternshipRegisterDTO body){
     51
     52        Map<String, String> response = new HashMap<>();
    4153
    4254        if(body.getAccountId().equals(this.workService.getInternshipById(id).getAccount().getId())){
    4355            Internship k = this.workService.editInternship(id, body.getTitle(), body.getDescription(), body.getSalary(), body.getOpenSpots());
    44             return new InternshipResponseDTO(k);
     56            if(k!=null){
     57                response.put("success", "Internship edited successfully!");
     58                return response;
     59            }
    4560        }
    46         return null;
     61
     62        response.put("error", "Internship edit failed!");
     63        return response;
    4764    }
    4865
    4966    @PostMapping("/project/{id}")
    50     public ProjectResponseDTO editProject(@PathVariable Long id,
     67    public Map<String, String> editProject(@PathVariable Long id,
    5168                                          @RequestBody ProjectRegisterDTO body){
     69
     70        Map<String, String> response = new HashMap<>();
    5271
    5372        if(body.getAccountId().equals(this.workService.getProjectById(id).getAccount().getId())) {
    5473            Project k = this.workService.editProject(id, body.getTitle(), body.getDescription(), body.getSalary());
    55             return new ProjectResponseDTO(k);
     74            if(k!=null){
     75                response.put("success", "Project edited successfully!");
     76                return response;
     77            }
    5678        }
    57         return null;
     79
     80        response.put("error", "Project edit failed!");
     81        return response;
    5882    }
    5983}
Note: See TracChangeset for help on using the changeset viewer.