diff --git a/spec/oas_v1.yaml b/spec/oas_v1.yaml index a046cf536..9c6457a8b 100644 --- a/spec/oas_v1.yaml +++ b/spec/oas_v1.yaml @@ -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 @@ -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: @@ -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': diff --git a/src/app/api/common/comments/getImpactMetricComments.ts b/src/app/api/common/comments/getImpactMetricComments.ts new file mode 100644 index 000000000..bdbd0d380 --- /dev/null +++ b/src/app/api/common/comments/getImpactMetricComments.ts @@ -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); diff --git a/src/app/api/v1/retrofunding/rounds/[roundId]/impactMetrics/[impactMetricId]/comments/[commentId]/route.ts b/src/app/api/v1/retrofunding/rounds/[roundId]/impactMetrics/[impactMetricId]/comments/[commentId]/route.ts new file mode 100644 index 000000000..96d72ec5b --- /dev/null +++ b/src/app/api/v1/retrofunding/rounds/[roundId]/impactMetrics/[impactMetricId]/comments/[commentId]/route.ts @@ -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 }); +} diff --git a/src/app/api/v1/retrofunding/rounds/[roundId]/impactMetrics/[impactMetricId]/comments/route.ts b/src/app/api/v1/retrofunding/rounds/[roundId]/impactMetrics/[impactMetricId]/comments/route.ts new file mode 100644 index 000000000..fbb12d35b --- /dev/null +++ b/src/app/api/v1/retrofunding/rounds/[roundId]/impactMetrics/[impactMetricId]/comments/route.ts @@ -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 }); +}