Skip to content

Commit

Permalink
Merge pull request #144 from GBGreenBravo/main
Browse files Browse the repository at this point in the history
[fix] 도서 상세페이지 조회 안 되던 이슈 해결
  • Loading branch information
GBGreenBravo authored Nov 22, 2023
2 parents a3e1491 + 99f1656 commit 670deb6
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.springframework.web.servlet.ModelAndView;

import java.util.List;
import java.util.Optional;

@Api(tags = "도서 관련 User API")
@RestController
Expand Down Expand Up @@ -53,7 +54,7 @@ public ModelAndView getBookById(@RequestParam Long id) {
ModelAndView mv = new ModelAndView("book/book-detail");
BookEntity book = bookService.getBookById(id).get();
mv.addObject("book", book);
List<BookReportEntity> bookReports = bookReportService.getPublicBookReportsByBookId(id);
Optional<List<BookReportEntity>> bookReports = Optional.of(bookReportService.getPublicBookReportsByBookId(id));
mv.addObject("bookReports", bookReports);
return mv;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/templates/book/book-detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ <h2 class="text-center my-4">관련 독후감 목록</h2>
<tbody>
<tr th:each="bookReport : ${bookReports.get()}">
<td><a th:href="@{'/book-report?id=' + ${bookReport.id}}" th:text="${bookReport.title}"></a></td>
<td th:text="${bookReport.memberId}"></td>
<td th:text="${bookReport.memberEntity.getNickname}"></td>
<td th:text="${#temporals.format(bookReport.createdAt, 'yyyy년 MM월 dd일')}"></td>
</tr>
</tbody>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@
xhr.onload = function() {
if (xhr.status === 200) {
alert('독후감이 생성되었습니다.');
let memberId = 1; // 동적으로 memberId를 설정하고자 하는 값으로 변경할 수 있음
window.location.href = '/my-book-reports?memberId=' + memberId;// 멤버 테이블 생성 후 수정해야 하는 작업입니다.
let memberId = document.getElementById('memberId').value;
window.location.href = '/my-book-reports?memberId=' + memberId;
} else {
alert('독후감 생성 중 오류가 발생했습니다.');
}
Expand All @@ -39,8 +39,8 @@
xhr.send(JSON.stringify(data));
}
function cancel() {
let memberId = 1; // 동적으로 memberId를 설정하고자 하는 값으로 변경할 수 있음
window.location.href = '/my-book-reports?memberId=' + memberId; // 취소 버튼 누르면 my-book-reports 이동
let memberId = document.getElementById('memberId').value;
window.location.href = '/my-book-reports?memberId=' + memberId;
}
</script>
<body>
Expand All @@ -49,6 +49,7 @@
<div class="container mt-5">
<div class="row">
<div class="col-lg-12">
<input type="hidden" id="memberId" name="memberId" th:value="${#authentication.principal.id}">
<!-- Review form -->
<form>
<!-- Title input -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@
<!-- Post title -->
<h1 class="fw-bolder mb-1" th:text="${bookReport.title}"></h1>
<!-- Post meta content -->
<div class="text-muted fst-italic mb-2" th:text="'Posted on ' + ${#temporals.format(bookReport.createdAt, 'yyyy년 MM월 dd일 HH:mm')} + ' by ' + '멤버 DB 추가 시, 연결 필요합니다.'"></div>
<div class="text-muted fst-italic mb-2" th:text="'Posted on ' + ${#temporals.format(bookReport.createdAt, 'yyyy년 MM월 dd일 HH:mm')} + ' by ' + ${bookReport.memberEntity.getNickname}"></div>
</header>
<div class="col-4 text-end" th:if="${#authorization.expression('isAuthenticated()')} and ${bookReport.memberEntity.getId} == ${#authentication.principal.id}">
<!-- Submit button -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
xhr.onload = function() {
if (xhr.status === 200) {
alert('독후감이 수정되었습니다.');
let memberId = 1; // 동적으로 memberId를 설정하고자 하는 값으로 변경할 수 있음
window.location.href = '/my-book-reports?memberId=' + memberId;// 멤버 테이블 생성 후 수정해야 하는 작업입니다.
let memberId = document.getElementById('memberId').value;
window.location.href = '/my-book-reports?memberId=' + memberId;
} else {
alert('독후감 수정 중 오류가 발생했습니다.');
}
Expand Down Expand Up @@ -75,6 +75,7 @@
</div>
<input type="hidden" id="id" name="id" th:value="${bookReport.id}">
<input type="hidden" id="createdBy" name="created-by" th:value="${bookReport.createdBy}">
<input type="hidden" id="memberId" name="memberId" th:value="${#authentication.principal.id}">
<!-- Submit button -->
<button type="button" class="btn btn-primary" th:onclick="|updateBookReport();|">수정</button>
<button type="button" class="btn btn-secondary" th:onclick="|cancel();|">취소</button>
Expand Down

0 comments on commit 670deb6

Please sign in to comment.