From c9185cb1137ffcb51bbe7fe142466293d8992086 Mon Sep 17 00:00:00 2001 From: Flip-Liquid <13227294+Flip-Liquid@users.noreply.github.com> Date: Mon, 22 Apr 2024 18:52:57 -0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=92=BB=20add=20mocked=20route=20for=20bal?= =?UTF-8?q?lots=20(#244)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * πŸ’» add mocked route for ballots * πŸ’» add ballot-by-address route and ✌️query ✌️ * πŸ’»πŸ€πŸ“ return body of ballot for /submit * πŸ”πŸ·οΈ feedback: rename ballotAddress to balltotCasterAddress * πŸ”πŸ’»πŸ·οΈ unify ballot address + submitter fields to ballotCasterAddress --- spec/oas_v1.yaml | 20 +++++--- src/app/api/common/ballots/getBallots.ts | 51 +++++++++++++++++++ .../[ballotCasterAddressOrEns]/route.ts | 12 +++++ .../submit/route.ts | 12 +++++ .../rounds/[roundId]/ballots/route.ts | 12 +++++ 5 files changed, 100 insertions(+), 7 deletions(-) create mode 100644 src/app/api/common/ballots/getBallots.ts create mode 100644 src/app/api/v1/retrofunding/rounds/[roundId]/ballots/[ballotCasterAddressOrEns]/route.ts create mode 100644 src/app/api/v1/retrofunding/rounds/[roundId]/ballots/[ballotCasterAddressOrEns]/submit/route.ts create mode 100644 src/app/api/v1/retrofunding/rounds/[roundId]/ballots/route.ts diff --git a/spec/oas_v1.yaml b/spec/oas_v1.yaml index 9c6457a8b..82c36d56b 100644 --- a/spec/oas_v1.yaml +++ b/spec/oas_v1.yaml @@ -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 @@ -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 @@ -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: > @@ -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. @@ -1629,6 +1631,10 @@ paths: responses: '200': description: OK + content: + application/json: + schema: + $ref: "#/components/schemas/RetroFundingBallot" '400': description: Bad Request '401': @@ -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: > @@ -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: > diff --git a/src/app/api/common/ballots/getBallots.ts b/src/app/api/common/ballots/getBallots.ts new file mode 100644 index 000000000..e5e67d5f1 --- /dev/null +++ b/src/app/api/common/ballots/getBallots.ts @@ -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); diff --git a/src/app/api/v1/retrofunding/rounds/[roundId]/ballots/[ballotCasterAddressOrEns]/route.ts b/src/app/api/v1/retrofunding/rounds/[roundId]/ballots/[ballotCasterAddressOrEns]/route.ts new file mode 100644 index 000000000..5bc1fed94 --- /dev/null +++ b/src/app/api/v1/retrofunding/rounds/[roundId]/ballots/[ballotCasterAddressOrEns]/route.ts @@ -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, + }); +} diff --git a/src/app/api/v1/retrofunding/rounds/[roundId]/ballots/[ballotCasterAddressOrEns]/submit/route.ts b/src/app/api/v1/retrofunding/rounds/[roundId]/ballots/[ballotCasterAddressOrEns]/submit/route.ts new file mode 100644 index 000000000..3d42848c5 --- /dev/null +++ b/src/app/api/v1/retrofunding/rounds/[roundId]/ballots/[ballotCasterAddressOrEns]/submit/route.ts @@ -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, + }); +} diff --git a/src/app/api/v1/retrofunding/rounds/[roundId]/ballots/route.ts b/src/app/api/v1/retrofunding/rounds/[roundId]/ballots/route.ts new file mode 100644 index 000000000..42054c973 --- /dev/null +++ b/src/app/api/v1/retrofunding/rounds/[roundId]/ballots/route.ts @@ -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, + }); +}