Skip to content

Commit

Permalink
Complete entity validation task
Browse files Browse the repository at this point in the history
  • Loading branch information
JackKaif committed Feb 19, 2024
1 parent 61ff91f commit 22065ac
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ public GuestDTO show(@PathVariable long id) {
}

// 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
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,36 @@

// 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
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,14 @@
import jakarta.persistence.GeneratedValue;
import static jakarta.persistence.GenerationType.IDENTITY;

import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.Future;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Pattern;
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)
Expand All @@ -34,7 +28,20 @@ public class Guest {
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
Expand Down

0 comments on commit 22065ac

Please sign in to comment.