Skip to content

Commit 2932d02

Browse files
committed
refactor/OPS-246 : 요구사항 리팩토링
1 parent 21994af commit 2932d02

File tree

8 files changed

+39
-13
lines changed

8 files changed

+39
-13
lines changed

src/main/java/org/tuna/zoopzoop/backend/domain/datasource/controller/DatasourceController.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ public ResponseEntity<?> search(
212212
@RequestParam(required = false) String title,
213213
@RequestParam(required = false) String summary,
214214
@RequestParam(required = false) String category,
215+
@RequestParam(required = false) Integer folderId,
215216
@RequestParam(required = false) String folderName,
216217
@RequestParam(required = false, defaultValue = "true") Boolean isActive,
217218
@PageableDefault(size = 8, sort = "createdAt", direction = Sort.Direction.DESC)
@@ -223,8 +224,9 @@ public ResponseEntity<?> search(
223224
DataSourceSearchCondition cond = DataSourceSearchCondition.builder()
224225
.title(title)
225226
.summary(summary)
226-
.folderName(folderName)
227227
.category(category)
228+
.folderId(folderId)
229+
.folderName(folderName)
228230
.isActive(isActive)
229231
.build();
230232

src/main/java/org/tuna/zoopzoop/backend/domain/datasource/dto/DataSourceSearchCondition.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ public class DataSourceSearchCondition {
99
private final String title;
1010
private final String summary;
1111
private final String category;
12+
private final Integer folderId;
1213
private final String folderName;
1314
private final Boolean isActive;
1415
}

src/main/java/org/tuna/zoopzoop/backend/domain/datasource/dto/reqBodyForCreateDataSource.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33

44
public record reqBodyForCreateDataSource(
55
@NotBlank String sourceUrl,
6-
Integer folderId // null 일 경우 default 폴더(최상위 폴더)
6+
Integer folderId // 0일 경우 default folder
77
) {}

src/main/java/org/tuna/zoopzoop/backend/domain/datasource/repository/DataSourceQRepositoryImpl.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ public Page<DataSourceSearchItem> search(Integer memberId, DataSourceSearchCondi
3636
QPersonalArchive pa = QPersonalArchive.personalArchive;
3737
QTag tag = QTag.tag;
3838

39-
// where
4039
BooleanBuilder where = new BooleanBuilder();
4140

4241
if (cond.getIsActive() == null || Boolean.TRUE.equals(cond.getIsActive())) {
@@ -56,6 +55,9 @@ public Page<DataSourceSearchItem> search(Integer memberId, DataSourceSearchCondi
5655
if (cond.getFolderName() != null && !cond.getFolderName().isBlank()) {
5756
where.and(ds.folder.name.eq(cond.getFolderName()));
5857
}
58+
if (cond.getFolderId() != null) {
59+
where.and(ds.folder.id.eq(cond.getFolderId()));
60+
}
5961

6062
BooleanBuilder ownership = new BooleanBuilder()
6163
.and(pa.member.id.eq(memberId));
@@ -113,7 +115,7 @@ public Page<DataSourceSearchItem> search(Integer memberId, DataSourceSearchCondi
113115
.map(row -> new DataSourceSearchItem(
114116
row.get(ds.id),
115117
row.get(ds.title),
116-
row.get(ds.dataCreatedDate), // LocalDate 그대로 내려줌
118+
row.get(ds.dataCreatedDate),
117119
row.get(ds.summary),
118120
row.get(ds.sourceUrl),
119121
row.get(ds.imageUrl),

src/main/java/org/tuna/zoopzoop/backend/domain/datasource/service/DataSourceService.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import org.tuna.zoopzoop.backend.domain.archive.archive.repository.PersonalArchiveRepository;
1111
import org.tuna.zoopzoop.backend.domain.archive.folder.entity.Folder;
1212
import org.tuna.zoopzoop.backend.domain.archive.folder.repository.FolderRepository;
13+
import org.tuna.zoopzoop.backend.domain.archive.folder.service.FolderService;
1314
import org.tuna.zoopzoop.backend.domain.datasource.dataprocessor.service.DataProcessorService;
1415
import org.tuna.zoopzoop.backend.domain.datasource.dto.DataSourceDto;
1516
import org.tuna.zoopzoop.backend.domain.datasource.dto.DataSourceSearchCondition;
@@ -30,6 +31,7 @@
3031
public class DataSourceService {
3132
private final DataSourceRepository dataSourceRepository;
3233
private final FolderRepository folderRepository;
34+
private final FolderService folderService;
3335
private final PersonalArchiveRepository personalArchiveRepository;
3436
private final TagRepository tagRepository;
3537
private final DataProcessorService dataProcessorService;
@@ -41,11 +43,15 @@ public class DataSourceService {
4143
@Transactional
4244
public int createDataSource(int currentMemberId, String sourceUrl, Integer folderId) {
4345
Folder folder;
44-
if(folderId == null)
46+
if( folderId == null) {
47+
throw new IllegalArgumentException("유효하지 않은 입력값입니다.");
48+
}
49+
if (folderId == 0) {
4550
folder = findDefaultFolder(currentMemberId);
46-
else
51+
} else {
4752
folder = folderRepository.findById(folderId)
4853
.orElseThrow(() -> new NoResultException("존재하지 않는 폴더입니다."));
54+
}
4955

5056
// 폴더 하위 자료 태그 수집(중복 X)
5157
List<Tag> contextTags = collectDistinctTagsOfFolder(folder.getId());
@@ -248,6 +254,20 @@ public Integer updateDataSource(Integer memberId, Integer dataSourceId, String n
248254
*/
249255
@Transactional
250256
public Page<DataSourceSearchItem> search(Integer memberId, DataSourceSearchCondition cond, Pageable pageable) {
257+
Integer folderId = cond.getFolderId();
258+
259+
if (folderId != null && folderId == 0) {
260+
int defaultFolderId = folderService.getDefaultFolderId(memberId);
261+
262+
cond = DataSourceSearchCondition.builder()
263+
.title(cond.getTitle())
264+
.summary(cond.getSummary())
265+
.category(cond.getCategory())
266+
.folderName(cond.getFolderName())
267+
.isActive(cond.getIsActive())
268+
.folderId(defaultFolderId)
269+
.build();
270+
}
251271
return dataSourceQRepository.search(memberId, cond, pageable);
252272
}
253273

src/test/java/org/tuna/zoopzoop/backend/domain/datasource/controller/DatasourceControllerTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,10 @@ void afterAll() {
170170

171171
// create
172172
@Test
173-
@DisplayName("자료 생성 성공 - folderId=null → default 폴더에 등록")
173+
@DisplayName("자료 생성 성공 - folderId=0 → default 폴더에 등록")
174174
@WithUserDetails(value = "KAKAO:testUser_sc1111", setupBefore = TestExecutionEvent.TEST_METHOD)
175175
void create_defaultFolder() throws Exception {
176-
var rq = new reqBodyForCreateDataSource("https://example.com/a", null);
176+
var rq = new reqBodyForCreateDataSource("https://example.com/a", 0);
177177

178178
mockMvc.perform(post("/api/v1/archive")
179179
.contentType(MediaType.APPLICATION_JSON)
@@ -184,6 +184,7 @@ void create_defaultFolder() throws Exception {
184184
.andExpect(jsonPath("$.data").isNumber());
185185
}
186186

187+
187188
@Test
188189
@DisplayName("자료 생성 성공 - folderId 지정 → 해당 폴더에 등록")
189190
@WithUserDetails(value = "KAKAO:testUser_sc1111", setupBefore = TestExecutionEvent.TEST_METHOD)

src/test/java/org/tuna/zoopzoop/backend/domain/datasource/crawler/service/VelogCrawlerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ class VelogCrawlerTest {
66

77
// 날짜 바뀐 velog 포스트에 대해 에러 처리 필요
88
// Text '어제' could not be parsed at index 0
9-
//java.time.format.DateTimeParseException
9+
// java.time.format.DateTimeParseException
1010
// @Test
1111
// void testExtract() throws IOException {
1212
// Document doc = Jsoup.connect("https://velog.io/@hyeonnnnn/VampireSurvivorsClone-04.-PoolManager").get();

src/test/java/org/tuna/zoopzoop/backend/domain/datasource/service/DataSourceServiceTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ void createDataSource_defaultFolder() throws IOException {
9292
return ds;
9393
});
9494

95-
int id = dataSourceService.createDataSource(currentMemberId, sourceUrl, null);
95+
int id = dataSourceService.createDataSource(currentMemberId, sourceUrl, 0);
9696
assertThat(id).isEqualTo(123);
9797
}
9898

@@ -161,7 +161,7 @@ void createDataSource_defaultFolderNotFound() {
161161

162162
// when / then
163163
assertThrows(NoResultException.class, () ->
164-
dataSourceService.createDataSource(currentMemberId, "https://x", null)
164+
dataSourceService.createDataSource(currentMemberId, "https://x", 0)
165165
);
166166
}
167167

@@ -242,7 +242,7 @@ void collectDistinctTagsOfFolder_success() {
242242
.thenReturn(List.of("AI", "Spring", "JPA"));
243243

244244
@SuppressWarnings("unchecked")
245-
List<Tag> ctxTags = (List<Tag>) ReflectionTestUtils.invokeMethod(
245+
List<Tag> ctxTags = ReflectionTestUtils.invokeMethod(
246246
dataSourceService, "collectDistinctTagsOfFolder", folderId
247247
);
248248

@@ -276,7 +276,7 @@ void buildDataSource_maps_dto_and_tags() throws Exception{
276276
when(dataProcessorService.process(eq(url), anyList())).thenReturn(returnedDto);
277277

278278
// when (private 메서드 호출)
279-
DataSource ds = (DataSource) ReflectionTestUtils.invokeMethod(
279+
DataSource ds = ReflectionTestUtils.invokeMethod(
280280
dataSourceService, "buildDataSource", folder, url, context
281281
);
282282

0 commit comments

Comments
 (0)