-
-
Notifications
You must be signed in to change notification settings - Fork 481
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Expose asset manipulation endpoints in the REST API
- Loading branch information
1 parent
eb0d821
commit 4439c91
Showing
6 changed files
with
630 additions
and
0 deletions.
There are no files selected for viewing
37 changes: 37 additions & 0 deletions
37
apps/web/app/api/v1/bookmarks/[bookmarkId]/assets/[assetId]/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,37 @@ | ||
import { NextRequest } from "next/server"; | ||
import { buildHandler } from "@/app/api/v1/utils/handler"; | ||
import { z } from "zod"; | ||
|
||
export const dynamic = "force-dynamic"; | ||
|
||
export const PUT = ( | ||
req: NextRequest, | ||
params: { params: { bookmarkId: string; assetId: string } }, | ||
) => | ||
buildHandler({ | ||
req, | ||
bodySchema: z.object({ assetId: z.string() }), | ||
handler: async ({ api, body }) => { | ||
await api.bookmarks.replaceAsset({ | ||
bookmarkId: params.params.bookmarkId, | ||
oldAssetId: params.params.assetId, | ||
newAssetId: body!.assetId, | ||
}); | ||
return { status: 204 }; | ||
}, | ||
}); | ||
|
||
export const DELETE = ( | ||
req: NextRequest, | ||
params: { params: { bookmarkId: string; assetId: string } }, | ||
) => | ||
buildHandler({ | ||
req, | ||
handler: async ({ api }) => { | ||
await api.bookmarks.detachAsset({ | ||
bookmarkId: params.params.bookmarkId, | ||
assetId: params.params.assetId, | ||
}); | ||
return { status: 204 }; | ||
}, | ||
}); |
36 changes: 36 additions & 0 deletions
36
apps/web/app/api/v1/bookmarks/[bookmarkId]/assets/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,36 @@ | ||
import { NextRequest } from "next/server"; | ||
import { buildHandler } from "@/app/api/v1/utils/handler"; | ||
|
||
import { zAssetSchema } from "@hoarder/shared/types/bookmarks"; | ||
|
||
export const dynamic = "force-dynamic"; | ||
|
||
export const GET = ( | ||
req: NextRequest, | ||
params: { params: { bookmarkId: string } }, | ||
) => | ||
buildHandler({ | ||
req, | ||
handler: async ({ api }) => { | ||
const resp = await api.bookmarks.getBookmark({ | ||
bookmarkId: params.params.bookmarkId, | ||
}); | ||
return { status: 200, resp: { assets: resp.assets } }; | ||
}, | ||
}); | ||
|
||
export const POST = ( | ||
req: NextRequest, | ||
params: { params: { bookmarkId: string } }, | ||
) => | ||
buildHandler({ | ||
req, | ||
bodySchema: zAssetSchema, | ||
handler: async ({ api, body }) => { | ||
const asset = await api.bookmarks.attachAsset({ | ||
bookmarkId: params.params.bookmarkId, | ||
asset: body!, | ||
}); | ||
return { status: 201, resp: asset }; | ||
}, | ||
}); |
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
Oops, something went wrong.