Implement artist GetByID

This commit is contained in:
zardzul
2026-03-14 20:00:36 +01:00
parent d5e608feeb
commit 6bff66b31b
6 changed files with 134 additions and 0 deletions
+25
View File
@@ -5,6 +5,7 @@ import (
"zardzul/music-index/repository"
"github.com/gin-gonic/gin"
"github.com/jackc/pgx/v5/pgtype"
)
type ArtistHandler struct {
@@ -31,3 +32,27 @@ func (handler *ArtistHandler) GetAll(c *gin.Context) {
c.JSON(http.StatusOK, artists)
}
// GetByID godoc
// @Summary List artist by ID
// @Tags artist
// @produce json
// @Param id path string true "Artist ID (UUID)"
// @Success 200 {array} map[string]interface{}
// @Failure 500 {object} ErrorResponse
// @Router /artists/:id [get]
func (handler *ArtistHandler) GetByID(c *gin.Context) {
idParam := c.Param("id")
var pgID pgtype.UUID
if err := pgID.Scan(idParam); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid artist id"})
return
}
artist, err := handler.repo.GetByID(c.Request.Context(), pgID)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}
c.JSON(http.StatusOK, artist)
}