summaryrefslogtreecommitdiffhomepage
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/com/blog/web/controllers/ArticleController.java14
-rw-r--r--src/main/resources/templates/index.html2
2 files changed, 15 insertions, 1 deletions
diff --git a/src/main/java/com/blog/web/controllers/ArticleController.java b/src/main/java/com/blog/web/controllers/ArticleController.java
index fc18dd7..9af5b92 100644
--- a/src/main/java/com/blog/web/controllers/ArticleController.java
+++ b/src/main/java/com/blog/web/controllers/ArticleController.java
@@ -2,7 +2,10 @@ package com.blog.web.controllers;
import com.blog.web.dto.ArticleDto;
import com.blog.web.models.Article;
+import com.blog.web.models.UserEntity;
+import com.blog.web.security.SecurityUtil;
import com.blog.web.services.ArticleService;
+import com.blog.web.services.UserService;
import jakarta.validation.Valid;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
@@ -15,14 +18,23 @@ import java.util.List;
@Controller
public class ArticleController {
private ArticleService articleService;
+ private UserService userService;
- public ArticleController(ArticleService articleService) {
+ public ArticleController(ArticleService articleService, UserService userService) {
this.articleService = articleService;
+ this.userService = userService;
}
@GetMapping("/articles")
public String listArticles(Model model) {
+ UserEntity user = new UserEntity();
List<ArticleDto> articles = articleService.findAllArticles();
+ String username = SecurityUtil.getSessionUser();
+ if(username != null) {
+ user = userService.findByUsername(username);
+ model.addAttribute("user", user);
+ }
+ model.addAttribute("user", user);
model.addAttribute("articles", articles);
return "index";
}
diff --git a/src/main/resources/templates/index.html b/src/main/resources/templates/index.html
index ea12d7e..1a71459 100644
--- a/src/main/resources/templates/index.html
+++ b/src/main/resources/templates/index.html
@@ -110,8 +110,10 @@
<div th:text="${article.title}" class="w-full font-bold text-xl text-gray-900 px-6">Lorem ipsum dolor sit amet.</div>
<p class="text-gray-800 font-serif text-base px-6 mb-5"></p>
</a>
+ <div th:if="${user.id} == ${article.createdBy.id}">
<a th:href="@{/articles/edit/{articleId}(articleId=${article.id})}" class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-1 px-2 ml-4 text-sm rounded">Edit</a>
<a th:href="@{/articles/delete/{articleId}(articleId=${article.id})}" class="bg-red-500 hover:bg-red-700 text-white font-bold py-1 px-2 ml-4 text-sm rounded">Delete</a>
+ </div>
</div>
<div class="flex-none mt-auto bg-white rounded-b rounded-t-none overflow-hidden shadow-lg p-6">
<div class="flex items-center justify-between">