-
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 comments routes (#247)
* π»ππ―οΈ 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
1 parent
0d9d15f
commit e0c94fe
Showing
4 changed files
with
120 additions
and
8 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
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,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); |
11 changes: 11 additions & 0 deletions
11
...etrofunding/rounds/[roundId]/impactMetrics/[impactMetricId]/comments/[commentId]/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,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 }); | ||
} |
29 changes: 29 additions & 0 deletions
29
...app/api/v1/retrofunding/rounds/[roundId]/impactMetrics/[impactMetricId]/comments/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 { 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 }); | ||
} |