Skip to content

Commit

Permalink
feat: list user tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
tonitienda committed Mar 20, 2024
1 parent 4cf2eef commit a9fe2f9
Show file tree
Hide file tree
Showing 10 changed files with 151 additions and 350 deletions.
10 changes: 8 additions & 2 deletions .requests/tasks.http
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
POST http://localhost:8080/tasks
POST http://localhost:8080/v0/tasks
Content-Type: application/json
X-User-ID: b78fe6be-0642-4cfa-9f19-9cc8e53b129d

{
"title": "Task 1",
"description": "Task 1 description"
}
}

###

GET http://localhost:8080/v0/tasks
Content-Type: application/json
X-User-ID: b78fe6be-0642-4cfa-9f19-9cc8e53b129d
7 changes: 6 additions & 1 deletion backend-golang-rest/pkg/tasks/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,12 @@ func (h *TasksHandler) GetTasks(c *gin.Context) error {
return err
}

c.JSON(http.StatusOK, tasks)
tasksResponse := make([]TaskResponse, 0, len(tasks))
for _, task := range tasks {
tasksResponse = append(tasksResponse, NewTaskResponse(task))
}

c.JSON(http.StatusOK, tasksResponse)
return nil
}

Expand Down
26 changes: 26 additions & 0 deletions webapp-react/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions webapp-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"@emotion/react": "^11.11.4",
"@emotion/styled": "^11.11.0",
"@fontsource/roboto": "^5.0.12",
"@mui/icons-material": "^5.15.14",
"@mui/material-nextjs": "^5.15.11",
"next": "14.1.4",
"react": "^18",
Expand Down
41 changes: 41 additions & 0 deletions webapp-react/src/api/tasks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
export async function getTasks() {
const res = await fetch("http://localhost:8080/v0/tasks?t=1", {
cache: "no-store",
headers: {
"X-User-ID": "b78fe6be-0642-4cfa-9f19-9cc8e53b129d",
},
});
// The return value is *not* serialized
// You can return Date, Map, Set, etc.

if (!res.ok) {
// This will activate the closest `error.js` Error Boundary
throw new Error("Failed to fetch data");
}

return res.json();
}

export async function addTask() {
const res = await fetch("http://localhost:8080/v0/tasks", {
method: "POST",
body: JSON.stringify({
title: "New task",
description: "This is a new task",
}),

headers: {
"X-User-ID": "b78fe6be-0642-4cfa-9f19-9cc8e53b129d",
"Content-Type": "application/json",
},
});
// The return value is *not* serialized
// You can return Date, Map, Set, etc.

if (!res.ok) {
// This will activate the closest `error.js` Error Boundary
throw new Error("Failed to add task");
}

return res.json();
}
107 changes: 0 additions & 107 deletions webapp-react/src/app/globals.css

This file was deleted.

5 changes: 2 additions & 3 deletions webapp-react/src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
import { AppRouterCacheProvider } from "@mui/material-nextjs/v13-appRouter";
import type { Metadata } from "next";
import { Inter } from "next/font/google";
import "./globals.css";
import { ThemeProvider } from "@mui/material/styles";
import theme from "../theme";

const inter = Inter({ subsets: ["latin"] });

export const metadata: Metadata = {
title: "Create Next App",
description: "Generated by create next app",
title: "Kadai",
description: "Manage your tasks!",
};

export default function RootLayout({
Expand Down
Loading

0 comments on commit a9fe2f9

Please sign in to comment.