Changeset 509cb95


Ignore:
Timestamp:
01/07/21 22:32:22 (3 years ago)
Author:
Vzdra <vladko.zdravkovski@…>
Branches:
master
Children:
a8e8545
Parents:
723994f
Message:

finalized register and login and added insert options for jobs

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

Legend:

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

    r723994f r509cb95  
    5656        }
    5757
     58        List<Skill> lista;
     59        lista = skillRepository.findAll();
     60
     61        userRepository.save(new User("asdf", "asdf", "Zoki", AccountType.USER, "Poki", lista, lista));
     62
    5863        addressRepository.save(new Address("asdf", "asdf", "asdf"));
    5964        companyRepository.save(new Company("asdf@asdf", "pass", "Co.co", AccountType.COMPANY, addressRepository.findAll().get(0)));
  • src/main/java/it/finki/tinki/helper/Matchmaker.java

    r723994f r509cb95  
    22
    33import it.finki.tinki.model.Skill;
     4import org.springframework.stereotype.Component;
     5
    46import java.util.List;
    57
     8@Component
    69public class Matchmaker {
    710
    8     public float match(List<Skill> work, List<Skill> user){
     11    public static float match(List<Skill> work, List<Skill> user){
    912
    1013        float coef = work.size();
  • src/main/java/it/finki/tinki/model/EmbeddedMatchId.java

    r723994f r509cb95  
    1818    @OneToOne
    1919    private User user;
     20
     21    public EmbeddedMatchId(){ }
     22
     23    public EmbeddedMatchId(Work work, User user){
     24        this.work = work;
     25        this.user = user;
     26    }
     27
    2028}
  • src/main/java/it/finki/tinki/model/Match.java

    r723994f r509cb95  
    1919    public Match(){}
    2020
    21     public Match(float coefficient, WorkType type) {
     21    public Match(EmbeddedMatchId embeddedMatchId, float coefficient, WorkType type) {
     22        this.combinedId = embeddedMatchId;
    2223        this.coefficient = coefficient;
    2324        this.type = type;
  • src/main/java/it/finki/tinki/model/dto/LoginResponseDTO.java

    r723994f r509cb95  
    1010    private String name;
    1111    private AccountType type;
     12    private String error;
     13
     14    public LoginResponseDTO() {
     15        this.error = "Invalid username or password!";
     16    }
    1217}
  • src/main/java/it/finki/tinki/repository/MatchRepository.java

    r723994f r509cb95  
    1111@Repository
    1212public interface MatchRepository extends JpaRepository<Match, Long> {
    13     List<Match> getAllByCombinedId_UserAndTypeOrderByCoefficientDesc(User user, WorkType type);
     13    List<Match> getAllByCombinedId_User_IdAndTypeOrderByCoefficientDesc(Long uId, WorkType type);
    1414}
  • src/main/java/it/finki/tinki/service/AccountService.java

    r723994f r509cb95  
    66
    77import java.util.List;
    8 import java.util.Map;
    98
    109public interface AccountService {
     
    1312    Account registerTeam(String email, String password, String name, int members);
    1413    Account registerCompany(String email, String password, String name, String country, String city, String street);
     14    Account findByIdAndType(Long accId, AccountType type);
    1515}
  • src/main/java/it/finki/tinki/service/MatchmakerService.java

    r723994f r509cb95  
    1212    List<Job> getMatchingJobsForUser(User user);
    1313    List<Project> getMatchingProjectsForUser(User user);
     14    void setUpUserJobMatches(Job job, User user);
     15    void setUpUserProjectMatches(Project project, User user);
     16    void setUpUserInternshipMatches(Internship internship, User user);
    1417}
  • src/main/java/it/finki/tinki/service/impl/AccountServiceImpl.java

    r723994f r509cb95  
    9696        return this.companyRepository.save(c);
    9797    }
     98
     99    public Account findByIdAndType(Long id, AccountType type){
     100        switch (type){
     101            case COMPANY:
     102                return this.companyRepository.findById(id).get();
     103            case TEAM:
     104                return this.teamRepository.findById(id).get();
     105            case USER:
     106                return this.userRepository.findById(id).get();
     107        }
     108
     109        return null;
     110    }
    98111}
  • src/main/java/it/finki/tinki/service/impl/MatchmakerServiceImpl.java

    r723994f r509cb95  
    11package it.finki.tinki.service.impl;
    22
     3import it.finki.tinki.helper.Matchmaker;
     4import it.finki.tinki.model.EmbeddedMatchId;
    35import it.finki.tinki.model.Jobs.Internship;
    46import it.finki.tinki.model.Jobs.Job;
    57import it.finki.tinki.model.Jobs.Project;
     8import it.finki.tinki.model.Jobs.Work;
    69import it.finki.tinki.model.Match;
    7 import it.finki.tinki.model.Users.Team;
     10import it.finki.tinki.model.Skill;
    811import it.finki.tinki.model.Users.User;
    912import it.finki.tinki.model.enumerator.WorkType;
     
    2730    @Override
    2831    public List<Internship> getMatchingInternshipsForUser(User user) {
    29         List<Match> matches = this.matchRepository.getAllByCombinedId_UserAndTypeOrderByCoefficientDesc(user, WorkType.INTERNSHIP);
     32        List<Match> matches = this.matchRepository.getAllByCombinedId_User_IdAndTypeOrderByCoefficientDesc(user.getId(), WorkType.INTERNSHIP);
    3033
    3134        List<Internship> internships = new ArrayList<>();
     
    3942    @Override
    4043    public List<Job> getMatchingJobsForUser(User user) {
    41         List<Match> matches = this.matchRepository.getAllByCombinedId_UserAndTypeOrderByCoefficientDesc(user, WorkType.JOB);
     44        List<Match> matches = this.matchRepository.getAllByCombinedId_User_IdAndTypeOrderByCoefficientDesc(user.getId(), WorkType.JOB);
    4245
    4346        List<Job> jobs = new ArrayList<>();
     
    5154    @Override
    5255    public List<Project> getMatchingProjectsForUser(User user) {
    53         List<Match> matches = this.matchRepository.getAllByCombinedId_UserAndTypeOrderByCoefficientDesc(user, WorkType.PROJECT);
     56        List<Match> matches = this.matchRepository.getAllByCombinedId_User_IdAndTypeOrderByCoefficientDesc(user.getId(), WorkType.PROJECT);
    5457
    5558        List<Project> projects = new ArrayList<>();
     
    6063        return projects;
    6164    }
     65
     66    @Override
     67    public void setUpUserJobMatches(Job job, User user) {
     68        List<Skill> jobSkill = job.getSkillsRequired();
     69        List<Skill> userSkill = user.getRetainedSkills();
     70
     71        float coef = Matchmaker.match(jobSkill, userSkill);
     72
     73        if(coef!=0){
     74            EmbeddedMatchId matchId = new EmbeddedMatchId(job, user);
     75            Match m = new Match(matchId, coef, WorkType.JOB);
     76            this.matchRepository.save(m);
     77        }
     78    }
     79
     80    @Override
     81    public void setUpUserProjectMatches(Project project, User user) {
     82        List<Skill> projectSkills = project.getSkillsRequired();
     83        List<Skill> userSkill = user.getRetainedSkills();
     84
     85        float coef = Matchmaker.match(projectSkills, userSkill);
     86
     87        if(coef!=0){
     88            EmbeddedMatchId matchId = new EmbeddedMatchId(project, user);
     89            Match m = new Match(matchId, coef, WorkType.PROJECT);
     90            this.matchRepository.save(m);
     91        }
     92    }
     93
     94    @Override
     95    public void setUpUserInternshipMatches(Internship internship, User user) {
     96        List<Skill> internshipSkills = internship.getSkillsTrained();
     97        List<Skill> userSkill = user.getSkillsToLearn();
     98
     99        float coef = Matchmaker.match(internshipSkills, userSkill);
     100
     101        if(coef!=0){
     102            EmbeddedMatchId matchId = new EmbeddedMatchId(internship, user);
     103            Match m = new Match(matchId, coef, WorkType.INTERNSHIP);
     104            this.matchRepository.save(m);
     105        }
     106    }
     107
     108
    62109}
  • src/main/java/it/finki/tinki/web/controller/LoginController.java

    r723994f r509cb95  
    22
    33import it.finki.tinki.model.Users.Account;
     4import it.finki.tinki.model.Users.Company;
    45import it.finki.tinki.model.Users.Team;
    56import it.finki.tinki.model.Users.User;
    6 import it.finki.tinki.model.dto.AccountLoginDTO;
    7 import it.finki.tinki.model.dto.AuthResponseDTO;
    8 import it.finki.tinki.model.dto.LoginResponseDTO;
    9 import it.finki.tinki.model.dto.UserResponseDTO;
     7import it.finki.tinki.model.dto.*;
    108import it.finki.tinki.model.enumerator.AccountType;
    119import it.finki.tinki.service.AccountService;
    1210import it.finki.tinki.service.MatchmakerService;
     11import it.finki.tinki.service.WorkService;
     12import org.apache.coyote.Response;
    1313import org.springframework.web.bind.annotation.*;
    1414import org.springframework.web.server.ResponseStatusException;
     
    2323    AccountService accountService;
    2424    MatchmakerService matchmakerService;
     25    WorkService workService;
    2526
    26     public LoginController(AccountService accountService, MatchmakerService matchmakerService) {
     27    public LoginController(AccountService accountService, MatchmakerService matchmakerService, WorkService workService) {
    2728        this.accountService = accountService;
    2829        this.matchmakerService = matchmakerService;
     30        this.workService = workService;
    2931    }
    3032
     
    3537
    3638        Account a1 = accountService.findUser(body.getEmail(), body.getPassword(), body.getType());
     39
    3740        if(a1!=null){
    3841            if(a1.getClass().equals(User.class)){
    3942
    4043                UserResponseDTO uDto = new UserResponseDTO();
     44
     45                uDto.setError(null);
    4146
    4247                uDto.setId(a1.getId());
     
    5459
    5560                return uDto;
     61
    5662            }else if(a1.getClass().equals(Team.class)){
    5763
     64                TeamResponseDTO tDto = new TeamResponseDTO();
     65
     66                tDto.setError(null);
     67
     68                tDto.setId(a1.getId());
     69                tDto.setEmail(a1.getEmail());
     70                tDto.setName(a1.getName());
     71                tDto.setType(AccountType.USER);
     72                tDto.setMembers(((Team) a1).getMembers());
     73
     74                tDto.setJobs(this.workService.getAllJobsByAccount(a1.getId()));
     75                tDto.setProjects(this.workService.getAllProjectsByAccount(a1.getId()));
     76
     77                return tDto;
     78
    5879            }else{
     80
     81                CompanyResponseDTO cDto = new CompanyResponseDTO();
     82
     83                cDto.setError(null);
     84
     85                cDto.setId(a1.getId());
     86                cDto.setEmail(a1.getEmail());
     87                cDto.setName(a1.getName());
     88                cDto.setType(AccountType.USER);
     89                cDto.setAddress(((Company) a1).getAddress());
     90
     91                cDto.setJobs(this.workService.getAllJobsByAccount(a1.getId()));
     92                cDto.setInternships(this.workService.getAllInternshipsByAccount(a1.getId()));
     93
     94                return cDto;
    5995
    6096            }
    6197        }
    6298
    63         return null;
     99        return new LoginResponseDTO();
    64100    }
    65101
  • src/main/java/it/finki/tinki/web/controller/RegisterController.java

    r723994f r509cb95  
    11package it.finki.tinki.web.controller;
    22
     3import it.finki.tinki.helper.Matchmaker;
     4import it.finki.tinki.model.Jobs.Internship;
     5import it.finki.tinki.model.Jobs.Job;
     6import it.finki.tinki.model.Jobs.Project;
    37import it.finki.tinki.model.Skill;
    48import it.finki.tinki.model.Users.Account;
     9import it.finki.tinki.model.Users.User;
    510import it.finki.tinki.service.AccountService;
     11import it.finki.tinki.service.MatchmakerService;
    612import it.finki.tinki.service.SkillService;
     13import it.finki.tinki.service.WorkService;
    714import org.springframework.web.bind.annotation.*;
    815
     
    1825    AccountService accountService;
    1926    SkillService skillService;
     27    WorkService workService;
     28    MatchmakerService matchmakerService;
    2029
    21     public RegisterController(AccountService accountService, SkillService skillService) {
     30    public RegisterController(AccountService accountService, SkillService skillService, WorkService workService, MatchmakerService matchmakerService) {
    2231        this.accountService = accountService;
    2332        this.skillService = skillService;
     33        this.workService = workService;
     34        this.matchmakerService = matchmakerService;
    2435    }
    2536
    2637    @RequestMapping(path = "/user", method = RequestMethod.POST)
    2738    private Map<String, String> registerUser(@RequestParam String email,
    28                                                 @RequestParam String password,
    29                                                 @RequestParam String name,
    30                                                 @RequestParam String surname,
    31                                                 @RequestParam List<Integer> retainedSkills,
    32                                                 @RequestParam List<Integer> skillsToLearn){
     39                                             @RequestParam String password,
     40                                             @RequestParam String name,
     41                                             @RequestParam String surname,
     42                                             @RequestParam List<Integer> retainedSkills,
     43                                             @RequestParam List<Integer> skillsToLearn){
    3344
    3445        List<Skill> retained = this.skillService.returnSkillsBasedOnId(retainedSkills);
     
    3950        Map<String, String> response = new HashMap<>();
    4051
    41         if(k!=null){
     52        if(k==null){
    4253            response.put("error", "There was an error when trying to register user.");
    4354        }else{
     55            List<Job> jobs = this.workService.getAllJobs();
     56            List<Project> projects = this.workService.getAllProjects();
     57            List<Internship> internships = this.workService.getAllInternships();
     58
     59            jobs.forEach(job -> {
     60                this.matchmakerService.setUpUserJobMatches(job, (User) k);
     61            });
     62
     63            projects.forEach(project -> {
     64                this.matchmakerService.setUpUserProjectMatches(project, (User) k);
     65            });
     66
     67            internships.forEach(internship -> {
     68                this.matchmakerService.setUpUserInternshipMatches(internship, (User) k);
     69            });
     70
    4471            response.put("success", "Registration completed successfully.");
    4572        }
     
    5885        Map<String, String> response = new HashMap<>();
    5986
    60         if(k!=null){
     87        if(k==null){
    6188            response.put("error", "There was an error when trying to register team.");
    6289        }else{
     
    79106        Map<String, String> response = new HashMap<>();
    80107
    81         if(k!=null){
     108        if(k==null){
    82109            response.put("error", "There was an error when trying to register company.");
    83110        }else{
Note: See TracChangeset for help on using the changeset viewer.