public async Task <ActionResult <PlaylistViewModel> > Post([FromBody] PodcastEntryViewModel entry) { var podcast = await _podcastRepository.GetAsync(entry.PodcastId); if (podcast == null) { return(NotFound()); } if (string.IsNullOrEmpty(entry.SourceUrl)) { return(BadRequest("SourceUrl is empty")); } var sourceUrl = await _youTubeParser.ConvertUserToChannel(entry.SourceUrl, podcast.AppUserId); var playlist = new Playlist { Podcast = podcast, SourceUrl = sourceUrl }; _playlistRepository.AddOrUpdate(playlist); try { await _unitOfWork.CompleteAsync(); } catch (DbUpdateException ex) { if (ex.InnerException != null && ex.InnerException.Message.Contains("IX_Playlists_SourceUrl")) { return(Conflict("This podcast is already monitoring this playlist")); } return(BadRequest("There was an error adding this playlist")); } BackgroundJob.Enqueue <ProcessPlaylistsJob>(job => job.Execute(playlist.Id, null)); return(_mapper.Map <Playlist, PlaylistViewModel>(playlist)); }
public async Task <ActionResult <PodcastEntryViewModel> > PreProcess(PodcastEntryViewModel item) { var entry = await _repository.GetAsync(item.Id); entry.ProcessingStatus = ProcessingStatus.Accepted; var response = _processor.GetInformation(item.Id, this.UserId); entry.ProcessingStatus = ProcessingStatus.Processing; await _unitOfWork.CompleteAsync(); var result = _mapper.Map <PodcastEntry, PodcastEntryViewModel>(entry); return(result); }
public async Task <IActionResult> ReSubmit([FromBody] PodcastEntryViewModel item) { var entry = await _repository.GetAsync(item.Id); entry.ProcessingStatus = ProcessingStatus.Processing; await _unitOfWork.CompleteAsync(); if (entry.ProcessingStatus != ProcessingStatus.Processed) { BackgroundJob.Enqueue <ProcessNewEntryJob>(e => e.ProcessEntry(entry.Id, null)); } return(Ok(entry)); }
public async Task <ActionResult <PodcastEntryViewModel> > Post([FromBody] PodcastEntryViewModel item) { if (!ModelState.IsValid) { return(BadRequest("Invalid podcast entry posted")); } PodcastEntry entry; if (item.Id != null) { entry = await _repository.GetAsync(item.Id); _mapper.Map(item, entry); } else { entry = _mapper.Map <PodcastEntryViewModel, PodcastEntry>(item); } if (entry is null) { return(BadRequest()); } if (entry.ProcessingStatus == ProcessingStatus.Uploading || entry.ProcessingStatus == ProcessingStatus.Processed) { // we're editing an existing entry await _repository.AddOrUpdateWithTags(entry); await _unitOfWork.CompleteAsync(); var result = _mapper.Map <PodcastEntry, PodcastEntryViewModel>(entry); return(Ok(result)); } //we're adding a new entry //TODO: This should return the properties bundle //with the status as a member var parser = new UrlTypeParser(); var urlType = await parser.GetUrlType(entry.SourceUrl); if (!urlType.Equals(UrlType.Invalid) && !urlType.Equals(UrlType.Playlist) && !urlType.Equals(UrlType.Channel)) { // check user quota var result = await _preProcessor.PreProcessEntry( _applicationUser, entry); switch (result) { case EntryProcessResult.QuotaExceeded: return(StatusCode(402)); case EntryProcessResult.GeneralFailure: return(BadRequest()); } _repository.GetContext() .Entry(entry) .State = EntityState.Detached; entry = await _repository.GetAsync(entry.Id); return(_mapper.Map <PodcastEntry, PodcastEntryViewModel>(entry)); } if (urlType.Equals(UrlType.Playlist)) { entry.ProcessingStatus = ProcessingStatus.Deferred; var result = _mapper.Map <PodcastEntry, PodcastEntryViewModel>(entry); return(Accepted(result)); } return(BadRequest("Failed to create podcast entry")); }