Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
pankaj-peerdb committed Dec 18, 2023
1 parent fd37ff7 commit b168f59
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 53 deletions.
5 changes: 4 additions & 1 deletion ui/app/api/mirrors/route.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { getTruePeer } from '@/app/api/peers/route';
import { getTruePeer } from '@/app/api/peers/getTruePeer';
import prisma from '@/app/utils/prisma';

export const dynamic = 'force-dynamic';

export async function GET(request: Request) {
const mirrors = await prisma.flows.findMany({
distinct: 'name',
Expand Down
60 changes: 60 additions & 0 deletions ui/app/api/peers/getTruePeer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { CatalogPeer } from '@/app/dto/PeersDTO';
import {
BigqueryConfig,
EventHubConfig,
EventHubGroupConfig,
Peer,
PostgresConfig,
S3Config,
SnowflakeConfig,
SqlServerConfig,
} from '@/grpc_generated/peers';

export const getTruePeer = (peer: CatalogPeer) => {
const newPeer: Peer = {
name: peer.name,
type: peer.type,
};
const options = peer.options;
let config:
| BigqueryConfig
| SnowflakeConfig
| PostgresConfig
| EventHubConfig
| S3Config
| SqlServerConfig
| EventHubGroupConfig;
switch (peer.type) {
case 0:
config = BigqueryConfig.decode(options);
newPeer.bigqueryConfig = config;
break;
case 1:
config = SnowflakeConfig.decode(options);
newPeer.snowflakeConfig = config;
break;
case 3:
config = PostgresConfig.decode(options);
newPeer.postgresConfig = config;
break;
case 4:
config = EventHubConfig.decode(options);
newPeer.eventhubConfig = config;
break;
case 5:
config = S3Config.decode(options);
newPeer.s3Config = config;
break;
case 6:
config = SqlServerConfig.decode(options);
newPeer.sqlserverConfig = config;
break;
case 7:
config = EventHubGroupConfig.decode(options);
newPeer.eventhubGroupConfig = config;
break;
default:
return newPeer;
}
return newPeer;
};
55 changes: 3 additions & 52 deletions ui/app/api/peers/route.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { getTruePeer } from '@/app/api/peers/getTruePeer';
import {
CatalogPeer,
PeerConfig,
Expand All @@ -8,13 +9,10 @@ import prisma from '@/app/utils/prisma';
import {
BigqueryConfig,
DBType,
EventHubConfig,
EventHubGroupConfig,
Peer,
PostgresConfig,
S3Config,
SnowflakeConfig,
SqlServerConfig,
} from '@/grpc_generated/peers';
import {
CreatePeerRequest,
Expand Down Expand Up @@ -63,6 +61,8 @@ const constructPeer = (
}
};

export const dynamic = 'force-dynamic';

export async function POST(request: Request) {
const body = await request.json();
console.log('POST Validate Peer:', body);
Expand Down Expand Up @@ -117,55 +117,6 @@ export async function POST(request: Request) {
}
}

export const getTruePeer = (peer: CatalogPeer) => {
const newPeer: Peer = {
name: peer.name,
type: peer.type,
};
const options = peer.options;
let config:
| BigqueryConfig
| SnowflakeConfig
| PostgresConfig
| EventHubConfig
| S3Config
| SqlServerConfig
| EventHubGroupConfig;
switch (peer.type) {
case 0:
config = BigqueryConfig.decode(options);
newPeer.bigqueryConfig = config;
break;
case 1:
config = SnowflakeConfig.decode(options);
newPeer.snowflakeConfig = config;
break;
case 3:
config = PostgresConfig.decode(options);
newPeer.postgresConfig = config;
break;
case 4:
config = EventHubConfig.decode(options);
newPeer.eventhubConfig = config;
break;
case 5:
config = S3Config.decode(options);
newPeer.s3Config = config;
break;
case 6:
config = SqlServerConfig.decode(options);
newPeer.sqlserverConfig = config;
break;
case 7:
config = EventHubGroupConfig.decode(options);
newPeer.eventhubGroupConfig = config;
break;
default:
return newPeer;
}
return newPeer;
};

// GET all the peers from the database
export async function GET(request: Request) {
const peers = await prisma.peers.findMany();
Expand Down

0 comments on commit b168f59

Please sign in to comment.