MW usage refactor

This commit is contained in:
nquidox 2026-03-21 15:21:30 +03:00
parent 229eebcf66
commit 21b54c4167
9 changed files with 98 additions and 48 deletions

View file

@ -6,6 +6,7 @@ import (
"github.com/google/uuid"
log "github.com/sirupsen/logrus"
"merch-api/pkg/responses"
"merch-api/pkg/router"
"merch-api/pkg/utils"
"net/http"
)
@ -24,8 +25,9 @@ func newController(s *service, u utils.Utils) *controller {
}
}
func (h *Handler) RegisterRoutes(r *gin.RouterGroup) {
func (h *Handler) RegisterRoutes(r *gin.RouterGroup, mw *router.Middlewares) {
merchGroup := r.Group("/merch")
merchGroup.Use(mw.AuthMW)
merchGroup.POST("/create", h.controller.create)
merchGroup.GET("/:id", h.controller.getOne)
@ -35,21 +37,28 @@ func (h *Handler) RegisterRoutes(r *gin.RouterGroup) {
merchGroup.DELETE("/:id", h.controller.deleteMerch)
originsGroup := merchGroup.Group("/origins")
originsGroup.Use(mw.AuthMW)
originsGroup.POST("", h.controller.createOrigin)
originsGroup.GET("", h.controller.getOrigins)
originsGroup.DELETE("", h.controller.deleteOrigin)
chartsGroup := r.Group("/prices")
chartsGroup.Use(mw.AuthMW)
chartsGroup.GET("", h.controller.getChartsPrices)
chartsGroup.GET("/:uuid", h.controller.getDistinctPrices)
zeroPricesGroup := merchGroup.Group("/zeroprices")
zeroPricesGroup.Use(mw.AuthMW)
zeroPricesGroup.GET("", h.controller.getZeroPrices)
zeroPricesGroup.DELETE("", h.controller.deleteZeroPrices)
zeroPricesGroup.DELETE("/period", h.controller.deleteZeroPricesPeriod)
labelsGroup := merchGroup.Group("/labels")
labelsGroup.Use(mw.AuthMW)
labelsGroup.POST("", h.controller.createLabel)
labelsGroup.GET("", h.controller.getLabels)
labelsGroup.PUT("/:uuid", h.controller.updateLabel)