1
1
package org .gluecoders .library .models ;
2
2
3
+ import com .fasterxml .jackson .annotation .JsonIgnore ;
4
+ import org .springframework .data .annotation .Id ;
5
+ import org .springframework .data .mongodb .core .mapping .Document ;
6
+
3
7
import java .io .Serializable ;
8
+ import java .time .Month ;
9
+ import java .time .YearMonth ;
4
10
import java .util .Arrays ;
5
11
import java .util .List ;
6
12
7
13
/**
8
14
* Created by Anand_Rajneesh on 6/10/2017.
9
15
*/
16
+ @ Document (collection = "books" )
10
17
public class Book implements Serializable {
11
18
19
+ @ Id @ JsonIgnore
20
+ private String id ;
12
21
private String title ;
13
22
private String author ;
14
- private int publishedYear ;
23
+ private YearMonth publishedYear ;
15
24
private List <String > categories ;
16
25
private String publisher ;
17
26
private long isbnCode ;
18
27
28
+
19
29
public Book () {
20
30
}
21
31
32
+ public String getId () {
33
+ return id ;
34
+ }
35
+
36
+ public void setId (String id ) {
37
+ this .id = id ;
38
+ }
39
+
22
40
public String getTitle () {
23
41
return title ;
24
42
}
@@ -59,14 +77,6 @@ public void setIsbnCode(long isbnCode) {
59
77
this .isbnCode = isbnCode ;
60
78
}
61
79
62
- public int getPublishedYear () {
63
- return publishedYear ;
64
- }
65
-
66
- public void setPublishedYear (int publishedYear ) {
67
- this .publishedYear = publishedYear ;
68
- }
69
-
70
80
@ Override
71
81
public boolean equals (Object obj ) {
72
82
return obj != null && obj instanceof Book && Long .compare (isbnCode , ((Book ) obj ).getIsbnCode ()) == 0 ;
@@ -81,6 +91,14 @@ public static Builder builder(){
81
91
return new Builder ();
82
92
}
83
93
94
+ public YearMonth getPublishedYear () {
95
+ return publishedYear ;
96
+ }
97
+
98
+ public void setPublishedYear (YearMonth publishedYear ) {
99
+ this .publishedYear = publishedYear ;
100
+ }
101
+
84
102
public static class Builder {
85
103
86
104
private Book book = new Book ();
@@ -100,8 +118,8 @@ public Builder isbn(long isbnCode){
100
118
return this ;
101
119
}
102
120
103
- public Builder yearOfPublishing (int year ){
104
- book .setPublishedYear (year );
121
+ public Builder yearOfPublishing (int year , Month month ){
122
+ book .setPublishedYear (YearMonth . of ( year , month ) );
105
123
return this ;
106
124
}
107
125
0 commit comments