public async Task <IActionResult> AcceptFollowRequest(long followerId) { Request.HttpContext.Items.TryGetValue(Constants.AuthenticatedUserKey, out var userAuthDtoObject); var userAuthDto = userAuthDtoObject as UserAuthDto; var followRequest = new FollowRequest { FolloweeId = userAuthDto.UserId, FollowerId = followerId }; var result = await _followLogic.AcceptFollowRequest(followRequest); return(Ok(result)); }
public void Delete_Follow_Request() { var userManager = new UserManager <ApplicationUser>(new TestUserStore()); FollowRequest request = new FollowRequest() { FromUserId = "402bd590-fdc7-49ad-9728-40efbfe512ec", ToUserId = "402bd590-fdc7-49ad-9728-40efbfe512ed", }; followRequestRepository.Setup(x => x.Get(It.IsAny <Expression <Func <FollowRequest, bool> > >())).Returns(request); AccountController contr = new AccountController(userService, userProfileService, goalService, updateService, commentService, followRequestService, followUserService, securityTokenService, userManager); var result = contr.RejectRequest("402bd590-fdc7-49ad-9728-40efbfe512ed", "402bd590-fdc7-49ad-9728-40efbfe512ec") as RedirectToRouteResult; Assert.AreEqual("Index", result.RouteValues["action"]); }
/// <summary> /// Create a new follow request. /// </summary> /// <remarks> /// <para> /// This expects the requester id to be equal to the current /// user id. A <see cref="NotAllowedException"/> is thrown /// otherwise. /// </para> /// <para> /// This doesn't actually return the created entity /// id since we already now said id. /// </para> /// </remarks> /// <param name="entity">The follow request.</param> /// <returns>The created follow requests id.</returns> public async Task <FollowRequestId> CreateAsync(FollowRequest entity) { if (entity is null) { throw new ArgumentNullException(nameof(entity)); } if (entity.Id is null) { throw new ArgumentNullException(nameof(entity.Id)); } // Only create the follow request if we are the requester if (!AppContext.HasUser || entity.Id.RequesterId != AppContext.UserId) { throw new NotAllowedException(); } // Only update if nonexistent if (await ExistsAsync(entity.Id)) { if ((await GetAsync(entity.Id)).FollowRequestStatus == FollowRequestStatus.Accepted) { return(entity.Id); } } var sql = @" INSERT INTO application.follow_request( receiver_id, requester_id ) VALUES ( @receiver_id, @requester_id ) ON CONFLICT (requester_id, receiver_id) DO UPDATE SET follow_request_status = 'pending'" ; await using var context = await CreateNewDatabaseContext(sql); MapToWriter(context, entity); await context.NonQueryAsync(); return(entity.Id); }
private void UpdateUI() { if (_artistInfo != null) { DownloadUpdateSprite(_icon, _artistInfo.Images); UpdateTextElement(_nameText, $"Name: {_artistInfo.Name}"); UpdateTextElement(_idText, $"Id: {_artistInfo.Id}"); UpdateTextElement(_uriText, $"URI: {_artistInfo.Uri}"); UpdateTextElement(_followersText, $"Followers: {_artistInfo.Followers.Total.ToString()}"); UpdateTextElement(_genresText, $"Genres: {string.Join(", ", _artistInfo.Genres.ToArray())}"); UpdateTextElement(_popularityText, $"Popularity: {_artistInfo.Popularity}"); UpdateTextElement(_typeText, $"Type: {_artistInfo.Type}"); } else { UpdateTextElement(_nameText, string.Empty); UpdateTextElement(_idText, string.Empty); UpdateTextElement(_uriText, string.Empty); UpdateTextElement(_followersText, string.Empty); UpdateTextElement(_genresText, string.Empty); UpdateTextElement(_popularityText, string.Empty); UpdateTextElement(_typeText, string.Empty); _icon.sprite = null; } // If follow btn set, add listener to on click to follow the current artist if (_followBtn != null) { _followBtn.onClick.AddListener(() => { SpotifyClient client = SpotifyService.Instance.GetSpotifyClient(); if (client != null) { List <string> allArtistIdsList = new List <string>() { ArtistId }; FollowRequest followRequest = new FollowRequest(FollowRequest.Type.Artist, allArtistIdsList); client.Follow.Follow(followRequest); } }); } }
public async Task <IActionResult> UnfollowUser([FromQuery] GuidRequest followee, CancellationToken cancellationToken) { var identifier = User.GetUserId(); var follow = new FollowRequest { FollowerId = identifier, FolloweeId = followee.Id }; var command = new RemoveFollowCommand { Follow = follow }; await _mediator.Send(command, cancellationToken); return(NoContent()); }
public override void BuildPacket() { base.BuildPacket(); var followRequest = new FollowRequest() { type = FollowType, user_id = GlobalVariables.CurrentUser.UserID, artist_id = ArtistID }; byte[] packetData; using (var stream = new MemoryStream()) { Serializer.Serialize(stream, followRequest); packetData = stream.ToArray(); } GlobalVariables.CountRequest++; Packet = StoreConnection.BuildServerPacket(packetData.Length + 16, (int)MessageType.Type.FOLLOW_UNFOLLOW, 2, packetData, GlobalVariables.CountRequest); }
public async Task <bool> FollowUser(FollowRequest req) { var user = await _dbContext.UserProfiles.Include(x => x.User).Where(x => x.User.Id == req.UserId).FirstOrDefaultAsync(); var toFollow = await _dbContext.UserProfiles.Include(x => x.User).Where(x => x.User.Id == req.FollowedUserId).FirstOrDefaultAsync(); var follower = new Follower { User = toFollow, FollowerType = FollowerType.Follower, FollowedBy = user }; if (user != null && toFollow != null && (user != toFollow)) { _dbContext.Followers.Add(follower); await _dbContext.SaveChangesAsync(); return(true); } return(false); }
public void Delete_Follow_Request() { var userManager = new UserManager<ApplicationUser>(new TestUserStore()); FollowRequest request = new FollowRequest() { FromUserId = "402bd590-fdc7-49ad-9728-40efbfe512ec", ToUserId = "402bd590-fdc7-49ad-9728-40efbfe512ed", }; followRequestRepository.Setup(x => x.Get(It.IsAny<Expression<Func<FollowRequest, bool>>>())).Returns(request); AccountController contr = new AccountController(userService, userProfileService, goalService, updateService, commentService, followRequestService, followUserService, securityTokenService,userManager); var result = contr.RejectRequest("402bd590-fdc7-49ad-9728-40efbfe512ed","402bd590-fdc7-49ad-9728-40efbfe512ec") as RedirectToRouteResult; Assert.AreEqual("Index", result.RouteValues["action"]); }
private static async Task Start(string _accessToken) { var spotify = new SpotifyClient(_accessToken); SearchRequest sReq; SearchResponse sRes; LibrarySaveAlbumsRequest librarySaveAlbumsRequest; FollowRequest followRequest; List <string> IDList = new List <string>(); HashSet <string> ArtistIDSet = new HashSet <string>(); List <string> notAddedMusicList = new List <string>(); List <string> addedMusicList = new List <string>(); SimpleAlbum album; for (int i = 1; i <= _artistAlbumPairs.Count; ++i) { sReq = new SearchRequest(SearchRequest.Types.Album, _artistAlbumPairs[i - 1].Key + " " + _artistAlbumPairs[i - 1].Value); sRes = spotify.Search.Item(sReq).Result; // maybe need await? if (sRes.Albums.Items.Count != 0) { var FoundAlbums = sRes.Albums; album = FoundAlbums.Items[0]; ArtistIDSet.Add(album.Artists[0].Id); IDList.Add(album.Id); Console.WriteLine("Added to library: " + album.Artists[0].Name + " - " + album.Name); addedMusicList.Add(album.Artists[0].Name + " - " + album.Name); } else { _notAddedArtistAlbumPairs.Add(_artistAlbumPairs[i - 1]); } if (i % 50 == 0) { librarySaveAlbumsRequest = new LibrarySaveAlbumsRequest(IDList); followRequest = new FollowRequest(FollowRequest.Type.Artist, new List <string>(ArtistIDSet)); await spotify.Library.SaveAlbums(librarySaveAlbumsRequest); await spotify.Follow.Follow(followRequest); IDList = new List <string>(); ArtistIDSet = new HashSet <string>(); System.Threading.Thread.Sleep(500); } if (i == _artistAlbumPairs.Count) { if (IDList.Count != 0) { librarySaveAlbumsRequest = new LibrarySaveAlbumsRequest(IDList); followRequest = new FollowRequest(FollowRequest.Type.Artist, new List <string>(ArtistIDSet)); await spotify.Library.SaveAlbums(librarySaveAlbumsRequest); await spotify.Follow.Follow(followRequest); break; } break; } } if (_notAddedArtistAlbumPairs != null && _notAddedArtistAlbumPairs.Count != 0) { foreach (var pair in _notAddedArtistAlbumPairs) { Console.WriteLine("Not added to library: " + pair.Key + " - " + pair.Value); } foreach (var pair in _notAddedArtistAlbumPairs) { notAddedMusicList.Add(pair.Key + " - " + pair.Value); } } WriteListToFile(notAddedMusicList, "not_added.txt"); WriteListToFile(addedMusicList, "added.txt"); _server.Dispose(); Environment.Exit(0); }
public HttpResponseMessage Post([FromBody] FollowRequest request) { return(_upsertFollowingModule.UpsertFollowing(request)); }
/// <summary> /// Map a follow request to the context. /// </summary> /// <param name="context">The context to map to.</param> /// <param name="entity">The entity to map from.</param> private static void MapToWriter(DatabaseContext context, FollowRequest entity) { context.AddParameterWithValue("receiver_id", entity.Id.ReceiverId); context.AddParameterWithValue("requester_id", entity.Id.RequesterId); }
private void UpdateUI() { if (_privateUserInfo != null) { if (_icon != null) { _icon.gameObject.SetActive(true); DownloadUpdateSprite(_icon, _privateUserInfo.Images); } UpdateTextElement(_nameText, $"Name: {_privateUserInfo.DisplayName}"); UpdateTextElement(_followersText, $"Followers: {_privateUserInfo.Followers.Total.ToString()}"); UpdateTextElement(_typeText, $"Type: {_privateUserInfo.Type}"); UpdateTextElement(_uriText, $"URI: {_privateUserInfo.Uri}"); UpdateTextElement(_idText, $"Id: {_privateUserInfo.Id}"); // PrivateProfile specific properties UpdateTextElement(_countryText, $"Country: {_privateUserInfo.Country}"); UpdateTextElement(_productText, $"Product: {_privateUserInfo.Product}"); // Disable follow, cant follow self if (_followBtn) { _followBtn.gameObject.SetActive(false); } } else if (_publicUserInfo != null) { if (_icon != null) { _icon.gameObject.SetActive(true); DownloadUpdateSprite(_icon, _publicUserInfo.Images); } UpdateTextElement(_nameText, $"Name: {_publicUserInfo.DisplayName}"); UpdateTextElement(_followersText, $"Followers: {_publicUserInfo.Followers.Total.ToString()}"); UpdateTextElement(_typeText, $"Type: {_publicUserInfo.Type}"); UpdateTextElement(_uriText, $"URI: {_publicUserInfo.Uri}"); UpdateTextElement(_idText, $"Id: {_publicUserInfo.Id}"); if (_productText) { _productText.gameObject.SetActive(false); } if (_countryText) { _countryText.gameObject.SetActive(false); } if (_followBtn != null) { _followBtn.onClick.AddListener(() => { SpotifyClient client = SpotifyService.Instance.GetSpotifyClient(); if (client != null) { List <string> allArtistIdsList = new List <string>() { UserId }; FollowRequest followRequest = new FollowRequest(FollowRequest.Type.Artist, allArtistIdsList); client.Follow.Follow(followRequest); } }); } } else { // Both null, not loaded UpdateTextElement(_nameText, string.Empty); UpdateTextElement(_followersText, string.Empty); UpdateTextElement(_typeText, string.Empty); UpdateTextElement(_uriText, string.Empty); UpdateTextElement(_idText, string.Empty); UpdateTextElement(_countryText, string.Empty); UpdateTextElement(_productText, string.Empty); if (_icon != null) { _icon.sprite = null; _icon.gameObject.SetActive(false); } } }