package billing import ( "rmser/internal/domain/billing" "github.com/google/uuid" "gorm.io/gorm" ) type pgRepository struct { db *gorm.DB } func NewRepository(db *gorm.DB) billing.Repository { return &pgRepository{db: db} } func (r *pgRepository) CreateOrder(order *billing.Order) error { return r.db.Create(order).Error } func (r *pgRepository) GetOrder(id uuid.UUID) (*billing.Order, error) { var order billing.Order err := r.db.Where("id = ?", id).First(&order).Error if err != nil { return nil, err } return &order, nil } func (r *pgRepository) UpdateOrderStatus(id uuid.UUID, status billing.OrderStatus, paymentID string) error { updates := map[string]interface{}{ "status": status, } if paymentID != "" { updates["payment_id"] = paymentID } return r.db.Model(&billing.Order{}).Where("id = ?", id).Updates(updates).Error } func (r *pgRepository) GetActiveOrdersByUser(userID uuid.UUID) ([]billing.Order, error) { var orders []billing.Order err := r.db.Where("user_id = ? AND status = ?", userID, billing.StatusPending). Order("created_at DESC"). Find(&orders).Error return orders, err }