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 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
20 changes: 13 additions & 7 deletions spec/oas_v1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,9 @@ components:
type: array
items:
$ref: "#/components/schemas/RetroFundingBallotAllocation"
submitterAddress:
ballotCasterAddress:
summary: Address of the ballot caster
description: The resolved address of the entity which cast the ballot.
type: string
RetroFundingBallotSubmission:
summary: Fields required for ballot submission
Expand Down Expand Up @@ -862,9 +864,9 @@ components:
schema:
type: integer
ballotIdParam:
name: ballotAddressOrEns
name: ballotCasterAddressOrEns
in: path
description: The address or ENS name of the ballot to retrieve
description: The address or ENS name of the caster of a given ballot to retrieve.
required: true
schema:
type: string
Expand Down Expand Up @@ -1583,7 +1585,7 @@ paths:
description: Unauthorized
'500':
description: Internal Server Error
/retrofunding/rounds/{roundId}/ballots/{ballotAddressOrEns}:
/retrofunding/rounds/{roundId}/ballots/{ballotCasterAddressOrEns}:
get:
summary: Gets a specific ballot for an RetroFunding round
description: >
Expand All @@ -1610,7 +1612,7 @@ paths:
description: Not Found
'500':
description: Internal Server Error
/retrofunding/rounds/{roundId}/ballots/{ballotAddressOrEns}/submit:
/retrofunding/rounds/{roundId}/ballots/{ballotCasterAddressOrEns}/submit:
post:
summary: Submits a particular ballot
description: Submits the content of a ballot to be counted as final for the round.
Expand All @@ -1629,6 +1631,10 @@ paths:
responses:
'200':
description: OK
content:
application/json:
schema:
$ref: "#/components/schemas/RetroFundingBallot"
'400':
description: Bad Request
'401':
Expand Down Expand Up @@ -1671,7 +1677,7 @@ paths:
description: Unauthorized
'500':
description: Internal Server Error
/retrofunding/rounds/{roundId}/ballots/{ballotAddressOrEns}/impactMetrics:
/retrofunding/rounds/{roundId}/ballots/{ballotCasterAddressOrEns}/impactMetrics:
get:
summary: Gets impact metrics for a specific RetroFunding ballot
description: >
Expand Down Expand Up @@ -1738,7 +1744,7 @@ paths:
description: Unauthorized
'500':
description: Internal Server Error
/retrofunding/rounds/{roundId}/ballots/{ballotAddressOrEns}/impactMetrics/{impactMetricId}:
/retrofunding/rounds/{roundId}/ballots/{ballotCasterAddressOrEns}/impactMetrics/{impactMetricId}:
delete:
summary: Removes an impact metric from a ballot
description: >
Expand Down
51 changes: 51 additions & 0 deletions src/app/api/common/ballots/getBallots.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { cache } from "react";

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

const defaultBallots = {
ballots: [
{
ballotId: 0,
roundId: roundId,
status: "PENDING",
allocations: [
{
metricId: 0,
allocation: "0",
},
],
ballotCasterAddress: "0xDa6d1F091B672C0f9e215eB9fa6B5a84bF2c5e11",
},
],
};

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

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

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; ballotCasterAddressOrEns: string } }
) {
const { roundId, ballotCasterAddressOrEns } = route.params;
const ballots = await fetchBallot(roundId, ballotCasterAddressOrEns);
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; ballotCasterAddressOrEns: string } }
) {
const { roundId, ballotCasterAddressOrEns } = route.params;
const ballot = await fetchBallot(roundId, ballotCasterAddressOrEns);
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