rentease/internal/booking/item_store.go
2024-09-08 23:16:50 +02:00

41 lines
937 B
Go

package booking
import "gorm.io/gorm/clause"
func (ps *PgStore) CreateItem(i *Item) error {
return ps.db.Create(i).Error
}
func (ps *PgStore) PayItem(id int) (*Item, error) {
i := new(Item)
if err := ps.db.Model(i).
Clauses(clause.Returning{}).
Where("id = ?", id).
Update("payment_status", "Completed").
Error; err != nil {
return nil, err
}
return i, nil
}
func (ps *PgStore) GetItem(id int) (*Item, error) {
i := &Item{Id: id}
err := ps.db.First(i).Error
return i, err
}
func (ps *PgStore) UpdateItem(id int, item string, paymentMethod string, paymentStatus string, qty int, price float64) (*Item, error) {
i := new(Item)
err := ps.db.Model(i).
Clauses(clause.Returning{}).
Where("id = ?", id).
Updates(map[string]any{
"item": item,
"payment_method": paymentMethod,
"payment_status": paymentStatus,
"quantity": qty,
"price": price,
}).
Error
return i, err
}