public async Task <Response> PostTweet(Tweet tweet) { if (!SessionUtil.IsLoggedIn()) { return(new Response() { status = Response.StatusCode.UserNotLoggedIn }); } if (insertTweet == null) { insertTweet = await session.PrepareAsync("insert into tweets (id, username, originaltext, timestamp, hashtags) values (?, ?, ?, ?, ?)" + "USING TIMESTAMP ?"); } Guid tweetId = Guid.NewGuid(); long timestamp = GetTimestamp(); var stmt = insertTweet.Bind(tweetId, SessionUtil.GetAccount().username, tweet.originalText, timestamp, tweet.hashtags); await session.ExecuteAsync(stmt); if (updateUserTweets == null) { updateUserTweets = await session.PrepareAsync("UPDATE user_tweets SET tweets = tweets + ? WHERE username = ?"); } stmt = updateUserTweets.Bind(new List <Guid>() { tweetId }, SessionUtil.GetAccount().username); await session.ExecuteAsync(stmt); return(new Response() { status = Response.StatusCode.OK }); }
/// <summary> /// Returns tweets for current user /// </summary> /// <returns></returns> public async Task <Response> GetUserFeed() { if (!SessionUtil.IsLoggedIn()) { return(new Response() { status = Response.StatusCode.UserNotLoggedIn }); } Response friends = await AccountsController.GetUserFriends(SessionUtil.GetAccount().username); ((List <string>)friends.result).Add(SessionUtil.GetAccount().username); List <Guid> tweetIds = new List <Guid>(); foreach (var friend in (List <string>)friends.result) { tweetIds.AddRange(await GetUserTweetIds(friend)); } return(new Response() { status = Response.StatusCode.OK, result = await GetTweetsById(tweetIds) }); }
public async Task <Response> AddFriend([System.Web.Mvc.Bind] Account user) { //we believe user does exist, since the add button was displayed on the client side //and user is loggedIn if (addFriend == null) { addFriend = await session.PrepareAsync("UPDATE friends SET friends = friends + ? WHERE username = ?"); } if (!SessionUtil.IsLoggedIn()) { return(new Response() { status = Response.StatusCode.UserNotLoggedIn }); } var stmt = addFriend.Bind(new List <string>() { user.username }, SessionUtil.GetAccount().username); await session.ExecuteAsync(stmt); return(new Response() { status = Response.StatusCode.OK }); }
public static async Task <Response> GetUserFriends(string username) { if (!SessionUtil.IsLoggedIn()) { return(new Response() { status = Response.StatusCode.UserNotLoggedIn }); } var session = SessionManager.GetSession(); if (getFriends == null) { getFriends = await session.PrepareAsync("select friends from friends where username = ?"); } var stmt = getFriends.Bind(username); var result = await session.ExecuteAsync(stmt); Row row = result.FirstOrDefault(); Response resp = new Response() { status = Response.StatusCode.OK }; if (row != null) { resp.result = ((IEnumerable <string>)row["friends"]).ToList(); } else { resp.result = new List <string>(); } return(resp); }
public async Task <Response> GetFriends() { Response resp = new Response(); if (SessionUtil.IsLoggedIn()) { resp = await GetUserFriends(SessionUtil.GetAccount().username); } else { resp.status = Response.StatusCode.UserNotLoggedIn; } return(resp); }
public Response IsLoggedIn() { Response resp = new Response(); if (SessionUtil.IsLoggedIn()) { resp.status = Response.StatusCode.UserLoggedIn; resp.result = SessionUtil.GetAccount().username; } else { resp.status = Response.StatusCode.UserNotLoggedIn; } return(resp); }
public async Task <Response> RemoveFriend([System.Web.Mvc.Bind] Account user) { if (removeFriend == null) { removeFriend = await session.PrepareAsync("UPDATE friends SET friends = friends - ? WHERE username = ?"); } if (!SessionUtil.IsLoggedIn()) { return(new Response() { status = Response.StatusCode.UserNotLoggedIn }); } var stmt = removeFriend.Bind(new List <string>() { user.username }, SessionUtil.GetAccount().username); await session.ExecuteAsync(stmt); return(new Response() { status = Response.StatusCode.OK }); }
public User IsLoggedIn() { return(SessionUtil.IsLoggedIn()); }