Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
KirillKurdyukov committed Aug 26, 2024
1 parent 832723a commit 1dc2505
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class AllTypesEntity implements Persistable<Integer> {
private double doubleColumn;
private BigDecimal decimalColumn;
private byte[] binaryColumn;
@YdbType("Date")
// @YdbType("Date")
private LocalDate dateColumn;
@YdbType("Datetime")
private LocalDateTime datetimeColumn;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package tech.ydb.data.books;

import java.time.LocalDateTime;
import java.time.Instant;
import java.util.List;
import java.util.Optional;
import java.util.Set;
Expand Down Expand Up @@ -35,11 +35,11 @@ public void crudTest() {
Assertions.assertEquals(1, authorRepository.findAuthorByName("Leo Tolstoy").get(0).getId());

Review review1 = createReview(
1, 1, "Ivan Ivanov", "Masterpiece!", 10, LocalDateTime.parse("2024-03-19T15:52:26")
1, 1, "Ivan Ivanov", "Masterpiece!", 10, Instant.parse("2024-03-19T15:52:26Z")
);

Review review2 = createReview(
2, 1, "Sergey Petrov", "Complex work, but I liked it", 9, LocalDateTime.parse("2024-03-19T16:14:05")
2, 1, "Sergey Petrov", "Complex work, but I liked it", 9, Instant.parse("2024-03-19T16:14:05Z")
);

List<Book> expected = List.of(
Expand All @@ -53,7 +53,7 @@ public void crudTest() {
Assertions.assertTrue(bookO.isPresent());

Review review3 = createReview(
3, 1, "Madiyar Nurgazin", "Great", 8, LocalDateTime.parse("2024-03-19T20:00:00")
3, 1, "Madiyar Nurgazin", "Great", 8, Instant.parse("2024-03-19T20:00:00Z")
);

Book book = bookO.get();
Expand Down Expand Up @@ -97,7 +97,7 @@ public void crudTest() {
List<Author> authors = authorRepository.findAuthorsByBookId(3);
Assertions.assertEquals(Set.of(author1, author2), Set.copyOf(authors));

Review review = createReview(4, 3, "Reader", "Text", 5, LocalDateTime.now());
Review review = createReview(4, 3, "Reader", "Text", 5, Instant.now());
reviewRepository.save(review);

bookRepository.deleteById(3L);
Expand All @@ -115,15 +115,15 @@ public void crudTest() {
@Test
public void pagingAndSortingTest() {
Review review1 = createReview(
1, 1, "Ivan Ivanov", "Masterpiece!", 10, LocalDateTime.parse("2024-03-19T15:52:26")
1, 1, "Ivan Ivanov", "Masterpiece!", 10, Instant.parse("2024-03-19T15:52:26Z")
);
Review review2 = createReview(
2, 1, "Sergey Petrov", "Complex work, but I liked it", 9, LocalDateTime.parse("2024-03-19T16:14:05")
2, 1, "Sergey Petrov", "Complex work, but I liked it", 9, Instant.parse("2024-03-19T16:14:05Z")
);
Review review3 = createReview(3, 1, "Reader", "Text", 100, LocalDateTime.parse("2024-03-19T21:00:00"));
Review review4 = createReview(4, 1, "Reader", "Text2", 80, LocalDateTime.parse("2024-03-19T22:00:00"));
Review review5 = createReview(5, 1, "Reader", "Text3", 75, LocalDateTime.parse("2024-03-19T23:00:00"));
Review review6 = createReview(6, 1, "Reader", "Text4", 50, LocalDateTime.parse("2024-03-20T00:00:00"));
Review review3 = createReview(3, 1, "Reader", "Text", 100, Instant.parse("2024-03-19T21:00:00Z"));
Review review4 = createReview(4, 1, "Reader", "Text2", 80, Instant.parse("2024-03-19T22:00:00Z"));
Review review5 = createReview(5, 1, "Reader", "Text3", 75, Instant.parse("2024-03-19T23:00:00Z"));
Review review6 = createReview(6, 1, "Reader", "Text4", 50, Instant.parse("2024-03-20T00:00:00Z"));
reviewRepository.saveAll(List.of(review3, review4, review5, review6));

Iterable<Review> reviews = reviewRepository.findByReader(
Expand All @@ -149,7 +149,7 @@ public void pagingAndSortingTest() {
Assertions.assertEquals(List.of(review5, review6), reviews);
}

private Review createReview(long id, long bookId, String reader, String text, long rating, LocalDateTime created) {
private Review createReview(long id, long bookId, String reader, String text, long rating, Instant created) {
Review review = new Review();
review.setId(id);
review.setBookId(bookId);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package tech.ydb.data.books.entity;

import java.time.LocalDateTime;

import java.time.Instant;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.data.annotation.Id;
Expand All @@ -21,10 +20,10 @@ public class Review implements Persistable<Long> {
private String reader;
private String text;
private long rating;
private LocalDateTime created;
private Instant created;

public Review() {
this.created = LocalDateTime.now();
this.created = Instant.now();
}

@Transient
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ databaseChangeLog:
type: bigint
- column:
name: created
type: datetime
type: timestamp
- column:
name: book_id
type: bigint
Expand Down

0 comments on commit 1dc2505

Please sign in to comment.