ui: update ProductPerformanceProfitability page to enhance table views and tabs management

This commit is contained in:
M_Kececi
2026-07-02 20:07:14 +03:00
parent 2fc9699ff1
commit 8d0f3c302a
4 changed files with 15 additions and 287 deletions
-55
View File
@@ -240,49 +240,6 @@ func GetProductPerformanceCustomersHandler(pg *sql.DB) http.HandlerFunc {
}
}
type productPerformanceRefreshPayload struct {
Mode string `json:"mode"`
Stage string `json:"stage"`
ResumeAfter int `json:"resume_after"`
SkipDelete bool `json:"skip_delete"`
ProductPrefix string `json:"product_prefix"`
StartDate string `json:"start_date"`
EndDate string `json:"end_date"`
}
func PostProductPerformanceRefreshHandler(pg *sql.DB) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json; charset=utf-8")
var payload productPerformanceRefreshPayload
if err := json.NewDecoder(r.Body).Decode(&payload); err != nil {
http.Error(w, "invalid payload", http.StatusBadRequest)
return
}
now := time.Now()
startDate := parseDateOrZero(payload.StartDate)
endDate := parseDateOrZero(payload.EndDate)
if endDate.IsZero() {
endDate = now
}
ctx, cancel := context.WithTimeout(r.Context(), 4*time.Hour)
defer cancel()
result, err := queries.RefreshProductPerformance(ctx, pg, queries.ProductPerformanceRefreshRequest{
Mode: payload.Mode,
Stage: payload.Stage,
ResumeAfter: payload.ResumeAfter,
SkipDelete: payload.SkipDelete,
ProductPrefix: payload.ProductPrefix,
StartDate: startDate,
EndDate: endDate,
})
if err != nil {
http.Error(w, "urun performans refresh hatasi: "+err.Error(), http.StatusInternalServerError)
return
}
_ = json.NewEncoder(w).Encode(result)
}
}
func intQuery(r *http.Request, key string, fallback int) int {
raw := strings.TrimSpace(r.URL.Query().Get(key))
if raw == "" {
@@ -302,15 +259,3 @@ func boolQuery(r *http.Request, key string, fallback bool) bool {
}
return raw == "1" || raw == "true" || raw == "yes" || raw == "on"
}
func parseDateOrZero(raw string) time.Time {
raw = strings.TrimSpace(raw)
if raw == "" {
return time.Time{}
}
t, err := time.Parse("2006-01-02", raw)
if err != nil {
return time.Time{}
}
return t
}