Skip to content
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
3,154 changes: 0 additions & 3,154 deletions full_log.txt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package DiffLens.back_end.domain.library.controller;

import DiffLens.back_end.domain.library.dto.LibraryCreateResult;
import DiffLens.back_end.domain.library.dto.LibraryRequestDto;
import DiffLens.back_end.domain.library.dto.LibraryResponseDTO;
import DiffLens.back_end.domain.library.dto.LibraryCompareRequestDTO;
import DiffLens.back_end.domain.library.dto.LibraryCompareResponseDTO;
import DiffLens.back_end.domain.library.service.LibraryService;
import DiffLens.back_end.domain.library.service.analysis.LibraryAnalysisService;
import DiffLens.back_end.domain.library.service.command.LibraryCommandService;
import DiffLens.back_end.domain.library.service.query.LibraryQueryService;
import DiffLens.back_end.domain.members.entity.Member;
import DiffLens.back_end.domain.members.service.auth.CurrentUserService;
import DiffLens.back_end.global.responses.exception.ApiResponse;
Expand All @@ -14,15 +17,15 @@
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "라이브러리 API")
@RestController
@RequestMapping("/libraries")
@RequiredArgsConstructor
public class LibraryController {

private final LibraryService libraryService;
private final LibraryAnalysisService libraryAnalysisService;
private final LibraryQueryService libraryQueryService;
private final LibraryCommandService libraryCommandService;
private final CurrentUserService currentUserService;

@GetMapping
Expand All @@ -49,7 +52,7 @@ public class LibraryController {
""")
public ApiResponse<LibraryResponseDTO.ListResult> libraryList() {
Member member = currentUserService.getCurrentUser();
LibraryResponseDTO.ListResult result = libraryService.getLibrariesByMember(member);
LibraryResponseDTO.ListResult result = libraryQueryService.getLibrariesByMember(member);
return ApiResponse.onSuccess(result);
}

Expand Down Expand Up @@ -79,12 +82,12 @@ public ApiResponse<LibraryResponseDTO.ListResult> libraryList() {
public ApiResponse<LibraryResponseDTO.CreateResult> createLibrary(
@RequestBody @Valid LibraryRequestDto.Create request) {
Member member = currentUserService.getCurrentUser();
LibraryService.LibraryCreateResult createResult = libraryService.createLibrary(request, member);
LibraryCreateResult createResult = libraryCommandService.createLibrary(request, member);

LibraryResponseDTO.CreateResult result = LibraryResponseDTO.CreateResult.from(
createResult.getLibrary(),
createResult.library(),
request.getSearchHistoryId(),
createResult.getPanelCount());
createResult.panelCount());
return ApiResponse.onSuccess(result);
}

Expand All @@ -107,7 +110,7 @@ public ApiResponse<LibraryResponseDTO.CreateResult> createLibrary(
""")
public ApiResponse<LibraryResponseDTO.LibraryDetail> getLibraryDetail(@PathVariable Long libraryId) {
Member member = currentUserService.getCurrentUser();
LibraryResponseDTO.LibraryDetail result = libraryService.getLibraryDetail(libraryId, member);
LibraryResponseDTO.LibraryDetail result = libraryQueryService.getLibraryDetail(libraryId, member);
return ApiResponse.onSuccess(result);
}

Expand Down Expand Up @@ -143,13 +146,13 @@ public ApiResponse<LibraryResponseDTO.CreateResult> addSearchHistoryToLibrary(
@PathVariable Long libraryId,
@PathVariable Long searchHistoryId) {
Member member = currentUserService.getCurrentUser();
LibraryService.LibraryCreateResult createResult = libraryService.addSearchHistoryToLibrary(libraryId,
searchHistoryId, member);
LibraryCreateResult createResult = libraryCommandService.addSearchHistoryToLibrary(libraryId, searchHistoryId, member);

LibraryResponseDTO.CreateResult result = LibraryResponseDTO.CreateResult.from(
createResult.getLibrary(),
createResult.library(),
searchHistoryId,
createResult.getPanelCount());
createResult.panelCount()
);
return ApiResponse.onSuccess(result);
}

