Compare commits
No commits in common. "8a11a1d5ea30d3315e51b905d29e8dd9ddc8ec0b" and "e22e8d4e5a22b02decd8aeadbacf9e59db4aa7df" have entirely different histories.
8a11a1d5ea
...
e22e8d4e5a
3 changed files with 7 additions and 70 deletions
23
docs/api.md
23
docs/api.md
|
|
@ -477,29 +477,6 @@ Liste les positions détaillées (par instrument) du compte jour par jour.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
### `GET /snapshots/pending`
|
|
||||||
|
|
||||||
Liste tous les comptes de l'owner ayant une invalidation en attente (i.e. snapshots non à jour suite à une mutation de transaction).
|
|
||||||
|
|
||||||
Utile pour savoir quels comptes doivent être recalculés avant de consulter leurs snapshots, ou pour déclencher un `recompute` ciblé.
|
|
||||||
|
|
||||||
**Réponse `200`** — liste vide si tout est à jour
|
|
||||||
```json
|
|
||||||
[
|
|
||||||
{ "account_id": 1, "recompute_from": "2026-06-10" },
|
|
||||||
{ "account_id": 3, "recompute_from": "2026-05-01" }
|
|
||||||
]
|
|
||||||
```
|
|
||||||
|
|
||||||
| Champ | Description |
|
|
||||||
|---|---|
|
|
||||||
| `account_id` | Identifiant du compte à recalculer |
|
|
||||||
| `recompute_from` | Date la plus ancienne depuis laquelle les snapshots sont invalides |
|
|
||||||
|
|
||||||
> Les invalidations sont insérées automatiquement à chaque create / update / delete / validate de transaction. Le job `daily-snapshot` les consomme toutes les 24h ; cet endpoint permet de les inspecter sans attendre.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
### `POST /accounts/{id}/snapshots/recompute`
|
### `POST /accounts/{id}/snapshots/recompute`
|
||||||
|
|
||||||
Recalcule immédiatement les snapshots d'un compte depuis sa **date d'invalidation** jusqu'à `today + horizon`.
|
Recalcule immédiatement les snapshots d'un compte depuis sa **date d'invalidation** jusqu'à `today + horizon`.
|
||||||
|
|
|
||||||
|
|
@ -14,8 +14,7 @@ type Config struct {
|
||||||
CoinGeckoKey string
|
CoinGeckoKey string
|
||||||
PriceFetchInterval time.Duration
|
PriceFetchInterval time.Duration
|
||||||
PriceCleanInterval time.Duration
|
PriceCleanInterval time.Duration
|
||||||
SnapshotHorizonDays int
|
SnapshotHorizonDays int // nombre de jours dans le futur couverts par les snapshots
|
||||||
CORSAllowedOrigins string // "*" ou liste comma-séparée d'origines
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func Load() *Config {
|
func Load() *Config {
|
||||||
|
|
@ -38,7 +37,6 @@ func Load() *Config {
|
||||||
PriceFetchInterval: fetchInterval,
|
PriceFetchInterval: fetchInterval,
|
||||||
PriceCleanInterval: 24 * time.Hour,
|
PriceCleanInterval: 24 * time.Hour,
|
||||||
SnapshotHorizonDays: horizonDays,
|
SnapshotHorizonDays: horizonDays,
|
||||||
CORSAllowedOrigins: getenv("CORS_ALLOWED_ORIGINS", "*"),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
|
||||||
|
|
||||||
"git.g3e.fr/H6N/account/internal/auth"
|
"git.g3e.fr/H6N/account/internal/auth"
|
||||||
"git.g3e.fr/H6N/account/internal/config"
|
"git.g3e.fr/H6N/account/internal/config"
|
||||||
|
|
@ -34,49 +33,12 @@ func New(cfg *config.Config, pool *pgxpool.Pool, logger *slog.Logger) *Server {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
s.corsMiddleware(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
// /health est exempt d'auth. Toutes les autres routes passent par le middleware owner.
|
||||||
if r.URL.Path == "/health" {
|
if r.URL.Path == "/health" {
|
||||||
s.mux.ServeHTTP(w, r)
|
s.mux.ServeHTTP(w, r)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
auth.Middleware(s.mux).ServeHTTP(w, r)
|
auth.Middleware(s.mux).ServeHTTP(w, r)
|
||||||
})).ServeHTTP(w, r)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *Server) corsMiddleware(next http.Handler) http.Handler {
|
|
||||||
allowedOrigins := strings.Split(s.cfg.CORSAllowedOrigins, ",")
|
|
||||||
wildcard := len(allowedOrigins) == 1 && strings.TrimSpace(allowedOrigins[0]) == "*"
|
|
||||||
|
|
||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
origin := r.Header.Get("Origin")
|
|
||||||
if origin != "" {
|
|
||||||
allowed := wildcard
|
|
||||||
if !allowed {
|
|
||||||
for _, o := range allowedOrigins {
|
|
||||||
if strings.TrimSpace(o) == origin {
|
|
||||||
allowed = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if allowed {
|
|
||||||
if wildcard {
|
|
||||||
w.Header().Set("Access-Control-Allow-Origin", "*")
|
|
||||||
} else {
|
|
||||||
w.Header().Set("Access-Control-Allow-Origin", origin)
|
|
||||||
w.Header().Add("Vary", "Origin")
|
|
||||||
}
|
|
||||||
w.Header().Set("Access-Control-Allow-Methods", "GET, POST, PUT, PATCH, DELETE, OPTIONS")
|
|
||||||
w.Header().Set("Access-Control-Allow-Headers", "Content-Type, X-Owner-ID")
|
|
||||||
w.Header().Set("Access-Control-Max-Age", "86400")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if r.Method == http.MethodOptions {
|
|
||||||
w.WriteHeader(http.StatusNoContent)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
next.ServeHTTP(w, r)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) routes() {
|
func (s *Server) routes() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue