Skip to content

Commit 4975056

Browse files
authored
[Optimize-4422][admin] CatalogueService add a new method findByTaskId (#4442)
1 parent 6bde30e commit 4975056

4 files changed

Lines changed: 78 additions & 0 deletions

File tree

dinky-admin/src/main/java/org/dinky/controller/CatalogueController.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,28 @@ public Result<List<TreeVo>> getCatalogueSortType() {
162162
return Result.succeed(catalogueSortType);
163163
}
164164

165+
/**
166+
* find catalogue by task id
167+
* @param taskId task id
168+
* @return {@link Result}< {@link Catalogue}>}
169+
*/
170+
@GetMapping("/findByTaskId")
171+
@ApiOperation("Find Catalogue By Task ID")
172+
@ApiImplicitParam(
173+
name = "taskId",
174+
value = "taskId",
175+
required = true,
176+
dataType = "Integer",
177+
dataTypeClass = Integer.class)
178+
public Result<Catalogue> findByTaskId(@RequestParam Integer taskId) {
179+
Catalogue catalogue = catalogueService.findByTaskId(taskId);
180+
if (catalogue != null) {
181+
return Result.succeed(catalogue);
182+
} else {
183+
return Result.failed(Status.CATALOGUE_NOT_EXIST);
184+
}
185+
}
186+
165187
/**
166188
* create catalogue and task
167189
* @param catalogueTaskDTO {@link CatalogueTaskDTO}

dinky-admin/src/main/java/org/dinky/service/catalogue/CatalogueService.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@ public interface CatalogueService extends ISuperService<Catalogue> {
6161
*/
6262
Catalogue findByParentIdAndName(Integer parentId, String name);
6363

64+
/**
65+
* Find a catalogue by its task ID.
66+
*
67+
* @param taskId The ID of the task to find the catalogue for.
68+
* @return A {@link Catalogue} object representing the found catalogue, or null if not found.
69+
*/
70+
Catalogue findByTaskId(Integer taskId);
71+
6472
/**
6573
* Save or update a catalogue and its tasks.
6674
*

dinky-admin/src/main/java/org/dinky/service/catalogue/impl/CatalogueServiceImpl.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,11 @@ public Catalogue findByParentIdAndName(Integer parentId, String name) {
248248
.eq(Catalogue::getName, name));
249249
}
250250

251+
@Override
252+
public Catalogue findByTaskId(Integer taskId) {
253+
return baseMapper.selectOne(new LambdaQueryWrapper<Catalogue>().eq(Catalogue::getTaskId, taskId));
254+
}
255+
251256
/**
252257
* check catalogue task name is exist
253258
*

dinky-admin/src/test/java/org/dinky/service/catalogue/impl/CatalogueServiceImplTest.java

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,4 +177,47 @@ public void importCatalogueTest() {
177177
catalogueServiceImplTest.importCatalogue(importCatalogueDto);
178178
verify(taskService, times(2)).saveBatch(anyList());
179179
}
180+
181+
@Test
182+
public void findByTaskIdTest() {
183+
// Given
184+
Integer taskId = 123;
185+
Catalogue expectedCatalogue = new Catalogue();
186+
expectedCatalogue.setId(1);
187+
expectedCatalogue.setName("Test Catalogue");
188+
expectedCatalogue.setTaskId(taskId);
189+
expectedCatalogue.setType("FlinkSQL");
190+
expectedCatalogue.setParentId(0);
191+
expectedCatalogue.setIsLeaf(true);
192+
193+
// Mock
194+
when(catalogueMapper.selectOne(any(LambdaQueryWrapper.class))).thenReturn(expectedCatalogue);
195+
196+
// When
197+
Catalogue result = catalogueServiceImplTest.findByTaskId(taskId);
198+
199+
// Then
200+
assertNotNull(result);
201+
assertEquals(expectedCatalogue.getId(), result.getId());
202+
assertEquals(expectedCatalogue.getName(), result.getName());
203+
assertEquals(expectedCatalogue.getTaskId(), result.getTaskId());
204+
assertEquals(expectedCatalogue.getType(), result.getType());
205+
assertEquals(expectedCatalogue.getParentId(), result.getParentId());
206+
assertEquals(expectedCatalogue.getIsLeaf(), result.getIsLeaf());
207+
}
208+
209+
@Test
210+
public void findByTaskIdNotFoundTest() {
211+
// Given
212+
Integer taskId = 999;
213+
214+
// Mock - return null when catalogue not found
215+
when(catalogueMapper.selectOne(any(LambdaQueryWrapper.class))).thenReturn(null);
216+
217+
// When
218+
Catalogue result = catalogueServiceImplTest.findByTaskId(taskId);
219+
220+
// Then
221+
assertNull(result);
222+
}
180223
}

0 commit comments

Comments
 (0)