private async Task <List <RedisPhoto> > GetAllUserPhotos(Guid userId) { using var conn = new NpgsqlConnection(_connectionStrings.Postgres); conn.Open(); using var cmd = new NpgsqlCommand { Connection = conn, CommandText = @"select id, date_created from photos where user_id = @p_user_id and deleted = false order by date_created desc" }; cmd.Parameters.AddWithValue("p_user_id", userId); var reader = await cmd.ExecuteReaderAsync(); var photos = new List <RedisPhoto>(); while (await reader.ReadAsync()) { var photo = new RedisPhoto { Id = reader.GetGuid(0), Time = reader.GetDateTime(1) }; photos.Add(photo); } return(photos); }
public async Task DeleteStoryFromFeed(Guid userId, Story story) { var redisPhoto = new RedisPhoto { Id = story.Id, Time = story.DateCreated }; await _redisRepository.RemovePhotoFromFeed(userId, redisPhoto); }
public async Task AddStoryToFeed(Guid userId, Story story) { var redisPhoto = new RedisPhoto { Id = story.Id, Time = story.DateCreated }; await _redisRepository.AddFeedPhoto(userId, redisPhoto); }
public async Task DeletePhotoFromFeed(Guid userId, Photo photo) { var subscribers = await _usersRepository.GetAllSubscribers(userId); var redisPhoto = new RedisPhoto { Id = photo.Id, Time = photo.DateCreated }; await Task.WhenAll(subscribers.Select(x => _redisRepository.RemovePhotoFromFeed(x, redisPhoto))); }
public async Task RemovePhotoFromFeed(Guid userId, RedisPhoto photo) { var conn = _connection.GetDatabase(); var jsonPhoto = JsonConvert.SerializeObject(photo); await conn.ListRemoveAsync(userId.ToString(), jsonPhoto); }
public async Task AddFeedPhoto(Guid userId, RedisPhoto photo) { var conn = _connection.GetDatabase(); var jsonPhoto = JsonConvert.SerializeObject(photo); await conn.ListLeftPushAsync(userId.ToString(), jsonPhoto); }