Files
bssapp/svc/routes/product.go
2026-02-11 17:46:22 +03:00

28 lines
627 B
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package routes
import (
"bssapp-backend/auth"
"bssapp-backend/queries"
"encoding/json"
"net/http"
)
// ✅ GET /api/products
func GetProductListHandler(w http.ResponseWriter, r *http.Request) {
claims, ok := auth.GetClaimsFromContext(r.Context())
if !ok || claims == nil {
http.Error(w, "unauthorized", http.StatusUnauthorized)
return
}
products, err := queries.GetProductList()
if err != nil {
http.Error(w, "Ürün listesi alınamadı: "+err.Error(), http.StatusInternalServerError)
return
}
w.Header().Set("Content-Type", "application/json; charset=utf-8")
_ = json.NewEncoder(w).Encode(products)
}