Complete API handlers refactoring to eliminate type switching and use repository pattern consistently
This commit is contained in:
38
cmd/serve.go
38
cmd/serve.go
@@ -16,6 +16,7 @@ import (
|
||||
|
||||
"github.com/insertr/insertr/internal/api"
|
||||
"github.com/insertr/insertr/internal/auth"
|
||||
"github.com/insertr/insertr/internal/config"
|
||||
"github.com/insertr/insertr/internal/content"
|
||||
"github.com/insertr/insertr/internal/db"
|
||||
"github.com/insertr/insertr/internal/engine"
|
||||
@@ -109,9 +110,9 @@ func runServe(cmd *cobra.Command, args []string) {
|
||||
siteManager := content.NewSiteManagerWithAuth(contentClient, cfg.Auth.DevMode, authProvider)
|
||||
|
||||
// Convert config sites to legacy format and register
|
||||
var legacySites []*content.SiteConfig
|
||||
var legacySites []*config.SiteConfig
|
||||
for _, site := range cfg.Server.Sites {
|
||||
legacySite := &content.SiteConfig{
|
||||
legacySite := &config.SiteConfig{
|
||||
SiteID: site.SiteID,
|
||||
Path: site.Path,
|
||||
SourcePath: site.SourcePath,
|
||||
@@ -173,24 +174,25 @@ func runServe(cmd *cobra.Command, args []string) {
|
||||
r.Get("/callback", authService.HandleOAuthCallback)
|
||||
})
|
||||
|
||||
// Content API routes
|
||||
router.Route("/api", func(r chi.Router) {
|
||||
// Public routes
|
||||
r.Get("/content/{siteID}/{id}", contentHandler.GetContent)
|
||||
r.Get("/content/{siteID}", contentHandler.GetAllContent)
|
||||
// Register all Content API routes
|
||||
contentHandler.RegisterRoutes(router)
|
||||
|
||||
// Protected routes (require authentication)
|
||||
r.Group(func(r chi.Router) {
|
||||
r.Use(authService.RequireAuth)
|
||||
r.Post("/content/{siteID}", contentHandler.CreateContent)
|
||||
r.Put("/content/{siteID}/{id}", contentHandler.UpdateContent)
|
||||
r.Delete("/content/{siteID}/{id}", contentHandler.DeleteContent)
|
||||
|
||||
// Version management
|
||||
r.Get("/content/{siteID}/{id}/versions", contentHandler.GetContentVersions)
|
||||
r.Post("/content/{siteID}/{id}/rollback/{version}", contentHandler.RollbackContent)
|
||||
// Serve insertr library assets (development only)
|
||||
if cfg.Auth.DevMode {
|
||||
router.Get("/insertr.js", func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/javascript")
|
||||
http.ServeFile(w, r, "./lib/dist/insertr.js")
|
||||
})
|
||||
})
|
||||
router.Get("/insertr.min.js", func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/javascript")
|
||||
http.ServeFile(w, r, "./lib/dist/insertr.min.js")
|
||||
})
|
||||
router.Get("/insertr.css", func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "text/css")
|
||||
http.ServeFile(w, r, "./lib/dist/insertr.css")
|
||||
})
|
||||
log.Printf("📦 Serving insertr library assets from ./lib/dist/ (dev mode)")
|
||||
}
|
||||
|
||||
// Serve static sites
|
||||
for _, siteConfig := range siteManager.GetAllSites() {
|
||||
|
||||
Reference in New Issue
Block a user