add customer name, service info, second pickup location, and structured address fields to deliveries

This commit is contained in:
Egor Pozharov
2026-04-16 20:16:21 +06:00
parent 7f775abf6a
commit ce6ea377ce
16 changed files with 852 additions and 77 deletions

View File

@@ -16,14 +16,23 @@ type Handler struct {
// DeliveryRequest represents the request body for creating or updating a delivery
type DeliveryRequest struct {
Date string `json:"date" binding:"required"` // DD-MM-YYYY
PickupLocation string `json:"pickup_location" binding:"required,oneof=warehouse symbat nursaya galaktika"`
ProductName string `json:"product_name" binding:"required"`
Address string `json:"address" binding:"required"`
Phone string `json:"phone" binding:"required"`
AdditionalPhone string `json:"additional_phone"`
HasElevator bool `json:"has_elevator"`
Comment string `json:"comment"`
Date string `json:"date" binding:"required"` // DD-MM-YYYY
PickupLocation string `json:"pickup_location" binding:"required,oneof=warehouse symbat nursaya galaktika"`
PickupLocation2 *string `json:"pickup_location_2" binding:"omitempty,oneof=warehouse symbat nursaya galaktika"`
ProductName string `json:"product_name" binding:"required"`
ProductName2 *string `json:"product_name_2"`
CustomerName string `json:"customer_name" binding:"required"`
Address string `json:"address" binding:"required"`
Street string `json:"street" binding:"required"`
House string `json:"house" binding:"required"`
Apartment *string `json:"apartment"`
Entrance *string `json:"entrance"`
Floor *string `json:"floor"`
Phone string `json:"phone" binding:"required"`
AdditionalPhone *string `json:"additional_phone"`
HasElevator bool `json:"has_elevator"`
ServiceInfo *string `json:"service_info"`
Comment string `json:"comment"`
}
func NewHandler(queries *sqlc.Queries) *Handler {
@@ -99,11 +108,20 @@ func (h *Handler) CreateDelivery(c *gin.Context) {
params := sqlc.CreateDeliveryParams{
Date: pgtype.Date{Time: t, Valid: true},
PickupLocation: req.PickupLocation,
PickupLocation2: pgtype.Text{String: derefString(req.PickupLocation2), Valid: req.PickupLocation2 != nil},
ProductName: req.ProductName,
ProductName2: pgtype.Text{String: derefString(req.ProductName2), Valid: req.ProductName2 != nil},
CustomerName: req.CustomerName,
Address: req.Address,
Street: req.Street,
House: req.House,
Apartment: pgtype.Text{String: derefString(req.Apartment), Valid: req.Apartment != nil},
Entrance: pgtype.Text{String: derefString(req.Entrance), Valid: req.Entrance != nil},
Floor: pgtype.Text{String: derefString(req.Floor), Valid: req.Floor != nil},
Phone: req.Phone,
AdditionalPhone: pgtype.Text{String: req.AdditionalPhone, Valid: req.AdditionalPhone != ""},
AdditionalPhone: pgtype.Text{String: derefString(req.AdditionalPhone), Valid: req.AdditionalPhone != nil},
HasElevator: req.HasElevator,
ServiceInfo: pgtype.Text{String: derefString(req.ServiceInfo), Valid: req.ServiceInfo != nil},
Comment: pgtype.Text{String: req.Comment, Valid: true},
}
res, err := h.queries.CreateDelivery(c.Request.Context(), params)
@@ -146,11 +164,20 @@ func (h *Handler) UpdateDelivery(c *gin.Context) {
ID: pgtype.UUID{Bytes: parsedID, Valid: true},
Date: pgtype.Date{Time: t, Valid: true},
PickupLocation: req.PickupLocation,
PickupLocation2: pgtype.Text{String: derefString(req.PickupLocation2), Valid: req.PickupLocation2 != nil},
ProductName: req.ProductName,
ProductName2: pgtype.Text{String: derefString(req.ProductName2), Valid: req.ProductName2 != nil},
CustomerName: req.CustomerName,
Address: req.Address,
Street: req.Street,
House: req.House,
Apartment: pgtype.Text{String: derefString(req.Apartment), Valid: req.Apartment != nil},
Entrance: pgtype.Text{String: derefString(req.Entrance), Valid: req.Entrance != nil},
Floor: pgtype.Text{String: derefString(req.Floor), Valid: req.Floor != nil},
Phone: req.Phone,
AdditionalPhone: pgtype.Text{String: req.AdditionalPhone, Valid: req.AdditionalPhone != ""},
AdditionalPhone: pgtype.Text{String: derefString(req.AdditionalPhone), Valid: req.AdditionalPhone != nil},
HasElevator: req.HasElevator,
ServiceInfo: pgtype.Text{String: derefString(req.ServiceInfo), Valid: req.ServiceInfo != nil},
Comment: pgtype.Text{String: req.Comment, Valid: true},
}); err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": "Failed to update delivery", "details": err.Error()})
@@ -231,3 +258,11 @@ func parseDate(dateStr string) (time.Time, error) {
}
return t, nil
}
// derefString safely dereferences a string pointer
func derefString(s *string) string {
if s == nil {
return ""
}
return *s
}