Exemplo n.º 1
0
 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;
 }
Exemplo n.º 2
0
        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");
        }
Exemplo n.º 3
0
 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());
     }
 }