69 lines
1.8 KiB
Go
69 lines
1.8 KiB
Go
package ordersRepo
|
|
|
|
import (
|
|
"git.ma-al.com/goc_daniel/b2b/app/db"
|
|
"git.ma-al.com/goc_daniel/b2b/app/model"
|
|
"git.ma-al.com/goc_daniel/b2b/app/utils/query/filters"
|
|
"git.ma-al.com/goc_daniel/b2b/app/utils/query/find"
|
|
)
|
|
|
|
type UIOrdersRepo interface {
|
|
Find(user_id uint, p find.Paging, filt *filters.FiltersList) (find.Found[model.CustomerOrder], error)
|
|
PlaceNewOrder(user_id uint, cart_id uint, country_id uint, address_info string) error
|
|
ChangeOrderAddress(user_id uint, order_id uint, country_id uint, address_info string) error
|
|
ChangeOrderStatus(user_id uint, order_id uint, status string) error
|
|
}
|
|
|
|
type OrdersRepo struct{}
|
|
|
|
func New() UIOrdersRepo {
|
|
return &OrdersRepo{}
|
|
}
|
|
|
|
func (repo *OrdersRepo) Find(user_id uint, p find.Paging, filt *filters.FiltersList) (find.Found[model.CustomerOrder], error) {
|
|
var list []model.CustomerOrder
|
|
var total int64
|
|
|
|
query := db.Get().
|
|
Model(&model.CustomerOrder{}).
|
|
Preload("Products").
|
|
Order("b2b_customer_orders.id DESC")
|
|
|
|
// Apply all filters
|
|
if filt != nil {
|
|
filt.ApplyAll(query)
|
|
}
|
|
|
|
// run counter first as query is without limit and offset
|
|
err := query.Count(&total).Error
|
|
if err != nil {
|
|
return find.Found[model.CustomerOrder]{}, err
|
|
}
|
|
|
|
err = query.
|
|
Limit(p.Limit()).
|
|
Offset(p.Offset()).
|
|
Find(&list).Error
|
|
if err != nil {
|
|
return find.Found[model.CustomerOrder]{}, err
|
|
}
|
|
|
|
return find.Found[model.CustomerOrder]{
|
|
Items: list,
|
|
Count: uint(total),
|
|
}, nil
|
|
}
|
|
|
|
func (repo *OrdersRepo) PlaceNewOrder(user_id uint, cart_id uint, country_id uint, address_info string) error {
|
|
|
|
return nil
|
|
}
|
|
|
|
func (repo *OrdersRepo) ChangeOrderAddress(user_id uint, order_id uint, country_id uint, address_info string) error {
|
|
return nil
|
|
}
|
|
|
|
func (repo *OrdersRepo) ChangeOrderStatus(user_id uint, order_id uint, status string) error {
|
|
return nil
|
|
}
|