perf(user/controller): eliminado CreateUserController

parent 38b5ce0a
package com.example.apprecetas.user.infrastructure.controller;
import com.example.apprecetas.exception.UnprocessableEntityException;
import com.example.apprecetas.user.application.CreateUserUseCase;
import com.example.apprecetas.user.infrastructure.controller.dto.UserInputDto;
import com.example.apprecetas.user.infrastructure.controller.dto.UserOutputDto;
import com.example.apprecetas.user.infrastructure.mapper.UserMapper;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.mapstruct.factory.Mappers;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.net.URI;
import java.util.stream.Collectors;
@RestController
@RequestMapping("/user")
@RequiredArgsConstructor
public class CreateUserController {
private final CreateUserUseCase service;
private final UserMapper mapper = Mappers.getMapper(UserMapper.class);
@PostMapping
public ResponseEntity<UserOutputDto> create(@Valid @RequestBody UserInputDto userInputDto, BindingResult result) {
if (result.hasErrors()) {
String errorMsg = result.getFieldErrors().stream()
.map(fieldError -> fieldError.getField() + ": " + fieldError.getDefaultMessage())
.collect(Collectors.joining("; "));
throw new UnprocessableEntityException(errorMsg);
}
try {
URI location = URI.create("/user");
return ResponseEntity.created(location).body(mapper.map(service.create(mapper.map(userInputDto))));
} catch (Exception e) {
throw new UnprocessableEntityException("Usuario ya registrado. Cambie sus credenciales.");
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment