Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 비회원일 때 북토크 상세조회 가능하도록 수정 #101

Merged
merged 1 commit into from
Oct 13, 2023
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
Expand Up @@ -38,11 +38,12 @@ public class BooktalkController {
@GetMapping("/search/{booktalkId}/detail")
@ResponseStatus(HttpStatus.OK)
@Operation(summary = "북토크 상세 조회")
@SecurityRequirement(name = "JWT Auth")
public ApiResponseDto<BooktalkDetailResponseDto> getBooktalkDetail(
@Parameter(hidden = true) @AuthenticationPrincipal User user,
@Parameter(example = "1") @PathVariable("booktalkId") Long booktalkId) {
return ApiResponseDto.success(SuccessStatus.GET_BOOKTALK_DETAIL_SUCCESS,
booktalkService.getBooktalkDetail(user.getUsername(), booktalkId));
booktalkService.getBooktalkDetail(user == null ? "" : user.getUsername(), booktalkId));
}

@GetMapping("/search")
Expand Down
9 changes: 6 additions & 3 deletions src/main/java/org/sophy/sophy/service/BooktalkService.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,13 @@ public BooktalkDeleteResponseDto deleteBooktalk(

// 북토크 상세 조회
public BooktalkDetailResponseDto getBooktalkDetail(String email, Long booktalkId) {
Member member = memberRepository.getMemberByEmail(email);
Booktalk booktalk = booktalkRepository.getBooktalkById(booktalkId);
Boolean isApply = member.getUserBookTalkList()
.stream().anyMatch(memberBooktalk -> memberBooktalk.getBooktalk().equals(booktalk));
boolean isApply = false;
if (!email.isEmpty()) {
Member member = memberRepository.getMemberByEmail(email);
isApply = member.getUserBookTalkList()
.stream().anyMatch(memberBooktalk -> memberBooktalk.getBooktalk().equals(booktalk));
}
return BooktalkDetailResponseDto.of(booktalk, isApply);
}

Expand Down