Skip to content

Commit

Permalink
πŸ’» mocked impact metrics routes (#245)
Browse files Browse the repository at this point in the history
* πŸ’» 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
Flip-Liquid committed Apr 22, 2024
1 parent c9185cb commit ca986f5
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 0 deletions.
57 changes: 57 additions & 0 deletions src/app/api/common/impactMetrics/getImpactMetrics.ts
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);
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,
});
}
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,
});
}
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,
});
}
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,
});
}

0 comments on commit ca986f5

Please sign in to comment.