mirror of
https://github.com/Dvorinka/MyClubServer.git
synced 2026-06-04 18:52:56 +00:00
dev day #67
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"fotbal-club/internal/services"
|
||||
"fotbal-club/pkg/logger"
|
||||
"net/http"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -245,9 +246,31 @@ func (ac *ArticleController) CreateArticle(c *gin.Context) {
|
||||
// 17. Reload with associations for response
|
||||
ac.DB.Preload("Author").Preload("Category").First(&article, article.ID)
|
||||
|
||||
// 18. Return success response
|
||||
// 18. Trigger prefetch cache update (async)
|
||||
if published {
|
||||
go func() {
|
||||
base := getBaseURL()
|
||||
logger.Info("CreateArticle: Triggering prefetch cache update for published article")
|
||||
services.PrefetchOnce(base)
|
||||
}()
|
||||
}
|
||||
|
||||
// 19. Return success response
|
||||
c.JSON(http.StatusCreated, article)
|
||||
}
|
||||
|
||||
// getBaseURL returns the base URL for internal API calls (used for prefetch trigger)
|
||||
func getBaseURL() string {
|
||||
base := strings.TrimSpace(os.Getenv("PREFETCH_TARGET"))
|
||||
if base == "" {
|
||||
port := strings.TrimSpace(os.Getenv("PORT"))
|
||||
if port == "" {
|
||||
port = "8080"
|
||||
}
|
||||
base = "http://127.0.0.1:" + port + "/api/v1"
|
||||
}
|
||||
return base
|
||||
}
|
||||
|
||||
// Note: Helper functions makeSlug, computeEstimatedReadMinutes, and deriveSeoDescription
|
||||
// are defined in base_controller.go and shared across the controllers package
|
||||
|
||||
Reference in New Issue
Block a user