Skip to content

Commit

Permalink
Merge pull request #19 from KUSITMS-MOAMOA/chore/#18
Browse files Browse the repository at this point in the history
[Chore/#18] 경험 기록 리스트 조회 API response dto 수정
  • Loading branch information
oosedus authored Feb 17, 2025
2 parents 0ff5dc5 + ee49a81 commit 0966719
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public RecordResponse.RecordListDto getRecordList(Long userId, String folderName
if (hasNext)
recordList = recordList.subList(0, listSize);

return RecordConverter.toRecordListDto(folderName, recordList, hasNext);
return RecordConverter.toRecordListDto(recordList, hasNext);
}

private List<Record> fetchRecords(User user, String folderName, Long lastRecordId) {
Expand All @@ -177,7 +177,7 @@ private List<Record> fetchRecords(User user, String folderName, Long lastRecordI
* @return
*/
@Transactional(readOnly = true)
public RecordResponse.KeywordRecordListDto getKeywordRecordList(Long userId, String keywordValue, Long lastRecordId) {
public RecordResponse.RecordListDto getKeywordRecordList(Long userId, String keywordValue, Long lastRecordId) {
User user = userDbService.findUserById(userId);

// 해당 keyword를 가진 ability 객체 조회 후 맵핑된 Record 객체 리스트 조회
Expand All @@ -189,7 +189,7 @@ public RecordResponse.KeywordRecordListDto getKeywordRecordList(Long userId, Str
if (hasNext)
recordList = recordList.subList(0, listSize);

return RecordConverter.toKeywordRecordListDto(recordList, hasNext);
return RecordConverter.toRecordListDto(recordList, hasNext);
}

private Keyword getKeyword(String keywordValue) {
Expand Down Expand Up @@ -222,7 +222,7 @@ public RecordResponse.RecordListDto getRecentRecordList(Long userId) {
// 최근 생성된 3개의 데이터만 조회
List<Record> recordList = recordDbService.findRecordListOrderByCreatedAt(user);

return RecordConverter.toRecordListDto("all", recordList, false);
return RecordConverter.toRecordListDto(recordList, false);
}

private void validTextLength(String title, String content) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,40 +75,14 @@ public static RecordResponse.RecordDto toRecordDto(Record record) {
.build();
}

public static RecordResponse.RecordListDto toRecordListDto(String folder, List<Record> recordList, boolean hasNext) {
public static RecordResponse.RecordListDto toRecordListDto(List<Record> recordList, boolean hasNext) {
List<RecordResponse.RecordDto> recordDtoList = recordList.stream()
.map(RecordConverter::toRecordDto)
.toList();

return RecordResponse.RecordListDto.builder()
.folder(folder)
.recordDtoList(recordDtoList)
.hasNext(hasNext)
.build();
}

public static RecordResponse.KeywordRecordDto toKeywordRecordDto(Record record) {
String content = record.getContent();
String truncatedContent = content.length() > 30 ? content.substring(0, 30) : content;

return RecordResponse.KeywordRecordDto.builder()
.analysisId(record.getAnalysis().getAnalysisId())
.recordId(record.getRecordId())
.folder(record.getFolder().getTitle())
.title(record.getTitle())
.content(truncatedContent)
.createdAt(record.getCreatedAtFormatted())
.build();
}

public static RecordResponse.KeywordRecordListDto toKeywordRecordListDto(List<Record> recordList, boolean hasNext) {
List<RecordResponse.KeywordRecordDto> keywordRecordDtoList = recordList.stream()
.map(RecordConverter::toKeywordRecordDto)
.toList();

return RecordResponse.KeywordRecordListDto.builder()
.recordDtoList(keywordRecordDtoList)
.hasNext(hasNext)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,30 +48,7 @@ public static class RecordDto {
@AllArgsConstructor
@Data
public static class RecordListDto {
private String folder;
private List<RecordDto> recordDtoList;
private boolean hasNext;
}

@Builder
@Getter
@AllArgsConstructor
@Data
public static class KeywordRecordDto {
private Long analysisId;
private Long recordId;
private String folder;
private String title;
private String content;
private String createdAt;
}

@Builder
@Getter
@AllArgsConstructor
@Data
public static class KeywordRecordListDto {
private List<KeywordRecordDto> recordDtoList;
private boolean hasNext;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ public ResponseEntity<ApiResponse<RecordResponse.RecordListDto>> getRecordListBy
}

@GetMapping("/keyword")
public ResponseEntity<ApiResponse<RecordResponse.KeywordRecordListDto>> getRecordListByKeyword(
public ResponseEntity<ApiResponse<RecordResponse.RecordListDto>> getRecordListByKeyword(
@UserId Long userId,
@RequestParam(name = "keyword") String keyword,
@RequestParam(name = "lastRecordId", defaultValue = "0") Long lastRecordId
) {
RecordResponse.KeywordRecordListDto recordResponse = recordService.getKeywordRecordList(userId, keyword, lastRecordId);
RecordResponse.RecordListDto recordResponse = recordService.getKeywordRecordList(userId, keyword, lastRecordId);
return ApiResponse.success(RecordSuccessStatus.KEYWORD_RECORD_LIST_GET_SUCCESS, recordResponse);
}

Expand Down

0 comments on commit 0966719

Please sign in to comment.