Implement artist GetByID
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user