use of com.rafaelvieira.letmebuy.dto.UserDTO in project letmebuy by rafaelrok.
the class UserService method update.
@Transactional
public UserDTO update(Long id, UserUpdateDTO dto) {
try {
User entity = repository.getOne(id);
copyDtoToEntity(dto, entity);
entity = repository.save(entity);
return new UserDTO(entity);
} catch (EntityNotFoundException e) {
throw new ResourceNotFoundException("Id not found " + id);
}
}
use of com.rafaelvieira.letmebuy.dto.UserDTO in project letmebuy by rafaelrok.
the class UserService method findById.
@Transactional(readOnly = true)
public UserDTO findById(Long id) {
authService.validateSelfOrAdmin(id);
Optional<User> obj = repository.findById(id);
User entity = obj.orElseThrow(() -> new ResourceNotFoundException("Entity not found"));
return new UserDTO(entity);
}
use of com.rafaelvieira.letmebuy.dto.UserDTO in project letmebuy by rafaelrok.
the class UserService method save.
@Transactional
public UserDTO save(UserInsertDTO dto) {
User entity = new User();
copyDtoToEntity(dto, entity);
entity.setPassword(passwordEncoder.encode(dto.getPassword()));
entity = repository.save(entity);
return new UserDTO(entity);
}
use of com.rafaelvieira.letmebuy.dto.UserDTO in project letmebuy by rafaelrok.
the class UserController method insert.
@PostMapping
public ResponseEntity<UserDTO> insert(@RequestBody @Valid UserInsertDTO dto) {
UserDTO newDto = service.save(dto);
URI uri = ServletUriComponentsBuilder.fromCurrentRequest().path("/{id}").buildAndExpand(newDto.getId()).toUri();
return ResponseEntity.created(uri).body(newDto);
}
Aggregations