relynolli-server/handlers/catalog/routes.go

37 lines
1.1 KiB
Go
Raw Permalink Normal View History

2024-03-15 21:27:45 +03:00
package catalog
import (
2024-03-23 21:16:41 +03:00
"os"
2024-03-15 21:27:45 +03:00
"relynolli-server/handlers/catalog/endpoints"
2024-03-21 23:44:50 +03:00
"relynolli-server/internal"
"time"
2024-03-26 02:21:35 +03:00
"github.com/gin-contrib/cache"
2024-03-23 21:16:41 +03:00
// "relynolli-server/internal"
// "time"
// "github.com/gin-contrib/cache"
2024-03-21 23:44:50 +03:00
"github.com/gin-gonic/gin"
2024-03-15 21:27:45 +03:00
)
func HandleRoutes(parent *gin.RouterGroup) {
h := endpoints.GetHandlers()
2024-03-21 23:44:50 +03:00
cacheStore := internal.InitCacheStore()
2024-03-15 21:27:45 +03:00
catalog := parent.Group("/catalog")
2024-03-23 21:16:41 +03:00
if os.Getenv("IS_PROD") == "1" {
// Caching for production usage
catalog.GET("", cache.CachePage(cacheStore, 15*time.Minute, h.GetCatalogItems))
2024-03-23 21:17:59 +03:00
catalog.GET("/filters", cache.CachePage(cacheStore, 15*time.Minute, h.GetFilters))
2024-03-26 02:21:35 +03:00
catalog.GET("/:code", cache.CachePage(cacheStore, 15*time.Minute, h.GetCatalogItem))
2024-05-03 11:57:53 +03:00
} else {
catalog.GET("", h.GetCatalogItems)
catalog.GET("/:code", h.GetCatalogItem)
catalog.GET("/filters", h.GetFilters)
2024-03-23 21:16:41 +03:00
}
// catalog.GET("/filters", cache.CachePage(cacheStore, 15, h.GetFilters))
// catalog.GET("/count", cache.CachePage(cacheStore, 15 * time.Minute, h.Count))
// catalog.GET("/:code", cache.CachePage(cacheStore, 15 * time.Minute, h.GetCatalogItem))
2024-03-15 21:27:45 +03:00
}