File tree 3 files changed +31
-9
lines changed
src/main/java/org/soujava/samples/mongodb/products
3 files changed +31
-9
lines changed Original file line number Diff line number Diff line change 5
5
import jakarta .nosql .Embeddable ;
6
6
import org .soujava .samples .mongodb .products .infra .FieldVisibilityStrategy ;
7
7
8
+
8
9
@ Embeddable (Embeddable .EmbeddableType .GROUPING )
9
10
@ JsonbVisibility (FieldVisibilityStrategy .class )
10
- public class Manufacturer {
11
-
12
- @ Column
13
- private String name ;
14
-
15
- @ Column
16
- private String address ;
11
+ public record Manufacturer (@ Column String name , @ Column String address , @ Column String contactNumber ) {
17
12
18
- @ Column
19
- private String contactNumber ;
20
13
}
Original file line number Diff line number Diff line change 9
9
import org .soujava .samples .mongodb .products .infra .FieldVisibilityStrategy ;
10
10
11
11
import java .util .List ;
12
+ import java .util .Objects ;
12
13
import java .util .Set ;
13
14
14
15
@ Entity
@@ -30,4 +31,29 @@ public class Product {
30
31
31
32
@ Column
32
33
private Set <Category > categories ;
34
+
35
+ @ Override
36
+ public boolean equals (Object o ) {
37
+ if (o == null || getClass () != o .getClass ()) {
38
+ return false ;
39
+ }
40
+ Product product = (Product ) o ;
41
+ return Objects .equals (id , product .id );
42
+ }
43
+
44
+ @ Override
45
+ public int hashCode () {
46
+ return Objects .hashCode (id );
47
+ }
48
+
49
+ @ Override
50
+ public String toString () {
51
+ return "Product{" +
52
+ "id='" + id + '\'' +
53
+ ", name='" + name + '\'' +
54
+ ", manufacturer=" + manufacturer +
55
+ ", tags=" + tags +
56
+ ", categories=" + categories +
57
+ '}' ;
58
+ }
33
59
}
Original file line number Diff line number Diff line change 4
4
import jakarta .data .Sort ;
5
5
import jakarta .data .page .PageRequest ;
6
6
import jakarta .enterprise .context .ApplicationScoped ;
7
+ import jakarta .inject .Inject ;
7
8
import jakarta .ws .rs .DELETE ;
8
9
import jakarta .ws .rs .DefaultValue ;
9
10
import jakarta .ws .rs .GET ;
@@ -27,6 +28,7 @@ public class ProductResource {
27
28
28
29
private final ProductRepository repository ;
29
30
31
+ @ Inject
30
32
public ProductResource (ProductRepository repository ) {
31
33
this .repository = repository ;
32
34
}
@@ -47,6 +49,7 @@ public List<Product> get(
47
49
48
50
@ POST
49
51
public Product insert (Product product ) {
52
+ LOGGER .info ("The product will be saved: " + product );
50
53
return repository .save (product );
51
54
}
52
55
You can’t perform that action at this time.
0 commit comments