-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
142 changed files
with
1,848 additions
and
2,148 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import { OpenAPIHono } from "@hono/zod-openapi" | ||
import { getConnection } from "@/v2/db/turso" | ||
import { eq } from "drizzle-orm" | ||
import { asset } from "@/v2/db/schema" | ||
import { createRoute } from "@hono/zod-openapi" | ||
import { GenericResponses } from "@/v2/lib/response-schemas" | ||
import { z } from "@hono/zod-openapi" | ||
|
||
const deleteAssetByIdSchema = z.object({ | ||
id: z.string().openapi({ | ||
param: { | ||
name: "id", | ||
in: "path", | ||
description: "The ID of the asset to delete.", | ||
example: "1", | ||
required: true, | ||
}, | ||
}), | ||
}) | ||
|
||
const deleteAssetByIdResponseSchema = z.object({ | ||
success: z.literal(true), | ||
}) | ||
|
||
const deleteAssetByIdRoute = createRoute({ | ||
path: "/{id}", | ||
method: "delete", | ||
description: | ||
"Delete an asset from their ID. Must be the owner of the asset or an admin.", | ||
tags: ["Asset"], | ||
request: { | ||
params: deleteAssetByIdSchema, | ||
}, | ||
responses: { | ||
200: { | ||
description: "True if the asset was deleted.", | ||
content: { | ||
"application/json": { | ||
schema: deleteAssetByIdResponseSchema, | ||
}, | ||
}, | ||
}, | ||
...GenericResponses, | ||
}, | ||
}) | ||
|
||
const handler = new OpenAPIHono<{ Bindings: Bindings; Variables: Variables }>() | ||
|
||
handler.openapi(deleteAssetByIdRoute, async (ctx) => { | ||
const assetId = ctx.req.valid("param").id | ||
|
||
const { drizzle } = await getConnection(ctx.env) | ||
|
||
const [existingAsset] = await drizzle | ||
.select({ id: asset.id }) | ||
.from(asset) | ||
.where(eq(asset.id, parseInt(assetId))) | ||
.limit(1) | ||
|
||
if (!existingAsset) { | ||
return ctx.json( | ||
{ | ||
success: true, | ||
message: "Asset not found", | ||
}, | ||
400 | ||
) | ||
} | ||
|
||
await drizzle.delete(asset).where(eq(asset.id, parseInt(assetId))) | ||
// await ctx.env.FILES_BUCKET.delete(asset.url) | ||
|
||
return ctx.json( | ||
{ | ||
success: true, | ||
}, | ||
200 | ||
) | ||
}) | ||
|
||
export default handler |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
43 changes: 42 additions & 1 deletion
43
src/v2/routes/asset/likes/all/route.ts → src/v2/routes/asset/get-asset-likes.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
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,138 @@ | ||
import { OpenAPIHono } from "@hono/zod-openapi" | ||
import { getConnection } from "@/v2/db/turso" | ||
import { asset } from "@/v2/db/schema" | ||
import { eq, sql } from "drizzle-orm" | ||
import { createRoute } from "@hono/zod-openapi" | ||
import { GenericResponses } from "@/v2/lib/response-schemas" | ||
import { z } from "@hono/zod-openapi" | ||
import { | ||
selectAssetCategorySchema, | ||
selectGameSchema, | ||
selectAssetSchema, | ||
selectAssetTagAssetSchema, | ||
selectAssetTagSchema, | ||
selectUserSchema, | ||
} from "@/v2/db/schema" | ||
|
||
const getAssetByIdSchema = z.object({ | ||
id: z.string().openapi({ | ||
param: { | ||
name: "id", | ||
in: "path", | ||
description: "The ID of the asset to retrieve.", | ||
required: true, | ||
}, | ||
}), | ||
}) | ||
|
||
const getAssetByIdResponseSchema = z.object({ | ||
success: z.literal(true), | ||
// mmm nested schemas | ||
asset: selectAssetSchema.extend({ | ||
assetTagAsset: z.array( | ||
selectAssetTagAssetSchema.extend({ | ||
assetTag: selectAssetTagSchema, | ||
}) | ||
), | ||
}), | ||
authUser: selectUserSchema.pick({ | ||
id: true, | ||
avatarUrl: true, | ||
displayName: true, | ||
username: true, | ||
usernameColour: true, | ||
pronouns: true, | ||
verified: true, | ||
bio: true, | ||
dateJoined: true, | ||
plan: true, | ||
role: true, | ||
}), | ||
game: selectGameSchema, | ||
assetCategory: selectAssetCategorySchema, | ||
// similarAssets: selectAssetSchema.array(), | ||
}) | ||
|
||
const getAssetByIdRoute = createRoute({ | ||
path: "/{id}", | ||
method: "get", | ||
description: "Get an asset by their ID.", | ||
tags: ["Asset"], | ||
request: { | ||
params: getAssetByIdSchema, | ||
}, | ||
responses: { | ||
200: { | ||
description: "The found asset & similar assets are returned.", | ||
content: { | ||
"application/json": { | ||
schema: getAssetByIdResponseSchema, | ||
}, | ||
}, | ||
}, | ||
...GenericResponses, | ||
}, | ||
}) | ||
|
||
const handler = new OpenAPIHono<{ Bindings: Bindings; Variables: Variables }>() | ||
|
||
handler.openapi(getAssetByIdRoute, async (ctx) => { | ||
const assetId = ctx.req.valid("param").id | ||
|
||
const { drizzle } = await getConnection(ctx.env) | ||
|
||
const foundAsset = await drizzle.query.asset.findFirst({ | ||
where: (asset, { eq }) => eq(asset.id, parseInt(assetId)), | ||
with: { | ||
assetTagAsset: { | ||
with: { | ||
assetTag: true, | ||
}, | ||
}, | ||
authUser: { | ||
columns: { | ||
id: true, | ||
avatarUrl: true, | ||
displayName: true, | ||
username: true, | ||
usernameColour: true, | ||
pronouns: true, | ||
verified: true, | ||
bio: true, | ||
dateJoined: true, | ||
plan: true, | ||
role: true, | ||
}, | ||
}, | ||
game: true, | ||
assetCategory: true, | ||
}, | ||
}) | ||
|
||
if (!foundAsset) { | ||
return ctx.json( | ||
{ | ||
success: false, | ||
message: "Asset not found", | ||
}, | ||
400 | ||
) | ||
} | ||
|
||
await drizzle | ||
.update(asset) | ||
.set({ | ||
viewCount: sql`${asset.viewCount} + 1`, | ||
}) | ||
.where(eq(asset.id, parseInt(assetId))) | ||
|
||
return ctx.json( | ||
{ | ||
success: true, | ||
asset: foundAsset, | ||
}, | ||
200 | ||
) | ||
}) | ||
|
||
export default handler |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.