[ci skip] more suggested improvements
This commit is contained in:
@@ -2,9 +2,9 @@ package handler
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"vctp/internal/report"
|
||||
"vctp/server/models"
|
||||
)
|
||||
|
||||
// SnapshotMigrate rebuilds the snapshot registry and normalizes hourly table names.
|
||||
@@ -19,20 +19,28 @@ func (h *Handler) SnapshotMigrate(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := context.Background()
|
||||
stats, err := report.MigrateSnapshotRegistry(ctx, h.Database)
|
||||
if err != nil {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
json.NewEncoder(w).Encode(map[string]interface{}{
|
||||
"status": "ERROR",
|
||||
"error": err.Error(),
|
||||
"stats": stats,
|
||||
writeJSON(w, http.StatusInternalServerError, models.SnapshotMigrationResponse{
|
||||
Status: "ERROR",
|
||||
Error: err.Error(),
|
||||
Stats: models.SnapshotMigrationStats{
|
||||
HourlyRenamed: stats.HourlyRenamed,
|
||||
HourlyRegistered: stats.HourlyRegistered,
|
||||
DailyRegistered: stats.DailyRegistered,
|
||||
MonthlyRegistered: stats.MonthlyRegistered,
|
||||
Errors: stats.Errors,
|
||||
},
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
json.NewEncoder(w).Encode(map[string]interface{}{
|
||||
"status": "OK",
|
||||
"stats": stats,
|
||||
writeJSON(w, http.StatusOK, models.SnapshotMigrationResponse{
|
||||
Status: "OK",
|
||||
Stats: models.SnapshotMigrationStats{
|
||||
HourlyRenamed: stats.HourlyRenamed,
|
||||
HourlyRegistered: stats.HourlyRegistered,
|
||||
DailyRegistered: stats.DailyRegistered,
|
||||
MonthlyRegistered: stats.MonthlyRegistered,
|
||||
Errors: stats.Errors,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user