From 5904a2ff60d71c3886390fd515ff6bf9956b96ca Mon Sep 17 00:00:00 2001 From: uPagge Date: Mon, 22 Mar 2021 17:50:54 +0300 Subject: [PATCH] valid service layer --- .../PersonControllerNoValidation.java | 29 +++++++++++++++++++ .../service/PersonService.java | 17 +++++++++++ 2 files changed, 46 insertions(+) create mode 100644 src/main/java/org/sadtech/example/springvalidation/controller/PersonControllerNoValidation.java create mode 100644 src/main/java/org/sadtech/example/springvalidation/service/PersonService.java diff --git a/src/main/java/org/sadtech/example/springvalidation/controller/PersonControllerNoValidation.java b/src/main/java/org/sadtech/example/springvalidation/controller/PersonControllerNoValidation.java new file mode 100644 index 0000000..46de153 --- /dev/null +++ b/src/main/java/org/sadtech/example/springvalidation/controller/PersonControllerNoValidation.java @@ -0,0 +1,29 @@ +package org.sadtech.example.springvalidation.controller; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.RequiredArgsConstructor; +import org.sadtech.example.springvalidation.dto.PersonDto; +import org.sadtech.example.springvalidation.service.PersonService; +import org.springframework.http.ResponseEntity; +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; + +@RestController +@RequestMapping("/api/no-valid/person") +@Tag(name = "Пользователи системы 2", description = "Валидация на уровне сервиса") +@RequiredArgsConstructor +public class PersonControllerNoValidation { + + private final PersonService personService; + + @PostMapping + @Operation(summary = "Сохранение пользователя") + public ResponseEntity save(@RequestBody PersonDto personDto) { + personService.save(personDto); + return ResponseEntity.ok("valid"); + } + +} diff --git a/src/main/java/org/sadtech/example/springvalidation/service/PersonService.java b/src/main/java/org/sadtech/example/springvalidation/service/PersonService.java new file mode 100644 index 0000000..3059daf --- /dev/null +++ b/src/main/java/org/sadtech/example/springvalidation/service/PersonService.java @@ -0,0 +1,17 @@ +package org.sadtech.example.springvalidation.service; + +import org.sadtech.example.springvalidation.dto.PersonDto; +import org.springframework.stereotype.Service; +import org.springframework.validation.annotation.Validated; + +import javax.validation.Valid; + +@Service +@Validated +public class PersonService { + + public void save(@Valid PersonDto personDto) { + // do something + } + +}