44 lines
1.2 KiB
Go
44 lines
1.2 KiB
Go
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)
|
|
}
|
|
} |