Changeset 33d4f5d for src


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
Files:
1 added
14 edited

Legend:

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

    r8f1f460 r33d4f5d  
    1111
    1212import javax.annotation.PostConstruct;
     13import java.text.DateFormat;
    1314import java.util.ArrayList;
     15import java.util.Date;
    1416import java.util.List;
    1517
     
    6163        lista = this.skillRepository.findAll();
    6264
    63         List<Skill> l2 = new ArrayList<>();
    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());
     65        List<Skill> lista2 = new ArrayList<>();
     66        lista2.add(this.skillRepository.findById(3L).get());
     67        lista2.add(this.skillRepository.findById(2L).get());
     68        lista2.add(this.skillRepository.findById(4L).get());
     69        lista2.add(this.skillRepository.findById(7L).get());
     70        lista2.add(this.skillRepository.findById(1L).get());
     71        lista2.add(this.skillRepository.findById(5L).get());
     72        lista2.add(this.skillRepository.findById(9L).get());
     73        lista2.add(this.skillRepository.findById(6L).get());
    7274
    7375
    74         List<Skill> l3 = new ArrayList<>();
    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());
     76        List<Skill> lista3 = new ArrayList<>();
     77        lista3.add(this.skillRepository.findById(3L).get());
     78        lista3.add(this.skillRepository.findById(2L).get());
     79        lista3.add(this.skillRepository.findById(4L).get());
     80        lista3.add(this.skillRepository.findById(7L).get());
    7981
    80         List<Long> ids = new ArrayList<>();
     82        List<Long> allSkills = new ArrayList<>();
    8183        lista.forEach(item -> {
    82             ids.add(item.getId());
     84            allSkills.add(item.getId());
    8385        });
    8486
    85         List<Long> smalls = new ArrayList<>();
    86         l2.forEach(item -> {
    87             smalls.add(item.getId());
     87        List<Long> skills8 = new ArrayList<>();
     88        lista2.forEach(item -> {
     89            skills8.add(item.getId());
    8890        });
    8991
    90         List<Long> sm2 = new ArrayList<>();
    91         l3.forEach(item -> {
    92             sm2.add(item.getId());
     92        List<Long> skills4 = new ArrayList<>();
     93        lista3.forEach(item -> {
     94            skills4.add(item.getId());
    9395        });
    9496
    95         Account c = this.accountService.registerCompany("company@company", "company", "Co.co", "Macedonia", "Skopje", "Pero Nakov");
     97        Account c = this.accountService.registerCompany("company@company", "company", "Co.Co", "Macedonia", "Skopje", "Pero Nakov");
     98        Account ct = this.accountService.registerCompany("company@co", "company", "Co.Co", "Macedonia", "Skopje", "Pero Nakov");
    9699        Account m = this.accountService.registerTeam("team@team", "team", "TeamRocket", 3);
    97100
    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);
     101        this.workService.insertJob("Team Job 1", "Team job 1 requires 3 members!", m.getId() ,1515, allSkills, AccountType.TEAM);
     102        this.workService.insertJob("Team Job 2", "Team job 2 requires 2 members!", m.getId() ,5511, skills4, AccountType.TEAM);
     103        this.workService.insertJob("Company Job 1", "Company job 1 requires 3 members!", c.getId() ,12345, allSkills, AccountType.COMPANY);
     104        this.workService.insertJob("Company Job 2", "Company job 2 requires 3 members!", ct.getId() ,8901, skills8, AccountType.COMPANY);
     105        this.workService.insertInternship("Internship 1", "Opportunity to learn new things!", c.getId() ,5000, skills4, 6, AccountType.COMPANY);
     106        this.workService.insertInternship("Internship 2", "Opportunity to learn new things!", c.getId() ,5000, allSkills, 3, AccountType.COMPANY);
     107        this.workService.insertProject("Project 1", "Project that lasts few days!", m.getId() ,5000, skills8, new Date(), AccountType.TEAM);
     108        this.workService.insertProject("Project 2", "Project that ends soon!", m.getId() ,5000, skills4, new Date(), AccountType.TEAM);
    102109
    103         this.accountService.registerUser("user@user", "user", "Zoki", "Poki", l3, lista);
     110        this.accountService.registerUser("user@user", "user", "Zoki", "Poki", lista3, lista);
    104111
    105112    }
  • src/main/java/it/finki/tinki/model/dto/response/work/InternshipResponseDTO.java

    r8f1f460 r33d4f5d  
    22
    33import it.finki.tinki.model.Address;
     4import it.finki.tinki.model.Skill;
    45import it.finki.tinki.model.Work.Internship;
    56import it.finki.tinki.model.Users.Company;
    67import lombok.Data;
     8
     9import java.util.List;
    710
    811@Data
     
    1114    int openSpots;
    1215    Address accountAddress;
     16    List<Skill> skillsTrained;
     17
     18    public InternshipResponseDTO(){
     19        super();
     20    }
    1321
    1422    public InternshipResponseDTO(Internship internship){
     
    1725        this.openSpots = internship.getOpenSpots();
    1826        this.accountAddress = ((Company) internship.getAccount()).getAddress();
     27        this.skillsTrained = internship.getSkillsTrained();
    1928    }
    2029}
  • src/main/java/it/finki/tinki/model/dto/response/work/JobResponseDTO.java

    r8f1f460 r33d4f5d  
    22
    33import it.finki.tinki.model.Address;
     4import it.finki.tinki.model.Skill;
    45import it.finki.tinki.model.Work.Job;
    56import it.finki.tinki.model.Users.Company;
     
    89import lombok.Data;
    910
     11import java.util.List;
     12
    1013@Data
    1114public class JobResponseDTO extends WorkResponseDTO {
    1215    Address accountAddress;
    1316    int members;
     17    List<Skill> skillsRequired;
     18
     19    public JobResponseDTO(){
     20        super();
     21    }
    1422
    1523    public JobResponseDTO(Job job){
    1624        super(job.getId(), job.getTitle(), job.getDescription(), job.getSalary(), job.getAccount());
     25        this.skillsRequired = job.getSkillsRequired();
    1726        if(job.getAccount().getAccountType()==AccountType.COMPANY){
    1827            this.accountAddress = ((Company) job.getAccount()).getAddress();
  • src/main/java/it/finki/tinki/model/dto/response/work/ProjectResponseDTO.java

    r8f1f460 r33d4f5d  
    11package it.finki.tinki.model.dto.response.work;
    22
     3import it.finki.tinki.model.Skill;
    34import it.finki.tinki.model.Work.Project;
    45import it.finki.tinki.model.Users.Team;
    56import lombok.Data;
    67
     8import java.util.Date;
     9import java.util.List;
     10
    711@Data
    812public class ProjectResponseDTO extends WorkResponseDTO {
    913    int members;
     14    Date validUntil;
     15    List<Skill> skillsRequired;
     16
     17    public ProjectResponseDTO(){
     18        super();
     19    }
    1020
    1121    public ProjectResponseDTO(Project project){
    1222        super(project.getId(), project.getTitle(), project.getDescription(), project.getSalary(), project.getAccount());
    1323        this.members = ((Team) project.getAccount()).getMembers();
     24        this.validUntil = project.getValidUntil();
     25        this.skillsRequired = project.getSkillsRequired();
    1426    }
    1527}
  • src/main/java/it/finki/tinki/model/dto/response/work/WorkResponseDTO.java

    r8f1f460 r33d4f5d  
    1414    String accountName;
    1515    AccountType accountType;
     16    String error;
    1617
    17     WorkResponseDTO(){}
     18    WorkResponseDTO(){
     19        this.error = "Error registering job!";
     20    }
    1821
    1922    WorkResponseDTO(Long id, String title, String description, int salary, Account account){
     23        this.error = null;
    2024        this.id = id;
    2125        this.title = title;
  • src/main/java/it/finki/tinki/repository/MatchRepository.java

    r8f1f460 r33d4f5d  
    1313public interface MatchRepository extends JpaRepository<Match, EmbeddedMatchId> {
    1414    List<Match> findAllByEmbeddedMatchIdUserAndTypeOrderByCoefficientDesc(User user, WorkType type);
     15    List<Match> deleteAllByEmbeddedMatchId_User_Id(Long userId);
    1516}
  • src/main/java/it/finki/tinki/service/MatchmakerService.java

    r8f1f460 r33d4f5d  
    11package it.finki.tinki.service;
    22
     3import it.finki.tinki.model.Match;
    34import it.finki.tinki.model.Work.Internship;
    45import it.finki.tinki.model.Work.Job;
     
    1516    void setUpUserProjectMatches(Project project, User user);
    1617    void setUpUserInternshipMatches(Internship internship, User user);
     18    List<Match> removeByUserId(Long userId);
    1719}
  • src/main/java/it/finki/tinki/service/impl/AccountServiceImpl.java

    r8f1f460 r33d4f5d  
    214214
    215215    private void setUpUser(User u){
     216
     217        this.matchmakerService.removeByUserId(u.getId());
     218
    216219        List<Job> jobs = this.jobRepository.findAll();
    217220        List<Project> projects = this.projectRepository.findAll();
  • src/main/java/it/finki/tinki/service/impl/MatchmakerServiceImpl.java

    r8f1f460 r33d4f5d  
    1717import org.springframework.stereotype.Service;
    1818
     19import javax.transaction.Transactional;
    1920import java.util.ArrayList;
    2021import java.util.List;
     
    118119        if(coef!=0){
    119120            EmbeddedMatchId embeddedMatchId = new EmbeddedMatchId(internship, user);
    120             Match m = new Match(embeddedMatchId, coef, WorkType.PROJECT);
     121            Match m = new Match(embeddedMatchId, coef, WorkType.INTERNSHIP);
    121122            this.matchRepository.save(m);
    122123        }
    123124    }
    124125
     126    @Transactional
     127    @Override
     128    public List<Match> removeByUserId(Long userId) {
     129        return this.matchRepository.deleteAllByEmbeddedMatchId_User_Id(userId);
     130    }
    125131
    126132}
  • 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.