From ae782025f67ea8fb5820ae56a1edee9231547da4 Mon Sep 17 00:00:00 2001 From: hak8or Date: Fri, 1 Sep 2017 04:55:02 -0400 Subject: [PATCH] Add project files. --- YTManager.sln | 25 ++++ YTManager/Controllers/ValuesController.cs | 95 ++++++++++++ YTManager/Controllers/VideosController.cs | 126 ++++++++++++++++ YTManager/MediaDB.cs | 21 +++ .../20170901083156_initial.Designer.cs | 86 +++++++++++ .../Migrations/20170901083156_initial.cs | 68 +++++++++ YTManager/Migrations/MediaDBModelSnapshot.cs | 85 +++++++++++ YTManager/Models/Channel.cs | 32 ++++ YTManager/Models/Video.cs | 41 ++++++ YTManager/Program.cs | 26 ++++ YTManager/Properties/launchSettings.json | 28 ++++ YTManager/ScaffoldingReadMe.txt | 39 +++++ YTManager/Startup.cs | 49 ++++++ YTManager/Tasks/FetchVideos.cs | 60 ++++++++ YTManager/YTManager.csproj | 31 ++++ YTManager/appsettings.Development.json | 10 ++ YTManager/appsettings.json | 15 ++ YTManager/wwwroot/admin.html | 109 ++++++++++++++ YTManager/wwwroot/admin.js | 139 ++++++++++++++++++ YTManager/wwwroot/index.css | 39 +++++ YTManager/wwwroot/index.html | 47 ++++++ YTManager/wwwroot/index.js | 73 +++++++++ 22 files changed, 1244 insertions(+) create mode 100644 YTManager.sln create mode 100644 YTManager/Controllers/ValuesController.cs create mode 100644 YTManager/Controllers/VideosController.cs create mode 100644 YTManager/MediaDB.cs create mode 100644 YTManager/Migrations/20170901083156_initial.Designer.cs create mode 100644 YTManager/Migrations/20170901083156_initial.cs create mode 100644 YTManager/Migrations/MediaDBModelSnapshot.cs create mode 100644 YTManager/Models/Channel.cs create mode 100644 YTManager/Models/Video.cs create mode 100644 YTManager/Program.cs create mode 100644 YTManager/Properties/launchSettings.json create mode 100644 YTManager/ScaffoldingReadMe.txt create mode 100644 YTManager/Startup.cs create mode 100644 YTManager/Tasks/FetchVideos.cs create mode 100644 YTManager/YTManager.csproj create mode 100644 YTManager/appsettings.Development.json create mode 100644 YTManager/appsettings.json create mode 100644 YTManager/wwwroot/admin.html create mode 100644 YTManager/wwwroot/admin.js create mode 100644 YTManager/wwwroot/index.css create mode 100644 YTManager/wwwroot/index.html create mode 100644 YTManager/wwwroot/index.js diff --git a/YTManager.sln b/YTManager.sln new file mode 100644 index 0000000..2c1af81 --- /dev/null +++ b/YTManager.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 15 +VisualStudioVersion = 15.0.26730.12 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "YTManager", "YTManager\YTManager.csproj", "{14F56CC1-67A1-477F-817C-A0A7B55AE954}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {14F56CC1-67A1-477F-817C-A0A7B55AE954}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {14F56CC1-67A1-477F-817C-A0A7B55AE954}.Debug|Any CPU.Build.0 = Debug|Any CPU + {14F56CC1-67A1-477F-817C-A0A7B55AE954}.Release|Any CPU.ActiveCfg = Release|Any CPU + {14F56CC1-67A1-477F-817C-A0A7B55AE954}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {DB293C09-A2E4-4179-ADA9-BAE2093F425A} + EndGlobalSection +EndGlobal diff --git a/YTManager/Controllers/ValuesController.cs b/YTManager/Controllers/ValuesController.cs new file mode 100644 index 0000000..2db8751 --- /dev/null +++ b/YTManager/Controllers/ValuesController.cs @@ -0,0 +1,95 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; +using Newtonsoft.Json.Linq; +using Microsoft.EntityFrameworkCore; + +namespace YTManager.Controllers { + [Produces("application/json")] + [Route("api/Admin")] + public class AdminController : Controller { + // POST api/Admin/refreshytvids + [HttpPost("refreshytvids")] + public void Post() { + Hangfire.BackgroundJob.Enqueue(() => YTManager.Tasks.FetchVideos.run()); + } + } + + [Produces("application/json")] + [Route("api/Channels")] + public class ChannelsController : Controller { + private readonly MediaDB _context; + + public ChannelsController(MediaDB context) + { + _context = context; + } + + // GET api/Channels + [HttpGet] + public IEnumerable Get() { + return _context.Channels.ToList(); + } + + // GET api/Channels/5 + [HttpGet("{id}")] + public Models.Channel Get(int id) { + return _context.Channels.Single(m => m.ChannelId == id); + } + + // GET: api/Channels/sdfs6DFS65f/Videos (using YouTube channel ID) + [HttpGet("{id}/Videos")] + public async Task GetVideos([FromRoute] string YTchannelID) { + if (!ModelState.IsValid) + return BadRequest(ModelState); + + // Verify the channel exists. + var Chan = await _context.Channels.SingleOrDefaultAsync(c => c.YTChannelID == YTchannelID); + if (Chan == null) + return NotFound(); + + // Send back the found stuff. + return Ok(_context.Entry(Chan).Collection(c => c.Videos).LoadAsync()); + } + + // POST api/values + [HttpPost] + public IActionResult Post([FromBody]JObject value) { + // Get the channel out of our json body. + Models.Channel posted = value.ToObject(); + + // Verify items aren't empty. + if ((posted.YTChannelID.Length == 0) || (posted.Description.Length == 0) || (posted.Title.Length == 0)) + return BadRequest(); + + // Verify the channel doesn't already exist. + if (_context.Channels.Any(c => c.YTChannelID == posted.YTChannelID)) + return BadRequest(); + + // Seems good, so add it. + _context.Channels.Add(posted); + _context.SaveChanges(); + return Ok(); + } + + // PUT api/values/5 + [HttpPut("{id}")] + public void Put(int id, [FromBody]JObject value) + { + Models.Channel posted = value.ToObject(); + posted.ChannelId = id; // Ensure an id is attached + _context.Channels.Update(posted); + _context.SaveChanges(); + } + + // DELETE api/values/5 + [HttpDelete("{id}")] + public void Delete(int id) + { + _context.Remove(_context.Channels.Single(m => m.ChannelId == id)); + _context.SaveChanges(); + } + } +} diff --git a/YTManager/Controllers/VideosController.cs b/YTManager/Controllers/VideosController.cs new file mode 100644 index 0000000..5f987fb --- /dev/null +++ b/YTManager/Controllers/VideosController.cs @@ -0,0 +1,126 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; +using YTManager; +using YTManager.Models; + +namespace YTManager.Controllers +{ + [Produces("application/json")] + [Route("api/Videos")] + public class VideosController : Controller + { + private readonly MediaDB _context; + + public VideosController(MediaDB context) + { + _context = context; + } + + // GET: api/Videos + [HttpGet] + public IEnumerable