get and delete methods
This commit is contained in:
parent
25d11b31da
commit
bc3eee6434
5 changed files with 154 additions and 6 deletions
|
|
@ -2,6 +2,7 @@ package merch
|
|||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/google/uuid"
|
||||
"merch-api/pkg/responses"
|
||||
"merch-api/pkg/utils"
|
||||
"net/http"
|
||||
|
|
@ -26,7 +27,7 @@ func (h *Handler) RegisterRoutes(r *gin.RouterGroup) {
|
|||
merchGroup.GET("/:id", h.controller.getOne)
|
||||
merchGroup.GET("/list", h.controller.getMany)
|
||||
merchGroup.PUT("/update", h.controller.update)
|
||||
merchGroup.DELETE("/delete", h.controller.delete)
|
||||
merchGroup.DELETE("/:id", h.controller.deleteMerch)
|
||||
|
||||
originsGroup := merchGroup.Group("/origins")
|
||||
originsGroup.POST("", h.controller.createOrigin)
|
||||
|
|
@ -73,11 +74,78 @@ func (co *controller) create(c *gin.Context) {
|
|||
|
||||
func (co *controller) getOne(c *gin.Context) {}
|
||||
|
||||
func (co *controller) getMany(c *gin.Context) {}
|
||||
// getMany godoc
|
||||
//
|
||||
// @Summary Get all merch
|
||||
// @Description Get all merch without origins
|
||||
// @Tags Merch
|
||||
// @Produce json
|
||||
// @Success 200 {array} merchDTO
|
||||
// @Success 204
|
||||
// @Failure 400 {object} responses.BadRequest
|
||||
// @Failure 401 {object} responses.Unauthorized
|
||||
// @Failure 500 {object} responses.InternalServerError
|
||||
// @Router /merch/list [GET]
|
||||
func (co *controller) getMany(c *gin.Context) {
|
||||
userUuid, err := co.utils.GetUserUuidFromContext(c)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusUnauthorized, responses.Unauthorized{Error: err.Error()})
|
||||
logErrController(err)
|
||||
return
|
||||
}
|
||||
|
||||
response, err := co.service.getMany(c, userUuid)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, responses.InternalServerError{Error: err.Error()})
|
||||
logErrController(err)
|
||||
return
|
||||
}
|
||||
|
||||
if len(response) == 0 {
|
||||
c.Status(http.StatusNoContent)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, response)
|
||||
}
|
||||
|
||||
func (co *controller) update(c *gin.Context) {}
|
||||
|
||||
func (co *controller) delete(c *gin.Context) {}
|
||||
// deleteMerch godoc
|
||||
//
|
||||
// @Summary Delete merch
|
||||
// @Description Marks merch and all its extra data as deleted by uuid.
|
||||
// @Tags Merch
|
||||
// @Accept json
|
||||
// @Param uuid path string true "merch uuid"
|
||||
// @Success 204
|
||||
// @Failure 400 {object} responses.BadRequest
|
||||
// @Failure 401 {object} responses.Unauthorized
|
||||
// @Failure 500 {object} responses.InternalServerError
|
||||
// @Router /merch/{uuid} [DELETE]
|
||||
func (co *controller) deleteMerch(c *gin.Context) {
|
||||
userUuid, err := co.utils.GetUserUuidFromContext(c)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusUnauthorized, responses.Unauthorized{Error: err.Error()})
|
||||
logErrController(err)
|
||||
return
|
||||
}
|
||||
|
||||
merchUuid := c.Param("id")
|
||||
if err = uuid.Validate(merchUuid); err != nil {
|
||||
c.JSON(http.StatusBadRequest, responses.BadRequest{Error: err.Error()})
|
||||
logErrController(err)
|
||||
return
|
||||
}
|
||||
|
||||
if err = co.service.deleteOneMerchRecord(c, userUuid, merchUuid); err != nil {
|
||||
c.JSON(http.StatusInternalServerError, responses.InternalServerError{Error: err.Error()})
|
||||
logErrController(err)
|
||||
return
|
||||
}
|
||||
|
||||
c.Status(http.StatusNoContent)
|
||||
}
|
||||
|
||||
// createOrigin godoc
|
||||
//
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue