-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
π» mocked impact metrics routes (#245)
* π» add routes for per-round and per-ballot impact metrics * π»π add get (singular) impact metric by id; tabs: 2-spaced; * π» add route for getting impact metric by id * π» add POST /rounds/ballots/ * π» add delete route for /ballots/impact metrics
- Loading branch information
1 parent
c9185cb
commit ca986f5
Showing
5 changed files
with
131 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { cache } from "react"; | ||
|
||
async function getImpactMetricsApi( | ||
roundId: string, | ||
ballotCasterAddressOrEns?: string | ||
) { | ||
const defaultPageMetadata = { | ||
hasNext: false, | ||
totalReturned: 1, | ||
nextOffset: 0, | ||
}; | ||
const defaultComments = [ | ||
{ | ||
id: "1", | ||
content: "Comment 1", | ||
commenter: "0x1234", | ||
createdAt: "2021-10-01T00:00:00Z", | ||
editedAt: "2021-10-01T00:00:00Z", | ||
}, | ||
]; | ||
const defaultImpactMetrics = [ | ||
{ | ||
id: "1", | ||
name: "Impact Metric 1", | ||
description: "Description of Impact Metric 1", | ||
externalLink: "https://www.opensource.observer/", | ||
comments: defaultComments, | ||
}, | ||
]; | ||
return { | ||
metadata: defaultPageMetadata, | ||
impactMetrics: defaultImpactMetrics, | ||
}; | ||
} | ||
|
||
async function getImpactMetricApi(impactMetricId: string) { | ||
const defaultComments = [ | ||
{ | ||
id: "1", | ||
content: "Comment 1", | ||
commenter: "0x1234", | ||
createdAt: "2021-10-01T00:00:00Z", | ||
editedAt: "2021-10-01T00:00:00Z", | ||
}, | ||
]; | ||
const defaultImpactMetric = { | ||
id: impactMetricId, | ||
name: `Impact Metric ${impactMetricId}`, | ||
description: `Description of Impact Metric ${impactMetricId}`, | ||
externalLink: "https://www.opensource.observer/", | ||
comments: defaultComments, | ||
}; | ||
return defaultImpactMetric; | ||
} | ||
|
||
export const fetchImpactMetricsApi = cache(getImpactMetricsApi); | ||
export const fetchImpactMetricApi = cache(getImpactMetricApi); |
15 changes: 15 additions & 0 deletions
15
...unds/[roundId]/ballots/[ballotCasterAddressOrEns]/impactMetrics/[impactMetricId]/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,15 @@ | ||
export async function DELETE( | ||
request: Request, | ||
route: { | ||
params: { | ||
roundId: string; | ||
ballotCasterAddressOrEns: string; | ||
impactMetricId: string; | ||
}; | ||
} | ||
) { | ||
const { roundId, ballotCasterAddressOrEns, impactMetricId } = route.params; | ||
return new Response(null, { | ||
status: 200, | ||
}); | ||
} |
29 changes: 29 additions & 0 deletions
29
...1/retrofunding/rounds/[roundId]/ballots/[ballotCasterAddressOrEns]/impactMetrics/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,29 @@ | ||
import { fetchImpactMetricsApi } from "@/app/api/common/impactMetrics/getImpactMetrics"; | ||
|
||
export async function GET( | ||
request: Request, | ||
route: { params: { roundId: string; ballotCasterAddressOrEns: string } } | ||
) { | ||
const { roundId, ballotCasterAddressOrEns } = route.params; | ||
const impactMetrics = await fetchImpactMetricsApi( | ||
roundId, | ||
ballotCasterAddressOrEns | ||
); | ||
return new Response(JSON.stringify(impactMetrics), { | ||
status: 200, | ||
}); | ||
} | ||
|
||
export async function POST( | ||
request: Request, | ||
route: { params: { roundId: string; ballotCasterAddressOrEns: string } } | ||
) { | ||
const { roundId, ballotCasterAddressOrEns } = route.params; | ||
const impactMetrics = await fetchImpactMetricsApi( | ||
roundId, | ||
ballotCasterAddressOrEns | ||
); | ||
return new Response(JSON.stringify(impactMetrics), { | ||
status: 200, | ||
}); | ||
} |
18 changes: 18 additions & 0 deletions
18
src/app/api/v1/retrofunding/rounds/[roundId]/impactMetrics/[impactMetricId]/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,18 @@ | ||
import { fetchImpactMetricApi } from "@/app/api/common/impactMetrics/getImpactMetrics"; | ||
|
||
export async function GET( | ||
request: Request, | ||
route: { | ||
params: { | ||
roundId: string; | ||
ballotCasterAddressOrEns: string; | ||
impactMetricId: string; | ||
}; | ||
} | ||
) { | ||
const { roundId, ballotCasterAddressOrEns, impactMetricId } = route.params; | ||
const impactMetrics = await fetchImpactMetricApi(impactMetricId); | ||
return new Response(JSON.stringify(impactMetrics), { | ||
status: 200, | ||
}); | ||
} |
12 changes: 12 additions & 0 deletions
12
src/app/api/v1/retrofunding/rounds/[roundId]/impactMetrics/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 { fetchImpactMetricsApi } from "@/app/api/common/impactMetrics/getImpactMetrics"; | ||
|
||
export async function GET( | ||
request: Request, | ||
route: { params: { roundId: string } } | ||
) { | ||
const { roundId } = route.params; | ||
const impactMetrics = await fetchImpactMetricsApi(roundId); | ||
return new Response(JSON.stringify(impactMetrics), { | ||
status: 200, | ||
}); | ||
} |