39 lines
1.0 KiB
Go
39 lines
1.0 KiB
Go
package routes
|
|
|
|
import (
|
|
"bssapp-backend/auth"
|
|
"bssapp-backend/models"
|
|
"bssapp-backend/queries"
|
|
"encoding/json"
|
|
"net/http"
|
|
)
|
|
|
|
// GET /api/statements
|
|
func GetStatementHeadersHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
|
claims, ok := auth.GetClaimsFromContext(r.Context())
|
|
if !ok || claims == nil {
|
|
http.Error(w, "unauthorized", http.StatusUnauthorized)
|
|
return
|
|
}
|
|
|
|
params := models.StatementParams{
|
|
StartDate: r.URL.Query().Get("startdate"),
|
|
EndDate: r.URL.Query().Get("enddate"),
|
|
AccountCode: r.URL.Query().Get("accountcode"),
|
|
LangCode: r.URL.Query().Get("langcode"),
|
|
Parislemler: r.URL.Query()["parislemler"],
|
|
}
|
|
|
|
statements, err := queries.GetStatements(params)
|
|
if err != nil {
|
|
http.Error(w, "Error fetching statements: "+err.Error(), http.StatusInternalServerError)
|
|
return
|
|
}
|
|
|
|
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
|
if err := json.NewEncoder(w).Encode(statements); err != nil {
|
|
http.Error(w, "Error encoding response: "+err.Error(), http.StatusInternalServerError)
|
|
}
|
|
}
|