valid service layer
This commit is contained in:
parent
ca21901618
commit
5904a2ff60
@ -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");
|
||||
}
|
||||
|
||||
}
|
@ -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
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user