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:
55
internal/service/video_mapper.go
Normal file
55
internal/service/video_mapper.go
Normal file
@@ -0,0 +1,55 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
|
||||
"google.golang.org/protobuf/types/known/timestamppb"
|
||||
appv1 "stream.api/internal/api/proto/app/v1"
|
||||
"stream.api/internal/database/model"
|
||||
)
|
||||
|
||||
func toProtoVideo(item *model.Video, jobID ...string) *appv1.Video {
|
||||
if item == nil {
|
||||
return nil
|
||||
}
|
||||
statusValue := stringValue(item.Status)
|
||||
if statusValue == "" {
|
||||
statusValue = "ready"
|
||||
}
|
||||
var linkedJobID *string
|
||||
if len(jobID) > 0 {
|
||||
linkedJobID = stringPointerOrNil(jobID[0])
|
||||
}
|
||||
return &appv1.Video{
|
||||
Id: item.ID,
|
||||
UserId: item.UserID,
|
||||
Title: item.Title,
|
||||
Description: item.Description,
|
||||
Url: item.URL,
|
||||
Status: strings.ToLower(statusValue),
|
||||
Size: item.Size,
|
||||
Duration: item.Duration,
|
||||
Format: item.Format,
|
||||
Thumbnail: item.Thumbnail,
|
||||
ProcessingStatus: item.ProcessingStatus,
|
||||
StorageType: item.StorageType,
|
||||
CreatedAt: timeToProto(item.CreatedAt),
|
||||
UpdatedAt: timestamppb.New(item.UpdatedAt.UTC()),
|
||||
JobId: linkedJobID,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *videosAppService) buildVideo(ctx context.Context, video *model.Video) (*appv1.Video, error) {
|
||||
if video == nil {
|
||||
return nil, nil
|
||||
}
|
||||
jobID, err := s.loadLatestVideoJobID(ctx, video.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if jobID != nil {
|
||||
return toProtoVideo(video, *jobID), nil
|
||||
}
|
||||
return toProtoVideo(video), nil
|
||||
}
|
||||
Reference in New Issue
Block a user