Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/archive integration #150

Merged
merged 6 commits into from
Jun 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions api/handlers/dispute.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package handlers

import (
"api/middleware"
"api/models"
"api/utilities"
"encoding/json"
Expand All @@ -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()
Expand Down
3 changes: 1 addition & 2 deletions api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ func main() {
userRouter.Use(middleware.JWTMiddleware)
handlers.SetupUserRoutes(userRouter, h)

disputeRouter := router.PathPrefix("/dispute").Subrouter()
disputeRouter.Use(middleware.JWTMiddleware)
disputeRouter := router.PathPrefix("/disputes").Subrouter()
handlers.SetupDisputeRoutes(disputeRouter, h)

// Swagger setup
Expand Down
4 changes: 4 additions & 0 deletions compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ services:
depends_on:
- "postgres"
- "redis-cache"
develop:
watch:
- action: rebuild
path: ./api
postgres:
image: postgres
ports:
Expand Down
61 changes: 13 additions & 48 deletions frontend/src/lib/api/archive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,58 +4,23 @@ import {
ArchiveSearchResponse,
} from "../interfaces/archive";
import { Result } from "@/lib/types";
import { API_URL } from "../utils";

export async function searchArchive(
params: ArchiveSearchRequest
): Promise<Result<ArchiveSearchResponse>> {
// 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().catch(async (e: Error) => ({
error: e.message,
}));
}
export async function fetchArchivedDispute(id: string): Promise<Result<ArchiveGetResponse>> {
// 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 fetch(`${API_URL}/disputes/archive/${id}`)
.then((res) => res.json())
.catch((e: Error) => ({
error: e.message,
}));
}
Loading