Skip to content

Commit a058e81

Browse files
committed
#74 ✨ feat: item이 저장된 폴더 목록 반환 api 추가
1 parent e756960 commit a058e81

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

src/main/java/com/finsight/finsight/domain/storage/domain/service/FolderService.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import com.finsight.finsight.domain.storage.exception.StorageException;
1010
import com.finsight.finsight.domain.storage.exception.code.StorageErrorCode;
1111
import com.finsight.finsight.domain.storage.persistence.entity.FolderEntity;
12+
import com.finsight.finsight.domain.storage.persistence.entity.FolderItemEntity;
1213
import com.finsight.finsight.domain.storage.persistence.entity.FolderType;
1314
import com.finsight.finsight.domain.storage.persistence.repository.FolderItemRepository;
1415
import com.finsight.finsight.domain.storage.persistence.repository.FolderRepository;
@@ -140,4 +141,27 @@ public List<FolderResponse> updateFolderOrder(Long userId, UpdateFolderOrderRequ
140141

141142
return getFolders(userId, folderType);
142143
}
144+
145+
/**
146+
* 특정 아이템(뉴스/용어)이 저장된 폴더 목록 조회
147+
*/
148+
public List<FolderResponse> getItemFolders(Long userId, String type, Long itemId) {
149+
FolderType folderType;
150+
try {
151+
folderType = FolderType.valueOf(type.toUpperCase());
152+
} catch (IllegalArgumentException e) {
153+
throw new StorageException(StorageErrorCode.FOLDER_TYPE_MISMATCH);
154+
}
155+
156+
List<FolderItemEntity> items = folderItemRepository.findByUserIdAndItemTypeAndItemId(
157+
userId, folderType, itemId);
158+
159+
return items.stream()
160+
.map(item -> {
161+
FolderEntity folder = item.getFolder();
162+
long itemCount = folderItemRepository.countByFolderFolderId(folder.getFolderId());
163+
return FolderResponse.from(folder, itemCount);
164+
})
165+
.toList();
166+
}
143167
}

src/main/java/com/finsight/finsight/domain/storage/presentation/FolderController.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,15 @@ public ResponseEntity<DataResponse<List<FolderResponse>>> updateFolderOrder(
7777
List<FolderResponse> response = folderService.updateFolderOrder(userDetails.getUserId(), request);
7878
return ResponseEntity.ok(DataResponse.from(response));
7979
}
80+
81+
@GetMapping("/items/{itemId}")
82+
@Operation(summary = "아이템이 저장된 폴더 조회", description = "특정 뉴스/용어가 저장된 폴더 목록을 반환합니다.")
83+
public ResponseEntity<DataResponse<List<FolderResponse>>> getItemFolders(
84+
@AuthenticationPrincipal CustomUserDetails userDetails,
85+
@PathVariable Long itemId,
86+
@RequestParam String type
87+
) {
88+
List<FolderResponse> response = folderService.getItemFolders(userDetails.getUserId(), type, itemId);
89+
return ResponseEntity.ok(DataResponse.from(response));
90+
}
8091
}

0 commit comments

Comments
 (0)