Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion mflix/server/java-spring/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.5.7</version>
<version>3.5.13</version>
<relativePath/>
</parent>

Expand Down Expand Up @@ -88,6 +88,20 @@
<scope>test</scope>
</dependency>

<!-- Testcontainers JUnit Jupiter integration -->
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
Comment thread
ozgliderpilot marked this conversation as resolved.
<scope>test</scope>
</dependency>

<!-- MongoDB Atlas Local container for Testcontainers -->
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>mongodb</artifactId>
Comment thread
ozgliderpilot marked this conversation as resolved.
<scope>test</scope>
</dependency>

<!-- Jackson Databind for JSON serialization/deserialization -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.mongodb.config.AbstractMongoClientConfiguration;
import org.springframework.data.mongodb.core.convert.MongoCustomConversions;
import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;
import org.springframework.lang.NonNull;

Expand Down Expand Up @@ -119,4 +120,9 @@ public MongoDatabase mongoDatabase() {

return client.getDatabase(databaseName);
}

@Bean
public MongoCustomConversions customConversions() {
return MongoCustomConversions.create(MongoCustomConversions.MongoConverterConfigurationAdapter::useNativeDriverJavaTimeCodecs);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.mongodb.samplemflix.model;

import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.Date;
import java.time.Instant;
import java.time.LocalDate;
import java.util.List;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
Expand Down Expand Up @@ -111,9 +112,14 @@ private Fields() {
private String fullplot;

/**
* Release date.
* Release date as a calendar date (no time-of-day or time zone).
*
* <p>A movie release date is a "date only" concept (e.g. "1999-03-31"), not a specific
* moment in time. We use {@link LocalDate} because it represents exactly that: a date
* without time-of-day or time zone information. Spring Data MongoDB maps this via the
* Jsr310 {@code LocalDateCodec}.
*/
private Date released;
private LocalDate released;

/**
* Runtime in minutes.
Expand Down Expand Up @@ -270,9 +276,12 @@ public static class Tomatoes {
private String production;

/**
* Last updated date.
* Timestamp of the last update to Tomatoes ratings.
*
* <p>Stored as BSON DateTime in MongoDB. Uses {@link Instant} for an immutable,
* UTC-only representation of this point-in-time event.
*/
private Date lastUpdated;
private Instant lastUpdated;

/**
* Nested class for viewer ratings.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.mongodb.samplemflix.model.dto;

import com.fasterxml.jackson.annotation.JsonInclude;
import java.util.Date;
import java.time.Instant;
import java.util.List;
import lombok.Builder;

Expand Down Expand Up @@ -61,9 +61,12 @@ public record MovieWithCommentsResult (
Integer totalComments,

/**
* Date of the most recent comment.
* Timestamp of the most recent comment as a UTC instant.
*
* <p>Uses {@link Instant} for an immutable, unambiguous UTC representation.
* BSON DateTime values are converted via {@code Date.toInstant()}.
*/
Date mostRecentCommentDate) {
Instant mostRecentCommentDate) {

/**
* Nested record for comment information.
Expand Down Expand Up @@ -91,8 +94,11 @@ public record CommentInfo (
String text,

/**
* Comment date.
* Comment timestamp as a UTC instant.
*
* <p>Stored as BSON DateTime in MongoDB. Uses {@link Instant} for immutability
* and unambiguous UTC semantics.
*/
Date date) {}
Instant date) {}
}

Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ private MovieWithCommentsResult mapToMovieWithCommentsResult(Document doc) {
.name(commentDoc.getString("name"))
.email(commentDoc.getString("email"))
.text(commentDoc.getString("text"))
.date(commentDoc.getDate("date"))
.date(commentDoc.get("date") != null ? commentDoc.getDate("date").toInstant() : null)
.build())
.collect(Collectors.toList());
}
Expand All @@ -598,7 +598,7 @@ private MovieWithCommentsResult mapToMovieWithCommentsResult(Document doc) {
.imdbRating(imdbRating)
.recentComments(recentComments)
.totalComments(doc.getInteger("totalComments"))
.mostRecentCommentDate(doc.getDate("mostRecentCommentDate"))
.mostRecentCommentDate(doc.getDate("mostRecentCommentDate") != null ? doc.getDate("mostRecentCommentDate").toInstant() : null)
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
import com.mongodb.samplemflix.model.dto.UpdateMovieRequest;
import com.mongodb.samplemflix.model.dto.VectorSearchResult;
import com.mongodb.samplemflix.service.MovieService;
import java.time.Instant;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -343,7 +343,7 @@ void testGetMoviesWithMostComments_Success() throws Exception {
.name("John Doe")
.email("[email protected]")
.text("Great movie!")
.date(new Date())
.date(Instant.now())
.build();

MovieWithCommentsResult result = MovieWithCommentsResult.builder()
Expand All @@ -356,7 +356,7 @@ void testGetMoviesWithMostComments_Success() throws Exception {
.imdbRating(8.5)
.recentComments(Arrays.asList(comment))
.totalComments(5)
.mostRecentCommentDate(new Date())
.mostRecentCommentDate(Instant.now())
.build();

when(movieService.getMoviesWithMostRecentComments(anyInt(), isNull())).thenReturn(Arrays.asList(result));
Expand Down
Loading
Loading