public ActionResult <PlaylistGetModel> GetPlaylist([FromHeader][Required] string jwtToken, [Required] string playlistId) { string userId = new PlaylistDataAccess().JwtTokenValidation(jwtToken); if (userId == "") { return(Unauthorized(new CustomResponseModel() { Code = "401", Phrase = "Unauthorized", Message = "Invalid Jwt Token" })); } PlaylistGetModel playlistGetModel = null; if (new PlaylistDataAccess().IsListenerOrArtist(userId)) { playlistGetModel = new PlaylistDataAccess().GetPlaylist(playlistId); } else { return(Unauthorized(new CustomResponseModel() { Code = "401", Phrase = "Unauthorized", Message = "User Must be a Listener or Artist" })); } if (playlistGetModel != null) { return(playlistGetModel); } return(BadRequest(new CustomResponseModel() { Code = "400", Phrase = "BadRequest", Message = "Could Not Get Playlist" })); }
//GET PLAYLIST public PlaylistGetModel GetPlaylist(string playlistId) { PlaylistGetModel playlistGetModel = null; var collection = new MongodbConnectionProvider().GeShantyDatabase().GetCollection <BsonDocument>("playlists"); var builder = Builders <BsonDocument> .Filter; var filter = builder.Eq("PlaylistId", playlistId); var result = collection.Find(filter).FirstOrDefault(); if (result != null) { playlistGetModel = BsonSerializer.Deserialize <PlaylistGetModel>(result); playlistGetModel.SongGetModels = new List <SongGetModel>(); foreach (BsonDocument res in result.GetValue("Songs").AsBsonArray) { playlistGetModel.SongGetModels.Add(BsonSerializer.Deserialize <SongGetModel>(res)); } } return(playlistGetModel); }