feat: restructure protected routes to use AuthMiddlewarey
This commit is contained in:
@@ -29,14 +29,12 @@ func NewRouter() *gin.Engine {
|
||||
auth.POST(constants.API_PATH_AUTH_LOGIN, utils.AsyncHandler(services.Login))
|
||||
}
|
||||
|
||||
// Protected routes (require JWT authentication)
|
||||
protected := v1.Group("")
|
||||
protected.Use(middlewares.AuthMiddleware())
|
||||
{
|
||||
protected.GET(constants.API_PATH_PROFILE, utils.AsyncHandler(services.GetProfile))
|
||||
}
|
||||
|
||||
warehouse := v1.Group(constants.API_GROUP_WAREHOUSE)
|
||||
warehouse := protected.Group(constants.API_GROUP_WAREHOUSE)
|
||||
{
|
||||
warehouse.GET("", utils.AsyncHandler(services.WareHouseList))
|
||||
warehouse.GET("/:id", utils.AsyncHandler(services.WareHouseGetByID))
|
||||
@@ -45,7 +43,7 @@ func NewRouter() *gin.Engine {
|
||||
warehouse.DELETE("/:id", utils.AsyncHandler(services.WareHouseDelete))
|
||||
}
|
||||
|
||||
room := v1.Group(constants.API_GROUP_ROOM)
|
||||
room := protected.Group(constants.API_GROUP_ROOM)
|
||||
{
|
||||
room.GET("", utils.AsyncHandler(services.RoomList))
|
||||
room.GET("/:id", utils.AsyncHandler(services.RoomGetByID))
|
||||
@@ -54,7 +52,7 @@ func NewRouter() *gin.Engine {
|
||||
room.DELETE("/:id", utils.AsyncHandler(services.RoomDelete))
|
||||
}
|
||||
|
||||
cabinet := v1.Group(constants.API_GROUP_CABINET)
|
||||
cabinet := protected.Group(constants.API_GROUP_CABINET)
|
||||
{
|
||||
cabinet.GET("", utils.AsyncHandler(services.CabinetList))
|
||||
cabinet.GET("/:id", utils.AsyncHandler(services.CabinetGetByID))
|
||||
@@ -63,7 +61,7 @@ func NewRouter() *gin.Engine {
|
||||
cabinet.DELETE("/:id", utils.AsyncHandler(services.CabinetDelete))
|
||||
}
|
||||
|
||||
shelve := v1.Group(constants.API_GROUP_SHELF)
|
||||
shelve := protected.Group(constants.API_GROUP_SHELF)
|
||||
{
|
||||
shelve.GET("", utils.AsyncHandler(services.ShelveList))
|
||||
shelve.GET("/:id", utils.AsyncHandler(services.ShelveGetByID))
|
||||
@@ -72,7 +70,7 @@ func NewRouter() *gin.Engine {
|
||||
shelve.DELETE("/:id", utils.AsyncHandler(services.ShelveDelete))
|
||||
}
|
||||
|
||||
container := v1.Group(constants.API_GROUP_CONTAINER)
|
||||
container := protected.Group(constants.API_GROUP_CONTAINER)
|
||||
{
|
||||
container.GET("", utils.AsyncHandler(services.ContainerList))
|
||||
container.GET("/:id", utils.AsyncHandler(services.ContainerGetByID))
|
||||
@@ -81,7 +79,7 @@ func NewRouter() *gin.Engine {
|
||||
container.DELETE("/:id", utils.AsyncHandler(services.ContainerDelete))
|
||||
}
|
||||
|
||||
componentType := v1.Group(constants.API_GROUP_COMPONENT_TYPE)
|
||||
componentType := protected.Group(constants.API_GROUP_COMPONENT_TYPE)
|
||||
{
|
||||
componentType.GET("", utils.AsyncHandler(services.ComponentTypeList))
|
||||
componentType.GET("/:id", utils.AsyncHandler(services.ComponentTypeGetByID))
|
||||
@@ -90,7 +88,7 @@ func NewRouter() *gin.Engine {
|
||||
componentType.DELETE("/:id", utils.AsyncHandler(services.ComponentTypeDelete))
|
||||
}
|
||||
|
||||
component := v1.Group(constants.API_GROUP_COMPONENT)
|
||||
component := protected.Group(constants.API_GROUP_COMPONENT)
|
||||
{
|
||||
component.GET("", utils.AsyncHandler(services.ComponentList))
|
||||
component.GET("/:id", utils.AsyncHandler(services.ComponentGetByID))
|
||||
@@ -99,7 +97,7 @@ func NewRouter() *gin.Engine {
|
||||
component.DELETE("/:id", utils.AsyncHandler(services.ComponentDelete))
|
||||
}
|
||||
|
||||
componentCode := v1.Group(constants.API_GROUP_COMPONENT_CODE)
|
||||
componentCode := protected.Group(constants.API_GROUP_COMPONENT_CODE)
|
||||
{
|
||||
componentCode.GET("", utils.AsyncHandler(services.ComponentCodeList))
|
||||
componentCode.GET("/:id", utils.AsyncHandler(services.ComponentCodeGetByID))
|
||||
@@ -108,7 +106,7 @@ func NewRouter() *gin.Engine {
|
||||
componentCode.DELETE("/:id", utils.AsyncHandler(services.ComponentCodeDelete))
|
||||
}
|
||||
|
||||
componentItem := v1.Group(constants.API_GROUP_COMPONENT_ITEM)
|
||||
componentItem := protected.Group(constants.API_GROUP_COMPONENT_ITEM)
|
||||
{
|
||||
componentItem.GET("", utils.AsyncHandler(services.ComponentItemList))
|
||||
componentItem.GET("/find/:componentId", utils.AsyncHandler(services.ComponentItemFind))
|
||||
@@ -119,7 +117,7 @@ func NewRouter() *gin.Engine {
|
||||
componentItem.DELETE("/:id", utils.AsyncHandler(services.ComponentItemDelete))
|
||||
}
|
||||
|
||||
invoiceConfig := v1.Group(constants.API_GROUP_INVOICE_CONFIG)
|
||||
invoiceConfig := protected.Group(constants.API_GROUP_INVOICE_CONFIG)
|
||||
{
|
||||
invoiceConfig.GET("", utils.AsyncHandler(services.InvoiceConfigList))
|
||||
invoiceConfig.GET("/:id", utils.AsyncHandler(services.InvoiceConfigGetByID))
|
||||
@@ -128,7 +126,7 @@ func NewRouter() *gin.Engine {
|
||||
invoiceConfig.DELETE("/:id", utils.AsyncHandler(services.InvoiceConfigDelete))
|
||||
}
|
||||
|
||||
invoiceConfigItem := v1.Group(constants.API_GROUP_INVOICE_CONFIG_ITEM)
|
||||
invoiceConfigItem := protected.Group(constants.API_GROUP_INVOICE_CONFIG_ITEM)
|
||||
{
|
||||
invoiceConfigItem.GET("", utils.AsyncHandler(services.InvoiceConfigItemList))
|
||||
invoiceConfigItem.GET("/:id", utils.AsyncHandler(services.InvoiceConfigItemGetByID))
|
||||
@@ -137,7 +135,7 @@ func NewRouter() *gin.Engine {
|
||||
invoiceConfigItem.DELETE("/:id", utils.AsyncHandler(services.InvoiceConfigItemDelete))
|
||||
}
|
||||
|
||||
invoice := v1.Group(constants.API_GROUP_INVOICE)
|
||||
invoice := protected.Group(constants.API_GROUP_INVOICE)
|
||||
{
|
||||
invoice.GET("", utils.AsyncHandler(services.InvoiceList))
|
||||
invoice.GET("/:id", utils.AsyncHandler(services.InvoiceGetByID))
|
||||
@@ -146,7 +144,7 @@ func NewRouter() *gin.Engine {
|
||||
invoice.DELETE("/:id", utils.AsyncHandler(services.InvoiceDelete))
|
||||
}
|
||||
|
||||
alternativeComponent := v1.Group(constants.API_GROUP_ALTERNATIVE_COMPONENT)
|
||||
alternativeComponent := protected.Group(constants.API_GROUP_ALTERNATIVE_COMPONENT)
|
||||
{
|
||||
alternativeComponent.GET("", utils.AsyncHandler(services.AlternativeComponentList))
|
||||
alternativeComponent.GET("/:id", utils.AsyncHandler(services.AlternativeComponentGetByID))
|
||||
@@ -155,6 +153,7 @@ func NewRouter() *gin.Engine {
|
||||
alternativeComponent.DELETE("/:id", utils.AsyncHandler(services.AlternativeComponentDelete))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
r.GET(constants.API_PATH_PING, services.PingHandler)
|
||||
r.GET(constants.API_PATH_DOCS, ginSwagger.WrapHandler(swaggerFiles.Handler))
|
||||
|
||||
Reference in New Issue
Block a user