feat: UserService implementation
This commit is contained in:
parent
c7ef32e28d
commit
9d6ba747a8
5 changed files with 36 additions and 11 deletions
|
@ -1,7 +1,9 @@
|
|||
package eu.ztsh.wymiana.service;
|
||||
|
||||
import eu.ztsh.wymiana.data.repository.UserRepository;
|
||||
import eu.ztsh.wymiana.exception.UserAlreadyExistsException;
|
||||
import eu.ztsh.wymiana.model.User;
|
||||
import eu.ztsh.wymiana.util.UserMapper;
|
||||
import eu.ztsh.wymiana.web.model.UserCreateRequest;
|
||||
import jakarta.validation.Valid;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
@ -15,13 +17,15 @@ public class UserService {
|
|||
|
||||
private final UserRepository userRepository;
|
||||
|
||||
|
||||
public User create(@Valid UserCreateRequest request) {
|
||||
throw new IllegalStateException("Not impplemented yet");
|
||||
if (userRepository.findById(request.pesel()).isPresent()) {
|
||||
throw new UserAlreadyExistsException(request);
|
||||
}
|
||||
return UserMapper.entityToPojo(userRepository.save(UserMapper.requestToEntity(request)));
|
||||
}
|
||||
|
||||
public Optional<User> get(String pesel) {
|
||||
throw new IllegalStateException("Not impplemented yet");
|
||||
return userRepository.findById(pesel).map(UserMapper::entityToPojo);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue