origins
This commit is contained in:
parent
b89fb42679
commit
669bfbf5a0
6 changed files with 232 additions and 12 deletions
|
|
@ -1,6 +1,10 @@
|
|||
package merch
|
||||
|
||||
import "github.com/gin-gonic/gin"
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"merch-api/pkg/responses"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type controller struct {
|
||||
service *service
|
||||
|
|
@ -21,6 +25,11 @@ func (h *Handler) RegisterRoutes(r *gin.RouterGroup) {
|
|||
merchGroup.PUT("/update", h.controller.update)
|
||||
merchGroup.DELETE("/delete", h.controller.delete)
|
||||
|
||||
originsGroup := merchGroup.Group("/origins")
|
||||
originsGroup.POST("", h.controller.createOrigin)
|
||||
originsGroup.GET("", h.controller.getOrigins)
|
||||
originsGroup.DELETE("", h.controller.deleteOrigin)
|
||||
|
||||
}
|
||||
|
||||
func (co *controller) create(c *gin.Context) {}
|
||||
|
|
@ -32,3 +41,89 @@ func (co *controller) getMany(c *gin.Context) {}
|
|||
func (co *controller) update(c *gin.Context) {}
|
||||
|
||||
func (co *controller) delete(c *gin.Context) {}
|
||||
|
||||
// createOrigin godoc
|
||||
//
|
||||
// @Summary Create new origin
|
||||
// @Description Create new origin with name
|
||||
// @Tags Origins
|
||||
// @Accept json
|
||||
// @Param origin body newOriginDTO true "origin body"
|
||||
// @Success 201
|
||||
// @Failure 400 {object} responses.BadRequest
|
||||
// @Failure 401 {object} responses.Unauthorized
|
||||
// @Failure 500 {object} responses.InternalServerError
|
||||
// @Router /merch/origins [POST]
|
||||
func (co *controller) createOrigin(c *gin.Context) {
|
||||
var origin *newOriginDTO
|
||||
|
||||
if err := c.ShouldBindJSON(&origin); err != nil {
|
||||
c.JSON(http.StatusBadRequest, responses.BadRequest{Error: err.Error()})
|
||||
logErrController(err)
|
||||
return
|
||||
}
|
||||
|
||||
if err := co.service.createOrigin(origin); err != nil {
|
||||
c.JSON(http.StatusInternalServerError, responses.InternalServerError{Error: err.Error()})
|
||||
logErrController(err)
|
||||
return
|
||||
}
|
||||
|
||||
logDebugController("create origin success")
|
||||
c.Status(http.StatusCreated)
|
||||
}
|
||||
|
||||
// getOrigins godoc
|
||||
//
|
||||
// @Summary Get all origins
|
||||
// @Description Get all origins
|
||||
// @Tags Origins
|
||||
// @Produce json
|
||||
// @Success 200 {object} originsDTO
|
||||
// @Success 204
|
||||
// @Failure 400 {object} responses.BadRequest
|
||||
// @Failure 401 {object} responses.Unauthorized
|
||||
// @Failure 500 {object} responses.InternalServerError
|
||||
// @Router /merch/origins [GET]
|
||||
func (co *controller) getOrigins(c *gin.Context) {
|
||||
response, err := co.service.getOrigins()
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, responses.InternalServerError{Error: err.Error()})
|
||||
logErrController(err)
|
||||
return
|
||||
}
|
||||
|
||||
logDebugController("get origins success")
|
||||
c.JSON(http.StatusOK, response)
|
||||
}
|
||||
|
||||
// deleteOrigin godoc
|
||||
//
|
||||
// @Summary Delete origin
|
||||
// @Description Marks origin as deleted by name.
|
||||
// @Tags Origins
|
||||
// @Accept json
|
||||
// @Param origin body deleteOriginDTO true "origin body"
|
||||
// @Success 204
|
||||
// @Failure 400 {object} responses.BadRequest
|
||||
// @Failure 401 {object} responses.Unauthorized
|
||||
// @Failure 500 {object} responses.InternalServerError
|
||||
// @Router /merch/origins [DELETE]
|
||||
func (co *controller) deleteOrigin(c *gin.Context) {
|
||||
var origin *deleteOriginDTO
|
||||
|
||||
if err := c.ShouldBindJSON(&origin); err != nil {
|
||||
c.JSON(http.StatusBadRequest, responses.BadRequest{Error: err.Error()})
|
||||
logErrController(err)
|
||||
return
|
||||
}
|
||||
|
||||
if err := co.service.deleteOrigin(origin); err != nil {
|
||||
c.JSON(http.StatusInternalServerError, responses.InternalServerError{Error: err.Error()})
|
||||
logErrController(err)
|
||||
return
|
||||
}
|
||||
|
||||
logDebugController("delete origin success")
|
||||
c.Status(http.StatusNoContent)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue