重构后端服务架构并优化前端错误处理
This commit is contained in:
44
go-backend/routes/routes.go
Normal file
44
go-backend/routes/routes.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package routes
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
"niumall-go/controllers"
|
||||
"niumall-go/middleware"
|
||||
)
|
||||
|
||||
func RegisterRoutes(router *gin.Engine) {
|
||||
// Public routes
|
||||
public := router.Group("/api")
|
||||
{
|
||||
// User authentication
|
||||
public.POST("/login", controllers.Login)
|
||||
|
||||
// Public user routes
|
||||
public.GET("/users", controllers.GetUsers)
|
||||
public.GET("/users/:id", controllers.GetUserByID)
|
||||
}
|
||||
|
||||
// Protected routes
|
||||
protected := router.Group("/api")
|
||||
protected.Use(middleware.AuthMiddleware())
|
||||
{
|
||||
// User routes
|
||||
protected.PUT("/users/:id", controllers.UpdateUser)
|
||||
protected.DELETE("/users/:id", controllers.DeleteUser)
|
||||
|
||||
// Order routes
|
||||
protected.GET("/orders", controllers.GetOrders)
|
||||
protected.GET("/orders/:id", controllers.GetOrderByID)
|
||||
protected.POST("/orders", controllers.CreateOrder)
|
||||
protected.PUT("/orders/:id", controllers.UpdateOrder)
|
||||
protected.DELETE("/orders/:id", controllers.DeleteOrder)
|
||||
|
||||
// Payment routes
|
||||
protected.GET("/payments", controllers.GetPayments)
|
||||
protected.GET("/payments/:id", controllers.GetPaymentByID)
|
||||
protected.POST("/payments", controllers.CreatePayment)
|
||||
protected.PUT("/payments/:id", controllers.UpdatePayment)
|
||||
protected.DELETE("/payments/:id", controllers.DeletePayment)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user