Huge cleanup and rework pass, postgres now usable too
This commit is contained in:
@ -28,7 +28,7 @@ namespace YTManager.Controllers {
|
||||
// GET api/Channels/5
|
||||
[HttpGet("{YTchannelID}")]
|
||||
public Task<Models.Channel> Get([FromQuery] string YTchannelID) {
|
||||
return db.Channels.SingleOrDefaultAsync(c => c.YTChannelID == YTchannelID);
|
||||
return db.Channels.SingleOrDefaultAsync(c => c.YoutubeID == YTchannelID);
|
||||
}
|
||||
|
||||
// GET: api/Channels/sdfs6DFS65f/Videos (using YouTube channel ID)
|
||||
@ -38,7 +38,7 @@ namespace YTManager.Controllers {
|
||||
return BadRequest(ModelState);
|
||||
|
||||
// Attempt to get the video from the database.
|
||||
var channel = await db.Channels.SingleOrDefaultAsync(m => m.YTChannelID == YTchannelID);
|
||||
var channel = await db.Channels.SingleOrDefaultAsync(m => m.YoutubeID == YTchannelID);
|
||||
|
||||
// If the channel wasn't found then send back not found.
|
||||
if (channel == null)
|
||||
@ -48,6 +48,27 @@ namespace YTManager.Controllers {
|
||||
return Ok(db.Entry(channel).Collection(c => c.Videos).LoadAsync());
|
||||
}
|
||||
|
||||
// POST api/Channels/sdfs6DFS65f
|
||||
[HttpPost("{YTchannelID}")]
|
||||
public async Task<IActionResult> Post([FromRoute] string YTchannelID) {
|
||||
// Check if we were able to parse.
|
||||
if (!ModelState.IsValid) return BadRequest(ModelState);
|
||||
|
||||
// Verify the channel doesn't already exist.
|
||||
if (db.Channels.Any(c => c.YoutubeID == YTchannelID))
|
||||
return BadRequest();
|
||||
|
||||
// Get the channel info.
|
||||
var ch = await Tasks.FetchVideos.Get_YTChannel(YTchannelID);
|
||||
|
||||
// Seems good, so add it.
|
||||
db.Channels.Add(ch);
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
// And all is well.
|
||||
return Ok();
|
||||
}
|
||||
|
||||
// POST api/Channels
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> Post([FromBody] Channel channel) {
|
||||
@ -55,28 +76,25 @@ namespace YTManager.Controllers {
|
||||
if (!ModelState.IsValid) return BadRequest(ModelState);
|
||||
|
||||
// Verify the channel doesn't already exist.
|
||||
if (db.Channels.Any(c => c.YTChannelID == channel.YTChannelID))
|
||||
if (db.Channels.Any(c => c.YoutubeID == channel.YoutubeID))
|
||||
return BadRequest();
|
||||
|
||||
// Seems good, so add it.
|
||||
db.Channels.Add(channel);
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
// Get all new videos for the channel.
|
||||
Hangfire.RecurringJob.Trigger(Startup.periodicupdatejobID);
|
||||
|
||||
// And all is well.
|
||||
return Ok();
|
||||
}
|
||||
|
||||
// DELETE api/Channels/5
|
||||
[HttpDelete("{YTChannelID}")]
|
||||
public async Task<IActionResult> Delete([FromQuery] string YTChannelID) {
|
||||
public async Task<IActionResult> Delete([FromRoute] string YTChannelID) {
|
||||
// Check if we were able to parse.
|
||||
if (!ModelState.IsValid) return BadRequest(ModelState);
|
||||
|
||||
// Attempt to find the channel.
|
||||
var channel = await db.Channels.SingleOrDefaultAsync(c => c.YTChannelID == YTChannelID);
|
||||
var channel = await db.Channels.SingleOrDefaultAsync(c => c.YoutubeID == YTChannelID);
|
||||
|
||||
// Check if such an entry exists already.
|
||||
if (channel == null)
|
||||
|
Reference in New Issue
Block a user