Skip to content

Commit 02d5fc6

Browse files
authored
Merge pull request #217 from FalkorDB/reorginize-api-folder
Fix #216 reorginize api folder
2 parents 086ec9d + beef368 commit 02d5fc6

File tree

7 files changed

+99
-242
lines changed

7 files changed

+99
-242
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { NextRequest, NextResponse } from "next/server";
2+
3+
export async function GET(request: NextRequest, { params }: { params: { graph: string } }) {
4+
5+
try {
6+
const result = await fetch(`${process.env.BEAKEND_URL}/list_commits`, {
7+
method: 'POST',
8+
body: JSON.stringify({ repo: params.graph }),
9+
headers: {
10+
"Authorization": process.env.SECRET_TOKEN!,
11+
"Content-Type": 'application/json'
12+
}
13+
})
14+
15+
if (!result.ok) {
16+
throw new Error(await result.text())
17+
}
18+
19+
const json = await result.json()
20+
21+
return NextResponse.json({ result: json }, { status: 200 })
22+
} catch (err) {
23+
return NextResponse.json({ message: (err as Error).message }, { status: 400 })
24+
}
25+
}
26+
27+
export async function POST(request: NextRequest, { params }: { params: { graph: string } }) {
28+
29+
}

app/api/repo/[graph]/info/route.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { NextRequest, NextResponse } from "next/server";
2+
3+
export async function GET(request: NextRequest, { params }: { params: { graph: string } }) {
4+
5+
try {
6+
const result = await fetch(`${process.env.BACKEND_URL}/repo_info`, {
7+
method: 'POST',
8+
body: JSON.stringify({ repo: params.graph }),
9+
headers: {
10+
"Authorization": process.env.SECRET_TOKEN!,
11+
"Content-Type": 'application/json'
12+
}
13+
})
14+
15+
if (!result.ok) {
16+
throw new Error(await result.text())
17+
}
18+
19+
const json = await result.json()
20+
21+
return NextResponse.json({ result: json }, { status: 200 })
22+
} catch (err) {
23+
return NextResponse.json({ message: (err as Error).message }, { status: 400 })
24+
}
25+
}

app/api/repo/[graph]/route.ts

