personalweb

archived
git clone git://git.wimdupont.com/personalweb.git
Log | Files | Refs | LICENSE

commit ae5eaf8108da05285c951f3abcfe312063b70e65
parent 8b93f3f8d7afd3bda24f9de2199b418c50438c29
Author: Wim Dupont <wim@wimdupont.com>
Date:   Wed, 20 Dec 2023 16:47:02 +0100

book series remove trailing zeroes


Former-commit-id: b483a903266e5b3b9eff519382056eafbc87a515
Diffstat:
Msrc/main/java/com/wimdupont/personalweb/model/dao/Book.java | 8+++++---
Msrc/main/java/com/wimdupont/personalweb/model/dto/BookDto.java | 12++++++------
Msrc/main/resources/templates/books.html | 5+++--
Msrc/test/java/com/wimdupont/personalweb/model/dao/BookMother.java | 4+++-
4 files changed, 17 insertions(+), 12 deletions(-)

diff --git a/src/main/java/com/wimdupont/personalweb/model/dao/Book.java b/src/main/java/com/wimdupont/personalweb/model/dao/Book.java @@ -4,6 +4,8 @@ import jakarta.persistence.Entity; import jakarta.persistence.Id; import org.hibernate.annotations.UuidGenerator; +import java.math.BigDecimal; + @Entity public class Book { @@ -17,7 +19,7 @@ public class Book { private String isbn; private String category; private String series; - private Double seriesNumber; + private BigDecimal seriesNumber; public String getId() { return id; @@ -67,11 +69,11 @@ public class Book { this.series = series; } - public Double getSeriesNumber() { + public BigDecimal getSeriesNumber() { return seriesNumber; } - public void setSeriesNumber(Double seriesNumber) { + public void setSeriesNumber(BigDecimal seriesNumber) { this.seriesNumber = seriesNumber; } } diff --git a/src/main/java/com/wimdupont/personalweb/model/dto/BookDto.java b/src/main/java/com/wimdupont/personalweb/model/dto/BookDto.java @@ -1,6 +1,6 @@ package com.wimdupont.personalweb.model.dto; -import org.springframework.util.StringUtils; +import java.math.BigDecimal; public record BookDto( @@ -10,16 +10,16 @@ public record BookDto( String isbn, String category, String series, - Double seriesNumber + BigDecimal seriesNumber ) { public String seriesWithNumber() { if (series != null) { return seriesNumber != null - ? String.format("(%s #%s)", series, seriesNumber) + ? String.format("(%s #%s)", series, seriesNumber.stripTrailingZeros()) : String.format("(%s)", series); } - return ""; + return null; } private BookDto(Builder builder) { @@ -39,7 +39,7 @@ public record BookDto( private String isbn; private String category; private String series; - private Double seriesNumber; + private BigDecimal seriesNumber; private Builder() { } @@ -78,7 +78,7 @@ public record BookDto( return this; } - public Builder seriesNumber(Double val) { + public Builder seriesNumber(BigDecimal val) { seriesNumber = val; return this; } diff --git a/src/main/resources/templates/books.html b/src/main/resources/templates/books.html @@ -19,9 +19,10 @@ <td> <a th:target="_blank" th:href="@{https://openlibrary.org/isbn/{isbn}(isbn=${book.isbn})}" - th:title="${book.title}"> + th:title="|${book.title} - ${book.author}|"> <span th:text="${book.title}"/> - <span class="series" th:text="${book.seriesWithNumber}"/> + <span th:if="${book.seriesWithNumber != null}" + class="series" th:text="${book.seriesWithNumber}"/> </a> </td> <td class="align-right" th:text="${book.author}"/> diff --git a/src/test/java/com/wimdupont/personalweb/model/dao/BookMother.java b/src/test/java/com/wimdupont/personalweb/model/dao/BookMother.java @@ -1,5 +1,7 @@ package com.wimdupont.personalweb.model.dao; +import java.math.BigDecimal; + public class BookMother { public static class Defaults { @@ -9,7 +11,7 @@ public class BookMother { public static final String ISBN = "isbn"; public static final String CATEGORY = "category"; public static final String SERIES = "series"; - public static final Double SERIES_NUMBER = 2.5; + public static final BigDecimal SERIES_NUMBER = BigDecimal.valueOf(2.5); } public static Book withDefaults() {