- 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.
55 lines
1.6 KiB
Go
55 lines
1.6 KiB
Go
package repository
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
|
|
"gorm.io/gorm"
|
|
"stream.api/internal/database/model"
|
|
)
|
|
|
|
type notificationRepository struct {
|
|
db *gorm.DB
|
|
}
|
|
|
|
func NewNotificationRepository(db *gorm.DB) *notificationRepository {
|
|
return ¬ificationRepository{db: db}
|
|
}
|
|
|
|
func (r *notificationRepository) ListByUser(ctx context.Context, userID string) ([]model.Notification, error) {
|
|
var rows []model.Notification
|
|
err := r.db.WithContext(ctx).
|
|
Where("user_id = ?", strings.TrimSpace(userID)).
|
|
Order("created_at DESC").
|
|
Find(&rows).Error
|
|
return rows, err
|
|
}
|
|
|
|
func (r *notificationRepository) MarkReadByIDAndUser(ctx context.Context, id string, userID string) (int64, error) {
|
|
res := r.db.WithContext(ctx).
|
|
Model(&model.Notification{}).
|
|
Where("id = ? AND user_id = ?", strings.TrimSpace(id), strings.TrimSpace(userID)).
|
|
Update("is_read", true)
|
|
return res.RowsAffected, res.Error
|
|
}
|
|
|
|
func (r *notificationRepository) MarkAllReadByUser(ctx context.Context, userID string) error {
|
|
return r.db.WithContext(ctx).
|
|
Model(&model.Notification{}).
|
|
Where("user_id = ? AND is_read = ?", strings.TrimSpace(userID), false).
|
|
Update("is_read", true).Error
|
|
}
|
|
|
|
func (r *notificationRepository) 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.Notification{})
|
|
return res.RowsAffected, res.Error
|
|
}
|
|
|
|
func (r *notificationRepository) DeleteAllByUser(ctx context.Context, userID string) error {
|
|
return r.db.WithContext(ctx).
|
|
Where("user_id = ?", strings.TrimSpace(userID)).
|
|
Delete(&model.Notification{}).Error
|
|
}
|