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
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public FolderFilesDto getFilesInFolder(Archive archive, Integer folderId) {
Folder folder = folderRepository.findByIdAndArchiveId(folderId, archive.getId())
.orElseThrow(() -> new NoResultException("존재하지 않는 폴더입니다."));

var files = dataSourceRepository.findAllByFolder(folder).stream()
var files = dataSourceRepository.findAllByFolderAndIsActiveTrue(folder).stream()
.map(ds -> new FileSummary(
ds.getId(),
ds.getTitle(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import org.tuna.zoopzoop.backend.domain.datasource.entity.QDataSource;
import org.tuna.zoopzoop.backend.domain.datasource.entity.QTag;

import java.time.LocalDateTime;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -139,7 +139,7 @@ private List<OrderSpecifier<?>> toOrderSpecifiers(Sort sort) {
switch (o.getProperty()) {
case "title" -> specs.add(new OrderSpecifier<>(dir, root.getString("title")));
case "createdAt" -> specs.add(
new OrderSpecifier<>(dir, root.getDateTime("createDate", LocalDateTime.class))
new OrderSpecifier<>(dir, root.getDate("dataCreatedDate", LocalDate.class))
);
default -> { /* 무시 */ }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ where ds.folder.id in (
""")
void deleteByArchiveId(@Param("archiveId") int archiveId);

List<DataSource> findAllByFolder(Folder folder);
List<DataSource> findAllByFolderAndIsActiveTrue(Folder folder);

List<DataSource> findAllByFolderId(Integer folderId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,62 @@ public int restoreMany(List<Integer> ids) {
}

// search
@Transactional
public Page<DataSourceSearchItem> searchInArchive(Integer archiveId, DataSourceSearchCondition cond, Pageable pageable) {
/**
* Personal 검색: memberId 스코프
*/
public Page<DataSourceSearchItem> searchByMember(int memberId,
DataSourceSearchCondition cond,
Pageable pageable) {
cond = normalizeFolder(memberId, null, cond);
return dataSourceQRepository.search(memberId, cond, pageable);
}

/**
* Space(공유) 검색: archiveId 스코프
*/
public Page<DataSourceSearchItem> searchByArchive(int archiveId,
DataSourceSearchCondition cond,
Pageable pageable) {
cond = normalizeFolder(null, archiveId, cond);
return dataSourceQRepository.searchInArchive(archiveId, cond, pageable);
}

/**
* folderId=0 -> 기본 폴더 치환
* memberId가 있으면 Personal, archiveId가 있으면 Shared로 판단
*/
private DataSourceSearchCondition normalizeFolder(Integer memberId,
Integer archiveId,
DataSourceSearchCondition cond) {
if (cond == null) return null;

Integer resolvedFolderId = cond.getFolderId();
if (resolvedFolderId != null && resolvedFolderId == 0) {
if (memberId != null) {
resolvedFolderId = folderRepository.findDefaultFolderByMemberId(memberId)
.orElseThrow(() -> new NoResultException("기본 폴더가 존재하지 않습니다."))
.getId();
} else if (archiveId != null) {
resolvedFolderId = folderRepository.findByArchiveIdAndIsDefaultTrue(archiveId)
.orElseThrow(() -> new NoResultException("공유 기본 폴더 없음"))
.getId();
} else {
throw new IllegalStateException("memberId 또는 archiveId 중 하나는 필요합니다.");
}
}

// cond를 보존하되 folderId만 치환한 새 객체로 반환
return DataSourceSearchCondition.builder()
.title(cond.getTitle())
.summary(cond.getSummary())
.category(cond.getCategory())
.keyword(cond.getKeyword())
.folderName(cond.getFolderName())
.isActive(cond.getIsActive()) // controller default=true, repo에서도 방어
.folderId(resolvedFolderId)
.build();
}

// ===== update: 공통 유틸 =====
// 이미지 유효성 검사
public void validateImage(MultipartFile image) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
import org.tuna.zoopzoop.backend.domain.datasource.dto.DataSourceSearchItem;
import org.tuna.zoopzoop.backend.domain.datasource.dto.UpdateOutcome;
import org.tuna.zoopzoop.backend.domain.datasource.entity.Tag;
import org.tuna.zoopzoop.backend.domain.datasource.repository.DataSourceQRepository;
import org.tuna.zoopzoop.backend.domain.datasource.repository.DataSourceRepository;
import org.tuna.zoopzoop.backend.global.aws.S3Service;

import java.io.IOException;
import java.util.*;
Expand All @@ -30,13 +28,10 @@ public class PersonalDataSourceService {

private final DataSourceService domain;
private final DataSourceRepository dataSourceRepository;
private final DataSourceQRepository dataSourceQRepository;
private final FolderRepository folderRepository;
private final PersonalArchiveRepository personalArchiveRepository;
private final DataProcessorService dataProcessorService;

private final S3Service s3Service;

private int getPersonalArchiveId(int memberId) {
PersonalArchive pa = personalArchiveRepository.findByMemberId(memberId)
.orElseThrow(() -> new NoResultException("개인 아카이브를 찾을 수 없습니다."));
Expand Down Expand Up @@ -191,20 +186,9 @@ public UpdateOutcome updateWithImage(int memberId, int dataSourceId,
}

// search
public Page<DataSourceSearchItem> search(int memberId, DataSourceSearchCondition cond, Pageable pageable) {
if (cond.getFolderId() != null && cond.getFolderId() == 0) {
int defaultFolderId = folderRepository.findDefaultFolderByMemberId(memberId)
.orElseThrow(() -> new NoResultException("기본 폴더가 존재하지 않습니다."))
.getId();
cond = DataSourceSearchCondition.builder()
.title(cond.getTitle())
.summary(cond.getSummary())
.category(cond.getCategory())
.folderName(cond.getFolderName())
.isActive(cond.getIsActive())
.folderId(defaultFolderId)
.build();
}
return dataSourceQRepository.search(memberId, cond, pageable);
public Page<DataSourceSearchItem> search(int memberId,
DataSourceSearchCondition cond,
Pageable pageable) {
return domain.searchByMember(memberId, cond, pageable);
}
}
Loading