-
Notifications
You must be signed in to change notification settings - Fork 1
feat(song): add song lyrics CRUD endpoints #46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
1a37ab5
5b52083
d90e76e
2711dac
b944c58
01decb2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,2 @@ | ||
| export * from "./ConflictError"; | ||
| export * from "./RateLimitError"; | ||
| export * from "./getErrorResponse"; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| import { Elysia } from "elysia"; | ||
| import { | ||
| ErrorResponseSchema, | ||
| SongLyricsCreateRequestSchema, | ||
| SongLyricsResponseSchema, | ||
| songService, | ||
| } from "@cvsa/core"; | ||
| import { authMiddleware } from "@/middlewares"; | ||
| import { traceTask } from "@/common/trace"; | ||
| import z from "zod"; | ||
|
|
||
| export const songLyricsCreateHandler = new Elysia({ name: "songLyricsCreateHandler" }) | ||
| .use(authMiddleware) | ||
| .post( | ||
| "/song/:id/lyric", | ||
| async ({ body, params, status }) => { | ||
| const lyric = await traceTask("songService.createLyric", async () => { | ||
| return await songService.createLyric(params.id, body); | ||
| }); | ||
| return status(201, lyric); | ||
| }, | ||
| { | ||
| body: SongLyricsCreateRequestSchema, | ||
| detail: { | ||
| summary: "Create Song Lyric", | ||
| description: "Add a new lyrics item for a song. Requires authentication.", | ||
| }, | ||
| response: { | ||
| 201: SongLyricsResponseSchema, | ||
| 400: ErrorResponseSchema, | ||
| 401: ErrorResponseSchema, | ||
| 404: ErrorResponseSchema, | ||
| }, | ||
| params: z.object({ | ||
| id: z.coerce.number().int().positive(), | ||
| }), | ||
| } | ||
| ); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import { Elysia } from "elysia"; | ||
| import { ErrorResponseSchema, songService } from "@cvsa/core"; | ||
| import { authMiddleware } from "@/middlewares"; | ||
| import { traceTask } from "@/common/trace"; | ||
| import z from "zod"; | ||
|
|
||
| export const songLyricsDeleteHandler = new Elysia({ name: "songLyricsDeleteHandler" }) | ||
| .use(authMiddleware) | ||
| .delete( | ||
| "/song/:id/lyric/:lyricId", | ||
| async ({ params, set }) => { | ||
| await traceTask("songService.deleteLyric", async () => { | ||
| return await songService.deleteLyric(params.id, params.lyricId); | ||
| }); | ||
| set.status = 204; | ||
| return null; | ||
| }, | ||
| { | ||
| detail: { | ||
| summary: "Delete Song Lyric", | ||
| description: "Delete a specific lyrics item for a song. Requires authentication.", | ||
| }, | ||
| response: { | ||
| 204: z.null(), | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion | 🟠 Major Avoid inline Zod schemas in this handler config.
As per coding guidelines: Also applies to: 29-32 🤖 Prompt for AI Agents |
||
| 400: ErrorResponseSchema, | ||
| 401: ErrorResponseSchema, | ||
| 404: ErrorResponseSchema, | ||
| }, | ||
| params: z.object({ | ||
| id: z.coerce.number().int().positive(), | ||
| lyricId: z.coerce.number().int().positive(), | ||
| }), | ||
| } | ||
| ); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import { Elysia } from "elysia"; | ||
| import { ErrorResponseSchema, SongLyricsResponseSchema, songService } from "@cvsa/core"; | ||
| import z from "zod"; | ||
| import { traceTask } from "@/common/trace"; | ||
|
|
||
| export const songLyricsGetHandler = new Elysia().get( | ||
| "/song/:id/lyric/:lyricId", | ||
| async ({ params, status }) => { | ||
| const lyric = await traceTask("songService.getLyric", async () => { | ||
| return await songService.getLyric(params.id, params.lyricId); | ||
| }); | ||
| return status(200, lyric); | ||
| }, | ||
| { | ||
| detail: { | ||
| summary: "Get Song Lyric", | ||
| description: "Retrieve a specific lyrics item for a song by its ID.", | ||
| }, | ||
| response: { | ||
| 200: SongLyricsResponseSchema, | ||
| 400: ErrorResponseSchema, | ||
| 404: ErrorResponseSchema, | ||
| }, | ||
| params: z.object({ | ||
| id: z.coerce.number().int().positive(), | ||
| lyricId: z.coerce.number().int().positive(), | ||
| }), | ||
|
Comment on lines
+24
to
+27
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion | 🟠 Major Move route param schema to core DTO module. Inline ♻️ Proposed refactor-import z from "zod";
+import { SongLyricPathParamsSchema } from "@cvsa/core";
...
- params: z.object({
- id: z.coerce.number().int().positive(),
- lyricId: z.coerce.number().int().positive(),
- }),
+ params: SongLyricPathParamsSchema,// packages/core/src/modules/catalog/song/dto.ts
export const SongLyricPathParamsSchema = z.object({
id: z.coerce.number().int().positive(),
lyricId: z.coerce.number().int().positive(),
});As per coding guidelines: 🤖 Prompt for AI Agents |
||
| } | ||
| ); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| import { Elysia } from "elysia"; | ||
| import { songLyricsListHandler } from "./list"; | ||
| import { songLyricsGetHandler } from "./get"; | ||
| import { songLyricsCreateHandler } from "./create"; | ||
| import { songLyricsUpdateHandler } from "./update"; | ||
| import { songLyricsDeleteHandler } from "./delete"; | ||
|
|
||
| export const songLyricsHandler = new Elysia({ name: "songLyricsHandler" }) | ||
| .use(songLyricsListHandler) | ||
| .use(songLyricsGetHandler) | ||
| .use(songLyricsCreateHandler) | ||
| .use(songLyricsUpdateHandler) | ||
| .use(songLyricsDeleteHandler); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import { Elysia } from "elysia"; | ||
| import { ErrorResponseSchema, SongLyricsListResponseSchema, songService } from "@cvsa/core"; | ||
| import z from "zod"; | ||
| import { traceTask } from "@/common/trace"; | ||
|
|
||
| export const songLyricsListHandler = new Elysia().get( | ||
| "/song/:id/lyrics", | ||
| async ({ params, status }) => { | ||
| const lyrics = await traceTask("songService.listLyrics", async () => { | ||
| return await songService.listLyrics(params.id); | ||
| }); | ||
| return status(200, lyrics); | ||
| }, | ||
| { | ||
| detail: { | ||
| summary: "List Song Lyrics", | ||
| description: "Retrieve all available lyrics for a specific song by its ID.", | ||
| }, | ||
| response: { | ||
| 200: SongLyricsListResponseSchema, | ||
| 400: ErrorResponseSchema, | ||
| 404: ErrorResponseSchema, | ||
| }, | ||
| params: z.object({ | ||
| id: z.coerce.number().int().positive(), | ||
| }), | ||
|
Comment on lines
+24
to
+26
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion | 🟠 Major Extract The inline params schema at Line 24-26 should be imported from As per coding guidelines: 🤖 Prompt for AI Agents |
||
| } | ||
| ); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| import { Elysia } from "elysia"; | ||
| import { | ||
| ErrorResponseSchema, | ||
| SongLyricsUpdateRequestSchema, | ||
| SongLyricsResponseSchema, | ||
| songService, | ||
| } from "@cvsa/core"; | ||
| import { authMiddleware } from "@/middlewares"; | ||
| import { traceTask } from "@/common/trace"; | ||
| import z from "zod"; | ||
|
|
||
| export const songLyricsUpdateHandler = new Elysia({ name: "songLyricsUpdateHandler" }) | ||
| .use(authMiddleware) | ||
| .patch( | ||
| "/song/:id/lyric/:lyricId", | ||
| async ({ body, params, status }) => { | ||
| const lyric = await traceTask("songService.updateLyric", async () => { | ||
| return await songService.updateLyric(params.id, params.lyricId, body); | ||
| }); | ||
| return status(200, lyric); | ||
| }, | ||
| { | ||
| body: SongLyricsUpdateRequestSchema, | ||
| detail: { | ||
| summary: "Update Song Lyric", | ||
| description: "Update a specific lyrics item for a song. Requires authentication.", | ||
| }, | ||
| response: { | ||
| 200: SongLyricsResponseSchema, | ||
| 400: ErrorResponseSchema, | ||
| 401: ErrorResponseSchema, | ||
| 404: ErrorResponseSchema, | ||
| }, | ||
| params: z.object({ | ||
| id: z.coerce.number().int().positive(), | ||
| lyricId: z.coerce.number().int().positive(), | ||
| }), | ||
|
Comment on lines
+34
to
+37
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion | 🟠 Major Extract Please replace the inline params schema at Line 34-37 with an imported shared schema from As per coding guidelines: 🤖 Prompt for AI Agents |
||
| } | ||
| ); | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion | 🟠 Major
Use a shared params schema from core DTOs.
The inline
paramsschema at Line 34-36 should be defined inpackages/core/src/modules/catalog/song/dto.tsand imported here.As per coding guidelines:
apps/backend/src/handlers/**/*.ts: Define all Zod schemas in packages/core/modules/<module>/dto.ts first; do not define them inline inside handlers.🤖 Prompt for AI Agents