/// <summary> /// Submits a YouTube video to the catalog. /// </summary> public override async Task <SubmitYouTubeVideoResponse> SubmitYouTubeVideo(SubmitYouTubeVideoRequest request, ServerCallContext context) { // Use a batch to insert the YouTube video into multiple tables PreparedStatement[] prepared = await _statementCache.GetOrAddAllAsync( "INSERT INTO videos (videoid, userid, name, description, location, preview_image_location, tags, added_date, location_type) " + "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)", "INSERT INTO user_videos (userid, added_date, videoid, name, preview_image_location) VALUES (?, ?, ?, ?, ?)", "INSERT INTO latest_videos (yyyymmdd, added_date, videoid, userid, name, preview_image_location) VALUES (?, ?, ?, ?, ?, ?) USING TTL ?"); // Calculate date-related info and location/thumbnail for YouTube video var addDate = DateTimeOffset.UtcNow; string yyyymmdd = addDate.ToString("yyyyMMdd"); string location = request.YouTubeVideoId; // TODO: Store URL instead of ID? string previewImageLocation = $"//img.youtube.com/vi/{request.YouTubeVideoId}/hqdefault.jpg"; var batch = new BatchStatement(); batch.Add(prepared[0].Bind(request.VideoId.ToGuid(), request.UserId.ToGuid(), request.Name, request.Description, location, previewImageLocation, request.Tags.ToArray(), addDate, (int)VideoLocationType.Youtube)) .Add(prepared[1].Bind(request.UserId.ToGuid(), addDate, request.VideoId.ToGuid(), request.Name, previewImageLocation)) .Add(prepared[2].Bind(yyyymmdd, addDate, request.VideoId.ToGuid(), request.UserId.ToGuid(), request.Name, previewImageLocation, LatestVideosTtlSeconds)) .SetTimestamp(addDate); // Send the batch to Cassandra await _session.ExecuteAsync(batch).ConfigureAwait(false); // Tell the world about the new YouTube video var message = new YouTubeVideoAdded { VideoId = request.VideoId, UserId = request.UserId, Name = request.Name, Description = request.Description, Location = location, PreviewImageLocation = previewImageLocation, AddedDate = addDate.ToTimestamp(), Timestamp = addDate.ToTimestamp() }; message.Tags.Add(request.Tags); await _bus.Publish(message).ConfigureAwait(false); return(new SubmitYouTubeVideoResponse()); }
public Task Handle(YouTubeVideoAdded busEvent) { return(HandleImpl(busEvent.VideoId, busEvent.AddedDate, busEvent.UserId, busEvent.Name, busEvent.PreviewImageLocation, busEvent.Tags, busEvent.Timestamp)); }
public Task Handle(YouTubeVideoAdded busEvent) { return(HandleImpl(busEvent)); }