profileShare

rasmusjy / tasteprint

Read-only snapshot

No repository description.

main default branch 169 files Expires Sep 13, 2026, 9:06 AM
Tasting.java 3,104 bytes
1 package com.tasteprint.tasting;
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 = "tasting")
14 class Tasting {
15
16 @Id
17 private UUID id;
18
19 @Column(name = "user_id", nullable = false)
20 private UUID userId;
21
22 @Column(name = "dish_slug", nullable = false, length = 120)
23 private String dishSlug;
24
25 @Column(name = "restaurant_name", length = 160)
26 private String restaurantName;
27
28 @Column(nullable = false, length = 100)
29 private String city;
30
31 @Column(name = "country_code", nullable = false, length = 2)
32 private String countryCode;
33
34 @Column(name = "tasted_on", nullable = false)
35 private LocalDate tastedOn;
36
37 @Column(nullable = false)
38 private short rating;
39
40 @Column(length = 500)
41 private String note;
42
43 @Column(name = "photo_url", length = 500)
44 private String photoUrl;
45
46 private Double latitude;
47
48 private Double longitude;
49
50 @Column(name = "created_at", nullable = false)
51 private Instant createdAt;
52
53 @Column(name = "updated_at", nullable = false)
54 private Instant updatedAt;
55
56 protected Tasting() {
57 }
58
59 Tasting(UUID id, UUID userId, SaveTastingRequest request, String countryCode, Instant now) {
60 this.id = id;
61 this.userId = userId;
62 this.dishSlug = request.dishSlug();
63 apply(request, countryCode, now);
64 this.createdAt = now;
65 }
66
67 void update(SaveTastingRequest request, String countryCode, Instant now) {
68 this.dishSlug = request.dishSlug();
69 apply(request, countryCode, now);
70 }
71
72 private void apply(SaveTastingRequest request, String countryCode, Instant now) {
73 this.restaurantName = clean(request.restaurantName());
74 this.city = request.city().trim();
75 this.countryCode = countryCode;
76 this.tastedOn = request.tastedOn();
77 this.rating = request.rating().shortValue();
78 this.note = clean(request.note());
79 this.photoUrl = clean(request.photoUrl());
80 this.latitude = request.latitude();
81 this.longitude = request.longitude();
82 this.updatedAt = now;
83 }
84
85 private String clean(String value) {
86 return value == null || value.isBlank() ? null : value.trim();
87 }
88
89 UUID id() {
90 return id;
91 }
92
93 UUID userId() {
94 return userId;
95 }
96
97 String dishSlug() {
98 return dishSlug;
99 }
100
101 String restaurantName() {
102 return restaurantName;
103 }
104
105 String city() {
106 return city;
107 }
108
109 String countryCode() {
110 return countryCode;
111 }
112
113 LocalDate tastedOn() {
114 return tastedOn;
115 }
116
117 int rating() {
118 return rating;
119 }
120
121 String note() {
122 return note;
123 }
124
125 String photoUrl() {
126 return photoUrl;
127 }
128
129 Double latitude() {
130 return latitude;
131 }
132
133 Double longitude() {
134 return longitude;
135 }
136
137 Instant createdAt() {
138 return createdAt;
139 }
140 }
141