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

@@ -0,0 +1,10 @@
-- Revert new fields for delivery improvements
ALTER TABLE deliveries DROP COLUMN IF EXISTS customer_name;
ALTER TABLE deliveries DROP COLUMN IF EXISTS service_info;
ALTER TABLE deliveries DROP COLUMN IF EXISTS pickup_location_2;
ALTER TABLE deliveries DROP COLUMN IF EXISTS product_name_2;
ALTER TABLE deliveries DROP COLUMN IF EXISTS street;
ALTER TABLE deliveries DROP COLUMN IF EXISTS house;
ALTER TABLE deliveries DROP COLUMN IF EXISTS apartment;
ALTER TABLE deliveries DROP COLUMN IF EXISTS entrance;
ALTER TABLE deliveries DROP COLUMN IF EXISTS floor;

View File

@@ -0,0 +1,18 @@
-- Add new fields for delivery improvements
-- Client information
ALTER TABLE deliveries ADD COLUMN customer_name text NOT NULL DEFAULT '';
-- Services (assembly, lifting, etc.)
ALTER TABLE deliveries ADD COLUMN service_info text;
-- Second pickup location
ALTER TABLE deliveries ADD COLUMN pickup_location_2 varchar(20);
ALTER TABLE deliveries ADD COLUMN product_name_2 text;
-- Structured address components
ALTER TABLE deliveries ADD COLUMN street text NOT NULL DEFAULT '';
ALTER TABLE deliveries ADD COLUMN house text NOT NULL DEFAULT '';
ALTER TABLE deliveries ADD COLUMN apartment text;
ALTER TABLE deliveries ADD COLUMN entrance text;
ALTER TABLE deliveries ADD COLUMN floor text;

View File

@@ -10,8 +10,12 @@ SELECT * FROM users WHERE username = $1;
SELECT * FROM deliveries WHERE date = $1;
-- name: CreateDelivery :one
INSERT INTO deliveries (date, pickup_location, product_name, address, phone, additional_phone, has_elevator, comment)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
INSERT INTO deliveries (
date, pickup_location, pickup_location_2, product_name, product_name_2,
customer_name, address, street, house, apartment, entrance, floor,
phone, additional_phone, has_elevator, service_info, comment
)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17)
RETURNING *;
-- name: GetDeliveryByID :one
@@ -21,7 +25,26 @@ SELECT * FROM deliveries WHERE id = $1;
DELETE FROM deliveries WHERE id = $1;
-- name: UpdateDelivery :exec
UPDATE deliveries SET date = $1, pickup_location = $2, product_name = $3, address = $4, phone = $5, additional_phone = $6, has_elevator = $7, comment = $8, updated_at = NOW() WHERE id = $9;
UPDATE deliveries SET
date = $1,
pickup_location = $2,
pickup_location_2 = $3,
product_name = $4,
product_name_2 = $5,
customer_name = $6,
address = $7,
street = $8,
house = $9,
apartment = $10,
entrance = $11,
floor = $12,
phone = $13,
additional_phone = $14,
has_elevator = $15,
service_info = $16,
comment = $17,
updated_at = NOW()
WHERE id = $18;
-- name: GetDeliveryCount :many
SELECT COUNT(*) as count, date FROM deliveries

View File

