[Core] [Dataset] Replace id to code

This commit is contained in:
qianmoQ 2024-04-16 19:26:43 +08:00
parent 9d30f17e15
commit 1548e3540c
8 changed files with 20 additions and 27 deletions

View File

@ -1,6 +1,5 @@
<code_scheme name="DataCapStyleScheme" version="173">
<option name="RIGHT_MARGIN" value="180" />
<option name="ENABLE_SECOND_REFORMAT" value="true" />
<option name="KEEP_CONTROL_STATEMENT_IN_ONE_LINE" value="false" />
<option name="KEEP_BLANK_LINES_BEFORE_RBRACE" value="0" />
<option name="CLASS_BRACE_STYLE" value="2" />

View File

@ -9,8 +9,6 @@ import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController()
@RequestMapping(value = "/api/v1/database")
public class DatabaseController
@ -26,9 +24,9 @@ public class DatabaseController
this.service = service;
}
@PostMapping(value = "source/{id}")
public CommonResponse<List<DatabaseEntity>> fetchBySource(@PathVariable Long id)
@PostMapping(value = "source/{code}")
public CommonResponse<Object> fetchBySource(@PathVariable String code)
{
return this.service.getAllBySource(id);
return this.service.getAllBySource(code);
}
}

View File

@ -3,16 +3,14 @@ package io.edurt.datacap.service.service;
import io.edurt.datacap.common.response.CommonResponse;
import io.edurt.datacap.service.entity.DatabaseEntity;
import java.util.List;
public interface DatabaseService
extends BaseService<DatabaseEntity>
{
/**
* Retrieves a list of DatabaseEntity objects based on the provided id.
*
* @param id the id used to filter the results
* @param code the code used to filter the results
* @return a list of DatabaseEntity objects that match the id
*/
CommonResponse<List<DatabaseEntity>> getAllBySource(Long id);
CommonResponse<Object> getAllBySource(String code);
}

View File

@ -1,31 +1,29 @@
package io.edurt.datacap.service.service.impl;
import io.edurt.datacap.common.response.CommonResponse;
import io.edurt.datacap.service.entity.DatabaseEntity;
import io.edurt.datacap.service.entity.SourceEntity;
import io.edurt.datacap.service.repository.SourceRepository;
import io.edurt.datacap.service.repository.metadata.DatabaseRepository;
import io.edurt.datacap.service.service.DatabaseService;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class DatabaseServiceImpl
implements DatabaseService
{
private final DatabaseRepository repository;
private final SourceRepository sourceRepository;
public DatabaseServiceImpl(DatabaseRepository repository)
public DatabaseServiceImpl(DatabaseRepository repository, SourceRepository sourceRepository)
{
this.repository = repository;
this.sourceRepository = sourceRepository;
}
@Override
public CommonResponse<List<DatabaseEntity>> getAllBySource(Long id)
public CommonResponse<Object> getAllBySource(String code)
{
SourceEntity source = SourceEntity.builder()
.id(id)
.build();
return CommonResponse.success(this.repository.findAllBySource(source));
return sourceRepository.findByCode(code)
.map(value -> CommonResponse.success(this.repository.findAllBySource(value)))
.orElse(CommonResponse.failure(String.format("Source [ %s ] not found", code)));
}
}

View File

@ -215,7 +215,7 @@ const createAdminRouter = (router: any) => {
component: () => import('@/views/pages/admin/source/SourceHome.vue')
},
{
path: 'source/:id/manager',
path: 'source/manager/:code',
meta: {
title: 'common.source',
isRoot: false

View File

@ -15,12 +15,12 @@ class DatabaseService
/**
* Retrieves all items by source ID.
*
* @param {number} id - The ID of the source.
* @param {number} code - The ID of the source.
* @return {Promise<ResponseModel>} A promise that resolves to the response model.
*/
getAllBySource(id: string): Promise<ResponseModel>
getAllBySource(code: string): Promise<ResponseModel>
{
return new HttpUtils().post(`${DEFAULT_PATH}/source/${id}`)
return new HttpUtils().post(`${DEFAULT_PATH}/source/${code}`)
}
}

View File

@ -42,7 +42,7 @@
<DropdownMenuContent>
<DropdownMenuGroup>
<DropdownMenuItem :disabled="(loginUserId !== row.user.id) || !row.available" class="cursor-pointer">
<RouterLink :to="`/admin/source/${row?.id}/manager`" target="_blank" class="flex items-center">
<RouterLink :to="`/admin/source/manager/${row?.code}`" target="_blank" class="flex items-center">
<Cog class="mr-2 h-4 w-4"/>
<span>{{ $t('source.common.manager') }}</span>
</RouterLink>

View File

@ -262,8 +262,8 @@ export default defineComponent({
{
this.loading = true
const router = useRouter()
const id = router.currentRoute?.value?.params['id']
DatabaseService.getAllBySource(id as unknown as string)
const code = router.currentRoute?.value?.params['code'] as string
DatabaseService.getAllBySource(code)
.then(response => {
if (response.status) {
response.data.forEach((item: { name: null; catalog: null; id: null }) => {