diff --git a/src/app/api/common/impactMetrics/getImpactMetrics.ts b/src/app/api/common/impactMetrics/getImpactMetrics.ts new file mode 100644 index 000000000..a9d07bdcc --- /dev/null +++ b/src/app/api/common/impactMetrics/getImpactMetrics.ts @@ -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); diff --git a/src/app/api/v1/retrofunding/rounds/[roundId]/ballots/[ballotCasterAddressOrEns]/impactMetrics/[impactMetricId]/route.ts b/src/app/api/v1/retrofunding/rounds/[roundId]/ballots/[ballotCasterAddressOrEns]/impactMetrics/[impactMetricId]/route.ts new file mode 100644 index 000000000..ef18706d9 --- /dev/null +++ b/src/app/api/v1/retrofunding/rounds/[roundId]/ballots/[ballotCasterAddressOrEns]/impactMetrics/[impactMetricId]/route.ts @@ -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, + }); +} diff --git a/src/app/api/v1/retrofunding/rounds/[roundId]/ballots/[ballotCasterAddressOrEns]/impactMetrics/route.ts b/src/app/api/v1/retrofunding/rounds/[roundId]/ballots/[ballotCasterAddressOrEns]/impactMetrics/route.ts new file mode 100644 index 000000000..da9f07903 --- /dev/null +++ b/src/app/api/v1/retrofunding/rounds/[roundId]/ballots/[ballotCasterAddressOrEns]/impactMetrics/route.ts @@ -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, + }); +} diff --git a/src/app/api/v1/retrofunding/rounds/[roundId]/impactMetrics/[impactMetricId]/route.ts b/src/app/api/v1/retrofunding/rounds/[roundId]/impactMetrics/[impactMetricId]/route.ts new file mode 100644 index 000000000..795503cef --- /dev/null +++ b/src/app/api/v1/retrofunding/rounds/[roundId]/impactMetrics/[impactMetricId]/route.ts @@ -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, + }); +} diff --git a/src/app/api/v1/retrofunding/rounds/[roundId]/impactMetrics/route.ts b/src/app/api/v1/retrofunding/rounds/[roundId]/impactMetrics/route.ts new file mode 100644 index 000000000..5c17a77d2 --- /dev/null +++ b/src/app/api/v1/retrofunding/rounds/[roundId]/impactMetrics/route.ts @@ -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, + }); +}