Changeset 721cb87 for src/main


Ignore:
Timestamp:
01/06/21 20:48:58 (4 years ago)
Author:
i-ina <76742075+i-ina@…>
Branches:
master
Children:
4a15c9c
Parents:
504c3ef
Message:

register company

Location:
src/main/java/it/finki/tinki
Files:
3 edited

Legend:

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

    r504c3ef r721cb87  
    55import org.springframework.stereotype.Repository;
    66
     7import java.util.Optional;
     8
    79@Repository
    810public interface CompanyRepository extends JpaRepository<Company, Long> {
    911    Company findByEmailAndPassword(String email, String password);
     12    Optional<Object> findByEmail(String email);
    1013}
  • src/main/java/it/finki/tinki/service/AccountService.java

    r504c3ef r721cb87  
    11package it.finki.tinki.service;
    22
     3import it.finki.tinki.model.Skill;
    34import it.finki.tinki.model.Users.Account;
    45import it.finki.tinki.model.enumerator.AccountType;
    56
     7import java.util.List;
    68import java.util.Map;
    79
    810public interface AccountService {
    911    Account findUser(String email, String password, AccountType type);
     12    Account registerUser(String email, String password, String name, String surname, List<Skill> retainedSkills, List<Skill> skillsToLearn);
     13    Account registerTeam(String email, String password, String name, int members);
     14    Account registerCompany(String email, String password, String name, String country, String city, String street);
    1015}
  • src/main/java/it/finki/tinki/service/impl/AccountServiceImpl.java

    r504c3ef r721cb87  
    8080        return this.teamRepository.save(t);
    8181    }
     82
     83    public Account registerCompany(String email, String password, String name, String country, String city, String street){
     84        if(email==null || email.isEmpty() || password==null || password.isEmpty() || name==null || name.isEmpty()
     85                || country==null || country.isEmpty() || city==null || city.isEmpty() || street==null || street.isEmpty()){
     86            throw new InvalidArgumentsException();
     87        }
     88
     89        if(this.companyRepository.findByEmail(email).isPresent()){
     90            throw new UserExistsException();
     91        }
     92
     93        Address a = new Address(country, city, street);
     94        this.addressRepository.save(a);
     95        Company c = new Company(email, password, name, AccountType.COMPANY, a);
     96        return this.companyRepository.save(c);
     97    }
    8298}
Note: See TracChangeset for help on using the changeset viewer.