From d696fec9982105e9520ce3990c3decd87661d006 Mon Sep 17 00:00:00 2001 From: "@hexlet/cli" Date: Mon, 19 Feb 2024 11:58:15 +0300 Subject: [PATCH] submit java-spring-ru/entity-validation --- .current.json | 2 +- java-spring-ru/entity-validation/gradlew | 0 .../exercise/controller/GuestsController.java | 114 +++++++++--------- .../java/exercise/dto/GuestCreateDTO.java | 74 ++++++------ .../src/main/java/exercise/model/Guest.java | 98 +++++++-------- 5 files changed, 144 insertions(+), 144 deletions(-) mode change 100644 => 100755 java-spring-ru/entity-validation/gradlew diff --git a/.current.json b/.current.json index ea74062..84c6fe0 100644 --- a/.current.json +++ b/.current.json @@ -1 +1 @@ -{"assignment":"java-spring-ru/dto-mapper"} +{"assignment":"java-spring-ru/entity-validation"} diff --git a/java-spring-ru/entity-validation/gradlew b/java-spring-ru/entity-validation/gradlew old mode 100644 new mode 100755 diff --git a/java-spring-ru/entity-validation/src/main/java/exercise/controller/GuestsController.java b/java-spring-ru/entity-validation/src/main/java/exercise/controller/GuestsController.java index 67cd9c3..605795b 100644 --- a/java-spring-ru/entity-validation/src/main/java/exercise/controller/GuestsController.java +++ b/java-spring-ru/entity-validation/src/main/java/exercise/controller/GuestsController.java @@ -1,57 +1,57 @@ -package exercise.controller; - -import exercise.mapper.GuestMapper; -import jakarta.validation.Valid; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.RestController; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.http.HttpStatus; -import org.springframework.web.bind.annotation.ResponseStatus; -import java.util.List; - -import exercise.repository.GuestRepository; -import exercise.dto.GuestDTO; -import exercise.dto.GuestCreateDTO; -import exercise.exception.ResourceNotFoundException; - -@RestController -@RequestMapping("/guests") -public class GuestsController { - - @Autowired - private GuestRepository guestRepository; - - @Autowired - private GuestMapper guestMapper; - - @GetMapping(path = "") - public List index() { - var products = guestRepository.findAll(); - return products.stream() - .map(p -> guestMapper.map(p)) - .toList(); - } - - @GetMapping(path = "/{id}") - public GuestDTO show(@PathVariable long id) { - - var guest = guestRepository.findById(id) - .orElseThrow(() -> new ResourceNotFoundException("Guest with id " + id + " not found")); - var guestDto = guestMapper.map(guest); - return guestDto; - } - - // BEGIN - @PostMapping("") - @ResponseStatus(HttpStatus.CREATED) - public GuestDTO create(@Valid @RequestBody GuestCreateDTO newGuest) { - var guest = guestMapper.map(newGuest); - guestRepository.save(guest); - return guestMapper.map(guest); - } - // END -} +package exercise.controller; + +import exercise.mapper.GuestMapper; +import jakarta.validation.Valid; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.ResponseStatus; +import java.util.List; + +import exercise.repository.GuestRepository; +import exercise.dto.GuestDTO; +import exercise.dto.GuestCreateDTO; +import exercise.exception.ResourceNotFoundException; + +@RestController +@RequestMapping("/guests") +public class GuestsController { + + @Autowired + private GuestRepository guestRepository; + + @Autowired + private GuestMapper guestMapper; + + @GetMapping(path = "") + public List index() { + var products = guestRepository.findAll(); + return products.stream() + .map(p -> guestMapper.map(p)) + .toList(); + } + + @GetMapping(path = "/{id}") + public GuestDTO show(@PathVariable long id) { + + var guest = guestRepository.findById(id) + .orElseThrow(() -> new ResourceNotFoundException("Guest with id " + id + " not found")); + var guestDto = guestMapper.map(guest); + return guestDto; + } + + // BEGIN + @PostMapping("") + @ResponseStatus(HttpStatus.CREATED) + public GuestDTO create(@Valid @RequestBody GuestCreateDTO newGuest) { + var guest = guestMapper.map(newGuest); + guestRepository.save(guest); + return guestMapper.map(guest); + } + // END +} diff --git a/java-spring-ru/entity-validation/src/main/java/exercise/dto/GuestCreateDTO.java b/java-spring-ru/entity-validation/src/main/java/exercise/dto/GuestCreateDTO.java index b0027dd..da786e6 100644 --- a/java-spring-ru/entity-validation/src/main/java/exercise/dto/GuestCreateDTO.java +++ b/java-spring-ru/entity-validation/src/main/java/exercise/dto/GuestCreateDTO.java @@ -1,37 +1,37 @@ -package exercise.dto; - -// BEGIN - -import jakarta.persistence.GeneratedValue; -import jakarta.persistence.Id; -import jakarta.validation.constraints.Email; -import jakarta.validation.constraints.FutureOrPresent; -import jakarta.validation.constraints.NotNull; -import jakarta.validation.constraints.Pattern; -import lombok.Getter; -import lombok.Setter; -import org.springframework.data.annotation.CreatedDate; - -import java.time.LocalDate; - -import static jakarta.persistence.GenerationType.IDENTITY; - -@Getter -@Setter -public class GuestCreateDTO { - @NotNull - private String name; - - @Email - private String email; - - @Pattern(regexp = "\\+\\d{11,13}") - private String phoneNumber; - - @Pattern(regexp = "\\d{4}") - private String clubCard; - - @FutureOrPresent - private LocalDate cardValidUntil; -} -// END +package exercise.dto; + +// BEGIN + +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.Id; +import jakarta.validation.constraints.Email; +import jakarta.validation.constraints.FutureOrPresent; +import jakarta.validation.constraints.NotNull; +import jakarta.validation.constraints.Pattern; +import lombok.Getter; +import lombok.Setter; +import org.springframework.data.annotation.CreatedDate; + +import java.time.LocalDate; + +import static jakarta.persistence.GenerationType.IDENTITY; + +@Getter +@Setter +public class GuestCreateDTO { + @NotNull + private String name; + + @Email + private String email; + + @Pattern(regexp = "\\+\\d{11,13}") + private String phoneNumber; + + @Pattern(regexp = "\\d{4}") + private String clubCard; + + @FutureOrPresent + private LocalDate cardValidUntil; +} +// END diff --git a/java-spring-ru/entity-validation/src/main/java/exercise/model/Guest.java b/java-spring-ru/entity-validation/src/main/java/exercise/model/Guest.java index 5c82d2c..efdf4d3 100644 --- a/java-spring-ru/entity-validation/src/main/java/exercise/model/Guest.java +++ b/java-spring-ru/entity-validation/src/main/java/exercise/model/Guest.java @@ -1,49 +1,49 @@ -package exercise.model; - -import jakarta.persistence.Column; -import jakarta.persistence.Id; -import jakarta.persistence.Entity; -import jakarta.persistence.Table; -import jakarta.persistence.EntityListeners; -import jakarta.persistence.GeneratedValue; -import static jakarta.persistence.GenerationType.IDENTITY; - -import jakarta.validation.constraints.*; -import org.springframework.data.annotation.CreatedDate; -import org.springframework.data.jpa.domain.support.AuditingEntityListener; - -import lombok.Getter; -import lombok.Setter; -import java.time.LocalDate; - -@Entity -@Table(name = "guests") -@EntityListeners(AuditingEntityListener.class) -@Getter -@Setter -public class Guest { - - @Id - @GeneratedValue(strategy = IDENTITY) - private long id; - - // BEGIN - @NotNull - private String name; - - @Email - private String email; - - @Pattern(regexp = "^\\+\\d{11,13}$") - private String phoneNumber; - - @Pattern(regexp = "^\\d{4}$") - private String clubCard; - - @FutureOrPresent - private LocalDate cardValidUntil; - // END - - @CreatedDate - private LocalDate createdAt; -} +package exercise.model; + +import jakarta.persistence.Column; +import jakarta.persistence.Id; +import jakarta.persistence.Entity; +import jakarta.persistence.Table; +import jakarta.persistence.EntityListeners; +import jakarta.persistence.GeneratedValue; +import static jakarta.persistence.GenerationType.IDENTITY; + +import jakarta.validation.constraints.*; +import org.springframework.data.annotation.CreatedDate; +import org.springframework.data.jpa.domain.support.AuditingEntityListener; + +import lombok.Getter; +import lombok.Setter; +import java.time.LocalDate; + +@Entity +@Table(name = "guests") +@EntityListeners(AuditingEntityListener.class) +@Getter +@Setter +public class Guest { + + @Id + @GeneratedValue(strategy = IDENTITY) + private long id; + + // BEGIN + @NotNull + private String name; + + @Email + private String email; + + @Pattern(regexp = "^\\+\\d{11,13}$") + private String phoneNumber; + + @Pattern(regexp = "^\\d{4}$") + private String clubCard; + + @FutureOrPresent + private LocalDate cardValidUntil; + // END + + @CreatedDate + private LocalDate createdAt; +}