Skip to content

Commit

Permalink
chore: health API
Browse files Browse the repository at this point in the history
  • Loading branch information
tructn committed May 21, 2024
1 parent 5e7033a commit 6b4129c
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 27 deletions.
6 changes: 4 additions & 2 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { Suspense, lazy, useState } from "react";
import { Routes, Route } from "react-router-dom";
import Loading from "./components/loading";
import { lazy, Suspense } from "react";
import { Route, Routes } from "react-router-dom";

const Layout = lazy(() => import("./screens/layout"));
const Dashboard = lazy(() => import("./screens/dashboard"));
const Matches = lazy(() => import("./screens/matches"));
const Players = lazy(() => import("./screens/players"));
const Health = lazy(() => import("./screens/health"));
const PageNotFound = lazy(() => import("./screens/pageNotFound"));

function App() {
Expand All @@ -16,6 +17,7 @@ function App() {
<Route path="/" element={<Dashboard />} />
<Route path="/players" element={<Players />} />
<Route path="/matches" element={<Matches />} />
<Route path="/health" element={<Health />} />
<Route path="*" element={<PageNotFound />} />
</Route>
</Routes>
Expand Down
28 changes: 28 additions & 0 deletions frontend/src/screens/health/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import httpClient from "../../common/httpClient";
import Page from "../../components/page";
import { Badge } from "@mantine/core";
import { useEffect, useState } from "react";

const Health = () => {
const [status, setStatus] = useState<any>();
useEffect(() => {
load();

async function load() {
const res = await httpClient.get("health");
console.log(res);
setStatus(res);
}
}, []);

return (
<Page title="Health">
<div className="flex items-center gap-3">
<span>API Health: </span>
<Badge className="uppercase">{status && status.message}</Badge>
</div>
</Page>
);
};

export default Health;
15 changes: 10 additions & 5 deletions frontend/src/screens/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
import cx from "clsx";
import Loading from "../components/loading";
import { FaChartArea, FaCog, FaFighterJet, FaUserClock } from "react-icons/fa";
import { FC, ReactNode, useState } from "react";
import { FiChevronLeft, FiChevronRight } from "react-icons/fi";
import { FiChevronLeft } from "react-icons/fi";
import { NavLink, Outlet } from "react-router-dom";
import { Suspense } from "react";
import {
FaChartArea,
FaFighterJet,
FaHeartbeat,
FaUserClock,
} from "react-icons/fa";

interface NavItemProps {
label?: string;
Expand Down Expand Up @@ -69,9 +74,9 @@ function Layout() {
/>
<NavItem
showLabel={!collapsed}
path="/settings"
label="Settings"
icon={<FaCog />}
path="/health"
label="Health"
icon={<FaHeartbeat />}
/>
</div>
<button
Expand Down
6 changes: 3 additions & 3 deletions handler/player.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ func (h playerHandler) Create(c *gin.Context) {
}

func (h playerHandler) GetAll(c *gin.Context) {
var p []domain.Player
h.db.Order("first_name ASC").Find(&p)
c.JSON(http.StatusOK, p)
var result []domain.Player
h.db.Order("first_name ASC").Find(&result)
c.JSON(http.StatusOK, result)
}

func (h playerHandler) Update(c *gin.Context) {
Expand Down
34 changes: 17 additions & 17 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func main() {
router.Use(cors.New(cors.Config{
AllowOrigins: []string{"http://localhost:5173", "https://goodracket.vercel.app"},
AllowMethods: []string{"PUT", "POST", "GET", "DELETE", "PATCH"},
AllowHeaders: []string{"*"},
AllowHeaders: []string{"Origin", "Content-Type", "Accept"},
ExposeHeaders: []string{"Content-Length"},
AllowCredentials: true,
MaxAge: 12 * time.Hour,
Expand Down Expand Up @@ -43,24 +43,24 @@ func main() {
})
})

router.GET("/health/origins", func(ctx *gin.Context) {
ctx.JSON(200, ctx.Request.Header.Get("Origin"))
})

// API v1
v1 := router.Group("/api/v1")
{
v1.GET("/players", playerHandler.GetAll)
v1.POST("/players", playerHandler.Create)
v1.DELETE("/players/:playerId", playerHandler.Delete)
v1.PUT("/players/:playerId", playerHandler.Update)

v1.POST("/matches", matchHandler.Create)
v1.GET("/matches", matchHandler.GetAll)
v1.GET("/matches/:matchId/registrations", matchHandler.GetRegistrationsByMatch)

v1.GET("/registrations", regHandler.GetAll)
v1.POST("/registrations", regHandler.Register)
v1.PUT("/registrations/:registrationId/paid", regHandler.MarkPaid)
v1.PUT("/registrations/:registrationId/unpaid", regHandler.MarkUnPaid)
v1.DELETE("/registrations/:registrationId", regHandler.Unregister)
}
v1.GET("/players", playerHandler.GetAll)
v1.POST("/players", playerHandler.Create)
v1.DELETE("/players/:playerId", playerHandler.Delete)
v1.PUT("/players/:playerId", playerHandler.Update)
v1.POST("/matches", matchHandler.Create)
v1.GET("/matches", matchHandler.GetAll)
v1.GET("/matches/:matchId/registrations", matchHandler.GetRegistrationsByMatch)
v1.GET("/registrations", regHandler.GetAll)
v1.POST("/registrations", regHandler.Register)
v1.PUT("/registrations/:registrationId/paid", regHandler.MarkPaid)
v1.PUT("/registrations/:registrationId/unpaid", regHandler.MarkUnPaid)
v1.DELETE("/registrations/:registrationId", regHandler.Unregister)

router.Run()
}

0 comments on commit 6b4129c

Please sign in to comment.