Skip to content

Commit

Permalink
refactor: ChattingHistoryCustomSlice, ChattingHistoryListDto 네이밍 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
yumyeonghan committed Dec 19, 2023
1 parent c3506b8 commit e003ee1
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 46 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package coffeemeet.server.chatting.history.presentation;

import coffeemeet.server.chatting.history.presentation.dto.ChattingMessageHistoriesHTTP;
import coffeemeet.server.chatting.history.presentation.dto.ChattingHistoryCustomSlice;
import coffeemeet.server.chatting.history.presentation.dto.ChattingRoomHistoriesHTTP;
import coffeemeet.server.chatting.history.service.ChattingRoomHistoryService;
import coffeemeet.server.chatting.history.service.dto.ChattingMessageHistoryListDto;
import coffeemeet.server.chatting.history.service.dto.ChattingHistoryListDto;
import coffeemeet.server.chatting.history.service.dto.ChattingRoomHistoryDto;
import coffeemeet.server.common.annotation.Login;
import coffeemeet.server.common.domain.AuthInfo;
Expand Down Expand Up @@ -33,14 +33,14 @@ public ResponseEntity<ChattingRoomHistoriesHTTP.Response> viewChattingRoomHistor
}

@GetMapping("/{roomHistoryId}")
public ResponseEntity<ChattingMessageHistoriesHTTP.Response> viewChattingRoomMessageHistories(
public ResponseEntity<ChattingHistoryCustomSlice.Response> viewChattingRoomMessageHistories(
@PathVariable Long roomHistoryId,
@RequestParam(defaultValue = "0") Long firstMessageId,
@RequestParam(defaultValue = "50") int pageSize) {
ChattingMessageHistoryListDto chattingMessageHistoryListDto = chattingRoomHistoryService.searchChattingMessageHistories(
ChattingHistoryListDto chattingHistoryListDto = chattingRoomHistoryService.searchChattingMessageHistories(
roomHistoryId, firstMessageId, pageSize);
return ResponseEntity.ok(
ChattingMessageHistoriesHTTP.Response.from(chattingMessageHistoryListDto));
ChattingHistoryCustomSlice.Response.from(chattingHistoryListDto));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@
import static lombok.AccessLevel.PRIVATE;

import coffeemeet.server.chatting.history.service.dto.ChattingHistory;
import coffeemeet.server.chatting.history.service.dto.ChattingMessageHistoryListDto;
import coffeemeet.server.chatting.history.service.dto.ChattingHistoryListDto;
import java.util.List;
import lombok.NoArgsConstructor;

@NoArgsConstructor(access = PRIVATE)
public final class ChattingMessageHistoriesHTTP {
public final class ChattingHistoryCustomSlice {

public record Response(
List<ChattingHistory> chatHistories,
boolean hasNext) {

public static Response from(ChattingMessageHistoryListDto chattingMessageHistoryListDto) {
return new Response(chattingMessageHistoryListDto.contents(),
chattingMessageHistoryListDto.hasNext());
public static Response from(ChattingHistoryListDto chattingHistoryListDto) {
return new Response(chattingHistoryListDto.contents(),
chattingHistoryListDto.hasNext());
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import coffeemeet.server.chatting.history.implement.ChattingRoomHistoryQuery;
import coffeemeet.server.chatting.history.implement.UserChattingHistoryQuery;
import coffeemeet.server.chatting.history.service.dto.ChattingHistory;
import coffeemeet.server.chatting.history.service.dto.ChattingMessageHistoryListDto;
import coffeemeet.server.chatting.history.service.dto.ChattingHistoryListDto;
import coffeemeet.server.chatting.history.service.dto.ChattingRoomHistoryDto;
import coffeemeet.server.user.domain.User;
import coffeemeet.server.user.implement.UserQuery;
Expand Down Expand Up @@ -45,7 +45,7 @@ public List<ChattingRoomHistoryDto> searchChattingRoomHistories(Long userId) {
}

// TODO: 11/20/23 캐쉬 로직 적용
public ChattingMessageHistoryListDto searchChattingMessageHistories(Long roomHistoryId,
public ChattingHistoryListDto searchChattingMessageHistories(Long roomHistoryId,
Long firstMessageId, int pageSize) {
ChattingRoomHistory chattingRoomHistory = chattingRoomHistoryQuery.getChattingRoomHistoryBy(
roomHistoryId);
Expand All @@ -58,7 +58,7 @@ public ChattingMessageHistoryListDto searchChattingMessageHistories(Long roomHis
.map(chattingMessageHistory -> ChattingHistory.of(
chattingMessageHistory.getUser(), chattingMessageHistory))
.toList();
return ChattingMessageHistoryListDto.of(historyDtoList, hasNext);
return ChattingHistoryListDto.of(historyDtoList, hasNext);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package coffeemeet.server.chatting.history.service.dto;

import java.util.List;

public record ChattingHistoryListDto(
List<ChattingHistory> contents,
boolean hasNext
) {

public static ChattingHistoryListDto of(List<ChattingHistory> contents,
boolean hasNext) {
return new ChattingHistoryListDto(contents, hasNext);
}

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;

import coffeemeet.server.auth.domain.RefreshToken;
import coffeemeet.server.chatting.history.presentation.dto.ChattingMessageHistoriesHTTP.Response;
import coffeemeet.server.chatting.history.presentation.dto.ChattingHistoryCustomSlice.Response;
import coffeemeet.server.chatting.history.presentation.dto.ChattingRoomHistoriesHTTP;
import coffeemeet.server.chatting.history.service.ChattingRoomHistoryService;
import coffeemeet.server.chatting.history.service.dto.ChattingMessageHistoryListDto;
import coffeemeet.server.chatting.history.service.dto.ChattingHistoryListDto;
import coffeemeet.server.chatting.history.service.dto.ChattingRoomHistoryDto;
import coffeemeet.server.common.config.ControllerTestConfig;
import coffeemeet.server.common.fixture.AuthFixture;
Expand Down Expand Up @@ -95,14 +95,14 @@ void viewChattingRoomMessageHistoriesTest() throws Exception {
Long firstMessageId = 51L;
int pageSize = 50;

ChattingMessageHistoryListDto chattingMessageHistoryListDto = ChattingFixture.chattingMessageHistoryListDto();
ChattingHistoryListDto chattingHistoryListDto = ChattingFixture.chattingMessageHistoryListDto();
Response response = ChattingFixture.chattingMessageHistoriesHTTPResponse(
chattingMessageHistoryListDto);
chattingHistoryListDto);

given(jwtTokenProvider.extractUserId(TOKEN)).willReturn(userId);
given(chattingRoomHistoryService.searchChattingMessageHistories(roomHistoryId, firstMessageId,
pageSize)).willReturn(
chattingMessageHistoryListDto);
chattingHistoryListDto);

// when, then
mockMvc.perform(get("/api/v1/chatting/room/histories/{roomHistoryId}", roomHistoryId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import coffeemeet.server.chatting.history.implement.ChattingMessageHistoryQuery;
import coffeemeet.server.chatting.history.implement.ChattingRoomHistoryQuery;
import coffeemeet.server.chatting.history.implement.UserChattingHistoryQuery;
import coffeemeet.server.chatting.history.service.dto.ChattingMessageHistoryListDto;
import coffeemeet.server.chatting.history.service.dto.ChattingHistoryListDto;
import coffeemeet.server.common.fixture.ChattingFixture;
import coffeemeet.server.user.implement.UserQuery;
import java.util.List;
Expand Down Expand Up @@ -67,7 +67,7 @@ void searchChattingMessageHistoriesTest(Long firstMessageId, int pageSize) {
chattingMessageHistories);

// when
ChattingMessageHistoryListDto responses = chattingRoomHistoryService.searchChattingMessageHistories(
ChattingHistoryListDto responses = chattingRoomHistoryService.searchChattingMessageHistories(
roomHistoryId, firstMessageId,
pageSize);

Expand Down
22 changes: 11 additions & 11 deletions src/test/java/coffeemeet/server/common/fixture/ChattingFixture.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
import coffeemeet.server.chatting.history.domain.ChattingMessageHistory;
import coffeemeet.server.chatting.history.domain.ChattingRoomHistory;
import coffeemeet.server.chatting.history.domain.UserChattingHistory;
import coffeemeet.server.chatting.history.presentation.dto.ChattingMessageHistoriesHTTP;
import coffeemeet.server.chatting.history.presentation.dto.ChattingHistoryCustomSlice;
import coffeemeet.server.chatting.history.presentation.dto.ChattingRoomHistoriesHTTP;
import coffeemeet.server.chatting.history.service.dto.ChattingMessageHistoryListDto;
import coffeemeet.server.chatting.history.service.dto.ChattingHistoryListDto;
import coffeemeet.server.chatting.history.service.dto.ChattingRoomHistoryDto;
import coffeemeet.server.user.domain.User;
import java.util.List;
Expand Down Expand Up @@ -125,18 +125,18 @@ public static ChattingRoomStatusHTTP.Response chatRoomStatusHTTPResponse(
return ChattingRoomStatusHTTP.Response.from(chattingRoomStatusDto);
}

public static ChattingMessageHistoryListDto chattingMessageHistoryListDto() {
return Instancio.of(ChattingMessageHistoryListDto.class)
public static ChattingHistoryListDto chattingMessageHistoryListDto() {
return Instancio.of(ChattingHistoryListDto.class)
.create();
}

public static ChattingMessageHistoriesHTTP.Response chattingMessageHistoriesHTTPResponse(
ChattingMessageHistoryListDto chattingMessageHistoryListDto) {
return Instancio.of(ChattingMessageHistoriesHTTP.Response.class)
.set(field(ChattingMessageHistoriesHTTP.Response::chatHistories),
chattingMessageHistoryListDto.contents())
.set(field(ChattingMessageHistoriesHTTP.Response::hasNext),
chattingMessageHistoryListDto.hasNext())
public static ChattingHistoryCustomSlice.Response chattingMessageHistoriesHTTPResponse(
ChattingHistoryListDto chattingHistoryListDto) {
return Instancio.of(ChattingHistoryCustomSlice.Response.class)
.set(field(ChattingHistoryCustomSlice.Response::chatHistories),
chattingHistoryListDto.contents())
.set(field(ChattingHistoryCustomSlice.Response::hasNext),
chattingHistoryListDto.hasNext())
.create();
}

Expand Down

0 comments on commit e003ee1

Please sign in to comment.