@@ -21,6 +21,15 @@ type Delivery struct {
Status string `db:"status" json:"status"`
CreatedAt pgtype.Timestamptz `db:"created_at" json:"created_at"`
UpdatedAt pgtype.Timestamptz `db:"updated_at" json:"updated_at"`
CustomerName string `db:"customer_name" json:"customer_name"`
ServiceInfo pgtype.Text `db:"service_info" json:"service_info"`
PickupLocation2 pgtype.Text `db:"pickup_location_2" json:"pickup_location_2"`
ProductName2 pgtype.Text `db:"product_name_2" json:"product_name_2"`
Street string `db:"street" json:"street"`
House string `db:"house" json:"house"`
Apartment pgtype.Text `db:"apartment" json:"apartment"`
Entrance pgtype.Text `db:"entrance" json:"entrance"`
Floor pgtype.Text `db:"floor" json:"floor"`
}
type User struct {

View File

@@ -12,19 +12,32 @@ import (
)
const createDelivery = `-- name: CreateDelivery :one
INSERT INTO deliveries (date, pickup_location, product_name, address, phone, additional_phone, has_elevator, comment)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
RETURNING id, date, pickup_location, product_name, address, phone, additional_phone, has_elevator, comment, status, created_at, updated_at
INSERT INTO deliveries (
date, pickup_location, pickup_location_2, product_name, product_name_2,
customer_name, address, street, house, apartment, entrance, floor,
phone, additional_phone, has_elevator, service_info, comment
)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16, $17)
RETURNING id, date, pickup_location, product_name, address, phone, additional_phone, has_elevator, comment, status, created_at, updated_at, customer_name, service_info, pickup_location_2, product_name_2, street, house, apartment, entrance, floor
`
type CreateDeliveryParams struct {
Date pgtype.Date `db:"date" json:"date"`
PickupLocation string `db:"pickup_location" json:"pickup_location"`
PickupLocation2 pgtype.Text `db:"pickup_location_2" json:"pickup_location_2"`
ProductName string `db:"product_name" json:"product_name"`
ProductName2 pgtype.Text `db:"product_name_2" json:"product_name_2"`
CustomerName string `db:"customer_name" json:"customer_name"`
Address string `db:"address" json:"address"`
Street string `db:"street" json:"street"`
House string `db:"house" json:"house"`
Apartment pgtype.Text `db:"apartment" json:"apartment"`
Entrance pgtype.Text `db:"entrance" json:"entrance"`
Floor pgtype.Text `db:"floor" json:"floor"`
Phone string `db:"phone" json:"phone"`
AdditionalPhone pgtype.Text `db:"additional_phone" json:"additional_phone"`
HasElevator bool `db:"has_elevator" json:"has_elevator"`
ServiceInfo pgtype.Text `db:"service_info" json:"service_info"`
Comment pgtype.Text `db:"comment" json:"comment"`
}
@@ -32,11 +45,20 @@ func (q *Queries) CreateDelivery(ctx context.Context, arg CreateDeliveryParams)
row := q.db.QueryRow(ctx, createDelivery,
arg.Date,
arg.PickupLocation,
arg.PickupLocation2,
arg.ProductName,
arg.ProductName2,
arg.CustomerName,
arg.Address,
arg.Street,
arg.House,
arg.Apartment,
arg.Entrance,
arg.Floor,
arg.Phone,
arg.AdditionalPhone,
arg.HasElevator,
arg.ServiceInfo,
arg.Comment,
)
var i Delivery
@@ -53,6 +75,15 @@ func (q *Queries) CreateDelivery(ctx context.Context, arg CreateDeliveryParams)
&i.Status,
&i.CreatedAt,
&i.UpdatedAt,
&i.CustomerName,
&i.ServiceInfo,
&i.PickupLocation2,
&i.ProductName2,
&i.Street,
&i.House,
&i.Apartment,
&i.Entrance,
&i.Floor,
)
return i, err
}
@@ -90,7 +121,7 @@ func (q *Queries) DeleteDelivery(ctx context.Context, id pgtype.UUID) error {
}
const getDeliveriesByDate = `-- name: GetDeliveriesByDate :many
SELECT id, date, pickup_location, product_name, address, phone, additional_phone, has_elevator, comment, status, created_at, updated_at FROM deliveries WHERE date = $1
SELECT id, date, pickup_location, product_name, address, phone, additional_phone, has_elevator, comment, status, created_at, updated_at, customer_name, service_info, pickup_location_2, product_name_2, street, house, apartment, entrance, floor FROM deliveries WHERE date = $1
`
func (q *Queries) GetDeliveriesByDate(ctx context.Context, date pgtype.Date) ([]Delivery, error) {
@@ -115,6 +146,15 @@ func (q *Queries) GetDeliveriesByDate(ctx context.Context, date pgtype.Date) ([]
&i.Status,
&i.CreatedAt,
&i.UpdatedAt,
&i.CustomerName,
&i.ServiceInfo,
&i.PickupLocation2,
&i.ProductName2,
&i.Street,
&i.House,
&i.Apartment,
&i.Entrance,
&i.Floor,
); err != nil {
return nil, err
}
@@ -127,7 +167,7 @@ func (q *Queries) GetDeliveriesByDate(ctx context.Context, date pgtype.Date) ([]
}
const getDeliveryByID = `-- name: GetDeliveryByID :one
SELECT id, date, pickup_location, product_name, address, phone, additional_phone, has_elevator, comment, status, created_at, updated_at FROM deliveries WHERE id = $1
SELECT id, date, pickup_location, product_name, address, phone, additional_phone, has_elevator, comment, status, created_at, updated_at, customer_name, service_info, pickup_location_2, product_name_2, street, house, apartment, entrance, floor FROM deliveries WHERE id = $1
`
func (q *Queries) GetDeliveryByID(ctx context.Context, id pgtype.UUID) (Delivery, error) {
@@ -146,6 +186,15 @@ func (q *Queries) GetDeliveryByID(ctx context.Context, id pgtype.UUID) (Delivery
&i.Status,
&i.CreatedAt,
&i.UpdatedAt,
&i.CustomerName,
&i.ServiceInfo,
&i.PickupLocation2,
&i.ProductName2,
&i.Street,
&i.House,
&i.Apartment,
&i.Entrance,
&i.Floor,
)
return i, err
}
@@ -198,17 +247,45 @@ func (q *Queries) GetUserByUsername(ctx context.Context, username string) (User,
}
const updateDelivery = `-- name: UpdateDelivery :exec
UPDATE deliveries SET date = $1, pickup_location = $2, product_name = $3, address = $4, phone = $5, additional_phone = $6, has_elevator = $7, comment = $8, updated_at = NOW() WHERE id = $9
UPDATE deliveries SET
date = $1,
pickup_location = $2,
pickup_location_2 = $3,
product_name = $4,
product_name_2 = $5,
customer_name = $6,
address = $7,
street = $8,
house = $9,
apartment = $10,
entrance = $11,
floor = $12,
phone = $13,
additional_phone = $14,
has_elevator = $15,
service_info = $16,
comment = $17,
updated_at = NOW()
WHERE id = $18
`
type UpdateDeliveryParams struct {
Date pgtype.Date `db:"date" json:"date"`
PickupLocation string `db:"pickup_location" json:"pickup_location"`
PickupLocation2 pgtype.Text `db:"pickup_location_2" json:"pickup_location_2"`
ProductName string `db:"product_name" json:"product_name"`
ProductName2 pgtype.Text `db:"product_name_2" json:"product_name_2"`
CustomerName string `db:"customer_name" json:"customer_name"`
Address string `db:"address" json:"address"`
Street string `db:"street" json:"street"`
House string `db:"house" json:"house"`
Apartment pgtype.Text `db:"apartment" json:"apartment"`
Entrance pgtype.Text `db:"entrance" json:"entrance"`
Floor pgtype.Text `db:"floor" json:"floor"`
Phone string `db:"phone" json:"phone"`
AdditionalPhone pgtype.Text `db:"additional_phone" json:"additional_phone"`
HasElevator bool `db:"has_elevator" json:"has_elevator"`
ServiceInfo pgtype.Text `db:"service_info" json:"service_info"`
Comment pgtype.Text `db:"comment" json:"comment"`
ID pgtype.UUID `db:"id" json:"id"`
}
@@ -217,11 +294,20 @@ func (q *Queries) UpdateDelivery(ctx context.Context, arg UpdateDeliveryParams)
_, err := q.db.Exec(ctx, updateDelivery,
arg.Date,
arg.PickupLocation,
arg.PickupLocation2,
arg.ProductName,
arg.ProductName2,
arg.CustomerName,
arg.Address,
arg.Street,
arg.House,
arg.Apartment,
arg.Entrance,
arg.Floor,
arg.Phone,
arg.AdditionalPhone,
arg.HasElevator,
arg.ServiceInfo,
arg.Comment,
arg.ID,
)