Update PegawaiDto
Penyesuaian validator json save kelengkapan data NIK pegawai
This commit is contained in:
parent
c4796f568e
commit
0ea04dfb6a
@ -1,5 +1,10 @@
|
||||
package com.jasamedika.medifirst2000.dto;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import javax.validation.constraints.Pattern;
|
||||
|
||||
import org.hibernate.validator.constraints.NotEmpty;
|
||||
|
||||
import com.jasamedika.medifirst2000.helper.Caption;
|
||||
|
||||
/**
|
||||
@ -7,9 +12,12 @@ import com.jasamedika.medifirst2000.helper.Caption;
|
||||
* @since Feb 24, 2023
|
||||
*/
|
||||
public class PegawaiDto {
|
||||
@NotNull(message = "ID Pegawai tidak boleh null")
|
||||
@Caption(value = "ID Pegawai")
|
||||
private Integer id;
|
||||
|
||||
@NotEmpty(message = "NIK harus diisi")
|
||||
@Pattern(regexp = "\\d{16}", message = "Format NIK tidak sesuai")
|
||||
@Caption(value = "NIK Pegawai")
|
||||
private String noIdentitas;
|
||||
|
||||
|
||||
@ -1472,7 +1472,7 @@ public class PegawaiController extends LocaleController<PegawaiVO> implements IB
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/kelengkapan", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
|
||||
public ResponseEntity<Boolean> completePegawai(@RequestBody PegawaiDto dto) {
|
||||
public ResponseEntity<Boolean> completePegawai(@Valid @RequestBody PegawaiDto dto) {
|
||||
try {
|
||||
pegawaiService.completeDataPegawai(dto);
|
||||
return RestUtil.getJsonResponse(true, HttpStatus.CREATED);
|
||||
|
||||
@ -20,6 +20,7 @@ import org.springframework.web.bind.annotation.ResponseStatus;
|
||||
|
||||
import com.jasamedika.medifirst2000.base.vo.validation.ValidationErrorVO;
|
||||
import com.jasamedika.medifirst2000.constants.Constants;;
|
||||
|
||||
/**
|
||||
* Exception Handler Rest Controller class
|
||||
*
|
||||
@ -30,10 +31,9 @@ import com.jasamedika.medifirst2000.constants.Constants;;
|
||||
@Order(1) // Pertama masuk
|
||||
public class RestErrorHandler {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory
|
||||
.getLogger(RestErrorHandler.class);
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(RestErrorHandler.class);
|
||||
|
||||
private MessageSource messageSource;
|
||||
private MessageSource messageSource;
|
||||
|
||||
@Autowired
|
||||
public RestErrorHandler(MessageSource validationNessageSource) {
|
||||
@ -43,8 +43,7 @@ public class RestErrorHandler {
|
||||
@ExceptionHandler(MethodArgumentNotValidException.class)
|
||||
@ResponseStatus(HttpStatus.BAD_REQUEST)
|
||||
@ResponseBody
|
||||
public ValidationErrorVO processValidationError(
|
||||
MethodArgumentNotValidException ex) {
|
||||
public ValidationErrorVO processValidationError(MethodArgumentNotValidException ex) {
|
||||
LOGGER.warn("Handling data validation error");
|
||||
BindingResult result = ex.getBindingResult();
|
||||
List<FieldError> fieldErrors = result.getFieldErrors();
|
||||
@ -56,20 +55,18 @@ public class RestErrorHandler {
|
||||
ValidationErrorVO dto = new ValidationErrorVO();
|
||||
|
||||
for (FieldError fieldError : fieldErrors) {
|
||||
String localizedErrorMessage = resolveLocalizedErrorMessage(fieldError);
|
||||
dto.addFieldError(fieldError.getField(), localizedErrorMessage);
|
||||
dto.addFieldError(fieldError.getField(), fieldError.getDefaultMessage());
|
||||
}
|
||||
|
||||
return dto;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* resolve error message with parameter locale
|
||||
*/
|
||||
private String resolveLocalizedErrorMessage(FieldError fieldError, String locale) {
|
||||
Locale currentLocale = LocaleContextHolder.getLocale();
|
||||
String localizedErrorMessage = messageSource.getMessage(fieldError,
|
||||
currentLocale);
|
||||
String localizedErrorMessage = messageSource.getMessage(fieldError, currentLocale);
|
||||
|
||||
// If the message was not found, return the most accurate field error
|
||||
// code instead.
|
||||
@ -82,13 +79,12 @@ public class RestErrorHandler {
|
||||
|
||||
return localizedErrorMessage;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* resolve error message with default locale
|
||||
*/
|
||||
private String resolveLocalizedErrorMessage(FieldError fieldError) {
|
||||
String localizedErrorMessage = messageSource.getMessage(fieldError,
|
||||
new Locale(Constants.Locale.INA));
|
||||
String localizedErrorMessage = messageSource.getMessage(fieldError, new Locale(Constants.Locale.INA));
|
||||
|
||||
// If the message was not found, return the most accurate field error
|
||||
// code instead.
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user