Skip to content
Open
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
3 changes: 2 additions & 1 deletion chat2db-community-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"build:desktop": "npm run build:web:desktop",
"build:prod": "npm run build:web:prod",
"build:web": "umi build",
"prebuild:web:community": "yarn test:chat-answer-update && yarn test:tree-title-highlight && yarn test:tree-data-update && yarn test:tree-node-lookup && yarn test:data-source-authorization && yarn test:data-source-mutation-refresh && yarn test:ai-model-config && yarn test:ai-model-select && yarn test:export-connections && yarn test:main-page-navigation && yarn test:console-tab-name && yarn test:file-manager-label && yarn test:local-file-encoding && yarn test:editor-close && yarn test:invoice-routing && yarn test:result-set-ui && yarn test:result-status",
"prebuild:web:community": "yarn test:chat-answer-update && yarn test:tree-title-highlight && yarn test:tree-data-update && yarn test:tree-node-lookup && yarn test:data-source-authorization && yarn test:data-source-mutation-refresh && yarn test:ai-model-config && yarn test:ai-model-select && yarn test:export-connections && yarn test:main-page-navigation && yarn test:console-tab-name && yarn test:file-manager-label && yarn test:local-file-encoding && yarn test:editor-close && yarn test:invoice-routing && yarn test:result-set-ui && yarn test:result-status && yarn test:connection-close-request",
"postbuild:web:community": "node ./scripts/verify-production-bundles.cjs",
"build:web:2java": "yarn run build:web:prod && rm -rf ../chat2db-community-server/chat2db-community-start/src/main/resources/thymeleaf/* && cp -r dist/index.html ../chat2db-community-server/chat2db-community-start/src/main/resources/thymeleaf/",
"build:web:desktop": "cross-env UMI_ENV=desktop cross-env APP_NAME=chat2db-pro cross-env APP_VERSION=${npm_config_app_version} cross-env PRINT_LOGS=${npm_config_print_logs} cross-env APP_PORT=${npm_config_app_port} umi build",
Expand Down Expand Up @@ -52,6 +52,7 @@
"test:result-markdown": "tsx src/blocks/SearchResult/components/ResultSetTable/event/onContextmenuCell/handleCopyAsMarkdown.test.ts",
"test:result-set-ui": "tsx src/blocks/SearchResult/components/ResultSet/resultSetUi.test.ts",
"test:result-status": "tsx src/blocks/SearchResult/components/StatusBar/resultSummary.test.ts",
"test:connection-close-request": "tsx src/service/connectionCloseRequest.test.ts",
"test:result-tab-preferences": "tsx src/blocks/SearchResult/resultTabPreferences.test.ts && tsx src/service/resultTabShortcut.test.ts",
"test:result-inspector": "tsx src/store/workspace/utils/resultInspector.test.ts && yarn test:search-result-tab-selection",
"test:result-operation-record": "tsx src/blocks/SearchResult/components/ResultSetTable/hooks/useOperationRecord.test.tsx && tsx src/blocks/SearchResult/components/ResultSetTable/event/onChangeCellValue/index.test.ts",
Expand Down
5 changes: 3 additions & 2 deletions chat2db-community-client/src/service/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
import { ISchemaItem } from '@/typings/schema';
import { UpdatePositionInTree } from '@/typings/tree';
import createRequest from './base';
import { connectionCloseRequest } from './connectionCloseRequest';

export interface IDriverResponse {
driverConfigList: {
Expand Down Expand Up @@ -152,8 +153,8 @@ const exportDataSource = createRequest<
method: 'post',
});

const closeConnection = createRequest<{ id: number }, void>('/api/connection/close', {
method: 'get',
const closeConnection = createRequest<{ id: number }, void>(connectionCloseRequest.path, {
method: connectionCloseRequest.method,
});

export default {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import assert from 'node:assert/strict';
import { connectionCloseRequest } from './connectionCloseRequest';

assert.deepEqual(connectionCloseRequest, {
path: '/api/connection/close',
method: 'post',
});

console.log('connection close request contract tests passed');
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
export const connectionCloseRequest = {
path: '/api/connection/close',
method: 'post' as const,
};
Original file line number Diff line number Diff line change
Expand Up @@ -194,14 +194,14 @@ public DataResult<DataSourceResponse> queryById(@RequestParam("id") Long id) {
/**
* Closes datasource connections by request parameters.
* <p>
* Endpoint: {@code GET /api/connection/close}.
* Endpoint: {@code POST /api/connection/close}.
*
* @param id identifier used to locate the target resource.
* @param request request containing the identifier of the connection to close.
* @return operation result for the request.
*/
@GetMapping("/close")
public ActionResult closeConnection(@RequestParam("id") Long id) {
dataSourceService.removeConnection(id);
@PostMapping("/close")
public ActionResult closeConnection(@RequestBody @Valid DataSourceCloseRequest request) {
dataSourceService.removeConnection(request.getId());
return ActionResult.isSuccess();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package ai.chat2db.community.web.api.controller;

import ai.chat2db.community.domain.api.service.db.IDbDataSourceService;
import ai.chat2db.community.web.api.model.request.data.source.DataSourceCloseRequest;
import jakarta.validation.Valid;
import org.junit.jupiter.api.Test;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.concurrent.atomic.AtomicReference;

import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

class DbDataSourceControllerTest {

@Test
void closeConnectionUsesPostBodyAndDelegatesConnectionId() throws Exception {
AtomicReference<Long> closedConnectionId = new AtomicReference<>();
IDbDataSourceService dataSourceService = (IDbDataSourceService) Proxy.newProxyInstance(
getClass().getClassLoader(),
new Class<?>[] {IDbDataSourceService.class},
(proxy, method, args) -> {
if ("removeConnection".equals(method.getName())) {
closedConnectionId.set((Long) args[0]);
return null;
}
throw new UnsupportedOperationException(method.getName());
});
DbDataSourceController controller = new DbDataSourceController(dataSourceService, null, null, null, null);
DataSourceCloseRequest request = new DataSourceCloseRequest();
request.setId(42L);

controller.closeConnection(request);

assertEquals(42L, closedConnectionId.get());

Method closeConnection = DbDataSourceController.class.getMethod(
"closeConnection", DataSourceCloseRequest.class);
PostMapping postMapping = closeConnection.getAnnotation(PostMapping.class);
assertNotNull(postMapping);
assertArrayEquals(new String[] {"/close"}, postMapping.value());
assertNull(closeConnection.getAnnotation(GetMapping.class));
assertTrue(closeConnection.getParameters()[0].isAnnotationPresent(RequestBody.class));
assertTrue(closeConnection.getParameters()[0].isAnnotationPresent(Valid.class));
}
}
Loading