mirror of
https://github.com/serty2005/rmser.git
synced 2026-02-04 19:02:33 -06:00
добавлен биллинг и тарифы
добавлена интеграция с юкасса
This commit is contained in:
47
internal/infrastructure/repository/billing/postgres.go
Normal file
47
internal/infrastructure/repository/billing/postgres.go
Normal file
@@ -0,0 +1,47 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user