- 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.
53 lines
1.2 KiB
Go
53 lines
1.2 KiB
Go
package service
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"google.golang.org/grpc/codes"
|
|
"google.golang.org/grpc/status"
|
|
"stream.api/internal/database/model"
|
|
)
|
|
|
|
func ensurePaidPlan(user *model.User) error {
|
|
if user == nil {
|
|
return status.Error(codes.Unauthenticated, "Unauthorized")
|
|
}
|
|
if user.PlanID == nil || strings.TrimSpace(*user.PlanID) == "" {
|
|
return status.Error(codes.PermissionDenied, adTemplateUpgradeRequiredMessage)
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func playerConfigActionAllowed(user *model.User, configCount int64, action string) error {
|
|
if user == nil {
|
|
return status.Error(codes.Unauthenticated, "Unauthorized")
|
|
}
|
|
if user.PlanID != nil && strings.TrimSpace(*user.PlanID) != "" {
|
|
return nil
|
|
}
|
|
|
|
switch action {
|
|
case "create":
|
|
if configCount > 0 {
|
|
return status.Error(codes.FailedPrecondition, playerConfigFreePlanLimitMessage)
|
|
}
|
|
return nil
|
|
case "delete":
|
|
return nil
|
|
case "update", "set-default", "toggle-active":
|
|
if configCount > 1 {
|
|
return status.Error(codes.FailedPrecondition, playerConfigFreePlanReconciliationMessage)
|
|
}
|
|
return nil
|
|
default:
|
|
return nil
|
|
}
|
|
}
|
|
|
|
func safeRole(role *string) string {
|
|
if role == nil || strings.TrimSpace(*role) == "" {
|
|
return "USER"
|
|
}
|
|
return *role
|
|
}
|