diff --git a/YTManager/Controllers/Admin.cs b/YTManager/Controllers/Admin.cs index 3c17eae..89625cc 100644 --- a/YTManager/Controllers/Admin.cs +++ b/YTManager/Controllers/Admin.cs @@ -53,14 +53,5 @@ namespace YTManager.Controllers { public IActionResult Get_Update_Status() { return Ok(get_massupdatedaemon() == null ? "false" : "true"); } - - // Testing - [HttpGet("Test")] - public async System.Threading.Tasks.Task Test() { - // await Tasks.FetchVideos.MassUpdate(Startup.DBStr); - // var vids = Tasks.FetchVideos.Get_YTVideos("UCsXVk37bltHxD1rDPwtNM8Q", 1).Result; - // return Ok(vids); - return Ok(); - } } } diff --git a/YTManager/Controllers/Channels.cs b/YTManager/Controllers/Channels.cs index fc5b0f5..ac8f802 100644 --- a/YTManager/Controllers/Channels.cs +++ b/YTManager/Controllers/Channels.cs @@ -1,14 +1,13 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; -using Microsoft.AspNetCore.Cors; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; +using System; namespace YTManager.Controllers { [Produces("application/json")] [Route("api/Channels")] - [EnableCors("AllowAllOrigins")] public class ChannelsController : Controller { // Custom return type for API accesses. Done this way to ensure we // always return the expected data regardless of the underlying model. @@ -16,6 +15,7 @@ namespace YTManager.Controllers { public string Title; public string Description; public string ID; + public List User_Tags; public List Video_IDs; public Channel_ForAPI(Models.Channel c) { @@ -23,6 +23,7 @@ namespace YTManager.Controllers { Description = c.Description; ID = c.YoutubeID; Video_IDs = c.Videos.Select(v => v.YoutubeID).ToList(); + User_Tags = c.UserTags == null ? new List() : c.UserTags.ToList(); } } @@ -38,6 +39,9 @@ namespace YTManager.Controllers { // Returns the most recently added channels. [HttpGet] public async Task Get() { + // Log this to the terminal. + Console.WriteLine($"{DateTime.Now} == Channels GET"); + // Get all the relevant channels. var chanels = await db.Channels .Include(c => c.Videos) @@ -53,5 +57,29 @@ namespace YTManager.Controllers { // Convert all the videos to what we will send back. return Ok(converted); } + + [HttpPost("{channelid}")] + public async Task PostChannel([FromRoute] string channelid) { + Console.WriteLine($"{DateTime.Now} == Channels POST -> {channelid}"); + + // Verify the channel looks resonable. + var expected_len = "UCyS4xQE6DK4_p3qXQwJQAyA".Length; + if (channelid.Length != expected_len) + return BadRequest($"Length should be {expected_len} but is {channelid.Length}"); + + // Only add it to the databse if it's not in there already. + if (db.Channels.Any(c => c.YoutubeID == channelid)) + return BadRequest($"Channel {channelid} is already in DB!"); + + // Get the channel contents from youtube. + var channel = await Tasks.FetchVideos.Get_YTChannel(channelid); + + // Add it to the databse. + await db.Channels.AddAsync(channel); + await db.SaveChangesAsync(); + + // Say all went ok. + return Ok(); + } } } diff --git a/YTManager/Controllers/Raw/Private_Channel.cs b/YTManager/Controllers/Raw/Private_Channel.cs index 09ad568..d31051b 100644 --- a/YTManager/Controllers/Raw/Private_Channel.cs +++ b/YTManager/Controllers/Raw/Private_Channel.cs @@ -82,23 +82,6 @@ namespace YTManager.Controllers.Private return NoContent(); } - [HttpPost("{channelid}")] - public async Task PostChannel([FromRoute] string channelid) { - // Only add it to the databse if it's not in there already. - if (db.Channels.Any(c => c.YoutubeID == channelid)) - return BadRequest(); - - // Get the channel contents from youtube. - var channel = await Tasks.FetchVideos.Get_YTChannel(channelid); - - // Add it to the databse. - await db.Channels.AddAsync(channel); - await db.SaveChangesAsync(); - - // Say all went ok. - return Ok(channel); - } - [HttpPost] public async Task PostChannel([FromBody] Channel channel) { diff --git a/YTManager/Controllers/Videos.cs b/YTManager/Controllers/Videos.cs index 512d626..54937c8 100644 --- a/YTManager/Controllers/Videos.cs +++ b/YTManager/Controllers/Videos.cs @@ -3,14 +3,12 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using System.Xml; -using Microsoft.AspNetCore.Cors; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; namespace YTManager.Controllers { [Produces("application/json")] [Route("api/Videos")] - [EnableCors("AllowAllOrigins")] public class VideosController : Controller { // Custom return type for API accesses. Done this way to ensure we // always return the expected data regardless of the underlying model. @@ -44,7 +42,7 @@ namespace YTManager.Controllers { Thumbnail = video.ThumbnailURL; Channel = video.Channel.Title; Seconds = (int)video.Duration.TotalSeconds; - Tags = video.Tags?.Select(t => t.Name).ToList(); + Tags = video.Tags == null ? new List() : video.Tags.ToList(); } } @@ -57,31 +55,7 @@ namespace YTManager.Controllers { // Constructor to fetch the db context. public VideosController(MediaDB context) => db = context; - // Returns the most recent videos. - [HttpGet] - public async Task GetVideos() { - // Get all the relevant videos. - var vids = await db.Videos - .OrderByDescending(i => i.AddedToYT) - .Take(max_per_query) - .Include(v => v.Channel) - .Include(v => v.Tags) - .ToListAsync(); - - // Convert them to what we will send out. - var converted = vids - .Select(v => new Video_ForAPI(v)) - .ToList(); - - // Convert all the videos to what we will send back. - return Ok(converted); - } - - struct Search_Query - { - // Tags. - public List Tags; - + struct Search_Query { // What the duration type is. public enum _Duration_Type { LessThan, GreaterThan, Unset }; public _Duration_Type Duration_Type; @@ -92,11 +66,27 @@ namespace YTManager.Controllers { // Remaining tokens. public List Remaining_Tokens; } - // Searches for videos using the specified tag(s). - [HttpGet("search/{searchstr}")] + [HttpGet] + public async Task Search() { + var converted = await db.Videos + .OrderByDescending(i => i.AddedToYT) + .Take(max_per_query) + .Include(v => v.Channel) + .Select(v => new Video_ForAPI(v)) + .ToListAsync(); + + // Convert all the videos to what we will send back. + return Ok(converted); + } + + // Searches for videos using the specified tag(s). + [HttpGet("{searchstr}")] public async Task Search([FromRoute] string searchstr) { + // Log this to the terminal. + Console.WriteLine($"{DateTime.Now} == Search request for -> {searchstr}."); + // What to use for searching videos with. var parsed_query = new Search_Query(); @@ -128,12 +118,6 @@ namespace YTManager.Controllers { } } - // Find which tokens are explicit tags - parsed_query.Tags = await db.Tags - .Where(t => parsed_query.Remaining_Tokens.Any(token => token == t.Name.ToLower())) - .ToListAsync(); - parsed_query.Tags.ForEach(tag => parsed_query.Remaining_Tokens.Remove(tag.Name.ToLower())); - // Get from the database all videos which satisfy the query via // AND'ing all the queries. var dbquery = db.Videos.Select(v => v); @@ -144,16 +128,14 @@ namespace YTManager.Controllers { else if (parsed_query.Duration_Type == Search_Query._Duration_Type.LessThan) dbquery = dbquery.Where(v => v.Duration <= parsed_query.Duration); - // Match videos where the tag matches. - parsed_query.Tags.ForEach(tag => dbquery = dbquery.Where(V => V.Tags.Any(vt => vt.Name == tag.Name))); - // Get all videos that match their title, description, or channel name // with the remaining tokens. parsed_query.Remaining_Tokens.ForEach(token => { dbquery = dbquery.Where(v => v.Channel.Title.ToLower().Contains(token) || v.Title.ToLower().Contains(token) || - v.Description.ToLower().Contains(token)); + v.Description.ToLower().Contains(token) || + v.YoutubeID.ToLower().Contains(token)); }); // Get all the relevant videos. @@ -161,7 +143,6 @@ namespace YTManager.Controllers { .OrderByDescending(i => i.AddedToYT) .Take(max_per_query) .Include(v => v.Channel) - .Include(v => v.Tags) .ToListAsync(); // Convert them to what we will send out. @@ -169,26 +150,8 @@ namespace YTManager.Controllers { .Select(v => new Video_ForAPI(v)) .ToList(); - // Convert all the videos to what we will send back. - return Ok(converted); - } - - // Returns the most recent videos of a channel. - [HttpGet("fromchannel/{channelName}")] - public async Task Get_Channel_Videos([FromRoute] string channelName) { - // Get all the relevant videos. - var vids = await db.Videos - .Where(v => v.Channel.Title == channelName) - .OrderByDescending(i => i.AddedToYT) - .Take(max_per_query) - .Include(v => v.Channel) - .Include(v => v.Tags) - .ToListAsync(); - - // Convert them to what we will send out. - var converted = vids - .Select(v => new Video_ForAPI(v)) - .ToList(); + // Log this to the terminal. + Console.WriteLine($"{DateTime.Now} == Search request for -> {searchstr} found {converted.Count()} videos."); // Convert all the videos to what we will send back. return Ok(converted); diff --git a/YTManager/MediaDB.cs b/YTManager/MediaDB.cs index d62c90c..8af8844 100644 --- a/YTManager/MediaDB.cs +++ b/YTManager/MediaDB.cs @@ -6,7 +6,6 @@ namespace YTManager { public DbSet Channels { get; set; } public DbSet Videos { get; set; } - public DbSet Tags { get; set; } public MediaDB(DbContextOptions options) : base(options){ } diff --git a/YTManager/Migrations/20180224055707_fix_channel_relationship.cs b/YTManager/Migrations/20180224055707_fix_channel_relationship.cs deleted file mode 100644 index feb301c..0000000 --- a/YTManager/Migrations/20180224055707_fix_channel_relationship.cs +++ /dev/null @@ -1,82 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; -using System; -using System.Collections.Generic; - -namespace YTManager.Migrations -{ - public partial class fix_channel_relationship : Migration - { - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropForeignKey( - name: "FK_Videos_Channels_ChannelPrimaryKey", - table: "Videos"); - - migrationBuilder.AlterColumn( - name: "ChannelPrimaryKey", - table: "Videos", - nullable: false, - oldClrType: typeof(long), - oldNullable: true); - - migrationBuilder.AddColumn( - name: "VideoPrimaryKey", - table: "Tags", - nullable: true); - - migrationBuilder.CreateIndex( - name: "IX_Tags_VideoPrimaryKey", - table: "Tags", - column: "VideoPrimaryKey"); - - migrationBuilder.AddForeignKey( - name: "FK_Tags_Videos_VideoPrimaryKey", - table: "Tags", - column: "VideoPrimaryKey", - principalTable: "Videos", - principalColumn: "PrimaryKey", - onDelete: ReferentialAction.Restrict); - - migrationBuilder.AddForeignKey( - name: "FK_Videos_Channels_ChannelPrimaryKey", - table: "Videos", - column: "ChannelPrimaryKey", - principalTable: "Channels", - principalColumn: "PrimaryKey", - onDelete: ReferentialAction.Cascade); - } - - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropForeignKey( - name: "FK_Tags_Videos_VideoPrimaryKey", - table: "Tags"); - - migrationBuilder.DropForeignKey( - name: "FK_Videos_Channels_ChannelPrimaryKey", - table: "Videos"); - - migrationBuilder.DropIndex( - name: "IX_Tags_VideoPrimaryKey", - table: "Tags"); - - migrationBuilder.DropColumn( - name: "VideoPrimaryKey", - table: "Tags"); - - migrationBuilder.AlterColumn( - name: "ChannelPrimaryKey", - table: "Videos", - nullable: true, - oldClrType: typeof(long)); - - migrationBuilder.AddForeignKey( - name: "FK_Videos_Channels_ChannelPrimaryKey", - table: "Videos", - column: "ChannelPrimaryKey", - principalTable: "Channels", - principalColumn: "PrimaryKey", - onDelete: ReferentialAction.Restrict); - } - } -} diff --git a/YTManager/Migrations/20180228202611_added_vid_duration.cs b/YTManager/Migrations/20180228202611_added_vid_duration.cs deleted file mode 100644 index 77256fc..0000000 --- a/YTManager/Migrations/20180228202611_added_vid_duration.cs +++ /dev/null @@ -1,25 +0,0 @@ -using Microsoft.EntityFrameworkCore.Migrations; -using System; -using System.Collections.Generic; - -namespace YTManager.Migrations -{ - public partial class added_vid_duration : Migration - { - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.AddColumn( - name: "Duration", - table: "Videos", - nullable: false, - defaultValue: "00:00:00"); - } - - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropColumn( - name: "Duration", - table: "Videos"); - } - } -} diff --git a/YTManager/Migrations/20180224051602_initial.Designer.cs b/YTManager/Migrations/20180304034317_initial.Designer.cs similarity index 82% rename from YTManager/Migrations/20180224051602_initial.Designer.cs rename to YTManager/Migrations/20180304034317_initial.Designer.cs index d85b0db..cab3af1 100644 --- a/YTManager/Migrations/20180224051602_initial.Designer.cs +++ b/YTManager/Migrations/20180304034317_initial.Designer.cs @@ -6,12 +6,13 @@ using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Storage; using Microsoft.EntityFrameworkCore.Storage.Internal; using System; +using System.Collections.Generic; using YTManager; namespace YTManager.Migrations { [DbContext(typeof(MediaDB))] - [Migration("20180224051602_initial")] + [Migration("20180304034317_initial")] partial class initial { protected override void BuildTargetModel(ModelBuilder modelBuilder) @@ -39,6 +40,8 @@ namespace YTManager.Migrations b.Property("Title") .IsRequired(); + b.Property>("UserTags"); + b.Property("YoutubeID") .IsRequired(); @@ -47,19 +50,6 @@ namespace YTManager.Migrations b.ToTable("Channels"); }); - modelBuilder.Entity("YTManager.Models.Tag", b => - { - b.Property("PrimaryKey") - .ValueGeneratedOnAdd(); - - b.Property("Name") - .IsRequired(); - - b.HasKey("PrimaryKey"); - - b.ToTable("Tags"); - }); - modelBuilder.Entity("YTManager.Models.Video", b => { b.Property("PrimaryKey") @@ -69,11 +59,16 @@ namespace YTManager.Migrations b.Property("AddedtoDB"); - b.Property("ChannelPrimaryKey"); + b.Property("ChannelPrimaryKey"); b.Property("Description") .IsRequired(); + b.Property("Duration"); + + b.Property>("Tags") + .IsRequired(); + b.Property("ThumbnailURL") .IsRequired(); @@ -92,9 +87,10 @@ namespace YTManager.Migrations modelBuilder.Entity("YTManager.Models.Video", b => { - b.HasOne("YTManager.Models.Channel") + b.HasOne("YTManager.Models.Channel", "Channel") .WithMany("Videos") - .HasForeignKey("ChannelPrimaryKey"); + .HasForeignKey("ChannelPrimaryKey") + .OnDelete(DeleteBehavior.Cascade); }); #pragma warning restore 612, 618 } diff --git a/YTManager/Migrations/20180224051602_initial.cs b/YTManager/Migrations/20180304034317_initial.cs similarity index 80% rename from YTManager/Migrations/20180224051602_initial.cs rename to YTManager/Migrations/20180304034317_initial.cs index ad2b941..613a523 100644 --- a/YTManager/Migrations/20180224051602_initial.cs +++ b/YTManager/Migrations/20180304034317_initial.cs @@ -20,6 +20,7 @@ namespace YTManager.Migrations Refreshed = table.Column(nullable: false), ThumbnailURL = table.Column(nullable: false), Title = table.Column(nullable: false), + UserTags = table.Column>(nullable: true), YoutubeID = table.Column(nullable: false) }, constraints: table => @@ -27,19 +28,6 @@ namespace YTManager.Migrations table.PrimaryKey("PK_Channels", x => x.PrimaryKey); }); - migrationBuilder.CreateTable( - name: "Tags", - columns: table => new - { - PrimaryKey = table.Column(nullable: false) - .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn), - Name = table.Column(nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Tags", x => x.PrimaryKey); - }); - migrationBuilder.CreateTable( name: "Videos", columns: table => new @@ -48,8 +36,10 @@ namespace YTManager.Migrations .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn), AddedToYT = table.Column(nullable: false), AddedtoDB = table.Column(nullable: false), - ChannelPrimaryKey = table.Column(nullable: true), + ChannelPrimaryKey = table.Column(nullable: false), Description = table.Column(nullable: false), + Duration = table.Column(nullable: false), + Tags = table.Column>(nullable: false), ThumbnailURL = table.Column(nullable: false), Title = table.Column(nullable: false), YoutubeID = table.Column(nullable: false) @@ -62,7 +52,7 @@ namespace YTManager.Migrations column: x => x.ChannelPrimaryKey, principalTable: "Channels", principalColumn: "PrimaryKey", - onDelete: ReferentialAction.Restrict); + onDelete: ReferentialAction.Cascade); }); migrationBuilder.CreateIndex( @@ -73,9 +63,6 @@ namespace YTManager.Migrations protected override void Down(MigrationBuilder migrationBuilder) { - migrationBuilder.DropTable( - name: "Tags"); - migrationBuilder.DropTable( name: "Videos"); diff --git a/YTManager/Migrations/20180228202611_added_vid_duration.Designer.cs b/YTManager/Migrations/20180305045634_Tag change.Designer.cs similarity index 78% rename from YTManager/Migrations/20180228202611_added_vid_duration.Designer.cs rename to YTManager/Migrations/20180305045634_Tag change.Designer.cs index b8811d6..f3337d7 100644 --- a/YTManager/Migrations/20180228202611_added_vid_duration.Designer.cs +++ b/YTManager/Migrations/20180305045634_Tag change.Designer.cs @@ -6,13 +6,14 @@ using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Storage; using Microsoft.EntityFrameworkCore.Storage.Internal; using System; +using System.Collections.Generic; using YTManager; namespace YTManager.Migrations { [DbContext(typeof(MediaDB))] - [Migration("20180228202611_added_vid_duration")] - partial class added_vid_duration + [Migration("20180305045634_Tag change")] + partial class Tagchange { protected override void BuildTargetModel(ModelBuilder modelBuilder) { @@ -39,6 +40,8 @@ namespace YTManager.Migrations b.Property("Title") .IsRequired(); + b.Property>("UserTags"); + b.Property("YoutubeID") .IsRequired(); @@ -47,23 +50,6 @@ namespace YTManager.Migrations b.ToTable("Channels"); }); - modelBuilder.Entity("YTManager.Models.Tag", b => - { - b.Property("PrimaryKey") - .ValueGeneratedOnAdd(); - - b.Property("Name") - .IsRequired(); - - b.Property("VideoPrimaryKey"); - - b.HasKey("PrimaryKey"); - - b.HasIndex("VideoPrimaryKey"); - - b.ToTable("Tags"); - }); - modelBuilder.Entity("YTManager.Models.Video", b => { b.Property("PrimaryKey") @@ -80,6 +66,9 @@ namespace YTManager.Migrations b.Property("Duration"); + b.Property>("Tags") + .IsRequired(); + b.Property("ThumbnailURL") .IsRequired(); @@ -96,13 +85,6 @@ namespace YTManager.Migrations b.ToTable("Videos"); }); - modelBuilder.Entity("YTManager.Models.Tag", b => - { - b.HasOne("YTManager.Models.Video") - .WithMany("Tags") - .HasForeignKey("VideoPrimaryKey"); - }); - modelBuilder.Entity("YTManager.Models.Video", b => { b.HasOne("YTManager.Models.Channel", "Channel") diff --git a/YTManager/Migrations/20180305045634_Tag change.cs b/YTManager/Migrations/20180305045634_Tag change.cs new file mode 100644 index 0000000..ef414ef --- /dev/null +++ b/YTManager/Migrations/20180305045634_Tag change.cs @@ -0,0 +1,19 @@ +using Microsoft.EntityFrameworkCore.Migrations; +using System; +using System.Collections.Generic; + +namespace YTManager.Migrations +{ + public partial class Tagchange : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + + } + } +} diff --git a/YTManager/Migrations/20180224055707_fix_channel_relationship.Designer.cs b/YTManager/Migrations/20180305052950_Made tags required.Designer.cs similarity index 77% rename from YTManager/Migrations/20180224055707_fix_channel_relationship.Designer.cs rename to YTManager/Migrations/20180305052950_Made tags required.Designer.cs index b50b353..ca16736 100644 --- a/YTManager/Migrations/20180224055707_fix_channel_relationship.Designer.cs +++ b/YTManager/Migrations/20180305052950_Made tags required.Designer.cs @@ -6,13 +6,14 @@ using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.EntityFrameworkCore.Storage; using Microsoft.EntityFrameworkCore.Storage.Internal; using System; +using System.Collections.Generic; using YTManager; namespace YTManager.Migrations { [DbContext(typeof(MediaDB))] - [Migration("20180224055707_fix_channel_relationship")] - partial class fix_channel_relationship + [Migration("20180305052950_Made tags required")] + partial class Madetagsrequired { protected override void BuildTargetModel(ModelBuilder modelBuilder) { @@ -39,6 +40,9 @@ namespace YTManager.Migrations b.Property("Title") .IsRequired(); + b.Property("UserTags") + .IsRequired(); + b.Property("YoutubeID") .IsRequired(); @@ -47,23 +51,6 @@ namespace YTManager.Migrations b.ToTable("Channels"); }); - modelBuilder.Entity("YTManager.Models.Tag", b => - { - b.Property("PrimaryKey") - .ValueGeneratedOnAdd(); - - b.Property("Name") - .IsRequired(); - - b.Property("VideoPrimaryKey"); - - b.HasKey("PrimaryKey"); - - b.HasIndex("VideoPrimaryKey"); - - b.ToTable("Tags"); - }); - modelBuilder.Entity("YTManager.Models.Video", b => { b.Property("PrimaryKey") @@ -78,6 +65,11 @@ namespace YTManager.Migrations b.Property("Description") .IsRequired(); + b.Property("Duration"); + + b.Property>("Tags") + .IsRequired(); + b.Property("ThumbnailURL") .IsRequired(); @@ -94,13 +86,6 @@ namespace YTManager.Migrations b.ToTable("Videos"); }); - modelBuilder.Entity("YTManager.Models.Tag", b => - { - b.HasOne("YTManager.Models.Video") - .WithMany("Tags") - .HasForeignKey("VideoPrimaryKey"); - }); - modelBuilder.Entity("YTManager.Models.Video", b => { b.HasOne("YTManager.Models.Channel", "Channel") diff --git a/YTManager/Migrations/20180305052950_Made tags required.cs b/YTManager/Migrations/20180305052950_Made tags required.cs new file mode 100644 index 0000000..dd05956 --- /dev/null +++ b/YTManager/Migrations/20180305052950_Made tags required.cs @@ -0,0 +1,28 @@ +using Microsoft.EntityFrameworkCore.Migrations; +using System; +using System.Collections.Generic; + +namespace YTManager.Migrations +{ + public partial class Madetagsrequired : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AlterColumn( + name: "UserTags", + table: "Channels", + nullable: false, + oldClrType: typeof(List), + oldNullable: true); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.AlterColumn>( + name: "UserTags", + table: "Channels", + nullable: true, + oldClrType: typeof(string[])); + } + } +} diff --git a/YTManager/Migrations/20180305055427_Fixed videos tags.Designer.cs b/YTManager/Migrations/20180305055427_Fixed videos tags.Designer.cs new file mode 100644 index 0000000..196c33e --- /dev/null +++ b/YTManager/Migrations/20180305055427_Fixed videos tags.Designer.cs @@ -0,0 +1,98 @@ +// +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage; +using Microsoft.EntityFrameworkCore.Storage.Internal; +using System; +using YTManager; + +namespace YTManager.Migrations +{ + [DbContext(typeof(MediaDB))] + [Migration("20180305055427_Fixed videos tags")] + partial class Fixedvideostags + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.SerialColumn) + .HasAnnotation("ProductVersion", "2.0.1-rtm-125"); + + modelBuilder.Entity("YTManager.Models.Channel", b => + { + b.Property("PrimaryKey") + .ValueGeneratedOnAdd(); + + b.Property("AddedtoDB"); + + b.Property("Description") + .IsRequired(); + + b.Property("Refreshed"); + + b.Property("ThumbnailURL") + .IsRequired(); + + b.Property("Title") + .IsRequired(); + + b.Property("UserTags") + .IsRequired(); + + b.Property("YoutubeID") + .IsRequired(); + + b.HasKey("PrimaryKey"); + + b.ToTable("Channels"); + }); + + modelBuilder.Entity("YTManager.Models.Video", b => + { + b.Property("PrimaryKey") + .ValueGeneratedOnAdd(); + + b.Property("AddedToYT"); + + b.Property("AddedtoDB"); + + b.Property("ChannelPrimaryKey"); + + b.Property("Description") + .IsRequired(); + + b.Property("Duration"); + + b.Property("Tags") + .IsRequired(); + + b.Property("ThumbnailURL") + .IsRequired(); + + b.Property("Title") + .IsRequired(); + + b.Property("YoutubeID") + .IsRequired(); + + b.HasKey("PrimaryKey"); + + b.HasIndex("ChannelPrimaryKey"); + + b.ToTable("Videos"); + }); + + modelBuilder.Entity("YTManager.Models.Video", b => + { + b.HasOne("YTManager.Models.Channel", "Channel") + .WithMany("Videos") + .HasForeignKey("ChannelPrimaryKey") + .OnDelete(DeleteBehavior.Cascade); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/YTManager/Migrations/20180305055427_Fixed videos tags.cs b/YTManager/Migrations/20180305055427_Fixed videos tags.cs new file mode 100644 index 0000000..19b58bf --- /dev/null +++ b/YTManager/Migrations/20180305055427_Fixed videos tags.cs @@ -0,0 +1,19 @@ +using Microsoft.EntityFrameworkCore.Migrations; +using System; +using System.Collections.Generic; + +namespace YTManager.Migrations +{ + public partial class Fixedvideostags : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + + } + } +} diff --git a/YTManager/Migrations/MediaDBModelSnapshot.cs b/YTManager/Migrations/MediaDBModelSnapshot.cs index 9cbb35d..db62a9a 100644 --- a/YTManager/Migrations/MediaDBModelSnapshot.cs +++ b/YTManager/Migrations/MediaDBModelSnapshot.cs @@ -38,6 +38,9 @@ namespace YTManager.Migrations b.Property("Title") .IsRequired(); + b.Property("UserTags") + .IsRequired(); + b.Property("YoutubeID") .IsRequired(); @@ -46,23 +49,6 @@ namespace YTManager.Migrations b.ToTable("Channels"); }); - modelBuilder.Entity("YTManager.Models.Tag", b => - { - b.Property("PrimaryKey") - .ValueGeneratedOnAdd(); - - b.Property("Name") - .IsRequired(); - - b.Property("VideoPrimaryKey"); - - b.HasKey("PrimaryKey"); - - b.HasIndex("VideoPrimaryKey"); - - b.ToTable("Tags"); - }); - modelBuilder.Entity("YTManager.Models.Video", b => { b.Property("PrimaryKey") @@ -79,6 +65,9 @@ namespace YTManager.Migrations b.Property("Duration"); + b.Property("Tags") + .IsRequired(); + b.Property("ThumbnailURL") .IsRequired(); @@ -95,13 +84,6 @@ namespace YTManager.Migrations b.ToTable("Videos"); }); - modelBuilder.Entity("YTManager.Models.Tag", b => - { - b.HasOne("YTManager.Models.Video") - .WithMany("Tags") - .HasForeignKey("VideoPrimaryKey"); - }); - modelBuilder.Entity("YTManager.Models.Video", b => { b.HasOne("YTManager.Models.Channel", "Channel") diff --git a/YTManager/Models/Channel.cs b/YTManager/Models/Channel.cs index a50fbed..9ca540a 100644 --- a/YTManager/Models/Channel.cs +++ b/YTManager/Models/Channel.cs @@ -33,6 +33,11 @@ namespace YTManager.Models { public DateTime Refreshed { get; set; } // Videos this channel has. + [Required] public List