Skip to content

Commit

Permalink
πŸ’»πŸ—―οΈ mocked comments routes (#247)
Browse files Browse the repository at this point in the history
* πŸ’»πŸ“πŸ—―οΈ comments spec fixup; add GET comments w/paginationn; return PUT comment

* 🀏 typo

* πŸ’»πŸ—―οΈ add support for PUT/GET/DELETE impact metric comments

* ✨ prettier
  • Loading branch information
Flip-Liquid committed Apr 22, 2024
1 parent 0d9d15f commit e0c94fe
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 8 deletions.
48 changes: 40 additions & 8 deletions spec/oas_v1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1822,11 +1822,46 @@ paths:
'500':
description: Internal Server Error
/retrofunding/rounds/{roundId}/impactMetrics/{impactMetricId}/comments:
get:
summary: Gets comments on an impact metric
description: >
Gets a paginated list of comments on a particular impact metric. Ordered by creation date.
operationId: getImpactMetricComments
tags:
- RetroFunding
- RetroFundingRounds
- impactMetrics
- comments
parameters:
- $ref: "#/components/parameters/roundIdParam"
- $ref: "#/components/parameters/impactMetricParam"
responses:
'200':
description: OK
content:
application/json:
schema:
type: object
properties:
metadata:
$ref: '#/components/schemas/PageMetadata'
comments:
type: array
items:
$ref: '#/components/schemas/Comment'
'400':
description: Bad Request
'401':
description: Unauthorized
'404':
description: Not Found
'500':
description: Internal Server Error
put:
summary: Comments on an impact metric
summary: Creates a comment on an impact metric
description: >
Creates or edits a comment on a specific impact metric for a specific round.
If supplied, comment ID is ignored.
If supplied, comment ID is ignored. Returns created comment.
operationId: putImpactMetricComment
tags:
- RetroFunding
Expand All @@ -1836,6 +1871,8 @@ paths:
parameters:
- $ref: "#/components/parameters/roundIdParam"
- $ref: "#/components/parameters/impactMetricParam"
- $ref: "#/components/parameters/limitParam"
- $ref: "#/components/parameters/offsetParam"
requestBody:
content:
application/json:
Expand All @@ -1847,12 +1884,7 @@ paths:
content:
application/json:
schema:
type: object
properties:
comments:
type: array
items:
$ref: '#/components/schemas/Comment'
$ref: '#/components/schemas/Comment'
'400':
description: Bad Request
'401':
Expand Down
40 changes: 40 additions & 0 deletions src/app/api/common/comments/getImpactMetricComments.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { cache } from "react";

async function getImpactMetricComments(
roundId: string,
impactMetricId: 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",
},
];
return defaultComments;
}

async function getImpactMetricComment(
roundId: string,
impactMetricId: string,
commentId: string
) {
const defaultComment = {
id: commentId,
content: `Comment id ${commentId}`,
commenter: "0x1234",
createdAt: "2021-10-01T00:00:00Z",
editedAt: "2021-10-01T00:00:00Z",
};
return defaultComment;
}

export const fetchImpactMetricComments = cache(getImpactMetricComments);
export const fetchImpactMetricComment = cache(getImpactMetricComment);
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { NextResponse, type NextRequest } from "next/server";

export async function DELETE(
request: NextRequest,
route: {
params: { roundId: string; impactMetricId: string; commentId: string };
}
) {
const { roundId, impactMetricId, commentId } = route.params;
return new Response(null, { status: 200 });
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { NextResponse, type NextRequest } from "next/server";
import {
fetchImpactMetricComments,
fetchImpactMetricComment,
} from "@/app/api/common/comments/getImpactMetricComments";

export async function GET(
request: NextRequest,
route: { params: { roundId: string; impactMetricId: string } }
) {
const { roundId, impactMetricId } = route.params;
const comments = fetchImpactMetricComments(roundId, impactMetricId);
return new Response(JSON.stringify(comments), { status: 200 });
}

export async function PUT(
request: NextRequest,
route: { params: { roundId: string; impactMetricId: string } }
) {
const { roundId, impactMetricId } = route.params;
const body = await request.json();
const { comment } = body;
const retrievedComment = fetchImpactMetricComment(
roundId,
impactMetricId,
comment.id
);
return new Response(JSON.stringify(retrievedComment), { status: 200 });
}

0 comments on commit e0c94fe

Please sign in to comment.