Skip to content

Commit 36dddd6

Browse files
bugfix
1 parent 40a1e38 commit 36dddd6

4 files changed

Lines changed: 27 additions & 19 deletions

File tree

meshwork/backend/app.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ async def add_task(task: Task):
3232
return {"message": f"Task {task.id} added"}
3333

3434

35+
@app.get("/v0/all_tasks")
36+
async def get_all_tasks() -> list[Task]:
37+
return TG.get_all_tasks()
38+
3539
@app.get("/v0/task/{task_id}")
3640
async def get_task(task_id: str) -> Task:
3741
return TG.get_task(task_id)
3842

3943

40-
@app.get("/v0/task/get_all")
41-
async def get_all_tasks() -> list[Task]:
42-
return TG.get_all_tasks()
43-
4444

4545
@app.delete("/v0/task/{task_id}")
4646
async def delete_task(task_id: str):

meshwork/backend/core/graph.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,12 @@ def get_task(self, task_id: str):
5252

5353
def get_all_tasks(self):
5454
"""Get all tasks from the graph."""
55+
if not self.graph.nodes:
56+
return []
5557
return [self.graph.nodes[node]["task"] for node in self.graph.nodes]
5658

5759
def edit_task(self, task_id: str, new_task: Task):
60+
# TODO: take only the necessary fields from new_task
5861
"""Edit a task in the graph."""
5962
self.graph.nodes[task_id]["task"] = new_task
6063
self.set_blocked_tasks()

meshwork/frontend/meshwork-ui/src/App.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,11 @@ function App() {
213213
await taskApi.healthCheck();
214214
setBackendAvailable(true);
215215

216+
// insert sampleTasks tasks into database
217+
for (const task of sampleTasks) {
218+
await taskApi.createTask(task);
219+
}
220+
216221
// Backend is available, try to fetch tasks
217222
const fetchedTasks = await taskApi.getTasks();
218223

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
1-
const API_BASE_URL = process.env.REACT_APP_API_URL || 'http://localhost:8000';
1+
const API_BASE_URL = process.env.REACT_APP_API_URL || "http://localhost:8000";
22

33
class TaskApiService {
44
async request(endpoint, options = {}) {
55
const url = `${API_BASE_URL}${endpoint}`;
66
const config = {
77
headers: {
8-
'Content-Type': 'application/json',
8+
"Content-Type": "application/json",
99
...options.headers,
1010
},
1111
...options,
1212
};
1313

14-
if (config.body && typeof config.body === 'object') {
14+
if (config.body && typeof config.body === "object") {
1515
config.body = JSON.stringify(config.body);
1616
}
1717

1818
try {
1919
const response = await fetch(url, config);
20-
20+
2121
if (!response.ok) {
2222
throw new Error(`HTTP error! status: ${response.status}`);
2323
}
24-
25-
const contentType = response.headers.get('content-type');
26-
if (contentType && contentType.includes('application/json')) {
24+
25+
const contentType = response.headers.get("content-type");
26+
if (contentType && contentType.includes("application/json")) {
2727
return await response.json();
2828
}
29-
29+
3030
return await response.text();
3131
} catch (error) {
3232
console.error(`API request failed: ${endpoint}`, error);
@@ -36,7 +36,7 @@ class TaskApiService {
3636

3737
// Get all tasks
3838
async getTasks() {
39-
return this.request('/v0/task/get_all');
39+
return this.request("/v0/all_tasks");
4040
}
4141

4242
// Get a specific task by ID
@@ -46,30 +46,30 @@ class TaskApiService {
4646

4747
// Create a new task
4848
async createTask(taskData) {
49-
return this.request('/v0/task/add/', {
50-
method: 'POST',
49+
return this.request("/v0/task/add/", {
50+
method: "POST",
5151
body: taskData,
5252
});
5353
}
5454

5555
// Update an existing task
5656
async updateTask(taskId, taskData) {
5757
return this.request(`/v0/task/${taskId}`, {
58-
method: 'PUT',
58+
method: "PUT",
5959
body: taskData,
6060
});
6161
}
6262

6363
// Delete a task
6464
async deleteTask(taskId) {
6565
return this.request(`/v0/task/${taskId}`, {
66-
method: 'DELETE',
66+
method: "DELETE",
6767
});
6868
}
6969

7070
// Health check
7171
async healthCheck() {
72-
return this.request('/health');
72+
return this.request("/health");
7373
}
7474
}
7575

@@ -86,4 +86,4 @@ export const {
8686
updateTask,
8787
deleteTask,
8888
healthCheck,
89-
} = taskApi;
89+
} = taskApi;

0 commit comments

Comments
 (0)