Lines changed: 16 additions & 215 deletions
Original file line numberDiff line numberDiff line change
@@ -26,228 +26,29 @@ export async function GET(request: NextRequest, { params }: { params: { graph: s
2626

2727
export async function POST(request: NextRequest, { params }: { params: { graph: string } }) {
2828

29-
const type = request.nextUrl.searchParams.get('type') || "count"
30-
const graphName = params.graph
29+
const prefix = request.nextUrl.searchParams.get('prefix')!
3130

3231
try {
33-
switch (type) {
34-
// case "commit": {
35-
// const result = await fetch(`${process.env.BEAKEND_URL}/list_commits`, {
36-
// method: 'POST',
37-
// body: JSON.stringify({ repo: graphName }),
38-
// headers: {
39-
// "Authorization": process.env.SECRET_TOKEN!,
40-
// "Content-Type": 'application/json'
41-
// }
42-
// })
43-
44-
// if (!result.ok) {
45-
// throw new Error(await result.text())
46-
// }
47-
48-
// const json = await result.json()
49-
50-
// return NextResponse.json({ result: json }, { status: 200 })
51-
// }
52-
// case "switchCommit": {
53-
// return NextResponse.json({
54-
// result: {
55-
// deletions: {
56-
// 'nodes': [
57-
// {
58-
// "alias": "",
59-
// "id": 2,
60-
// "labels": [
61-
// "Function"
62-
// ],
63-
// "properties": {
64-
// "args": [
65-
// [
66-
// "cls",
67-
// "Unknown"
68-
// ]
69-
// ],
70-
// "name": "setUpClass",
71-
// "path": "tests/test_kg_gemini.py",
72-
// "src": "def setUpClass(cls):\n\n cls.ontology = Ontology([], [])\n\n cls.ontology.add_entity(\n Entity(\n label=\"Actor\",\n attributes=[\n Attribute(\n name=\"name\",\n attr_type=AttributeType.STRING,\n unique=True,\n required=True,\n ),\n ],\n )\n )\n cls.ontology.add_entity(\n Entity(\n label=\"Movie\",\n attributes=[\n Attribute(\n name=\"title\",\n attr_type=AttributeType.STRING,\n unique=True,\n required=True,\n ),\n ],\n )\n )\n cls.ontology.add_relation(\n Relation(\n label=\"ACTED_IN\",\n source=\"Actor\",\n target=\"Movie\",\n attributes=[\n Attribute(\n name=\"role\",\n attr_type=AttributeType.STRING,\n unique=False,\n required=False,\n ),\n ],\n )\n )\n\n cls.graph_name = \"IMDB_gemini\"\n\n model = GeminiGenerativeModel(model_name=\"gemini-1.5-flash-001\")\n cls.kg = KnowledgeGraph(\n name=cls.graph_name,\n ontology=cls.ontology,\n model_config=KnowledgeGraphModelConfig.with_model(model),\n )",
73-
// "src_end": 82,
74-
// "src_start": 29
75-
// }
76-
// },
77-
// {
78-
// "alias": "",
79-
// "id": 13,
80-
// "labels": [
81-
// "Function"
82-
// ],
83-
// "properties": {
84-
// "args": [
85-
// [
86-
// "self",
87-
// "Unknown"
88-
// ],
89-
// [
90-
// "restaurants_kg",
91-
// "KnowledgeGraph"
92-
// ],
93-
// [
94-
// "attractions_kg",
95-
// "KnowledgeGraph"
96-
// ]
97-
// ],
98-
// "name": "import_data",
99-
// "path": "tests/test_multi_agent.py",
100-
// "src": "def import_data(\n self,\n restaurants_kg: KnowledgeGraph,\n attractions_kg: KnowledgeGraph,\n ):\n with open(\"tests/data/cities.json\") as f:\n cities = loads(f.read())\n with open(\"tests/data/restaurants.json\") as f:\n restaurants = loads(f.read())\n with open(\"tests/data/attractions.json\") as f:\n attractions = loads(f.read())\n\n for city in cities:\n restaurants_kg.add_node(\n \"City\",\n {\n \"name\": city[\"name\"],\n \"weather\": city[\"weather\"],\n \"population\": city[\"population\"],\n },\n )\n restaurants_kg.add_node(\"Country\", {\"name\": city[\"country\"]})\n restaurants_kg.add_edge(\n \"IN_COUNTRY\",\n \"City\",\n \"Country\",\n {\"name\": city[\"name\"]},\n {\"name\": city[\"country\"]},\n )\n\n attractions_kg.add_node(\n \"City\",\n {\n \"name\": city[\"name\"],\n \"weather\": city[\"weather\"],\n \"population\": city[\"population\"],\n },\n )\n attractions_kg.add_node(\"Country\", {\"name\": city[\"country\"]})\n attractions_kg.add_edge(\n \"IN_COUNTRY\",\n \"City\",\n \"Country\",\n {\"name\": city[\"name\"]},\n {\"name\": city[\"country\"]},\n )\n\n for restaurant in restaurants:\n restaurants_kg.add_node(\n \"Restaurant\",\n {\n \"name\": restaurant[\"name\"],\n \"description\": restaurant[\"description\"],\n \"rating\": restaurant[\"rating\"],\n \"food_type\": restaurant[\"food_type\"],\n },\n )\n restaurants_kg.add_edge(\n \"IN_CITY\",\n \"Restaurant\",\n \"City\",\n {\"name\": restaurant[\"name\"]},\n {\"name\": restaurant[\"city\"]},\n )\n\n for attraction in attractions:\n attractions_kg.add_node(\n \"Attraction\",\n {\n \"name\": attraction[\"name\"],\n \"description\": attraction[\"description\"],\n \"type\": attraction[\"type\"],\n },\n )\n attractions_kg.add_edge(\n \"IN_CITY\",\n \"Attraction\",\n \"City\",\n {\"name\": attraction[\"name\"]},\n {\"name\": attraction[\"city\"]},\n )",
101-
// "src_end": 310,
102-
// "src_start": 230
103-
// }
104-
// },
105-
// ],
106-
// 'edges': [
107-
// {
108-
// "alias": "",
109-
// "dest_node": 13,
110-
// "id": 460,
111-
// "properties": {},
112-
// "relation": "CALLS",
113-
// "src_node": 2
114-
// },
115-
// ]
116-
// },
117-
// additions: {
118-
// 'nodes': [
119-
// {
120-
// "alias": "",
121-
// "id": 13,
122-
// "labels": [
123-
// "File"
124-
// ],
125-
// "properties": {
126-
// "ext": ".py",
127-
// "name": "test_kg_gemini.py",
128-
// "path": "tests"
129-
// }
130-
// },
131-
// {
132-
// "alias": "",
133-
// "id": 2,
134-
// "labels": [
135-
// "Class"
136-
// ],
137-
// "properties": {
138-
// "doc": "\"\"\"\n Test Knowledge Graph\n \"\"\"",
139-
// "name": "TestKGGemini",
140-
// "path": "tests/test_kg_gemini.py",
141-
// "src_end": 106,
142-
// "src_start": 23
143-
// }
144-
// },
145-
// ],
146-
// 'edges': [
147-
// {
148-
// "alias": "",
149-
// "dest_node": 13,
150-
// "id": 460,
151-
// "properties": {},
152-
// "relation": "DEFINES",
153-
// "src_node": 2
154-
// },
155-
// ],
156-
// },
157-
// modifications: {
158-
// 'nodes': [
159-
// {
160-
// "alias": "",
161-
// "id": 3,
162-
// "labels": [
163-
// "Function"
164-
// ],
165-
// "properties": {
166-
// "args": [
167-
// []
168-
// ],
169-
// "name": "",
170-
// "path": "",
171-
// "src": "",
172-
// "src_end": 0,
173-
// "src_start": 0
174-
// }
175-
// },
176-
// {
177-
// "alias": "",
178-
// "id": 61,
179-
// "labels": [
180-
// "Function"
181-
// ],
182-
// "properties": {
183-
// "args": [
184-
// [],
185-
// []
186-
// ],
187-
// "doc": "",
188-
// "name": "",
189-
// "path": "",
190-
// "ret_type": "",
191-
// "src": "",
192-
// "src_end": 0,
193-
// "src_start": 0
194-
// }
195-
// },
196-
// ],
197-
// 'edges': [
198-
// {
199-
// "alias": "",
200-
// "dest_node": 61,
201-
// "id": 439,
202-
// "properties": {
203-
// name: "Source"
204-
// },
205-
// "relation": "CALLS",
206-
// "src_node": 3
207-
// },
208-
// ]
209-
// }
210-
// }
211-
// }, { status: 200 })
212-
// }
213-
case "autoComplete": {
214-
const prefix = request.nextUrl.searchParams.get('prefix')!
215-
const result = await fetch(`${process.env.BACKEND_URL}/auto_complete`, {
216-
method: 'POST',
217-
body: JSON.stringify({ repo: graphName, prefix }),
218-
headers: {
219-
"Authorization": process.env.SECRET_TOKEN!,
220-
"Content-Type": 'application/json'
221-
}
222-
})
223-
224-
if (!result.ok) {
225-
throw new Error(await result.text())
226-
}
227-
228-
const json = await result.json()
32+
if (!prefix) {
33+
throw new Error("Prefix is required")
34+
}
22935

230-
return NextResponse.json({ result: json }, { status: 200 })
36+
const result = await fetch(`${process.env.BACKEND_URL}/auto_complete`, {
37+
method: 'POST',
38+
body: JSON.stringify({ repo: params.graph, prefix }),
39+
headers: {
40+
"Authorization": process.env.SECRET_TOKEN!,
41+
"Content-Type": 'application/json'
23142
}
232-
default: {
233-
const result = await fetch(`${process.env.BACKEND_URL}/repo_info`, {
234-
method: 'POST',
235-
body: JSON.stringify({ repo: graphName }),
236-
headers: {
237-
"Authorization": process.env.SECRET_TOKEN!,
238-
"Content-Type": 'application/json'
239-
}
240-
})
43+
})
24144

242-
if (!result.ok) {
243-
throw new Error(await result.text())
244-
}
45+
if (!result.ok) {
46+
throw new Error(await result.text())
47+
}
24548

246-
const json = await result.json()
49+
const json = await result.json()
24750

248-
return NextResponse.json({ result: json }, { status: 200 })
249-
}
250-
}
51+
return NextResponse.json({ result: json }, { status: 200 })
25152
} catch (err) {
25253
return NextResponse.json({ message: (err as Error).message }, { status: 400 })
25354
}

app/components/Input.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export default function Input({ value, onValueChange, handelSubmit, graph, icon,
4545
return
4646
}
4747

48-
const result = await fetch(`/api/repo/${graph.Id}/?prefix=${value}&type=autoComplete`, {
48+
const result = await fetch(`/api/repo/${graph.Id}/?prefix=${value}`, {
4949
method: 'POST'
5050
})
5151

app/components/code-graph.tsx

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,8 @@ export function CodeGraph({
168168
}, [selectedObjects, selectedObj, isSelectedObj]);
169169

170170
async function fetchCount() {
171-
const result = await fetch(`/api/repo/${graphName}`, {
172-
method: 'POST'
171+
const result = await fetch(`/api/repo/${graphName}/info`, {
172+
method: 'GET'
173173
})
174174

175175
if (!result.ok) {
@@ -198,27 +198,29 @@ export function CodeGraph({
198198

199199
const run = async () => {
200200
fetchCount()
201-
// const result = await fetch(`/api/repo/${graphName}/?type=commit`, {
202-
// method: 'POST'
203-
// })
204-
205-
// if (!result.ok) {
206-
// toast({
207-
// variant: "destructive",
208-
// title: "Uh oh! Something went wrong.",
209-
// description: await result.text(),
210-
// })
211-
// return
212-
// }
213-
214-
// const json = await result.json()
215-
// const commitsArr = json.result.commits
216-
// setCommits(commitsArr)
217-
218-
// if (commitsArr.length > 0) {
219-
// setCurrentCommit(commitsArr[commitsArr.length - 1].hash)
220-
// setCommitIndex(commitsArr.length)
221-
// }
201+
/*
202+
const result = await fetch(`/api/repo/${graphName}/commit`, {
203+
method: 'GET'
204+
})
205+
206+
if (!result.ok) {
207+
toast({
208+
variant: "destructive",
209+
title: "Uh oh! Something went wrong.",
210+
description: await result.text(),
211+
})
212+
return
213+
}
214+
215+
const json = await result.json()
216+
const commitsArr = json.result.commits
217+
setCommits(commitsArr)
218+
219+
if (commitsArr.length > 0) {
220+
setCurrentCommit(commitsArr[commitsArr.length - 1].hash)
221+
setCommitIndex(commitsArr.length)
222+
}
223+
*/
222224
}
223225

224226
run()

0 commit comments

Comments
 (0)