Ignore:
Timestamp:
01/06/21 21:42:22 (4 years ago)
Author:
i-ina <76742075+i-ina@…>
Branches:
master
Children:
9d4220d
Parents:
721cb87
Message:

added user registration

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

Legend:

Unmodified
Added
Removed
  • src/main/java/it/finki/tinki/controller/RegisterController.java

    r721cb87 r4a15c9c  
    11package it.finki.tinki.controller;
    22
    3 import it.finki.tinki.repository.AddressRepository;
    4 import it.finki.tinki.repository.CompanyRepository;
    5 import it.finki.tinki.repository.TeamRepository;
    6 import it.finki.tinki.repository.UserRepository;
    7 import org.springframework.web.bind.annotation.CrossOrigin;
    8 import org.springframework.web.bind.annotation.RequestMapping;
    9 import org.springframework.web.bind.annotation.RestController;
     3import it.finki.tinki.model.Skill;
     4import it.finki.tinki.model.Users.Account;
     5import it.finki.tinki.model.Users.User;
     6import it.finki.tinki.service.AccountService;
     7import it.finki.tinki.service.SkillService;
     8import org.springframework.http.ResponseEntity;
     9import org.springframework.web.bind.annotation.*;
     10
     11import java.util.ArrayList;
     12import java.util.HashMap;
     13import java.util.List;
     14import java.util.Map;
    1015
    1116@RestController
     
    1419public class RegisterController {
    1520
     21    AccountService accountService;
     22    SkillService skillService;
    1623
     24    public RegisterController(AccountService accountService, SkillService skillService) {
     25        this.accountService = accountService;
     26        this.skillService = skillService;
     27    }
     28
     29    @RequestMapping(path = "/user", method = RequestMethod.POST)
     30    private Map<String, String> registerUser(@RequestParam String email,
     31                                                @RequestParam String password,
     32                                                @RequestParam String name,
     33                                                @RequestParam String surname,
     34                                                @RequestParam List<Integer> retainedSkills,
     35                                                @RequestParam List<Integer> skillsToLearn){
     36
     37        List<Skill> retained = this.skillService.returnSkillsBasedOnId(retainedSkills);
     38        List<Skill> toLearn = this.skillService.returnSkillsBasedOnId(skillsToLearn);
     39
     40        Account k = this.accountService.registerUser(email, password, name, surname, retained, toLearn);
     41
     42        Map<String, String> response = new HashMap<>();
     43
     44        if(k!=null){
     45            response.put("error", "There was an error when trying to register user.");
     46        }else{
     47            response.put("success", "Registration completed successfully.");
     48        }
     49
     50        return response;
     51    }
    1752
    1853
  • src/main/java/it/finki/tinki/repository/SkillRepository.java

    r721cb87 r4a15c9c  
    55import org.springframework.stereotype.Repository;
    66
     7import java.util.Optional;
     8
    79@Repository
    810public interface SkillRepository extends JpaRepository<Skill, Long> {
     11    Optional<Skill> findById(Long id);
    912}
  • src/main/java/it/finki/tinki/service/impl/AccountServiceImpl.java

    r721cb87 r4a15c9c  
    4040
    4141        if(type.equals(AccountType.USER)){
    42             User u1 = userRepository.findByEmailAndPassword(email, password);
     42            User u1 = this.userRepository.findByEmailAndPassword(email, password);
    4343            return u1;
    4444        }
    4545        else if(type.equals(AccountType.TEAM)){
    46             Team t1 = teamRepository.findByEmailAndPassword(email, password);
     46            Team t1 = this.teamRepository.findByEmailAndPassword(email, password);
    4747            return t1;
    4848        }
    4949        else if(type.equals(AccountType.COMPANY)){
    50             Company c1 = companyRepository.findByEmailAndPassword(email, password);
     50            Company c1 = this.companyRepository.findByEmailAndPassword(email, password);
    5151            return c1;
    5252        }
Note: See TracChangeset for help on using the changeset viewer.