Skip to content

Commit

Permalink
Merge pull request #109 from BOOK-TALK/#107-opentalkJoin
Browse files Browse the repository at this point in the history
[feat] #107 오픈톡 참여하기 api 에 즐찾 여부 추가
  • Loading branch information
chanwoo7 authored Aug 24, 2024
2 parents f13dac8 + 9e60ba1 commit beaa85c
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ public ResponseEntity<?> opentalkMain() throws Exception {


// [오픈톡 참여하기]
@Operation(summary="오픈톡 참여하기", description="isbn, pageSize를 입력으로 받아, 오픈톡 ID, 채팅 내역 반환",
@Operation(summary="오픈톡 참여하기", description="isbn, pageSize를 입력으로 받아 오픈톡 ID, 즐찾여부, 채팅 내역 반환",
parameters = {@Parameter(name = "isbn", description = "책 ISBN"), @Parameter(name = "pageSize", description = "페이지 당 개수")},
responses = {@ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = OpentalkResponseDto.class)),
description = OpentalkResponseDto.description)})
responses = {@ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = OpentalkJoinResponseDto.class)),
description = OpentalkJoinResponseDto.description)})
@PostMapping("/join")
public ResponseEntity<?> joinOpentalk(@RequestParam String isbn, int pageSize) {
RequestLogger.param(new String[]{"isbn"}, isbn);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
@Setter
public class OpentalkDto {
private Long id;
private String isbn13;
private String bookName;
private String bookImageURL;
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,8 @@
@Builder
public class OpentalkJoinResponseDto {
private final Long opentalkId;
private final boolean isFavorite; //즐찾 여부
private final List<MessageResponseDto> messageResponseDto; //nullable

public static final String description = "opentalkId : 오픈톡 DB ID | isFavorite : 즐찾여부 | messageResponseDto : 0번째 페이지의 채팅 리스트";
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class OpentalkResponseParser {
public void setSimpleBookInfo(OpentalkDto opentalkDto, DetailResponseDto responseDto){
log.trace("OpentalkResponseParser > setSimpleBookInfo()");

opentalkDto.setIsbn13(responseDto.getBookInfoDto().getIsbn13());
opentalkDto.setBookName(responseDto.getBookInfoDto().getBookname());
opentalkDto.setBookImageURL(responseDto.getBookInfoDto().getBookImageURL());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,17 @@ public OpentalkJoinResponseDto joinOpentalk(String isbn, int pageSize){
Long opentalkId = checkExistOpentalk(isbn);
if(opentalkId == null){
opentalkId = createOpentalkIdByIsbn(isbn);
return OpentalkJoinResponseDto.builder().opentalkId(opentalkId).messageResponseDto(null).build();
return OpentalkJoinResponseDto.builder().opentalkId(opentalkId).messageResponseDto(null).isFavorite(false).build();
}
Pageable pageRequest = PageRequest.of(0, pageSize, Sort.by("createdAt").descending());
Page<Message> messagePage = messageService.getMessage(opentalkId, pageRequest);
List<MessageResponseDto> response = messageService.pageToDto(messagePage);
return OpentalkJoinResponseDto.builder().opentalkId(opentalkId).messageResponseDto(response).build();

// 즐찾 여부
UserOpentalk userOpentalk= userOpentalkRepository.findByUserIdAndOpentalkId(userService.loadLoggedinUser(), opentalkRepository.findById(opentalkId).get());
boolean isFavorite = userOpentalk != null;

return OpentalkJoinResponseDto.builder().opentalkId(opentalkId).messageResponseDto(response).isFavorite(isFavorite).build();
}

@Transactional
Expand Down

0 comments on commit beaa85c

Please sign in to comment.