-
Notifications
You must be signed in to change notification settings - Fork 1
feat(artist): add CRUD endpoints for artists #51
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,32 @@ | ||
| import { Elysia } from "elysia"; | ||
| import { | ||
| CreateArtistRequestSchema, | ||
| ErrorResponseSchema, | ||
| ArtistResponseSchema, | ||
| artistService, | ||
| } from "@cvsa/core"; | ||
| import { authMiddleware } from "@/middlewares"; | ||
| import { traceTask } from "@/common/trace"; | ||
|
|
||
| export const artistCreateHandler = new Elysia({ name: "artistCreateHandler" }) | ||
| .use(authMiddleware) | ||
| .post( | ||
| "/artist", | ||
| async ({ body, status }) => { | ||
| const artist = await traceTask("artistService.create", async () => { | ||
| return await artistService.create(body); | ||
| }); | ||
| return status(201, artist); | ||
| }, | ||
| { | ||
| body: CreateArtistRequestSchema, | ||
| detail: { | ||
| summary: "Create Artist", | ||
| description: "Create a new artist entry in the catalog. Requires authentication.", | ||
| }, | ||
| response: { | ||
| 201: ArtistResponseSchema, | ||
| 401: ErrorResponseSchema, | ||
| }, | ||
| } | ||
| ); | ||
This file contains hidden or 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,34 @@ | ||
| import { Elysia } from "elysia"; | ||
| import { z } from "zod"; | ||
| import { ErrorResponseSchema, artistService } from "@cvsa/core"; | ||
| import { authMiddleware } from "@/middlewares"; | ||
| import { traceTask } from "@/common/trace"; | ||
|
|
||
| export const artistDeleteHandler = new Elysia({ name: "artistDeleteHandler" }) | ||
| .use(authMiddleware) | ||
| .delete( | ||
| "/artist/:id", | ||
| async ({ params, set }) => { | ||
| await traceTask("artistService.delete", async () => { | ||
| return await artistService.delete(params.id); | ||
| }); | ||
| set.status = 204; | ||
| return null; | ||
| }, | ||
| { | ||
| params: z.object({ | ||
| id: z.coerce.number().int().positive(), | ||
| }), | ||
| detail: { | ||
| summary: "Delete Artist", | ||
| description: | ||
| "Soft delete an artist from the catalog. Requires authentication. The artist record is marked as deleted but retained in the database for data integrity.", | ||
| }, | ||
| response: { | ||
| 204: z.null(), | ||
| 400: ErrorResponseSchema, | ||
| 401: ErrorResponseSchema, | ||
| 404: ErrorResponseSchema, | ||
| }, | ||
| } | ||
| ); |
This file contains hidden or 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 { Elysia } from "elysia"; | ||
| import { ErrorResponseSchema, ArtistDetailsResponseSchema, artistService } from "@cvsa/core"; | ||
| import z from "zod"; | ||
| import { traceTask } from "@/common/trace"; | ||
|
|
||
| export const artistDetailsHandler = new Elysia().get( | ||
| "/artist/:id", | ||
| async ({ params, status }) => { | ||
| const artist = await traceTask("artistService.getDetails", async () => { | ||
| return await artistService.getDetails(params.id); | ||
| }); | ||
| return status(200, artist); | ||
| }, | ||
| { | ||
| detail: { | ||
| summary: "Artist Details", | ||
| description: | ||
| "Retrieve detailed information about a specific artist by its ID. Includes name, description, aliases, and metadata.", | ||
| }, | ||
| response: { | ||
| 200: ArtistDetailsResponseSchema, | ||
| 400: ErrorResponseSchema, | ||
| 404: ErrorResponseSchema, | ||
| }, | ||
| params: z.object({ | ||
| id: z.coerce.number().int().positive(), | ||
| }), | ||
| } | ||
| ); |
This file contains hidden or 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 { Elysia } from "elysia"; | ||
| import { artistCreateHandler } from "./create"; | ||
| import { artistUpdateHandler } from "./update"; | ||
| import { artistDeleteHandler } from "./delete"; | ||
| import { artistDetailsHandler } from "./get"; | ||
|
|
||
| export const artistHandler = new Elysia({ name: "artistHandler" }) | ||
| .use(artistDetailsHandler) | ||
| .use(artistCreateHandler) | ||
| .use(artistUpdateHandler) | ||
| .use(artistDeleteHandler); |
This file contains hidden or 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,39 @@ | ||
| import { Elysia } from "elysia"; | ||
| import { z } from "zod"; | ||
| import { | ||
| UpdateArtistRequestSchema, | ||
| ErrorResponseSchema, | ||
| artistService, | ||
| ArtistResponseSchema, | ||
| } from "@cvsa/core"; | ||
| import { authMiddleware } from "@/middlewares"; | ||
| import { traceTask } from "@/common/trace"; | ||
|
|
||
| export const artistUpdateHandler = new Elysia({ name: "artistUpdateHandler" }) | ||
| .use(authMiddleware) | ||
| .patch( | ||
| "/artist/:id", | ||
| async ({ params, body, status }) => { | ||
| const artist = await traceTask("artistService.update", async () => { | ||
| return await artistService.update(params.id, body); | ||
| }); | ||
| return status(200, artist); | ||
| }, | ||
| { | ||
| body: UpdateArtistRequestSchema, | ||
| params: z.object({ | ||
| id: z.coerce.number().int().positive(), | ||
| }), | ||
| detail: { | ||
| summary: "Update Artist", | ||
| description: | ||
| "Update metadata of an existing artist identified by its ID. Requires authentication.", | ||
| }, | ||
| response: { | ||
| 200: ArtistResponseSchema, | ||
| 400: ErrorResponseSchema, | ||
| 401: ErrorResponseSchema, | ||
| 404: ErrorResponseSchema, | ||
| }, | ||
| } | ||
| ); |
This file contains hidden or 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 |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| export * from "./auth"; | ||
| export * from "./catalog/song"; | ||
| export * from "./catalog/engine"; | ||
| export * from "./catalog/artist"; | ||
| export * from "./dev"; |
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.