Merge remote-tracking branch 'origin/master'

This commit is contained in:
M_Kececi
2026-04-03 14:16:05 +03:00
parent 67ef80936a
commit e1064010f3
6 changed files with 133 additions and 9 deletions

View File

@@ -603,6 +603,11 @@ func InitRoutes(pgDB *sql.DB, mssql *sql.DB, ml *mailer.GraphMailer) *mux.Router
"order", "view",
wrapV3(http.HandlerFunc(routes.GetProductAttributesHandler)),
)
bindV3(r, pgDB,
"/api/product-item-attributes", "GET",
"order", "view",
wrapV3(http.HandlerFunc(routes.GetProductItemAttributesHandler)),
)
bindV3(r, pgDB,
"/api/product-stock-query", "GET",
"order", "view",

View File

@@ -7,3 +7,9 @@ type ProductAttributeOption struct {
AttributeCode string `json:"attribute_code"`
AttributeDescription string `json:"attribute_description"`
}
type ProductItemAttributeValue struct {
ItemTypeCode int16 `json:"item_type_code"`
AttributeTypeCode int `json:"attribute_type_code"`
AttributeCode string `json:"attribute_code"`
}

View File

@@ -47,3 +47,13 @@ ORDER BY
CASE WHEN a.AttributeCode IN ('-', '.') THEN 0 ELSE 1 END,
a.AttributeCode;
`
const GetProductItemAttributes = `
SELECT
a.ItemTypeCode,
a.AttributeTypeCode,
ISNULL(a.AttributeCode, '') AS AttributeCode
FROM dbo.prItemAttribute AS a WITH(NOLOCK)
WHERE a.ItemTypeCode = @p1
AND ISNULL(LTRIM(RTRIM(a.ItemCode)), '') = ISNULL(LTRIM(RTRIM(@p2)), '')
`

View File

@@ -52,3 +52,50 @@ func GetProductAttributesHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json; charset=utf-8")
_ = json.NewEncoder(w).Encode(list)
}
func GetProductItemAttributesHandler(w http.ResponseWriter, r *http.Request) {
claims, ok := auth.GetClaimsFromContext(r.Context())
if !ok || claims == nil {
http.Error(w, "unauthorized", http.StatusUnauthorized)
return
}
itemTypeCode := int16(1)
if raw := r.URL.Query().Get("itemTypeCode"); raw != "" {
v, err := strconv.Atoi(raw)
if err != nil || v <= 0 {
http.Error(w, "itemTypeCode gecersiz", http.StatusBadRequest)
return
}
itemTypeCode = int16(v)
}
itemCode := r.URL.Query().Get("itemCode")
if itemCode == "" {
http.Error(w, "itemCode zorunlu", http.StatusBadRequest)
return
}
rows, err := db.MssqlDB.Query(queries.GetProductItemAttributes, itemTypeCode, itemCode)
if err != nil {
http.Error(w, "Product item attributes alinamadi: "+err.Error(), http.StatusInternalServerError)
return
}
defer rows.Close()
list := make([]models.ProductItemAttributeValue, 0, 64)
for rows.Next() {
var x models.ProductItemAttributeValue
if err := rows.Scan(
&x.ItemTypeCode,
&x.AttributeTypeCode,
&x.AttributeCode,
); err != nil {
continue
}
list = append(list, x)
}
w.Header().Set("Content-Type", "application/json; charset=utf-8")
_ = json.NewEncoder(w).Encode(list)
}