Changeset 14b648e for src


Ignore:
Timestamp:
01/08/21 20:46:33 (4 years ago)
Author:
Vzdra <vladko.zdravkovski@…>
Branches:
master
Children:
bd38a55
Parents:
31fc5c8
Message:

refactor and edit team/company/user

Location:
src/main/java/it/finki/tinki
Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • src/main/java/it/finki/tinki/repository/CompanyRepository.java

    r31fc5c8 r14b648e  
    1010public interface CompanyRepository extends JpaRepository<Company, Long> {
    1111    Company findByEmailAndPassword(String email, String password);
    12     Optional<Object> findByEmail(String email);
     12    Optional<Company> findByEmail(String email);
     13    Optional<Company> findByIdAndEmail(Long id, String email);
    1314}
  • src/main/java/it/finki/tinki/repository/TeamRepository.java

    r31fc5c8 r14b648e  
    11package it.finki.tinki.repository;
    22
     3import it.finki.tinki.model.Users.Company;
    34import it.finki.tinki.model.Users.Team;
    45import org.springframework.data.jpa.repository.JpaRepository;
     
    1112    Team findByEmailAndPassword(String email, String password);
    1213    Optional<Team> findByEmail(String email);
     14    Optional<Team> findByIdAndEmail(Long id, String email);
    1315}
  • src/main/java/it/finki/tinki/repository/UserRepository.java

    r31fc5c8 r14b648e  
    1111    User findByEmailAndPassword(String email, String password);
    1212    Optional<User> findByEmail(String email);
     13    Optional<User> findByIdAndEmail(Long id, String email);
    1314}
  • src/main/java/it/finki/tinki/service/AccountService.java

    r31fc5c8 r14b648e  
    33import it.finki.tinki.model.Skill;
    44import it.finki.tinki.model.Users.Account;
     5import it.finki.tinki.model.Users.Company;
     6import it.finki.tinki.model.Users.Team;
     7import it.finki.tinki.model.Users.User;
    58import it.finki.tinki.model.enumerator.AccountType;
    69
    710import java.util.List;
     11import java.util.Optional;
    812
    913public interface AccountService {
     
    1317    Account registerCompany(String email, String password, String name, String country, String city, String street);
    1418    Account findByIdAndType(Long accId, AccountType type);
     19    User editUser(Long id, String email, String name, String surname, List<Skill> retainedSkills, List<Skill> skillsToLearn);
     20    Company editCompany(Long id, String email, String name, String country, String city, String street);
     21    Optional<?> findByIdAndEmail(Long id, String email, AccountType type);
     22    Team editTeam(Long id, String email, String name, int members);
    1523}
  • src/main/java/it/finki/tinki/service/impl/AccountServiceImpl.java

    r31fc5c8 r14b648e  
    1919
    2020import java.util.List;
     21import java.util.Optional;
    2122
    2223@Service
     
    8182        User ru = this.userRepository.save(u);
    8283
    83         List<Job> jobs = this.jobRepository.findAll();
    84         List<Project> projects = this.projectRepository.findAll();
    85         List<Internship> internships = this.internshipRepository.findAll();
    86 
    87         if(jobs.size()!=0){
    88             for (Job job : jobs) {
    89                 this.matchmakerService.setUpUserJobMatches(job, u);
    90             }
    91         }
    92 
    93         if(projects.size()!=0){
    94             for (Project project : projects) {
    95                 this.matchmakerService.setUpUserProjectMatches(project, u);
    96             }
    97         }
    98 
    99         if(internships.size()!=0){
    100             for(Internship internship : internships){
    101                 this.matchmakerService.setUpUserInternshipMatches(internship, u);
    102             }
    103         }
     84        setUpUser(ru);
    10485
    10586        return ru;
     
    147128        return null;
    148129    }
     130
     131    public Optional<?> findByIdAndEmail(Long id, String email, AccountType accountType){
     132
     133        switch (accountType){
     134            case USER:
     135                return this.userRepository.findByIdAndEmail(id, email);
     136            case TEAM:
     137                return this.teamRepository.findByIdAndEmail(id, email);
     138            case COMPANY:
     139                return this.companyRepository.findByIdAndEmail(id, email);
     140        }
     141
     142        return Optional.empty();
     143    }
     144
     145    public User editUser(Long id, String email, String name, String surname, List<Skill> retainedSkills, List<Skill> skillsToLearn){
     146        if(email==null || email.isEmpty() || name==null || name.isEmpty() || surname==null || surname.isEmpty()){
     147            throw new InvalidArgumentsException();
     148        }
     149
     150        User u = this.userRepository.findById(id).get();
     151        Optional<User> t = this.userRepository.findByEmail(email);
     152
     153        if(t.isPresent() && !t.get().equals(u)){
     154            throw new UserExistsException();
     155        }
     156
     157        u.setEmail(email);
     158        u.setName(name);
     159        u.setSurname(surname);
     160        u.setRetainedSkills(retainedSkills);
     161        u.setSkillsToLearn(skillsToLearn);
     162
     163        User m = this.userRepository.save(u);
     164
     165        setUpUser(m);
     166
     167        return m;
     168    }
     169
     170    public Company editCompany(Long id, String email, String name, String country, String city, String street){
     171        if(email==null || email.isEmpty() || name==null || name.isEmpty()
     172                || country==null || country.isEmpty() || city==null || city.isEmpty() || street==null || street.isEmpty()){
     173            throw new InvalidArgumentsException();
     174        }
     175
     176        Company c = this.companyRepository.findById(id).get();
     177        Optional<Company> t = this.companyRepository.findByEmail(email);
     178
     179        if(t.isPresent() && !t.get().equals(c)){
     180            throw new UserExistsException();
     181        }
     182
     183        c.setEmail(email);
     184        c.setName(name);
     185
     186        Address ad = c.getAddress();
     187        ad.setCountry(country);
     188        ad.setCity(city);
     189        ad.setStreet(street);
     190
     191        this.addressRepository.save(ad);
     192        return this.companyRepository.save(c);
     193    }
     194
     195    public Team editTeam(Long id, String email, String name, int members){
     196        if(email==null || email.isEmpty() || name==null || name.isEmpty()){
     197            throw new InvalidArgumentsException();
     198        }
     199
     200        Team t = this.teamRepository.findById(id).get();
     201        Optional<Team> tt = this.teamRepository.findByEmail(email);
     202
     203        if(tt.isPresent() && !tt.get().equals(t)){
     204            throw new UserExistsException();
     205        }
     206
     207        t.setEmail(email);
     208        t.setName(name);
     209        t.setMembers(members);
     210
     211        return this.teamRepository.save(t);
     212    }
     213
     214
     215    private void setUpUser(User u){
     216        List<Job> jobs = this.jobRepository.findAll();
     217        List<Project> projects = this.projectRepository.findAll();
     218        List<Internship> internships = this.internshipRepository.findAll();
     219
     220        if(jobs.size()!=0){
     221            for (Job job : jobs) {
     222                this.matchmakerService.setUpUserJobMatches(job, u);
     223            }
     224        }
     225
     226        if(projects.size()!=0){
     227            for (Project project : projects) {
     228                this.matchmakerService.setUpUserProjectMatches(project, u);
     229            }
     230        }
     231
     232        if(internships.size()!=0){
     233            for(Internship internship : internships){
     234                this.matchmakerService.setUpUserInternshipMatches(internship, u);
     235            }
     236        }
     237    }
    149238}
  • src/main/java/it/finki/tinki/web/controller/RegisterController.java

    r31fc5c8 r14b648e  
    6969
    7070    @RequestMapping(path = "/company", method = RequestMethod.POST)
    71     private Map<String, String> registeCompany(@RequestBody CompanyRegisterDTO body){
     71    private Map<String, String> registerCompany(@RequestBody CompanyRegisterDTO body){
    7272
    7373        Account k = this.accountService.registerCompany(body.getEmail(),
Note: See TracChangeset for help on using the changeset viewer.