From 5ab13f0a2dcd981479cab7f5e263d6334ba46080 Mon Sep 17 00:00:00 2001 From: Vincent Date: Sat, 22 Jun 2024 20:14:45 +0200 Subject: [PATCH 1/6] feat: Uncommented API calls --- frontend/src/lib/api/archive.ts | 55 +++++---------------------------- 1 file changed, 7 insertions(+), 48 deletions(-) diff --git a/frontend/src/lib/api/archive.ts b/frontend/src/lib/api/archive.ts index af952a24..c2317e60 100644 --- a/frontend/src/lib/api/archive.ts +++ b/frontend/src/lib/api/archive.ts @@ -4,58 +4,17 @@ import { ArchiveSearchResponse, } from "../interfaces/archive"; import { Result } from "@/lib/types"; +import { API_URL } from "../utils"; export async function searchArchive( params: ArchiveSearchRequest ): Promise> { - // Uncomment once we have API - // return await fetch(`${API_URL}/disputes/search`, { - // method: "POST", - // body: JSON.stringify(params), - // }).then((res) => res.json()); - - return { - data: [...Array(params.limit ?? 10).keys()] - .map((i) => i + (params.offset ?? 0)) - .map((i) => ({ - id: i.toString(), - - title: `Dispute #${i}`, - summary: - "Lorem ipsum dolor sit amet consectetur adipisicing elit. Soluta suscipit ducimus sequi alias tempora maxime odio libero delectus possimus aliquam ullam asperiores dolorem cumque, sunt numquam obcaecati. Eligendi, fugit commodi.", - - category: ["cooked", "cool"], - - date_filed: "yesterday", - date_resolved: "today", - - resolution: "nah, i'd win", - })), - }; + const res = await fetch(`${API_URL}/disputes/archive/search`, { + method: "POST", + body: JSON.stringify(params), + }); + return res.json(); } export async function fetchArchivedDispute(id: string): Promise> { - // Uncomment once we have API - // return await fetch(`${API_URL}/disputes/archive/${id}`) - // .then((res) => res.json()); - - return { - data: { - id: id, - - title: `Dispute #${id}`, - summary: "Lorem Ipsum", - - category: ["cooked", "cool"], - - date_filed: "yesterday", - date_resolved: "today", - - resolution: "nah, i'd win", - events: [...Array(10).keys()].map((i) => ({ - timestamp: `${i}`, - type: "uploaded", - description: "documents uploaded", - })), - }, - }; + return await fetch(`${API_URL}/disputes/archive/${id}`).then((res) => res.json()); } From cfbae005e69325eecc98142bd03ac61744e15b1b Mon Sep 17 00:00:00 2001 From: Caelan Hill Date: Sat, 22 Jun 2024 20:22:43 +0200 Subject: [PATCH 2/6] fixed auth issue --- api/handlers/dispute.go | 10 +++++++--- api/main.go | 1 - 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/api/handlers/dispute.go b/api/handlers/dispute.go index 4301571a..da51603d 100644 --- a/api/handlers/dispute.go +++ b/api/handlers/dispute.go @@ -1,6 +1,7 @@ package handlers import ( + "api/middleware" "api/models" "api/utilities" "encoding/json" @@ -14,9 +15,12 @@ import ( ) func SetupDisputeRoutes(router *mux.Router, h Handler) { - router.HandleFunc("", h.getSummaryListOfDisputes).Methods(http.MethodGet) - router.HandleFunc("/{id}", h.getDispute).Methods(http.MethodGet) - router.HandleFunc("/{id}", h.patchDispute).Methods(http.MethodPatch) + //dispute routes + disputeRouter := router.PathPrefix("").Subrouter() + disputeRouter.Use(middleware.JWTMiddleware) + disputeRouter.HandleFunc("", h.getSummaryListOfDisputes).Methods(http.MethodGet) + disputeRouter.HandleFunc("/{id}", h.getDispute).Methods(http.MethodGet) + disputeRouter.HandleFunc("/{id}", h.patchDispute).Methods(http.MethodPatch) //archive routes archiveRouter := router.PathPrefix("/archive").Subrouter() diff --git a/api/main.go b/api/main.go index e37742ec..6aaf1ad4 100644 --- a/api/main.go +++ b/api/main.go @@ -48,7 +48,6 @@ func main() { handlers.SetupUserRoutes(userRouter, h) disputeRouter := router.PathPrefix("/dispute").Subrouter() - disputeRouter.Use(middleware.JWTMiddleware) handlers.SetupDisputeRoutes(disputeRouter, h) // Swagger setup From a92d06b89960997735967e1c0d46e83553e84711 Mon Sep 17 00:00:00 2001 From: Caelan Hill Date: Sat, 22 Jun 2024 20:26:03 +0200 Subject: [PATCH 3/6] corrected type --- api/handlers/dispute.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/handlers/dispute.go b/api/handlers/dispute.go index da51603d..96bd07ec 100644 --- a/api/handlers/dispute.go +++ b/api/handlers/dispute.go @@ -25,7 +25,7 @@ func SetupDisputeRoutes(router *mux.Router, h Handler) { //archive routes archiveRouter := router.PathPrefix("/archive").Subrouter() archiveRouter.HandleFunc("/search", h.getSummaryListOfArchives).Methods(http.MethodPost) - archiveRouter.HandleFunc("/{id}", h.getArchive).Methods(http.MethodGet) + archiveRouter.HandleFunc("/{id}", h.getArchive).Methods(http.MethodPost) } // @Summary Get a summary list of disputes From 4d8209ae01ac959e2194d1929dde3045f01b685b Mon Sep 17 00:00:00 2001 From: Caelan Hill Date: Sat, 22 Jun 2024 20:31:01 +0200 Subject: [PATCH 4/6] changed route --- api/main.go | 2 +- compose.yaml | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/api/main.go b/api/main.go index 6aaf1ad4..21a5f8f4 100644 --- a/api/main.go +++ b/api/main.go @@ -47,7 +47,7 @@ func main() { userRouter.Use(middleware.JWTMiddleware) handlers.SetupUserRoutes(userRouter, h) - disputeRouter := router.PathPrefix("/dispute").Subrouter() + disputeRouter := router.PathPrefix("/disputes").Subrouter() handlers.SetupDisputeRoutes(disputeRouter, h) // Swagger setup diff --git a/compose.yaml b/compose.yaml index 8c37798f..3fc53765 100644 --- a/compose.yaml +++ b/compose.yaml @@ -16,6 +16,10 @@ services: depends_on: - "postgres" - "redis-cache" + develop: + watch: + - action: rebuild + path: ./api postgres: image: postgres ports: From eeb6635b43e88b1fb71cb56c9480d984fc09f5b3 Mon Sep 17 00:00:00 2001 From: Caelan Hill Date: Sat, 22 Jun 2024 20:35:16 +0200 Subject: [PATCH 5/6] changed method type --- api/handlers/dispute.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/handlers/dispute.go b/api/handlers/dispute.go index 96bd07ec..da51603d 100644 --- a/api/handlers/dispute.go +++ b/api/handlers/dispute.go @@ -25,7 +25,7 @@ func SetupDisputeRoutes(router *mux.Router, h Handler) { //archive routes archiveRouter := router.PathPrefix("/archive").Subrouter() archiveRouter.HandleFunc("/search", h.getSummaryListOfArchives).Methods(http.MethodPost) - archiveRouter.HandleFunc("/{id}", h.getArchive).Methods(http.MethodPost) + archiveRouter.HandleFunc("/{id}", h.getArchive).Methods(http.MethodGet) } // @Summary Get a summary list of disputes From 52970af30b0db3216e165d88921abb6756bdfe96 Mon Sep 17 00:00:00 2001 From: Vincent Date: Sat, 22 Jun 2024 20:37:32 +0200 Subject: [PATCH 6/6] feat: Added catch to archive errors --- frontend/src/lib/api/archive.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/frontend/src/lib/api/archive.ts b/frontend/src/lib/api/archive.ts index c2317e60..ad364301 100644 --- a/frontend/src/lib/api/archive.ts +++ b/frontend/src/lib/api/archive.ts @@ -13,8 +13,14 @@ export async function searchArchive( method: "POST", body: JSON.stringify(params), }); - return res.json(); + return res.json().catch(async (e: Error) => ({ + error: e.message, + })); } export async function fetchArchivedDispute(id: string): Promise> { - return await fetch(`${API_URL}/disputes/archive/${id}`).then((res) => res.json()); + return fetch(`${API_URL}/disputes/archive/${id}`) + .then((res) => res.json()) + .catch((e: Error) => ({ + error: e.message, + })); }