public static async Task <List <PostQueryDTO> > GetFeed(string userId, long fromTime = 0, long continuationTime = 0)
        {
            // select
            var sqlString = $"SELECT TOP 30 p.id, p.post_id, p.tags, p.track_id, p.track_name, p.date_created, p.type, p.has_image, p.title, p.summary, p.url FROM p";

            // where user id
            sqlString += $" WHERE ARRAY_CONTAINS(p.subscriber_list, \"{userId}\")";

            // continuation or fromTime
            if (fromTime != 0)
            {
                sqlString += $" and p.date_created > {fromTime}";
            }
            else if (continuationTime != 0)
            {
                sqlString += $" and p.date_created < {continuationTime}";
            }


            // chronological
            sqlString += " ORDER BY p.date_created DESC";

            List <PostCosmos> posts = await CosmosRepository <PostCosmos> .GetItemsSqlAsync(sqlString);

            return(ConvertCosmosResultToQueryDTO(posts));
        }
        // TODO: fix query posts
        public static async Task <PostReturnObject> QueryPosts(PostQuery query)
        {
            List <PostQueryDTO> data = await CosmosRepository <PostQueryDTO> .GetItemsSqlAsync(query.sql);

            string continuation = data.Count > 1 ? data[data.Count - 1].date_created.ToString() : null;

            return(new PostReturnObject()
            {
                continuation = continuation,
                count = data.Count,
                data = data
            });
        }
Esempio n. 3
0
        public static async Task <TrackAuth> CreateTrack(TrackAuth track)
        {
            if (track.PartitionKey == null || track.name == null)
            {
                return(null);
            }

            var extendedUser = await ExtendedUserRepository.GetExtendedUser(track.PartitionKey);

            // check private maxed out
            if (track.is_private)
            {
                if (extendedUser.Private_Tracks >= extendedUser.Private_Tracks_Max)
                {
                    return(null);
                }
            }

            // check public maxed out
            if (!track.is_private)
            {
                if (extendedUser.Public_Tracks >= extendedUser.Public_Tracks_Max)
                {
                    return(null);
                }
            }

            track.RowKey       = track.RowKey ?? Guid.NewGuid().ToString();
            track.subscribers  = 0;
            track.rate_limit   = extendedUser.Rate_Per_Track;
            track.track_key    = AuthRepository.GenerateRandomString(64);
            track.track_secret = AuthRepository.GenerateSHA256(track.RowKey + track.track_key);

            // insert into table storage
            var newTrack = await TableStorageRepository.InsertTrackAuth(track);

            if (newTrack == null)
            {
                return(null);
            }

            // insert into Cosmos
            await(dynamic) CosmosRepository <Track> .CreateItemAsync(new Track(track));

            // increment user's track count
            ExtendedUserRepository.IncrementTrackCount(track.PartitionKey, track.is_private);

            return(newTrack);
        }
Esempio n. 4
0
        public static async Task <bool> DeleteTrack(string trackId)
        {
            // decrement the count
            var track = await GetTrack(trackId);

            ExtendedUserRepository.DecrementTrackCount(track.PartitionKey, track.is_private);

            // send messages to queue
            TableStorageRepository.AddMessageToQueue("delete-posts-from-track", trackId);
            TableStorageRepository.AddMessageToQueue("delete-tracktags-from-track", trackId);

            // then delete track cosmos
            CosmosRepository <Track> .DeleteItemAsync(trackId);

            // then delete profile pics
            DeleteImages(trackId);

            // then delete from table storage, and return
            return(await TableStorageRepository.DeleteTrack(trackId));
        }
 // cosmos stuff
 public static async Task <PostCosmos> InsertPostToCosmos(PostCosmos post)
 {
     return(await(dynamic) CosmosRepository <PostCosmos> .CreateItemAsync(post));
 }
 public static void DeletePostFromCosmos(string postId)
 {
     CosmosRepository <PostDTO> .DeleteItemAsync(postId);
 }