Skip to content

Commit

Permalink
feat(database):imeplement database create
Browse files Browse the repository at this point in the history
  • Loading branch information
CorrectRoadH committed Dec 12, 2023
1 parent 128897c commit 1ecd813
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 50 deletions.
4 changes: 2 additions & 2 deletions dashboard/src/pages/business/database/blocks/postgre.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React from 'react'
import { DatabaseConnectionConfig } from '../../../../types'
import { DatabaseConnectConfig } from "@/api/openapi";
import styles from '../style/blocks.module.less';
import { Button, Card,Typography } from '@arco-design/web-react';
const { Text, Title } = Typography;

interface PostgresProps {
config: DatabaseConnectionConfig
config: DatabaseConnectConfig
}
const Postgres = ({config}:PostgresProps)=>{
return (
Expand Down
4 changes: 2 additions & 2 deletions dashboard/src/pages/business/database/blocks/redis.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React from 'react'
import { DatabaseConnectionConfig } from '../../../../types'
import styles from '../style/blocks.module.less';
import { Button, Card,Typography } from '@arco-design/web-react';
const { Text, Title } = Typography;
import { DatabaseConnectConfig } from "@/api/openapi";

interface RedisProps {
config: DatabaseConnectionConfig
config: DatabaseConnectConfig
}
const Redis = ({config}:RedisProps)=>{
return (
Expand Down
34 changes: 25 additions & 9 deletions dashboard/src/pages/business/database/create-database-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ const CreateDatabase = () => {
form.validate().then((res)=>{
const config:DatabaseConnectConfig = {
title: res.title,
"id": uuid(),
"databaseType":"redis",
"host": res.host,
"port": Number(res.port),
"username":"",
id: uuid(),
databaseType:"redis",
host: res.host,
port: Number(res.port),
username:"",
password: res?.password || "",
"database":""
database:""
}
console.log(config)
axios.post("/admin/v1/database/test", config).then((res) => {
Expand Down Expand Up @@ -77,11 +77,27 @@ const CreateDatabase = () => {
onOk={()=>{
form.validate().then((res)=>{
setConfirmLoading(true);
console.log(res)
createDatabase(res).then((res)=>{

const config:DatabaseConnectConfig = {
title: res?.title || "",
id: uuid(),
databaseType: res.type,
host: res.host,
port: Number(res.port),
username: res?.username || "",
password: res?.password || "",
database: res?.database || ""
}

console.log(config)
createDatabase(config).then(()=>{
toast.success("create success");
setConfirmLoading(false);
setVisible(false);
}).catch((err)=>{
toast.error(err.response.data.msg);
setConfirmLoading(false);
})
setConfirmLoading(false);
})
}}

Expand Down
53 changes: 23 additions & 30 deletions dashboard/src/pages/business/database/overview.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,18 @@
import React, { useEffect, useState } from "react";
import { Card, Divider, Typography,Grid } from "@arco-design/web-react";
import { DatabaseConnectionConfig } from "../../../types";
import axios from "axios";
import React from "react";
import { Card, Divider, Typography,Grid, Skeleton } from "@arco-design/web-react";
import Redis from "./blocks/redis";
import Postgres from "./blocks/postgre";
import CreateDatabase from "./create-database-editor";
import { useDatabase } from "@/api";


const { Row, Col } = Grid;
const { Title } = Typography;

const Overview = () => {

// TODO extract to a hook
const [data, setData] = useState<DatabaseConnectionConfig[]>([]);

const fetchData = () => {
axios.get('/admin/v1/database').then((res) => {
setData(res.data.dataSourceConfig);
});
}
const {database,isLoading} = useDatabase();

useEffect(() => {
fetchData()
}, []);
return (
<Card>
<Typography.Title heading={5}>
Expand All @@ -34,36 +23,40 @@ const Overview = () => {

<Title heading={6}>Redis</Title>

<Row>
<Row gutter={20}>
<Skeleton loading={isLoading} text={{ rows: 2, width: 60 }} animation>
{
data
database
.filter((item) => item.databaseType === 'redis')
.map((item) => (
<Col key={`database-item-${item.id}`} span={6}>
<Redis config={item} />
</Col>
))
}
</Skeleton>
</Row>

<Divider />

<div>
<Title heading={6}>Postgres</Title>

<Row>
{
data
.filter((item) => item.databaseType === 'postgres')
.map((item) => (
<>
<Col key={item.id} span={6}>
<Postgres config={item} />
</Col>
</>
))
}
</Row>
<Row gutter={20}>
<Skeleton loading={isLoading} text={{ rows: 2, width: 60 }} animation>
{
database
.filter((item) => item.databaseType === 'postgres')
.map((item) => (
<>
<Col key={item.id} span={6}>
<Postgres config={item} />
</Col>
</>
))
}
</Skeleton>
</Row>
</div>


Expand Down
6 changes: 3 additions & 3 deletions dashboard/src/pages/business/workplace/business-item.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import { Button, Card, Drawer, Grid, Skeleton, Typography } from '@arco-design/web-react';
import React, { useState, useEffect } from 'react';
import React, { useState } from 'react';
import styles from './style/overview.module.less';
import BusinessEditor from './business-editor';
import { BusinessType } from '../../../types/type';
import { Business } from '@/api/openapi';

const { Row, Col } = Grid;

const { Title,Text } = Typography;
interface BusinessItemProps {
business: BusinessType;
business: Business;
}

const BusinessItem = ({business}:BusinessItemProps) => {
Expand Down
1 change: 0 additions & 1 deletion dashboard/src/pages/business/workplace/overview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
} from '@arco-design/web-react';
import styles from './style/overview.module.less';
import BusinessItem from './business-item';
import { BusinessType } from '@/types';
import CreateBusinessEditor from './create-business-editor';
import { useBusiness } from '@/api';

Expand Down
2 changes: 1 addition & 1 deletion dashboard/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ interface DatabaseConnectionConfig{
database: string;
}
type BusinessType = {
title: string;
title?: string;
id: string;
type: string;
};
Expand Down
7 changes: 6 additions & 1 deletion internal/adapter/in/restful/route/admin_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,12 @@ func (a *adminApiService) GetDatabaseConfigureList(ctx echo.Context) error {
}

func (a *adminApiService) CreateDatabase(ctx echo.Context) error {
err := a.databaseUseCase.CreateDatabase(ctx.Request().Context(), domain.DatabaseConnectConfig{})
var databaseConnectConfig codegen.DatabaseConnectConfig
if err := ctx.Bind(&databaseConnectConfig); err != nil {
return ctx.JSON(http.StatusBadRequest, err)
}

err := a.databaseUseCase.CreateDatabase(ctx.Request().Context(), convertDatabaseConnectConfig(databaseConnectConfig))
if err != nil {
return ctx.JSON(http.StatusInternalServerError, codegen.ResponseInternalServerError{
Status: utils.Ptr("error"),
Expand Down
3 changes: 2 additions & 1 deletion internal/adapter/out/admin/database_adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ func NewDatabaseAdapter(config domain.PostgresConfig) out.DatabasePort {
}

func (d *DatabaseAdapter) CreateDatabaseConnectConfig(config domain.DatabaseConnectConfig) error {
return d.db.Create(&config).Error
fmt.Println(config)
return d.db.Create(config).Error
}

func (d *DatabaseAdapter) DatabaseConnectConfig(configId string) (domain.DatabaseConnectConfig, error) {
Expand Down

0 comments on commit 1ecd813

Please sign in to comment.