39 lines
1.1 KiB
Go
39 lines
1.1 KiB
Go
package routes
|
|
|
|
import (
|
|
"bssapp-backend/auth"
|
|
"bssapp-backend/queries"
|
|
"encoding/json"
|
|
"net/http"
|
|
|
|
"github.com/gorilla/mux"
|
|
)
|
|
|
|
// GET /api/statements/{accountCode}/details?startdate=...&enddate=...&parislemler=1&parislemler=2
|
|
func GetStatementDetailsHandler(w http.ResponseWriter, r *http.Request) {
|
|
|
|
claims, ok := auth.GetClaimsFromContext(r.Context())
|
|
if !ok || claims == nil {
|
|
http.Error(w, "unauthorized", http.StatusUnauthorized)
|
|
return
|
|
}
|
|
|
|
vars := mux.Vars(r)
|
|
accountCode := vars["accountCode"]
|
|
|
|
startDate := r.URL.Query().Get("startdate")
|
|
endDate := r.URL.Query().Get("enddate")
|
|
parislemler := r.URL.Query()["parislemler"]
|
|
|
|
details, err := queries.GetStatementDetails(accountCode, startDate, endDate, parislemler)
|
|
if err != nil {
|
|
http.Error(w, "Error fetching statement details: "+err.Error(), http.StatusInternalServerError)
|
|
return
|
|
}
|
|
|
|
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
|
if err := json.NewEncoder(w).Encode(details); err != nil {
|
|
http.Error(w, "Error encoding response: "+err.Error(), http.StatusInternalServerError)
|
|
}
|
|
}
|