Changeset 5f9d25a for src


Ignore:
Timestamp:
01/11/21 18:57:03 (4 years ago)
Author:
Vzdra <vladko.zdravkovski@…>
Branches:
master
Children:
8f1f460
Parents:
fc8421e
Message:

refactoring controllers

Location:
src/main/java/it/finki/tinki
Files:
2 added
9 edited

Legend:

Unmodified
Added
Removed
  • src/main/java/it/finki/tinki/bootstrap/DataHolder.java

    rfc8421e r5f9d25a  
    3434    @PostConstruct
    3535    public void init(){
    36         if(skillRepository.findAll().size()==0){
     36        if(this.skillRepository.findAll().size()==0){
    3737            Skill s1 = new Skill("C++");
    3838            Skill s2 = new Skill("Java");
     
    4646            Skill s0 = new Skill("Go");
    4747
    48             skillRepository.save(s1);
    49             skillRepository.save(s2);
    50             skillRepository.save(s3);
    51             skillRepository.save(s4);
    52             skillRepository.save(s5);
    53             skillRepository.save(s6);
    54             skillRepository.save(s7);
    55             skillRepository.save(s8);
    56             skillRepository.save(s9);
    57             skillRepository.save(s0);
     48            this.skillRepository.save(s1);
     49            this.skillRepository.save(s2);
     50            this.skillRepository.save(s3);
     51            this.skillRepository.save(s4);
     52            this.skillRepository.save(s5);
     53            this.skillRepository.save(s6);
     54            this.skillRepository.save(s7);
     55            this.skillRepository.save(s8);
     56            this.skillRepository.save(s9);
     57            this.skillRepository.save(s0);
    5858        }
    5959
    6060        List<Skill> lista;
    61         lista = skillRepository.findAll();
     61        lista = this.skillRepository.findAll();
    6262
    6363        List<Skill> l2 = new ArrayList<>();
    64         l2.add(skillRepository.getOne(3L));
    65         l2.add(skillRepository.getOne(10L));
    66         l2.add(skillRepository.getOne(1L));
    67         l2.add(skillRepository.getOne(2L));
    68         l2.add(skillRepository.getOne(4L));
    69         l2.add(skillRepository.getOne(5L));
    70         l2.add(skillRepository.getOne(6L));
    71         l2.add(skillRepository.getOne(7L));
     64        l2.add(this.skillRepository.findById(3L).get());
     65        l2.add(this.skillRepository.findById(2L).get());
     66        l2.add(this.skillRepository.findById(4L).get());
     67        l2.add(this.skillRepository.findById(7L).get());
     68        l2.add(this.skillRepository.findById(1L).get());
     69        l2.add(this.skillRepository.findById(5L).get());
     70        l2.add(this.skillRepository.findById(9L).get());
     71        l2.add(this.skillRepository.findById(6L).get());
    7272
    7373
    7474        List<Skill> l3 = new ArrayList<>();
    75         l3.add(skillRepository.getOne(3L));
    76         l3.add(skillRepository.getOne(10L));
    77         l3.add(skillRepository.getOne(5L));
    78         l3.add(skillRepository.getOne(6L));
    79         l3.add(skillRepository.getOne(7L));
     75        l3.add(this.skillRepository.findById(3L).get());
     76        l3.add(this.skillRepository.findById(2L).get());
     77        l3.add(this.skillRepository.findById(4L).get());
     78        l3.add(this.skillRepository.findById(7L).get());
    8079
    8180        List<Long> ids = new ArrayList<>();
     
    9493        });
    9594
    96         Account c = this.accountService.registerCompany("asdf@asdf", "pass", "Co.co", "Macedonia", "Skopje", "Pero Nakov");
    97         Account m = this.accountService.registerTeam("asdf", "asd", "TeamRocket", 3);
     95        Account c = this.accountService.registerCompany("company@company", "company", "Co.co", "Macedonia", "Skopje", "Pero Nakov");
     96        Account m = this.accountService.registerTeam("team@team", "team", "TeamRocket", 3);
    9897
    99         Job z = this.workService.insertJob("asdfq", "asdfqw", m.getId() ,5000, smalls, AccountType.TEAM);
    100         Job n = this.workService.insertJob("asdfq", "asdfqw", c.getId() ,5000, sm2, AccountType.COMPANY);
    101         Job j = this.workService.insertJob("Asdf", "Asdfa", c.getId() ,5000, ids, AccountType.COMPANY);
    102         Job k = this.workService.insertJob("Asdf", "Asdfa", m.getId() ,5000, ids, AccountType.TEAM);
     98        this.workService.insertJob("asdfq", "asdfqw", m.getId() ,5000, smalls, AccountType.TEAM);
     99        this.workService.insertJob("asdfq", "asdfqw", c.getId() ,5000, sm2, AccountType.COMPANY);
     100        this.workService.insertJob("Asdf", "Asdfa", c.getId() ,5000, ids, AccountType.COMPANY);
     101        this.workService.insertJob("Asdf", "Asdfa", m.getId() ,5000, ids, AccountType.TEAM);
    103102
    104         Account u = this.accountService.registerUser("asdf", "asdfq", "Zoki", "Poki", lista, lista);
     103        this.accountService.registerUser("user@user", "user", "Zoki", "Poki", l3, lista);
    105104
    106105    }
  • src/main/java/it/finki/tinki/model/dto/response/account/CompanyResponseDTO.java

    rfc8421e r5f9d25a  
    1616
    1717    public CompanyResponseDTO(){
     18        super();
    1819        this.jobs = new ArrayList<>();
    1920        this.internships = new ArrayList<>();
  • src/main/java/it/finki/tinki/model/dto/response/account/TeamResponseDTO.java

    rfc8421e r5f9d25a  
    1515
    1616    public TeamResponseDTO(){
     17        super();
    1718        this.jobs = new ArrayList<>();
    1819        this.projects = new ArrayList<>();
  • src/main/java/it/finki/tinki/service/impl/WorkServiceImpl.java

    rfc8421e r5f9d25a  
    77import it.finki.tinki.model.Skill;
    88import it.finki.tinki.model.Users.Account;
    9 import it.finki.tinki.model.Work.Work;
    109import it.finki.tinki.model.dto.response.work.InternshipResponseDTO;
    1110import it.finki.tinki.model.dto.response.work.JobResponseDTO;
    1211import it.finki.tinki.model.dto.response.work.ProjectResponseDTO;
    13 import it.finki.tinki.model.dto.response.work.WorkResponseDTO;
    1412import it.finki.tinki.model.enumerator.AccountType;
    1513import it.finki.tinki.repository.*;
  • src/main/java/it/finki/tinki/web/controller/AccountEditController.java

    rfc8421e r5f9d25a  
    1313import it.finki.tinki.model.enumerator.AccountType;
    1414import it.finki.tinki.service.AccountService;
     15import it.finki.tinki.service.BuilderService;
    1516import it.finki.tinki.service.SkillService;
    1617import org.springframework.web.bind.annotation.*;
     
    2627    AccountService accountService;
    2728    SkillService skillService;
     29    BuilderService builderService;
    2830
    29     public AccountEditController(AccountService accountService, SkillService skillService) {
     31    public AccountEditController(AccountService accountService, SkillService skillService, BuilderService builderService) {
    3032        this.accountService = accountService;
    3133        this.skillService = skillService;
     34        this.builderService = builderService;
    3235    }
    3336
    34     @PostMapping(path = "/user/{id}/{email}")
     37    @PostMapping(path = "/user/{id}")
    3538    public UserResponseDTO editUser(@PathVariable(name = "id") Long id,
    36                                     @PathVariable(name = "email") String email,
    3739                                    @RequestBody UserRegisterDTO body){
    3840
    39         Optional<?> a = this.accountService.findByIdAndEmail(id, email, AccountType.USER);
     41        Optional<?> a = this.accountService.findByIdAndEmail(id, body.getEmail(), AccountType.USER);
    4042
    4143        if(a.isPresent()){
    4244            List<Skill> retained = this.skillService.returnSkillsBasedOnId(body.getRetainedSkills());
    4345            List<Skill> toLearn = this.skillService.returnSkillsBasedOnId(body.getSkillsToLearn());
    44 
    4546            User u = this.accountService.editUser(id, body.getEmail(), body.getName(), body.getSurname(), retained, toLearn);
    46 
    47             UserResponseDTO userResponseDTO = new UserResponseDTO();
    48 
    49             userResponseDTO.setId(u.getId());
    50             userResponseDTO.setEmail(u.getEmail());
    51             userResponseDTO.setType(AccountType.USER);
    52             userResponseDTO.setError(null);
    53             userResponseDTO.setName(u.getName());
    54             userResponseDTO.setSurname(u.getSurname());
    55             userResponseDTO.setRetained(u.getRetainedSkills());
    56             userResponseDTO.setToLearn(u.getSkillsToLearn());
    57 
    58             return userResponseDTO;
     47            return this.builderService.buildUserResponseDTO(u);
    5948        }
    6049
    61         return null;
     50        return new UserResponseDTO();
    6251    }
    6352
    64     @PostMapping(path = "/company/{id}/{email}")
     53    @PostMapping(path = "/company/{id}")
    6554    public CompanyResponseDTO editCompany(@PathVariable(name = "id") Long id,
    66                                           @PathVariable(name = "email") String email,
    6755                                          @RequestBody CompanyRegisterDTO body){
    6856
    69         Optional<?> a = this.accountService.findByIdAndEmail(id, email, AccountType.COMPANY);
     57        Optional<?> a = this.accountService.findByIdAndEmail(id, body.getEmail(), AccountType.COMPANY);
    7058
    7159        if(a.isPresent()){
    7260            Company c = this.accountService.editCompany(id, body.getEmail(), body.getName(), body.getCountry(), body.getCity(), body.getStreet());
    73 
    74             CompanyResponseDTO companyResponseDTO = new CompanyResponseDTO();
    75 
    76             companyResponseDTO.setId(c.getId());
    77             companyResponseDTO.setEmail(c.getEmail());
    78             companyResponseDTO.setError(null);
    79             companyResponseDTO.setType(AccountType.COMPANY);
    80             companyResponseDTO.setName(c.getName());
    81             companyResponseDTO.setAddress(c.getAddress());
    82 
    83             return companyResponseDTO;
     61            return this.builderService.buildCompanyResponseDTO(c);
    8462        }
    8563
    86         return null;
     64        return new CompanyResponseDTO();
    8765    }
    8866
    89     @PostMapping(path = "/team/{id}/{email}")
     67    @PostMapping(path = "/team/{id}")
    9068    public TeamResponseDTO editTeam(@PathVariable(name = "id") Long id,
    91                                     @PathVariable(name = "email") String email,
    9269                                    @RequestBody TeamRegisterDTO body){
    9370
    94         Optional<?> a = this.accountService.findByIdAndEmail(id, email, AccountType.TEAM);
     71        Optional<?> a = this.accountService.findByIdAndEmail(id, body.getEmail(), AccountType.TEAM);
    9572
    9673        if(a.isPresent()){
    9774            Team t = this.accountService.editTeam(id, body.getEmail(), body.getName(), body.getMembers());
    98 
    99             TeamResponseDTO teamResponseDTO = new TeamResponseDTO();
    100 
    101             teamResponseDTO.setId(t.getId());
    102             teamResponseDTO.setEmail(t.getEmail());
    103             teamResponseDTO.setError(null);
    104             teamResponseDTO.setType(AccountType.TEAM);
    105             teamResponseDTO.setName(t.getName());
    106             teamResponseDTO.setMembers(t.getMembers());
    107 
    108             return teamResponseDTO;
     75            return this.builderService.buildTeamResponseDTO(t);
    10976        }
    11077
    111         return null;
     78        return new TeamResponseDTO();
    11279    }
    11380}
  • src/main/java/it/finki/tinki/web/controller/AccountRegisterController.java

    rfc8421e r5f9d25a  
    3838        List<Skill> retained = this.skillService.returnSkillsBasedOnId(body.getRetainedSkills());
    3939        List<Skill> toLearn = this.skillService.returnSkillsBasedOnId(body.getSkillsToLearn());
    40 
    4140        Account k = this.accountService.registerUser(body.getEmail(), body.getPassword(), body.getName(), body.getSurname(), retained, toLearn);
    42 
    4341        Map<String, String> response = new HashMap<>();
    4442
     
    5654
    5755        Account k = this.accountService.registerTeam(body.getEmail(), body.getPassword(), body.getName(), body.getMembers());
    58 
    5956        Map<String, String> response = new HashMap<>();
    6057
     
    7370        Account k = this.accountService.registerCompany(body.getEmail(),
    7471                body.getPassword(), body.getName(), body.getCountry(), body.getCity(), body.getStreet());
    75 
    7672        Map<String, String> response = new HashMap<>();
    7773
  • src/main/java/it/finki/tinki/web/controller/LoginController.java

    rfc8421e r5f9d25a  
    1818import it.finki.tinki.model.enumerator.AccountType;
    1919import it.finki.tinki.service.AccountService;
     20import it.finki.tinki.service.BuilderService;
    2021import it.finki.tinki.service.MatchmakerService;
    2122import it.finki.tinki.service.WorkService;
     
    3132
    3233    AccountService accountService;
    33     MatchmakerService matchmakerService;
    3434    WorkService workService;
     35    BuilderService builderService;
    3536
    36     public LoginController(AccountService accountService, MatchmakerService matchmakerService, WorkService workService) {
     37    public LoginController(AccountService accountService, WorkService workService, BuilderService builderService) {
    3738        this.accountService = accountService;
    38         this.matchmakerService = matchmakerService;
    3939        this.workService = workService;
     40        this.builderService = builderService;
    4041    }
    4142
     
    4344    public LoginResponseDTO loginProcess(@RequestBody AccountLoginDTO body) throws ResponseStatusException {
    4445
    45         System.out.println(body);
    4646        Account a1 = accountService.findUser(body.getEmail(), body.getPassword(), body.getType());
    4747
    4848        if(a1!=null){
    4949            if(a1.getClass().equals(User.class)){
    50                 return processUser(a1);
     50                return this.builderService.buildUserResponseDTO(a1);
    5151            }else if(a1.getClass().equals(Team.class)){
    52                 return processTeam(a1);
     52                return this.builderService.buildTeamResponseDTO(a1);
    5353            }else{
    54                 return processCompany(a1);
     54                return this.builderService.buildCompanyResponseDTO(a1);
    5555            }
    5656        }
    5757
    5858        return new LoginResponseDTO();
    59     }
    60 
    61     private UserResponseDTO processUser(Account a1){
    62         UserResponseDTO uDto = new UserResponseDTO();
    63 
    64         uDto.setError(null);
    65 
    66         uDto.setId(a1.getId());
    67         uDto.setEmail(a1.getEmail());
    68         uDto.setName(a1.getName());
    69         uDto.setType(AccountType.USER);
    70         uDto.setSurname(((User) a1).getSurname());
    71 
    72         uDto.setRetained(((User) a1).getRetainedSkills());
    73         uDto.setToLearn(((User) a1).getSkillsToLearn());
    74 
    75         List<Job> matchedJobs = this.matchmakerService.getMatchingJobsForUser((User) a1);
    76         List<Project> matchedProjects = this.matchmakerService.getMatchingProjectsForUser((User) a1);
    77         List<Internship> matchedInternships = this.matchmakerService.getMatchingInternshipsForUser((User) a1);
    78 
    79         matchedJobs.forEach(job -> {
    80             JobResponseDTO dto = new JobResponseDTO(job);
    81             uDto.getJobs().add(dto);
    82         });
    83 
    84         matchedProjects.forEach(project -> {
    85             ProjectResponseDTO dto = new ProjectResponseDTO(project);
    86             uDto.getProjects().add(dto);
    87         });
    88 
    89         matchedInternships.forEach(internship -> {
    90             InternshipResponseDTO dto = new InternshipResponseDTO(internship);
    91             uDto.getInternships().add(dto);
    92         });
    93 
    94 
    95         return uDto;
    96     }
    97 
    98     private TeamResponseDTO processTeam(Account a1){
    99         TeamResponseDTO tDto = new TeamResponseDTO();
    100 
    101         tDto.setError(null);
    102 
    103         tDto.setId(a1.getId());
    104         tDto.setEmail(a1.getEmail());
    105         tDto.setName(a1.getName());
    106         tDto.setType(AccountType.TEAM);
    107         tDto.setMembers(((Team) a1).getMembers());
    108 
    109         List<Job> jobs = this.workService.getAllJobsByAccount(a1.getId());
    110         List<Project> projects = this.workService.getAllProjectsByAccount(a1.getId());
    111 
    112         jobs.forEach(job -> {
    113             JobResponseDTO dto = new JobResponseDTO(job);
    114             tDto.getJobs().add(dto);
    115         });
    116 
    117         projects.forEach(project -> {
    118             ProjectResponseDTO dto = new ProjectResponseDTO(project);
    119             tDto.getProjects().add(dto);
    120         });
    121 
    122         return tDto;
    123     }
    124 
    125     private CompanyResponseDTO processCompany(Account a1){
    126         CompanyResponseDTO cDto = new CompanyResponseDTO();
    127 
    128         cDto.setError(null);
    129 
    130         cDto.setId(a1.getId());
    131         cDto.setEmail(a1.getEmail());
    132         cDto.setName(a1.getName());
    133         cDto.setType(AccountType.COMPANY);
    134         cDto.setAddress(((Company) a1).getAddress());
    135 
    136         List<Job> jobs = this.workService.getAllJobsByAccount(a1.getId());
    137         List<Internship> internships = this.workService.getAllInternshipsByAccount(a1.getId());
    138 
    139         jobs.forEach(job -> {
    140             JobResponseDTO dto = new JobResponseDTO(job);
    141             cDto.getJobs().add(dto);
    142         });
    143 
    144         internships.forEach(internship -> {
    145             InternshipResponseDTO dto = new InternshipResponseDTO(internship);
    146             cDto.getInternships().add(dto);
    147         });
    148 
    149         return cDto;
    15059    }
    15160
     
    16473        return this.workService.fullTextProjectSearch(text);
    16574    }
    166 
    16775}
  • src/main/java/it/finki/tinki/web/controller/WorkEditController.java

    rfc8421e r5f9d25a  
    2525    }
    2626
    27     @PostMapping("/job/{userId}/{id}")
    28     public JobResponseDTO editJob(@PathVariable Long userId,
    29                                   @PathVariable Long id,
     27    @PostMapping("/job/{id}")
     28    public JobResponseDTO editJob(@PathVariable Long id,
    3029                                  @RequestBody JobRegisterDTO body){
    3130
    32         if(userId.equals(this.workService.getJobById(id).getAccount().getId())) {
     31        if(body.getAccountId().equals(this.workService.getJobById(id).getAccount().getId())) {
    3332            Job k = this.workService.editJob(id, body.getTitle(), body.getDescription(), body.getSalary());
    34 
    3533            return new JobResponseDTO(k);
    3634        }
    37 
    3835        return null;
    3936    }
    4037
    41     @PostMapping("/internship/{userId}/{id}")
    42     public InternshipResponseDTO editInternship(@PathVariable Long userId,
    43                                                 @PathVariable Long id,
     38    @PostMapping("/internship/{id}")
     39    public InternshipResponseDTO editInternship(@PathVariable Long id,
    4440                                                @RequestBody InternshipRegisterDTO body){
    4541
    46         if(userId.equals(this.workService.getJobById(id).getAccount().getId())){
     42        if(body.getAccountId().equals(this.workService.getJobById(id).getAccount().getId())){
    4743            Internship k = this.workService.editInternship(id, body.getTitle(), body.getDescription(), body.getSalary(), body.getOpenSpots());
    48 
    4944            return new InternshipResponseDTO(k);
    5045        }
    51 
    5246        return null;
    5347    }
    5448
    55     @PostMapping("/project/{userId}/{id}")
    56     public ProjectResponseDTO editProject(@PathVariable Long userId,
    57                                           @PathVariable Long id,
     49    @PostMapping("/project/{id}")
     50    public ProjectResponseDTO editProject(@PathVariable Long id,
    5851                                          @RequestBody ProjectRegisterDTO body){
    5952
    60         if(userId.equals(this.workService.getJobById(id).getAccount().getId())) {
     53        if(body.getAccountId().equals(this.workService.getJobById(id).getAccount().getId())) {
    6154            Project k = this.workService.editProject(id, body.getTitle(), body.getDescription(), body.getSalary());
    62 
    6355            return new ProjectResponseDTO(k);
    6456        }
    65 
    6657        return null;
    6758    }
  • src/main/java/it/finki/tinki/web/controller/WorkRegisterController.java

    rfc8421e r5f9d25a  
    2626    @PostMapping("/job")
    2727    public JobResponseDTO registerJob(@RequestBody JobRegisterDTO body){
    28 
    2928        Job j = this.workService.insertJob(body.getTitle(),
    3029                body.getDescription(), body.getAccountId(), body.getSalary(), body.getSkillsRequired(), body.getType());
    31 
    3230        return new JobResponseDTO(j);
    3331    }
     
    3533    @PostMapping("/internship")
    3634    public InternshipResponseDTO registerInternship(@RequestBody InternshipRegisterDTO body){
    37 
    3835        Internship j = this.workService.insertInternship(body.getTitle(),
    3936                body.getDescription(), body.getAccountId(), body.getSalary(), body.getSkillsTrained(), body.getOpenSpots(), body.getType());
    40 
    4137        return new InternshipResponseDTO(j);
    4238    }
     
    4440    @PostMapping("/project")
    4541    public ProjectResponseDTO registerProject(@RequestBody ProjectRegisterDTO body){
    46 
    4742        Project j = this.workService.insertProject(body.getTitle(),
    4843                body.getDescription(), body.getAccountId(), body.getSalary(), body.getSkillsRequired(), body.getValidUntil(), body.getType());
    49 
    5044        return new ProjectResponseDTO(j);
    5145    }
Note: See TracChangeset for help on using the changeset viewer.