feat: add updated_at to modpacks and /api/launcher/modpacks/summary endpoint
This commit is contained in:
@@ -75,6 +75,7 @@ func main() {
|
|||||||
|
|
||||||
r.Route("/launcher", func(r chi.Router) {
|
r.Route("/launcher", func(r chi.Router) {
|
||||||
r.Get("/modpacks/{name}/manifest", launcherHandler.GetModpackManifest)
|
r.Get("/modpacks/{name}/manifest", launcherHandler.GetModpackManifest)
|
||||||
|
r.Get("/modpacks/summary", launcherHandler.GetModpacksSummary)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
r.Route("/authserver", func(r chi.Router) {
|
r.Route("/authserver", func(r chi.Router) {
|
||||||
|
|||||||
@@ -35,3 +35,15 @@ func (h *LauncherHandler) GetModpackManifest(w http.ResponseWriter, r *http.Requ
|
|||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
json.NewEncoder(w).Encode(manifest)
|
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)
|
||||||
|
}
|
||||||
|
|||||||
@@ -101,3 +101,28 @@ func (r *ModpackRepository) GetAllFileHashes(ctx context.Context) (map[string]st
|
|||||||
|
|
||||||
return hashes, rows.Err()
|
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
|
||||||
|
}
|
||||||
|
|||||||
@@ -10,6 +10,13 @@ type Modpack struct {
|
|||||||
MinecraftVersion string `json:"minecraft_version"`
|
MinecraftVersion string `json:"minecraft_version"`
|
||||||
IsActive bool `json:"is_active"`
|
IsActive bool `json:"is_active"`
|
||||||
CreatedAt time.Time `json:"created_at"`
|
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 представляет метаданные одного файла в модпаке
|
// ModpackFile представляет метаданные одного файла в модпаке
|
||||||
|
|||||||
Reference in New Issue
Block a user