重构后端服务架构并优化前端错误处理

This commit is contained in:
ylweng
2025-09-12 01:21:43 +08:00
parent d550a8ed51
commit 3a48a67757
53 changed files with 3925 additions and 0 deletions

View 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)
}
}