Merge remote-tracking branch 'origin/master'
This commit is contained in:
@@ -14,6 +14,62 @@ import (
|
||||
"github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
func BulkUpdateOrderLineDueDateHandler(mssql *sql.DB) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
|
||||
claims, ok := auth.GetClaimsFromContext(r.Context())
|
||||
if !ok || claims == nil {
|
||||
http.Error(w, "unauthorized", http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
|
||||
user := utils.UserFromClaims(claims)
|
||||
if user == nil {
|
||||
http.Error(w, "Kullanici dogrulanamadi", http.StatusUnauthorized)
|
||||
return
|
||||
}
|
||||
|
||||
orderHeaderID := mux.Vars(r)["id"]
|
||||
if orderHeaderID == "" {
|
||||
http.Error(w, "OrderHeaderID bulunamadi", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
var payload struct {
|
||||
DueDate string `json:"dueDate"`
|
||||
}
|
||||
if err := json.NewDecoder(r.Body).Decode(&payload); err != nil {
|
||||
http.Error(w, "Gecersiz JSON", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
username := user.Username
|
||||
if username == "" {
|
||||
username = user.V3Username
|
||||
}
|
||||
|
||||
updatedLines, headerUpdated, err := queries.BulkUpdateOrderLineDueDate(mssql, orderHeaderID, payload.DueDate, username)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
_ = json.NewEncoder(w).Encode(map[string]any{
|
||||
"code": "ORDER_BULK_DUE_DATE_UPDATE_FAILED",
|
||||
"message": "Siparis satir terminleri guncellenemedi.",
|
||||
"detail": err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
_ = json.NewEncoder(w).Encode(map[string]any{
|
||||
"success": true,
|
||||
"orderHeaderID": orderHeaderID,
|
||||
"dueDate": payload.DueDate,
|
||||
"updatedLines": updatedLines,
|
||||
"headerUpdated": headerUpdated,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// ================================
|
||||
// POST /api/order/update
|
||||
// ================================
|
||||
|
||||
Reference in New Issue
Block a user