Skip to content

Commit 3a06ceb

Browse files
committed
Add @tostring to Movie entity and align ApiResponse with record accessors
Add @tostring(onlyExplicitlyIncluded = true) to Movie, including id, title, and year for meaningful debug output. Rename ApiResponse methods from JavaBean style (isSuccess/getTimestamp) to record accessor style (success/timestamp) and drop the bridge methods from ErrorResponse and SuccessResponse since records already generate matching accessors.
1 parent 3519b60 commit 3a06ceb

4 files changed

Lines changed: 9 additions & 24 deletions

File tree

mflix/server/java-spring/src/main/java/com/mongodb/samplemflix/model/Movie.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import lombok.EqualsAndHashCode;
88
import lombok.Getter;
99
import lombok.Setter;
10+
import lombok.ToString;
1011
import org.bson.types.ObjectId;
1112
import org.springframework.data.annotation.Id;
1213
import org.springframework.data.mongodb.core.mapping.Document;
@@ -19,11 +20,12 @@
1920
* for awards, IMDB ratings, and Tomatoes ratings.
2021
*
2122
* <p>Note: We use Lombok annotations to reduce boilerplate code:
22-
* - @Getter @Setter @EqualsAndHashCode: Generates getters, setters, equals, and hashCode
23+
* - @Getter @Setter @ToString @EqualsAndHashCode: Generates getters, setters, toString, equals, and hashCode
2324
* - @Builder: Provides a fluent builder pattern for object construction
2425
*/
2526
@Getter
2627
@Setter
28+
@ToString(onlyExplicitlyIncluded = true)
2729
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
2830
@Builder
2931
@Document(collection = "movies")
@@ -77,17 +79,20 @@ private Fields() {
7779
*/
7880
@JsonProperty("_id")
7981
@Id
82+
@ToString.Include
8083
@EqualsAndHashCode.Include
8184
private ObjectId id;
8285

8386
/**
8487
* Movie title (required field).
8588
*/
89+
@ToString.Include
8690
private String title;
8791

8892
/**
8993
* Release year.
9094
*/
95+
@ToString.Include
9196
private Integer year;
9297

9398
/**

mflix/server/java-spring/src/main/java/com/mongodb/samplemflix/model/response/ApiResponse.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ public interface ApiResponse {
1717
*
1818
* @return true for successful responses, false for error responses
1919
*/
20-
boolean isSuccess();
20+
boolean success();
2121

2222
/**
23-
* Gets the timestamp when the response was generated.
23+
* Returns the timestamp when the response was generated.
2424
*
2525
* @return ISO 8601 formatted timestamp string
2626
*/
27-
String getTimestamp();
27+
String timestamp();
2828
}

mflix/server/java-spring/src/main/java/com/mongodb/samplemflix/model/response/ErrorResponse.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,6 @@ public static class ErrorResponseBuilder {
5050
private String timestamp = Instant.now().toString();
5151
}
5252

53-
@Override
54-
public boolean isSuccess() {
55-
return success;
56-
}
57-
58-
@Override
59-
public String getTimestamp() {
60-
return timestamp;
61-
}
62-
6353
/**
6454
* Nested class for detailed error information.
6555
*/

mflix/server/java-spring/src/main/java/com/mongodb/samplemflix/model/response/SuccessResponse.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,6 @@ public static class SuccessResponseBuilder<T> {
5353
private String timestamp = Instant.now().toString();
5454
}
5555

56-
@Override
57-
public boolean isSuccess() {
58-
return success;
59-
}
60-
61-
@Override
62-
public String getTimestamp() {
63-
return timestamp;
64-
}
65-
6656
/**
6757
* Nested class for pagination metadata.
6858
*/

0 commit comments

Comments
 (0)