/// <summary> /// Deletes a vlog like in our database. /// </summary> /// <remarks> /// This expects the current user to own the vlog. /// </remarks> /// <param name="id">The vlog like id.</param> public async Task DeleteAsync(VlogLikeId id) { if (id is null) { throw new ArgumentNullException(nameof(id)); } if (!AppContext.HasUser || !AppContext.IsUser(id.UserId)) { throw new NotAllowedException(); } var sql = @" DELETE FROM entities.vlog_like AS vl WHERE vl.user_id = @user_id AND vl.vlog_id = @vlog_id"; await using var context = await CreateNewDatabaseContext(sql); context.AddParameterWithValue("user_id", id.UserId); context.AddParameterWithValue("vlog_id", id.VlogId); await context.NonQueryAsync(); }
/// <summary> /// Gets a vlog like from our database. /// </summary> /// <param name="id">The vlog like id.</param> /// <returns>The vlog like.</returns> public async Task <VlogLike> GetAsync(VlogLikeId id) { if (id is null) { throw new ArgumentNullException(nameof(id)); } var sql = @" SELECT vl.date_created, vl.user_id, vl.vlog_id FROM entities.vlog_like_nondeleted AS vl WHERE vl.vlog_id = @vlog_id AND vl.user_id = @user_id LIMIT 1"; await using var context = await CreateNewDatabaseContext(sql); context.AddParameterWithValue("user_id", id.UserId); context.AddParameterWithValue("vlog_id", id.VlogId); await using var reader = await context.ReaderAsync(); return(MapFromReader(reader)); }
/// <summary> /// Notify a user that one of the users vlogs received /// a new like. /// </summary> /// <remarks> /// This is dispatched to the <see cref="DispatchManager"/>. /// </remarks> /// <param name="receivingUserId">User that received the vlog like.</param> /// <param name="vlogLikeId">The vlog like id.</param> public virtual Task NotifyVlogLikedAsync(Guid receivingUserId, VlogLikeId vlogLikeId) { if (vlogLikeId is null) { throw new ArgumentNullException(nameof(vlogLikeId)); } var notificationContext = _notificationFactory.BuildVlogGainedLike(receivingUserId, vlogLikeId.VlogId, vlogLikeId.UserId); _logger.LogTrace($"Notifying user {receivingUserId} that {vlogLikeId.VlogId} gained a like"); _dispatchManager.Dispatch <NotifyBackgroundTask <DataVlogGainedLike> >(notificationContext); return(Task.CompletedTask); }
/// <summary> /// Checks if a vlog like with given id exists. /// </summary> /// <param name="id">The id to check for.</param> public async Task <bool> ExistsAsync(VlogLikeId id) { if (id is null) { throw new ArgumentNullException(nameof(id)); } var sql = @" SELECT EXISTS ( SELECT 1 FROM entities.vlog_like_nondeleted AS vl WHERE vl.user_id = @user_id AND vl.vlog_id = @vlog_id )"; await using var context = await CreateNewDatabaseContext(sql); context.AddParameterWithValue("user_id", id.UserId); context.AddParameterWithValue("vlog_id", id.VlogId); return(await context.ScalarAsync <bool>()); }
/// <summary> /// Gets a vlog like from our data store. /// </summary> /// <param name="vlogLikeId">The vlog like id.</param> /// <returns>The vlog like.</returns> public Task <VlogLike> GetAsync(VlogLikeId vlogLikeId) => _vlogLikeRepository.GetAsync(vlogLikeId);
/// <summary> /// Checks if a vlog like exists in our data store. /// </summary> /// <param name="vlogLikeId">The vlog like id to check.</param> public Task <bool> ExistsAsync(VlogLikeId vlogLikeId) => _vlogLikeRepository.ExistsAsync(vlogLikeId);
/// <summary> /// Does nothing and returns <see cref="Task.CompletedTask"/>. /// </summary> public Task NotifyVlogLikedAsync(Guid receivingUserId, VlogLikeId vlogLikeId) => Task.CompletedTask;