valid service layer

This commit is contained in:
uPagge 2021-03-22 17:50:54 +03:00
parent ca21901618
commit 5904a2ff60
No known key found for this signature in database
GPG Key ID: 964B40928E4C9088
2 changed files with 46 additions and 0 deletions

View File

@ -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<String> save(@RequestBody PersonDto personDto) {
personService.save(personDto);
return ResponseEntity.ok("valid");
}
}

View File

@ -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
}
}