TasteChallenge.java
1,822 bytes
| 1 | package com.tasteprint.social; |
|---|---|
| 2 | |
| 3 | import java.time.Instant; |
| 4 | import java.time.LocalDate; |
| 5 | import java.util.UUID; |
| 6 | |
| 7 | import jakarta.persistence.Column; |
| 8 | import jakarta.persistence.Entity; |
| 9 | import jakarta.persistence.Id; |
| 10 | import jakarta.persistence.Table; |
| 11 | |
| 12 | @Entity |
| 13 | @Table(name = "taste_challenge") |
| 14 | class TasteChallenge { |
| 15 | |
| 16 | @Id |
| 17 | private UUID id; |
| 18 | |
| 19 | @Column(name = "owner_id", nullable = false) |
| 20 | private UUID ownerId; |
| 21 | |
| 22 | @Column(nullable = false, length = 100) |
| 23 | private String title; |
| 24 | |
| 25 | @Column(name = "destination_code", nullable = false, length = 2) |
| 26 | private String destinationCode; |
| 27 | |
| 28 | @Column(name = "join_code", nullable = false, length = 8, unique = true) |
| 29 | private String joinCode; |
| 30 | |
| 31 | @Column(name = "starts_on", nullable = false) |
| 32 | private LocalDate startsOn; |
| 33 | |
| 34 | @Column(name = "ends_on", nullable = false) |
| 35 | private LocalDate endsOn; |
| 36 | |
| 37 | @Column(name = "created_at", nullable = false) |
| 38 | private Instant createdAt; |
| 39 | |
| 40 | protected TasteChallenge() { |
| 41 | } |
| 42 | |
| 43 | TasteChallenge(UUID id, UUID ownerId, CreateChallengeRequest request, |
| 44 | String destinationCode, String joinCode, Instant now) { |
| 45 | this.id = id; |
| 46 | this.ownerId = ownerId; |
| 47 | this.title = request.title().trim(); |
| 48 | this.destinationCode = destinationCode; |
| 49 | this.joinCode = joinCode; |
| 50 | this.startsOn = request.startsOn(); |
| 51 | this.endsOn = request.endsOn(); |
| 52 | this.createdAt = now; |
| 53 | } |
| 54 | |
| 55 | UUID id() { |
| 56 | return id; |
| 57 | } |
| 58 | |
| 59 | UUID ownerId() { |
| 60 | return ownerId; |
| 61 | } |
| 62 | |
| 63 | String title() { |
| 64 | return title; |
| 65 | } |
| 66 | |
| 67 | String destinationCode() { |
| 68 | return destinationCode; |
| 69 | } |
| 70 | |
| 71 | String joinCode() { |
| 72 | return joinCode; |
| 73 | } |
| 74 | |
| 75 | LocalDate startsOn() { |
| 76 | return startsOn; |
| 77 | } |
| 78 | |
| 79 | LocalDate endsOn() { |
| 80 | return endsOn; |
| 81 | } |
| 82 | } |
| 83 | |