- Added videoWorkflowRepository with methods to manage video and user interactions. - Introduced catalog_mapper for converting database models to protobuf representations. - Created domain_helpers for normalizing domain and ad format values. - Defined service interfaces for payment, account, notification, domain, ad template, player config, video, and user management. - Implemented OAuth helpers for generating state and caching keys. - Developed payment_proto_helpers for mapping payment-related models to protobuf. - Added service policy helpers to enforce plan requirements and user permissions. - Created user_mapper for converting user payloads to protobuf format. - Implemented value_helpers for handling various value conversions and nil checks. - Developed video_helpers for normalizing video statuses and managing storage types. - Created video_mapper for mapping video models to protobuf format. - Implemented render workflow for managing video creation and job processing.
47 lines
1.2 KiB
Go
47 lines
1.2 KiB
Go
package repository
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
|
|
"gorm.io/gorm"
|
|
"stream.api/internal/database/model"
|
|
)
|
|
|
|
type domainRepository struct {
|
|
db *gorm.DB
|
|
}
|
|
|
|
func NewDomainRepository(db *gorm.DB) *domainRepository {
|
|
return &domainRepository{db: db}
|
|
}
|
|
|
|
func (r *domainRepository) ListByUser(ctx context.Context, userID string) ([]model.Domain, error) {
|
|
var rows []model.Domain
|
|
err := r.db.WithContext(ctx).
|
|
Where("user_id = ?", strings.TrimSpace(userID)).
|
|
Order("created_at DESC").
|
|
Find(&rows).Error
|
|
return rows, err
|
|
}
|
|
|
|
func (r *domainRepository) CountByUserAndName(ctx context.Context, userID string, name string) (int64, error) {
|
|
var count int64
|
|
err := r.db.WithContext(ctx).
|
|
Model(&model.Domain{}).
|
|
Where("user_id = ? AND name = ?", strings.TrimSpace(userID), strings.TrimSpace(name)).
|
|
Count(&count).Error
|
|
return count, err
|
|
}
|
|
|
|
func (r *domainRepository) Create(ctx context.Context, item *model.Domain) error {
|
|
return r.db.WithContext(ctx).Create(item).Error
|
|
}
|
|
|
|
func (r *domainRepository) DeleteByIDAndUser(ctx context.Context, id string, userID string) (int64, error) {
|
|
res := r.db.WithContext(ctx).
|
|
Where("id = ? AND user_id = ?", strings.TrimSpace(id), strings.TrimSpace(userID)).
|
|
Delete(&model.Domain{})
|
|
return res.RowsAffected, res.Error
|
|
}
|