public ChannelVideosDTO getAllVideosByChannel(string accessToken, int channelID) { User loggedInUser = getValidatedUser(accessToken); Channel channel = _videoMapper.getChannelById(channelID); if (channel == null) { throw new AppObjectNotFoundException("no channel found with this id"); } List<Video> videos = _videoMapper.getAllVideosInChannel(channelID); ChannelVideosDTO channelVids = new ChannelVideosDTO { channelID = channel.ID, title = channel.title, videos = videoToDTO(videos) }; return channelVids; }
public void getAllVideosByChannelTest() { VideoMapperMock mapper = new VideoMapperMock(); mapper.returnVideos = new List <Video>(); VideoService service = new VideoService(new TokenServiceMock(), mapper, new AccountMapperMock()); Exception ex = Assert.Throws <AppObjectNotFoundException>(() => service.getAllVideosByChannel("test", 2)); mapper.returnChannel = new Channel { ID = 1, title = "test", }; ChannelVideosDTO vidsInChannel = service.getAllVideosByChannel("test", 2); Assert.Equal(vidsInChannel.channelID, 1); Assert.Equal(vidsInChannel.title, "test"); }
public IActionResult getVideosInChannel(int channelID) { try { string accessToken = Request.Headers["Authorization"]; ChannelVideosDTO videos = _videoService.getAllVideosByChannel(accessToken, channelID); return(Ok(videos)); } catch (InvalidParametersException e) { return(BadRequest(e.Message)); } catch (AppObjectNotFoundException e) { return(NotFound(e.Message)); } catch (AppValidationException) { return(Unauthorized()); } }