public async Task <IActionResult> GetUserInfo() { int userId = ClaimHelper.FindNameIdentifier(HttpContext.User.Claims); var result = await _userService.GetByKeys(userId); if (result == null) { return(NotFound("User not found")); } UserDto userDto = _mapper.Map <User, UserDto>(result); return(Ok(userDto)); }
public async Task <IActionResult> GetPlaylist([FromQuery] int playlistId) { int userId = ClaimHelper.FindNameIdentifier(HttpContext.User.Claims); var result = await _playlistService.GetPlaylist(playlistId, userId); if (result == null) { return(NotFound("Playlist does not exist")); } var playlistDto = _mapper.Map <PlaylistSong, PlaylistSongDto>(result); return(Ok(playlistDto)); }
public async Task <IActionResult> GetPlaylistForUser() { int userId = ClaimHelper.FindNameIdentifier(HttpContext.User.Claims); var playlistSongs = await _playlistService.GetPlaylistsForUser(userId); if (playlistSongs.Count == 0) { return(NotFound("No playlists for user")); } var playlistsDto = _mapper.Map <ICollection <PlaylistSong>, ICollection <PlaylistSongDto> >(playlistSongs); return(Ok(playlistsDto)); }
public async Task <IActionResult> GetUsersLikedSongs() { int userId = ClaimHelper.FindNameIdentifier(HttpContext.User.Claims); var result = await _songService.GetUserLikedSongs(userId); if (!result.Success) { return(BadRequest(result.Message)); } var songListDto = _mapper.Map <ICollection <Song>, ICollection <SongDto> >(result.Resource); return(Ok(songListDto)); }
public async Task <IActionResult> UnfollowPlaylist([FromRoute] int playlistId) { int userId = ClaimHelper.FindNameIdentifier(HttpContext.User.Claims); var response = await _playlistService.UnfollowPlaylist(userId, playlistId); if (!response.Success) { return(BadRequest(response.Message)); } var playlistDto = _mapper.Map <Playlist, PlaylistDto>(response.Resource); return(Ok(playlistDto)); }
public async Task <IActionResult> DeleteSongFromPlaylist([FromRoute] int songId, [FromQuery] int playlistId) { int userId = ClaimHelper.FindNameIdentifier(HttpContext.User.Claims); var response = await _songService.DeleteSongFromPlaylist(userId, playlistId, songId); if (!response.Success) { return(BadRequest(response.Message)); } var songDto = _mapper.Map <Song, SongDto>(response.Resource); return(Ok(songDto)); }
public async Task <IActionResult> DislikeSong([FromQuery] int songId) { int userId = ClaimHelper.FindNameIdentifier(HttpContext.User.Claims); var result = await _songService.DislikeSong(userId, songId); if (!result.Success) { return(BadRequest(result.Message)); } var songDto = _mapper.Map <Song, SongDto>(result.Resource); return(Ok(songDto)); }
public async Task <IActionResult> GetFriends() { int userId = ClaimHelper.FindNameIdentifier(HttpContext.User.Claims); var response = await _friendService.GetFriends(userId); if (!response.Success) { return(BadRequest(response.Message)); } var userFriendsDto = _mapper.Map <UserFriends, UserFriendsDto>(response.Resource); return(Ok(userFriendsDto)); }
public async Task <IActionResult> DeleteFriendRequest([FromQuery] string username) { int userId = ClaimHelper.FindNameIdentifier(HttpContext.User.Claims); var response = await _friendService.DeleteFriendRequest(userId, username); if (!response.Success) { return(BadRequest(response.Message)); } FriendDto friendDto = _mapper.Map <Friend, FriendDto>(response.Resource); return(Ok(friendDto)); }
public async Task <IActionResult> CreatePlaylist([FromBody] PlaylistDto playlistDto) { int userId = ClaimHelper.FindNameIdentifier(HttpContext.User.Claims); var playlist = _mapper.Map <PlaylistDto, Playlist>(playlistDto); var response = await _playlistService.CreatePlaylist(userId, playlist); if (!response.Success) { return(BadRequest(response.Message)); } playlistDto = _mapper.Map <Playlist, PlaylistDto>(response.Resource); return(Ok(playlistDto)); }
public async Task <IActionResult> AddYoutuubeVideoToPlaylist([FromQuery] int playlistId, [FromQuery] string youtubeId, [FromBody] SongDto songDto) { int userId = ClaimHelper.FindNameIdentifier(HttpContext.User.Claims); Song song = _mapper.Map <SongDto, Song>(songDto); var response = await _songService.AddYoutubeVideoToPlaylist(userId, playlistId, youtubeId, song); if (!response.Success) { return(BadRequest(response.Message)); } songDto = _mapper.Map <Song, SongDto>(response.Resource); return(Ok(songDto)); }
public async Task <IActionResult> AcceptFriendRequest([FromBody] FriendDto friendDto) { int userId = ClaimHelper.FindNameIdentifier(HttpContext.User.Claims); var response = await _friendService.UpdateFriendRequest(friendDto.SenderUsername, friendDto.ReceiverUsername, FriendType.Friend, userId); if (!response.Success) { return(BadRequest(response.Message)); } friendDto = _mapper.Map <Friend, FriendDto>(response.Resource); return(Ok(friendDto)); }
public async Task <IActionResult> GetPlaylistForUsername(string username) { int userId = ClaimHelper.FindNameIdentifier(HttpContext.User.Claims); var respone = await _playlistService.GetPlaylistForUsername(username, userId); if (!respone.Success) { return(BadRequest(respone.Message)); } if (respone.Resource.Count == 0) { return(NotFound("No playlist for user")); } var playlistsDto = _mapper.Map <ICollection <PlaylistSong>, ICollection <PlaylistSongDto> >(respone.Resource); return(Ok(playlistsDto)); }
public async Task <IActionResult> UpdatePlaylist([FromRoute] int playlistId, [FromBody] PlaylistDto playlistDto) { if (playlistId != playlistDto.Id) { return(BadRequest("ID's of playlist don't match")); } int userId = ClaimHelper.FindNameIdentifier(HttpContext.User.Claims); var playlist = _mapper.Map <PlaylistDto, Playlist>(playlistDto); var response = await _playlistService.UpdatePlaylist(userId, playlistId, playlist); if (!response.Success) { return(BadRequest(response.Message)); } playlistDto = _mapper.Map <Playlist, PlaylistDto>(response.Resource); return(Ok(playlistDto)); }