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

💻 add mocked route for ballots #244

Merged
merged 7 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
4 changes: 4 additions & 0 deletions spec/oas_v1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1629,6 +1629,10 @@ paths:
responses:
'200':
description: OK
content:
application/json:
schema:
$ref: "#/components/schemas/RetroFundingBallot"
'400':
description: Bad Request
'401':
Expand Down
53 changes: 53 additions & 0 deletions src/app/api/common/ballots/getBallots.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { cache } from "react";

async function getBallotsApi(roundId: string) {
const defaultPaginationMetadata = {
hasNext: false,
totalReturned: 1,
nextOffset: 1,
};

const defaultBallots = {
ballots: [
{
address: "0x",
Flip-Liquid marked this conversation as resolved.
Show resolved Hide resolved
ballotId: 0,
roundId: roundId,
status: "PENDING",
allocations: [
{
metricId: 0,
allocation: "0",
},
],
submitterAddress: "0xDa6d1F091B672C0f9e215eB9fa6B5a84bF2c5e11",
},
],
};

return {
metadata: defaultPaginationMetadata,
ballots: [defaultBallots],
};
}

async function getBallotApi(roundId: string, ballotAddressOrEns: string) {
const defaultBallot = {
address: ballotAddressOrEns,
ballotId: 0,
roundId: roundId,
status: "PENDING",
allocations: [
{
metricId: 0,
allocation: "0",
},
],
submitterAddress: "0xDa6d1F091B672C0f9e215eB9fa6B5a84bF2c5e11",
};

return defaultBallot;
}

export const fetchBallots = cache(getBallotsApi);
export const fetchBallot = cache(getBallotApi);
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { fetchBallot } from "@/app/api/common/ballots/getBallots";

export async function GET(
request: Request,
route: { params: { roundId: string; ballotAddressOrEns: string } }
) {
const { roundId, ballotAddressOrEns } = route.params;
const ballots = await fetchBallot(roundId, ballotAddressOrEns);
return new Response(JSON.stringify(ballots), {
status: 200,
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { fetchBallot } from "@/app/api/common/ballots/getBallots";

export async function POST(
request: Request,
route: { params: { roundId: string; ballotAddressOrEns: string } }
) {
const { roundId, ballotAddressOrEns } = route.params;
const ballot = await fetchBallot(roundId, ballotAddressOrEns);
return new Response(JSON.stringify(ballot), {
status: 200,
});
}
12 changes: 12 additions & 0 deletions src/app/api/v1/retrofunding/rounds/[roundId]/ballots/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { fetchBallots } from "@/app/api/common/ballots/getBallots";

export async function GET(
request: Request,
route: { params: { roundId: string } }
) {
const { roundId } = route.params;
const ballots = await fetchBallots(roundId);
return new Response(JSON.stringify(ballots), {
status: 200,
});
}
Loading