feat: sync project
This commit is contained in:
@@ -8,6 +8,7 @@ import (
|
||||
"github.com/gin-contrib/cors"
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
"mengyastore-backend/internal/auth"
|
||||
"mengyastore-backend/internal/config"
|
||||
"mengyastore-backend/internal/handlers"
|
||||
"mengyastore-backend/internal/storage"
|
||||
@@ -23,6 +24,14 @@ func main() {
|
||||
if err != nil {
|
||||
log.Fatalf("init store failed: %v", err)
|
||||
}
|
||||
orderStore, err := storage.NewOrderStore("data/json/orders.json")
|
||||
if err != nil {
|
||||
log.Fatalf("init order store failed: %v", err)
|
||||
}
|
||||
siteStore, err := storage.NewSiteStore("data/json/site.json")
|
||||
if err != nil {
|
||||
log.Fatalf("init site store failed: %v", err)
|
||||
}
|
||||
|
||||
r := gin.Default()
|
||||
r.Use(cors.New(cors.Config{
|
||||
@@ -38,10 +47,20 @@ func main() {
|
||||
c.JSON(http.StatusOK, gin.H{"status": "ok"})
|
||||
})
|
||||
|
||||
authClient := auth.NewSproutGateClient(cfg.AuthAPIURL)
|
||||
|
||||
publicHandler := handlers.NewPublicHandler(store)
|
||||
adminHandler := handlers.NewAdminHandler(store, cfg)
|
||||
orderHandler := handlers.NewOrderHandler(store, orderStore, authClient)
|
||||
statsHandler := handlers.NewStatsHandler(orderStore, siteStore)
|
||||
|
||||
r.GET("/api/products", publicHandler.ListProducts)
|
||||
r.POST("/api/checkout", orderHandler.CreateOrder)
|
||||
r.POST("/api/products/:id/view", publicHandler.RecordProductView)
|
||||
r.GET("/api/stats", statsHandler.GetStats)
|
||||
r.POST("/api/site/visit", statsHandler.RecordVisit)
|
||||
r.GET("/api/orders", orderHandler.ListMyOrders)
|
||||
r.POST("/api/orders/:id/confirm", orderHandler.ConfirmOrder)
|
||||
|
||||
r.GET("/api/admin/token", adminHandler.GetAdminToken)
|
||||
r.GET("/api/admin/products", adminHandler.ListAllProducts)
|
||||
|
||||
Reference in New Issue
Block a user