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

bugfixes and refactoring

Location:
src/main/java/it/finki/tinki/web/controller
Files:
1 added
5 edited

Legend:

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

    r8f1f460 r33d4f5d  
    3535    }
    3636
    37     @PostMapping(path = "/user/{id}")
     37    @PostMapping(path = "/user/{id}/{email}")
    3838    public UserResponseDTO editUser(@PathVariable(name = "id") Long id,
     39                                    @PathVariable(name = "email") String email,
    3940                                    @RequestBody UserRegisterDTO body){
    4041
    41         Optional<?> a = this.accountService.findByIdAndEmail(id, body.getEmail(), AccountType.USER);
     42        Optional<?> a = this.accountService.findByIdAndEmail(id, email, AccountType.USER);
    4243
    4344        if(a.isPresent()){
     
    5152    }
    5253
    53     @PostMapping(path = "/company/{id}")
     54    @PostMapping(path = "/company/{id}/{email}")
    5455    public CompanyResponseDTO editCompany(@PathVariable(name = "id") Long id,
     56                                          @PathVariable(name = "email") String email,
    5557                                          @RequestBody CompanyRegisterDTO body){
    5658
    57         Optional<?> a = this.accountService.findByIdAndEmail(id, body.getEmail(), AccountType.COMPANY);
     59        Optional<?> a = this.accountService.findByIdAndEmail(id, email, AccountType.COMPANY);
    5860
    5961        if(a.isPresent()){
     
    6567    }
    6668
    67     @PostMapping(path = "/team/{id}")
     69    @PostMapping(path = "/team/{id}/{email}")
    6870    public TeamResponseDTO editTeam(@PathVariable(name = "id") Long id,
     71                                    @PathVariable(name = "email") String email,
    6972                                    @RequestBody TeamRegisterDTO body){
    7073
    71         Optional<?> a = this.accountService.findByIdAndEmail(id, body.getEmail(), AccountType.TEAM);
     74        Optional<?> a = this.accountService.findByIdAndEmail(id, email, AccountType.TEAM);
    7275
    7376        if(a.isPresent()){
  • src/main/java/it/finki/tinki/web/controller/AccountRegisterController.java

    r8f1f460 r33d4f5d  
    77import it.finki.tinki.model.dto.register.account.UserRegisterDTO;
    88import it.finki.tinki.service.AccountService;
    9 import it.finki.tinki.service.MatchmakerService;
    109import it.finki.tinki.service.SkillService;
    11 import it.finki.tinki.service.WorkService;
    1210import org.springframework.web.bind.annotation.*;
    1311
     
    2321    AccountService accountService;
    2422    SkillService skillService;
    25     WorkService workService;
    26     MatchmakerService matchmakerService;
    2723
    28     public AccountRegisterController(AccountService accountService, SkillService skillService, WorkService workService, MatchmakerService matchmakerService) {
     24    public AccountRegisterController(AccountService accountService, SkillService skillService) {
    2925        this.accountService = accountService;
    3026        this.skillService = skillService;
    31         this.workService = workService;
    32         this.matchmakerService = matchmakerService;
    3327    }
    3428
  • src/main/java/it/finki/tinki/web/controller/LoginController.java

    r8f1f460 r33d4f5d  
    11package it.finki.tinki.web.controller;
    22
    3 import it.finki.tinki.model.Work.Internship;
    4 import it.finki.tinki.model.Work.Job;
    5 import it.finki.tinki.model.Work.Project;
    63import it.finki.tinki.model.Users.Account;
    7 import it.finki.tinki.model.Users.Company;
    84import it.finki.tinki.model.Users.Team;
    95import it.finki.tinki.model.Users.User;
    106import it.finki.tinki.model.dto.*;
    117import it.finki.tinki.model.dto.response.account.LoginResponseDTO;
    12 import it.finki.tinki.model.dto.response.account.CompanyResponseDTO;
    13 import it.finki.tinki.model.dto.response.account.TeamResponseDTO;
    14 import it.finki.tinki.model.dto.response.account.UserResponseDTO;
    15 import it.finki.tinki.model.dto.response.work.InternshipResponseDTO;
    16 import it.finki.tinki.model.dto.response.work.JobResponseDTO;
    17 import it.finki.tinki.model.dto.response.work.ProjectResponseDTO;
    18 import it.finki.tinki.model.enumerator.AccountType;
    198import it.finki.tinki.service.AccountService;
    209import it.finki.tinki.service.BuilderService;
    21 import it.finki.tinki.service.MatchmakerService;
    2210import it.finki.tinki.service.WorkService;
    2311import org.springframework.web.bind.annotation.*;
     
    3220
    3321    AccountService accountService;
    34     WorkService workService;
    3522    BuilderService builderService;
    3623
    37     public LoginController(AccountService accountService, WorkService workService, BuilderService builderService) {
     24    public LoginController(AccountService accountService, BuilderService builderService) {
    3825        this.accountService = accountService;
    39         this.workService = workService;
    4026        this.builderService = builderService;
    4127    }
     
    5844        return new LoginResponseDTO();
    5945    }
    60 
    61     @GetMapping(path = "/job/search")
    62     public List<JobResponseDTO> jobRes(@RequestParam(name = "text") String text){
    63         return this.workService.fullTextJobSearch(text);
    64     }
    65 
    66     @GetMapping(path = "/internship/search")
    67     public List<InternshipResponseDTO> internshipRes(@RequestParam(name = "text") String text){
    68         return this.workService.fullTextInternshipSearch(text);
    69     }
    70 
    71     @GetMapping(path = "/project/search")
    72     public List<ProjectResponseDTO> projectRes(@RequestParam(name = "text") String text){
    73         return this.workService.fullTextProjectSearch(text);
    74     }
    7546}
  • 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}
  • src/main/java/it/finki/tinki/web/controller/WorkRegisterController.java

    r8f1f460 r33d4f5d  
    11package it.finki.tinki.web.controller;
    22
     3import it.finki.tinki.model.Users.Account;
    34import it.finki.tinki.model.Work.Internship;
    45import it.finki.tinki.model.Work.Job;
     
    1011import it.finki.tinki.model.dto.response.work.JobResponseDTO;
    1112import it.finki.tinki.model.dto.response.work.ProjectResponseDTO;
     13import it.finki.tinki.model.enumerator.AccountType;
    1214import it.finki.tinki.service.WorkService;
    1315import org.springframework.web.bind.annotation.*;
     
    2628    @PostMapping("/job")
    2729    public JobResponseDTO registerJob(@RequestBody JobRegisterDTO body){
    28         Job j = this.workService.insertJob(body.getTitle(),
    29                 body.getDescription(), body.getAccountId(), body.getSalary(), body.getSkillsRequired(), body.getType());
    30         return new JobResponseDTO(j);
     30
     31        if(body.getType() != AccountType.USER){
     32            Job j = this.workService.insertJob(body.getTitle(),
     33                    body.getDescription(), body.getAccountId(), body.getSalary(), body.getSkillsRequired(), body.getType());
     34            return new JobResponseDTO(j);
     35        }
     36
     37        return new JobResponseDTO();
    3138    }
    3239
    3340    @PostMapping("/internship")
    3441    public InternshipResponseDTO registerInternship(@RequestBody InternshipRegisterDTO body){
    35         Internship j = this.workService.insertInternship(body.getTitle(),
    36                 body.getDescription(), body.getAccountId(), body.getSalary(), body.getSkillsTrained(), body.getOpenSpots(), body.getType());
    37         return new InternshipResponseDTO(j);
     42        if(body.getType() == AccountType.COMPANY){
     43            Internship j = this.workService.insertInternship(body.getTitle(),
     44                    body.getDescription(), body.getAccountId(), body.getSalary(), body.getSkillsTrained(), body.getOpenSpots(), body.getType());
     45            return new InternshipResponseDTO(j);
     46        }
     47
     48        return new InternshipResponseDTO();
    3849    }
    3950
    4051    @PostMapping("/project")
    4152    public ProjectResponseDTO registerProject(@RequestBody ProjectRegisterDTO body){
    42         Project j = this.workService.insertProject(body.getTitle(),
    43                 body.getDescription(), body.getAccountId(), body.getSalary(), body.getSkillsRequired(), body.getValidUntil(), body.getType());
    44         return new ProjectResponseDTO(j);
     53
     54        if(body.getType() == AccountType.TEAM){
     55            Project j = this.workService.insertProject(body.getTitle(),
     56                    body.getDescription(), body.getAccountId(), body.getSalary(), body.getSkillsRequired(), body.getValidUntil(), body.getType());
     57            return new ProjectResponseDTO(j);
     58        }
     59
     60        return new ProjectResponseDTO();
    4561    }
    4662}
Note: See TracChangeset for help on using the changeset viewer.