Expand Down Expand Up @@ -179,7 +182,7 @@ public ApiResponse<LibraryResponseDTO.CreateResult> addSearchHistoryToLibrary(
public ApiResponse<LibraryCompareResponseDTO.CompareResult> compareLibraries(
@RequestBody @Valid LibraryCompareRequestDTO.Compare request) {
Member member = currentUserService.getCurrentUser();
LibraryCompareResponseDTO.CompareResult result = libraryService.compareLibraries(request, member);
LibraryCompareResponseDTO.CompareResult result = libraryAnalysisService.compareLibraries(request, member);
return ApiResponse.onSuccess(result);
}

Expand Down Expand Up @@ -208,7 +211,7 @@ public ApiResponse<LibraryCompareResponseDTO.CompareResult> compareLibraries(
public ApiResponse<LibraryResponseDTO.LibraryDashboard> getLibraryDashboard(
@PathVariable("libraryId") Long libraryId) {
Member member = currentUserService.getCurrentUser();
LibraryResponseDTO.LibraryDashboard result = libraryService.getLibraryDashboard(libraryId, member);
LibraryResponseDTO.LibraryDashboard result = libraryAnalysisService.getLibraryDashboard(libraryId, member);
return ApiResponse.onSuccess(result);
}

Expand Down Expand Up @@ -238,8 +241,7 @@ public ApiResponse<LibraryResponseDTO.LibraryPanels> getLibraryPanels(
@RequestParam(value = "page", defaultValue = "1") Integer page,
@RequestParam(value = "size", defaultValue = "20") Integer size) {
Member member = currentUserService.getCurrentUser();
LibraryResponseDTO.LibraryPanels result = libraryService.getLibraryPanels(libraryId, page, size,
member);
LibraryResponseDTO.LibraryPanels result = libraryQueryService.getLibraryPanels(libraryId, page, size, member);
return ApiResponse.onSuccess(result);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package DiffLens.back_end.domain.library.converter.dtoConvert;

import DiffLens.back_end.domain.library.dto.LibraryResponseDTO;
import DiffLens.back_end.domain.library.entity.Library;
import DiffLens.back_end.domain.library.entity.SearchHistoryLibrary;
import DiffLens.back_end.domain.members.entity.Member;
import DiffLens.back_end.domain.panel.entity.Panel;
import DiffLens.back_end.domain.search.entity.SearchHistory;
import DiffLens.back_end.global.dto.ResponsePageDTO;
import DiffLens.back_end.global.responses.code.status.error.ErrorStatus;
import DiffLens.back_end.global.responses.exception.handler.ErrorHandler;

import java.util.List;

public class LibraryQueryConverter {

public static List<LibraryResponseDTO.LibraryDetail.PanelInfo> toPanelInfos(List<Panel> panels) {
return panels.stream()
.map(panel -> LibraryResponseDTO.LibraryDetail.PanelInfo.builder()
.panelId(panel.getId())
.gender(panel.getGender() != null ? panel.getGender().toString() : null)
.age(panel.getAge())
.ageGroup(panel.getAgeGroup())
.residence(panel.getRegion())
.maritalStatus(panel.getMaritalStatus())
.childrenCount(panel.getChildrenCount())
.occupation(panel.getOccupation())
.profileSummary(panel.getProfileSummary())
.build())
.toList();
}

public static List<LibraryResponseDTO.LibraryDetail.SearchHistoryInfo> toSearchHistoryInfos(
List<SearchHistoryLibrary> historyLinks
) {
return historyLinks.stream()
.map(shl -> {
SearchHistory history = shl.getHistory();
return LibraryResponseDTO.LibraryDetail.SearchHistoryInfo.builder()
.searchHistoryId(history.getId())
.content(history.getContent())
.date(toStringOrNull(history.getDate()))
.panelCount(history.getPanelIds() != null ? history.getPanelIds().size() : 0)
.createdAt(toStringOrNull(history.getCreatedDate()))
.build();
})
.toList();
}

public static LibraryResponseDTO.LibraryPanels emptyPanelResponse(Integer size) {
return LibraryResponseDTO.LibraryPanels.builder()
.keys(List.of("respondent_id", "gender", "age", "residence", "personal_income"))
.values(List.of())
.pageInfo(ResponsePageDTO.OffsetLimitPageInfo.builder()
.offset(0)
.currentPage(1)
.currentPageCount(0)
.totalPageCount(0)
.limit(size)
.totalCount(0L)
.hasNext(false)
.hasPrevious(false)
.build())
.build();
}

private static String toStringOrNull(Object obj) {
return obj != null ? obj.toString() : null;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package DiffLens.back_end.domain.library.dto;

import DiffLens.back_end.domain.library.entity.Library;

public record LibraryCompareRedisKeySuffix(
Long lib1Id,
Long lib2Id
) {

public static LibraryCompareRedisKeySuffix of(Library lib1, Library lib2) {
return new LibraryCompareRedisKeySuffix(lib1.getId(), lib2.getId());
}

public static LibraryCompareRedisKeySuffix of(Long lib1, Long lib2) {
return new LibraryCompareRedisKeySuffix(lib1, lib2);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package DiffLens.back_end.domain.library.dto;

import DiffLens.back_end.domain.library.entity.Library;

// 라이브러리 생성 결과를 담는 내부 레코드
public record LibraryCreateResult(
Library library,
int panelCount
) {

public static LibraryCreateResult of(Library library, int panelCount) {
return new LibraryCreateResult(library, panelCount);
}

}
Loading
Loading