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
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.ll.spring_additional.boundedContext.answer.controller;

import java.security.Principal;
import java.util.List;

import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -96,4 +97,13 @@ public String answerVote(Principal principal, @PathVariable("id") Integer id) {
return String.format("redirect:/question/detail/%s#answer_%s",
answer.getQuestion().getId(), answer.getId());
}

@GetMapping("/recent_list")
public String showRecentList(Model model) {
List<Answer> answerList = answerService.getAnswerTop15Latest();

model.addAttribute("answerList", answerList);

return "answer/recent_list";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@ public interface AnswerRepository extends JpaRepository<Answer, Integer> {
Long countByAuthor(SiteUser author);

List<Answer> findTop5ByAuthorOrderByCreateDateDesc(SiteUser user);

List<Answer> findTop15ByOrderByCreateDateDesc();
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,8 @@ public Long getAnswerCount(SiteUser author) {
public List<Answer> getAnswerTop5LatestByUser(SiteUser user) {
return answerRepository.findTop5ByAuthorOrderByCreateDateDesc(user);
}

public List<Answer> getAnswerTop15Latest() {
return answerRepository.findTop15ByOrderByCreateDateDesc();
}
}
36 changes: 36 additions & 0 deletions src/main/resources/templates/answer/recent_list.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<html layout:decorate="~{common/layout}">
<main layout:fragment="content" class="container my-3">
<div class="d-flex gap-4 align-items-center">
<H3>최근 답변</H3>
<h5 class="text-secondary">가장 최근에 달린 답변 15개까지 나타납니다.</h5>
</div>
<table class="table">
<thead class="table-dark">
<tr class="text-center">
<th>구분</th>
<th>글쓴이</th>
<th style="width:50%">제목(내용)</th>
<th>날짜</th>
</tr>
</thead>
<tbody>
<tr class="text-center" th:each="answer, loop : ${answerList}">
<td>-</td> <!-- TODO : 카테고리 후 수정 필요 -->
<td th:text="${answer.author.username}"></td>
<td class="text-start">
<a th:href="@{|/question/detail/${answer.question.id}#answer_${answer.id}|}">
<div class="d-flex gap-1">
<p th:if="${answer.question.subject.length() <= 10}" th:text="${'('+answer.question.subject + ')'}"></p>
<p th:if="${answer.question.subject.length() > 10}" th:text="${'('+answer.question.subject.substring(0,10) + '...)'}"></p>

<p th:if="${answer.content.length() <= 10}" th:text="${'('+answer.content + ')'}"></p>
<p th:if="${answer.content.length() > 10}" th:text="${'('+answer.content.substring(0,10) + '...)'}"></p>
</div>
</a>
</td>
<td th:text="${#temporals.format(answer.createDate, 'yyyy년 M월 d일 h:mm a')}"></td>
</tr>
</tbody>
</table>
</main>
</html>
3 changes: 3 additions & 0 deletions src/main/resources/templates/common/navbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
<li class="nav-item">
<a class="nav-link" th:href="@{/user/mypage}" sec:authorize="isAuthenticated()" >마이페이지</a>
</li>
<li class="nav-item">
<a class="nav-link" th:href="@{/answer/recent_list}">최근답변</a>
</li>
</ul>
</div>
</div>
Expand Down