feat: Implement video workflow repository and related services
- 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.
This commit is contained in:
86
internal/service/user_mapper.go
Normal file
86
internal/service/user_mapper.go
Normal file
@@ -0,0 +1,86 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"google.golang.org/protobuf/types/known/timestamppb"
|
||||
appv1 "stream.api/internal/api/proto/app/v1"
|
||||
"stream.api/internal/database/model"
|
||||
)
|
||||
|
||||
func protoUserFromPayload(user *userPayload) *appv1.User {
|
||||
if user == nil {
|
||||
return nil
|
||||
}
|
||||
return &appv1.User{
|
||||
Id: user.ID,
|
||||
Email: user.Email,
|
||||
Username: user.Username,
|
||||
Avatar: user.Avatar,
|
||||
Role: user.Role,
|
||||
GoogleId: user.GoogleID,
|
||||
StorageUsed: user.StorageUsed,
|
||||
PlanId: user.PlanID,
|
||||
PlanStartedAt: timeToProto(user.PlanStartedAt),
|
||||
PlanExpiresAt: timeToProto(user.PlanExpiresAt),
|
||||
PlanTermMonths: user.PlanTermMonths,
|
||||
PlanPaymentMethod: user.PlanPaymentMethod,
|
||||
PlanExpiringSoon: user.PlanExpiringSoon,
|
||||
WalletBalance: user.WalletBalance,
|
||||
Language: user.Language,
|
||||
Locale: user.Locale,
|
||||
CreatedAt: timeToProto(user.CreatedAt),
|
||||
UpdatedAt: timestamppb.New(user.UpdatedAt),
|
||||
}
|
||||
}
|
||||
|
||||
func toProtoUser(user *userPayload) *appv1.User {
|
||||
return protoUserFromPayload(user)
|
||||
}
|
||||
|
||||
func toProtoPreferences(pref *model.UserPreference) *appv1.Preferences {
|
||||
if pref == nil {
|
||||
return nil
|
||||
}
|
||||
return &appv1.Preferences{
|
||||
EmailNotifications: boolValue(pref.EmailNotifications),
|
||||
PushNotifications: boolValue(pref.PushNotifications),
|
||||
MarketingNotifications: pref.MarketingNotifications,
|
||||
TelegramNotifications: pref.TelegramNotifications,
|
||||
Language: model.StringValue(pref.Language),
|
||||
Locale: model.StringValue(pref.Locale),
|
||||
}
|
||||
}
|
||||
|
||||
func toProtoNotification(item model.Notification) *appv1.Notification {
|
||||
return &appv1.Notification{
|
||||
Id: item.ID,
|
||||
Type: normalizeNotificationType(item.Type),
|
||||
Title: item.Title,
|
||||
Message: item.Message,
|
||||
Read: item.IsRead,
|
||||
ActionUrl: item.ActionURL,
|
||||
ActionLabel: item.ActionLabel,
|
||||
CreatedAt: timeToProto(item.CreatedAt),
|
||||
}
|
||||
}
|
||||
|
||||
func normalizeNotificationType(value string) string {
|
||||
lower := strings.ToLower(strings.TrimSpace(value))
|
||||
switch {
|
||||
case strings.Contains(lower, "video"):
|
||||
return "video"
|
||||
case strings.Contains(lower, "payment"), strings.Contains(lower, "billing"):
|
||||
return "payment"
|
||||
case strings.Contains(lower, "warning"):
|
||||
return "warning"
|
||||
case strings.Contains(lower, "error"):
|
||||
return "error"
|
||||
case strings.Contains(lower, "success"):
|
||||
return "success"
|
||||
case strings.Contains(lower, "system"):
|
||||
return "system"
|
||||
default:
|
||||
return "info"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user