repository valid
This commit is contained in:
parent
5904a2ff60
commit
f42e720332
1
.gitignore
vendored
1
.gitignore
vendored
@ -81,3 +81,4 @@ crashlytics-build.properties
|
|||||||
fabric.properties
|
fabric.properties
|
||||||
.idea/httpRequests
|
.idea/httpRequests
|
||||||
.idea/caches/build_file_checksums.ser
|
.idea/caches/build_file_checksums.ser
|
||||||
|
/data/
|
||||||
|
@ -0,0 +1,28 @@
|
|||||||
|
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.repository.PersonRepository;
|
||||||
|
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
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@RequestMapping("/api/valid-repa/person")
|
||||||
|
@Tag(name = "Пользователи системы 3", description = "Валидация на уровне репозитория")
|
||||||
|
public class PersonControllerValidRepository {
|
||||||
|
|
||||||
|
private final PersonRepository personRepository;
|
||||||
|
|
||||||
|
@PostMapping
|
||||||
|
@Operation(summary = "Сохранение пользователя")
|
||||||
|
public ResponseEntity<PersonDto> save(@RequestBody PersonDto personDto) {
|
||||||
|
return ResponseEntity.ok(personRepository.save(personDto));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -3,15 +3,26 @@ package org.sadtech.example.springvalidation.dto;
|
|||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import lombok.Setter;
|
import lombok.Setter;
|
||||||
|
|
||||||
|
import javax.persistence.Column;
|
||||||
|
import javax.persistence.Entity;
|
||||||
|
import javax.persistence.GeneratedValue;
|
||||||
|
import javax.persistence.GenerationType;
|
||||||
|
import javax.persistence.Id;
|
||||||
|
import javax.persistence.Table;
|
||||||
|
import javax.persistence.Transient;
|
||||||
import javax.validation.constraints.Max;
|
import javax.validation.constraints.Max;
|
||||||
import javax.validation.constraints.Min;
|
import javax.validation.constraints.Min;
|
||||||
import javax.validation.constraints.NotBlank;
|
import javax.validation.constraints.NotBlank;
|
||||||
import javax.validation.constraints.Pattern;
|
import javax.validation.constraints.Pattern;
|
||||||
|
|
||||||
|
@Entity
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
|
@Table(name = "person")
|
||||||
public class PersonDto {
|
public class PersonDto {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
private Long id;
|
private Long id;
|
||||||
|
|
||||||
@NotBlank
|
@NotBlank
|
||||||
@ -19,8 +30,10 @@ public class PersonDto {
|
|||||||
|
|
||||||
@Min(1)
|
@Min(1)
|
||||||
@Max(10)
|
@Max(10)
|
||||||
|
@Column(name = "number")
|
||||||
private int numberBetweenOneAndTen;
|
private int numberBetweenOneAndTen;
|
||||||
|
|
||||||
|
@Column(name = "ip_address")
|
||||||
@Pattern(regexp = "^((25[0-5]|(2[0-4]|1[0-9]|[1-9]|)[0-9])(\\.(?!$)|$)){4}$")
|
@Pattern(regexp = "^((25[0-5]|(2[0-4]|1[0-9]|[1-9]|)[0-9])(\\.(?!$)|$)){4}$")
|
||||||
private String ipAddress;
|
private String ipAddress;
|
||||||
|
|
||||||
|
@ -0,0 +1,8 @@
|
|||||||
|
package org.sadtech.example.springvalidation.repository;
|
||||||
|
|
||||||
|
import org.sadtech.example.springvalidation.dto.PersonDto;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
public interface PersonRepository extends JpaRepository<PersonDto, Long> {
|
||||||
|
|
||||||
|
}
|
@ -1,3 +1,8 @@
|
|||||||
spring:
|
spring:
|
||||||
liquibase:
|
liquibase:
|
||||||
change-log: classpath:db/changelog/changelog.xml
|
change-log: classpath:db/changelog/changelog.xml
|
||||||
|
datasource:
|
||||||
|
url: jdbc:h2:file:./data/validation;DB_CLOSE_DELAY=-1;AUTO_SERVER=TRUE
|
||||||
|
password: password
|
||||||
|
username: sa
|
||||||
|
driver-class-name: org.h2.Driver
|
@ -3,6 +3,14 @@
|
|||||||
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
||||||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd">
|
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.1.xsd">
|
||||||
|
|
||||||
|
<changeSet id="create-person" author="uPagge">
|
||||||
|
<createTable tableName="person">
|
||||||
|
<column name="id" type="int" autoIncrement="true">
|
||||||
|
<constraints primaryKey="true" nullable="false"/>
|
||||||
|
</column>
|
||||||
|
<column name="number" type="int"/>
|
||||||
|
<column name="name" type="varchar(64)"/>
|
||||||
|
<column name="ip_address" type="varchar(64)"/>
|
||||||
|
</createTable>
|
||||||
|
</changeSet>
|
||||||
</databaseChangeLog>
|
</databaseChangeLog>
|
Loading…
Reference in New Issue
Block a user