feat: add updated_at to modpacks and /api/launcher/modpacks/summary endpoint

This commit is contained in:
2026-01-04 14:38:21 +03:00
parent e98d10ae1d
commit 275c1f2d50
4 changed files with 45 additions and 0 deletions

View File

@@ -75,6 +75,7 @@ func main() {
r.Route("/launcher", func(r chi.Router) {
r.Get("/modpacks/{name}/manifest", launcherHandler.GetModpackManifest)
r.Get("/modpacks/summary", launcherHandler.GetModpacksSummary)
})
})
r.Route("/authserver", func(r chi.Router) {

View File

@@ -35,3 +35,15 @@ func (h *LauncherHandler) GetModpackManifest(w http.ResponseWriter, r *http.Requ
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(manifest)
}
func (h *LauncherHandler) GetModpacksSummary(w http.ResponseWriter, r *http.Request) {
summaries, err := h.ModpackRepo.GetModpacksSummary(r.Context())
if err != nil {
http.Error(w, "Failed to get modpacks summary", http.StatusInternalServerError)
return
}
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(summaries)
}

View File

@@ -101,3 +101,28 @@ func (r *ModpackRepository) GetAllFileHashes(ctx context.Context) (map[string]st
return hashes, rows.Err()
}
// GetModpacksSummary возвращает список всех активных модпаков с датой последнего обновления.
func (r *ModpackRepository) GetModpacksSummary(ctx context.Context) ([]models.ModpackSummary, error) {
query := `
SELECT name, updated_at
FROM modpacks
WHERE is_active = TRUE`
rows, err := r.DB.Query(ctx, query)
if err != nil {
return nil, err
}
defer rows.Close()
var summaries []models.ModpackSummary
for rows.Next() {
var s models.ModpackSummary
if err := rows.Scan(&s.Name, &s.UpdatedAt); err != nil {
return nil, err
}
summaries = append(summaries, s)
}
return summaries, nil
}

View File

@@ -10,6 +10,13 @@ type Modpack struct {
MinecraftVersion string `json:"minecraft_version"`
IsActive bool `json:"is_active"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
// ModpackSummary используется лаунчером для проверки наличия обновлений
type ModpackSummary struct {
Name string `json:"name"`
UpdatedAt time.Time `json:"updated_at"`
}
// ModpackFile представляет метаданные одного файла в модпаке