-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
π» add mocked route for ballots (#244)
* π» 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
- Loading branch information
1 parent
cc11b41
commit fdf7044
Showing
5 changed files
with
100 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
12 changes: 12 additions & 0 deletions
12
src/app/api/v1/retrofunding/rounds/[roundId]/ballots/[ballotCasterAddressOrEns]/route.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}); | ||
} |
12 changes: 12 additions & 0 deletions
12
...p/api/v1/retrofunding/rounds/[roundId]/ballots/[ballotCasterAddressOrEns]/submit/route.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
12
src/app/api/v1/retrofunding/rounds/[roundId]/ballots/route.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}); | ||
} |