commit ccb4eb5715c403212912da00b6110c1087b105f8
parent 34f70ea2e78752b25f827cdc614a1b96025b5649
Author: WimDupont <WimDupont@users.noreply.gitlab.com>
Date: Wed, 25 Aug 2021 10:03:11 +0200
cleanup and added date to blog articles
Diffstat:
8 files changed, 43 insertions(+), 31 deletions(-)
diff --git a/src/main/java/com/wimdupont/personalweb/api/dto/affirmation/Affirmation.java b/src/main/java/com/wimdupont/personalweb/api/dto/affirmation/Affirmation.java
@@ -6,9 +6,9 @@ import lombok.Data;
import lombok.NoArgsConstructor;
@Data
-@Builder(toBuilder = true)
-@AllArgsConstructor
+@Builder
@NoArgsConstructor
+@AllArgsConstructor
public class Affirmation {
private String affirmation;
diff --git a/src/main/java/com/wimdupont/personalweb/controller/BlogController.java b/src/main/java/com/wimdupont/personalweb/controller/BlogController.java
@@ -1,5 +1,6 @@
package com.wimdupont.personalweb.controller;
+import com.wimdupont.personalweb.model.dto.ArticleDto;
import com.wimdupont.personalweb.util.Constants;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
@@ -12,10 +13,13 @@ import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
+import java.time.Instant;
+import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
+import java.util.TimeZone;
@Slf4j
@Controller
@@ -25,12 +29,16 @@ public class BlogController {
@GetMapping
public String getBlog(Model model) {
- List<String> articles = new ArrayList<>();
+ List<ArticleDto> articles = new ArrayList<>();
File[] files = new File(String.format("%s/html", Constants.ARTICLES_DIRECTORY)).listFiles();
if (files != null) {
- Arrays.sort(files, Comparator.comparingLong(File::lastModified));
+ Arrays.sort(files, Comparator.comparingLong(File::lastModified).reversed());
for (File htmlArticle : files) {
- articles.add(htmlArticle.getName().replaceFirst(".html", ""));
+ articles.add(ArticleDto.builder()
+ .name(htmlArticle.getName().replaceFirst(".html", ""))
+ .date(LocalDate.ofInstant(Instant.ofEpochMilli(htmlArticle.lastModified()), TimeZone.getDefault().toZoneId()))
+ .build()
+ );
}
model.addAttribute("articles", articles);
}
diff --git a/src/main/java/com/wimdupont/personalweb/converter/Converter.java b/src/main/java/com/wimdupont/personalweb/converter/Converter.java
@@ -1,9 +1,7 @@
package com.wimdupont.personalweb.converter;
-import com.wimdupont.personalweb.model.dto.DTO;
-
-public interface Converter<E, D extends DTO> {
+public interface Converter<E, D> {
D convert(E entity);
diff --git a/src/main/java/com/wimdupont/personalweb/model/dao/Book.java b/src/main/java/com/wimdupont/personalweb/model/dao/Book.java
@@ -11,7 +11,7 @@ import javax.persistence.GeneratedValue;
import javax.persistence.Id;
@Entity
-@Builder(toBuilder = true)
+@Builder
@Data
@NoArgsConstructor
@AllArgsConstructor
diff --git a/src/main/java/com/wimdupont/personalweb/model/dto/ArticleDto.java b/src/main/java/com/wimdupont/personalweb/model/dto/ArticleDto.java
@@ -0,0 +1,16 @@
+package com.wimdupont.personalweb.model.dto;
+
+
+import lombok.Builder;
+import lombok.Value;
+
+import java.time.LocalDate;
+
+@Value
+@Builder
+public class ArticleDto {
+
+ String name;
+ LocalDate date;
+
+}
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,23 +1,17 @@
package com.wimdupont.personalweb.model.dto;
-import com.fasterxml.jackson.databind.annotation.JsonSerialize;
-import lombok.AllArgsConstructor;
import lombok.Builder;
-import lombok.Data;
-import lombok.NoArgsConstructor;
+import lombok.Value;
-@Data
-@JsonSerialize
-@Builder(toBuilder = true)
-@AllArgsConstructor
-@NoArgsConstructor
-public class BookDto implements DTO{
+@Value
+@Builder
+public class BookDto {
- private String id;
- private String title;
- private String author;
- private String isbn;
- private String category;
- private String series;
- private Double seriesNumber;
+ String id;
+ String title;
+ String author;
+ String isbn;
+ String category;
+ String series;
+ Double seriesNumber;
}
diff --git a/src/main/java/com/wimdupont/personalweb/model/dto/DTO.java b/src/main/java/com/wimdupont/personalweb/model/dto/DTO.java
@@ -1,4 +0,0 @@
-package com.wimdupont.personalweb.model.dto;
-
-public interface DTO {
-}
diff --git a/src/main/resources/templates/blog.html b/src/main/resources/templates/blog.html
@@ -13,7 +13,7 @@
<div th:insert="navigation"/>
</header>
<tr th:each="article : ${articles}">
- <p><a th:href="@{/blog/article/{article}(article=${article})}">[[${article}]]</a></p>
+ <p><a th:href="@{/blog/article/{article}(article=${article.name})}">[[${article.name}]]</a> - [[${article.date}]]</p>
</tr>
</div>
</body>