28 lines
627 B
Go
28 lines
627 B
Go
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)
|
||
}
|