ci: add Gitea Actions workflows and placeholder tests
Some checks failed
CI / ci (push) Failing after 47s

This commit is contained in:
Cosmo
2026-03-01 00:05:08 +00:00
parent 2a50e50771
commit b91e67ac1d
6 changed files with 240 additions and 0 deletions

View File

@@ -0,0 +1,58 @@
package handler
import (
"encoding/json"
"net/http"
"os"
"github.com/go-chi/chi/v5"
"github.com/jmoiron/sqlx"
"github.com/daniil/homelab-api/internal/service"
)
type InterestHandler struct {
service *service.InterestService
secretKey string
}
func NewInterestHandler(db *sqlx.DB) *InterestHandler {
secretKey := os.Getenv("INTERNAL_API_KEY")
if secretKey == "" {
secretKey = "pulse-internal-2026"
}
return &InterestHandler{
service: service.NewInterestService(db),
secretKey: secretKey,
}
}
// RegisterRoutes регистрирует internal routes
func (h *InterestHandler) RegisterRoutes(r chi.Router) {
r.Post("/internal/calculate-interest", h.CalculateInterest)
}
// CalculateInterest запускает расчёт процентов для всех вкладов
// POST /internal/calculate-interest
// Header: X-Internal-Key: <secret>
func (h *InterestHandler) CalculateInterest(w http.ResponseWriter, r *http.Request) {
// Verify internal API key
key := r.Header.Get("X-Internal-Key")
if key != h.secretKey {
http.Error(w, "Unauthorized", http.StatusUnauthorized)
return
}
results, err := h.service.CalculateAllDepositsInterest()
if err != nil {
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(map[string]string{"error": err.Error()})
return
}
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(map[string]interface{}{
"message": "Interest calculation completed",
"results": results,
})
}