playlist stuff
This commit is contained in:
parent
31cd9b2856
commit
66b0d11415
@ -8,7 +8,7 @@ using NadekoBot.Services.Database.Impl;
|
||||
namespace NadekoBot.Migrations
|
||||
{
|
||||
[DbContext(typeof(NadekoSqliteContext))]
|
||||
[Migration("20160930001917_first")]
|
||||
[Migration("20161001173937_first")]
|
||||
partial class first
|
||||
{
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
@ -357,6 +357,22 @@ namespace NadekoBot.Migrations
|
||||
b.ToTable("ModulePrefixes");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("NadekoBot.Services.Database.Models.MusicPlaylist", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd();
|
||||
|
||||
b.Property<string>("Author");
|
||||
|
||||
b.Property<ulong>("AuthorId");
|
||||
|
||||
b.Property<string>("Name");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("MusicPlaylists");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("NadekoBot.Services.Database.Models.Permission", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
@ -398,6 +414,30 @@ namespace NadekoBot.Migrations
|
||||
b.ToTable("PlayingStatus");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("NadekoBot.Services.Database.Models.PlaylistSong", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd();
|
||||
|
||||
b.Property<int?>("MusicPlaylistId");
|
||||
|
||||
b.Property<string>("Provider");
|
||||
|
||||
b.Property<int>("ProviderType");
|
||||
|
||||
b.Property<string>("Query");
|
||||
|
||||
b.Property<string>("Title");
|
||||
|
||||
b.Property<string>("Uri");
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.HasIndex("MusicPlaylistId");
|
||||
|
||||
b.ToTable("PlaylistSong");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("NadekoBot.Services.Database.Models.Quote", b =>
|
||||
{
|
||||
b.Property<int>("Id")
|
||||
@ -589,6 +629,13 @@ namespace NadekoBot.Migrations
|
||||
.HasForeignKey("BotConfigId");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("NadekoBot.Services.Database.Models.PlaylistSong", b =>
|
||||
{
|
||||
b.HasOne("NadekoBot.Services.Database.Models.MusicPlaylist")
|
||||
.WithMany("Songs")
|
||||
.HasForeignKey("MusicPlaylistId");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("NadekoBot.Services.Database.Models.RaceAnimal", b =>
|
||||
{
|
||||
b.HasOne("NadekoBot.Services.Database.Models.BotConfig")
|
@ -122,6 +122,21 @@ namespace NadekoBot.Migrations
|
||||
table.PrimaryKey("PK_LogSettings", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "MusicPlaylists",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(nullable: false)
|
||||
.Annotation("Autoincrement", true),
|
||||
Author = table.Column<string>(nullable: true),
|
||||
AuthorId = table.Column<ulong>(nullable: false),
|
||||
Name = table.Column<string>(nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_MusicPlaylists", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Permission",
|
||||
columns: table => new
|
||||
@ -390,6 +405,30 @@ namespace NadekoBot.Migrations
|
||||
onDelete: ReferentialAction.Restrict);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "PlaylistSong",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(nullable: false)
|
||||
.Annotation("Autoincrement", true),
|
||||
MusicPlaylistId = table.Column<int>(nullable: true),
|
||||
Provider = table.Column<string>(nullable: true),
|
||||
ProviderType = table.Column<int>(nullable: false),
|
||||
Query = table.Column<string>(nullable: true),
|
||||
Title = table.Column<string>(nullable: true),
|
||||
Uri = table.Column<string>(nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_PlaylistSong", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_PlaylistSong_MusicPlaylists_MusicPlaylistId",
|
||||
column: x => x.MusicPlaylistId,
|
||||
principalTable: "MusicPlaylists",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Restrict);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "GuildConfigs",
|
||||
columns: table => new
|
||||
@ -535,6 +574,11 @@ namespace NadekoBot.Migrations
|
||||
table: "PlayingStatus",
|
||||
column: "BotConfigId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_PlaylistSong_MusicPlaylistId",
|
||||
table: "PlaylistSong",
|
||||
column: "MusicPlaylistId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_RaceAnimals_BotConfigId",
|
||||
table: "RaceAnimals",
|
||||
@ -588,6 +632,9 @@ namespace NadekoBot.Migrations
|
||||
migrationBuilder.DropTable(
|
||||
name: "PlayingStatus");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "PlaylistSong");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Quotes");
|
||||
|
||||
@ -612,6 +659,9 @@ namespace NadekoBot.Migrations
|
||||
migrationBuilder.DropTable(
|
||||
name: "GuildConfigs");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "MusicPlaylists");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "BotConfig");
|
||||
|
@ -571,7 +571,7 @@ namespace NadekoBot.Modules.Music
|
||||
|
||||
if (mpl == null)
|
||||
{
|
||||
await channel.SendMessageAsync("Can't find playlist with that ID").ConfigureAwait(false);
|
||||
await channel.SendMessageAsync("`Can't find playlist with that ID`").ConfigureAwait(false);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -619,26 +619,34 @@ namespace NadekoBot.Modules.Music
|
||||
|
||||
bool success = false;
|
||||
MusicPlaylist pl = null;
|
||||
using (var uow = DbHandler.UnitOfWork())
|
||||
try
|
||||
{
|
||||
pl = uow.MusicPlaylists.Get(id);
|
||||
|
||||
if (pl != null)
|
||||
using (var uow = DbHandler.UnitOfWork())
|
||||
{
|
||||
if (NadekoBot.Credentials.IsOwner(umsg.Author) || pl.AuthorId == umsg.Author.Id)
|
||||
{
|
||||
uow.MusicPlaylists.Remove(pl.Id);
|
||||
await uow.CompleteAsync().ConfigureAwait(false);
|
||||
}
|
||||
else
|
||||
success = false;
|
||||
}
|
||||
}
|
||||
pl = uow.MusicPlaylists.Get(id);
|
||||
|
||||
if (success)
|
||||
await channel.SendMessageAsync("Failed to delete that playlist. It either doesn't exist, or you are not its author.").ConfigureAwait(false);
|
||||
else
|
||||
await channel.SendMessageAsync("`Playlist successfully deleted.`").ConfigureAwait(false);
|
||||
if (pl != null)
|
||||
{
|
||||
if (NadekoBot.Credentials.IsOwner(umsg.Author) || pl.AuthorId == umsg.Author.Id)
|
||||
{
|
||||
uow.MusicPlaylists.Remove(pl);
|
||||
await uow.CompleteAsync().ConfigureAwait(false);
|
||||
success = true;
|
||||
}
|
||||
else
|
||||
success = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!success)
|
||||
await channel.SendMessageAsync("Failed to delete that playlist. It either doesn't exist, or you are not its author.").ConfigureAwait(false);
|
||||
else
|
||||
await channel.SendMessageAsync("`Playlist successfully deleted.`").ConfigureAwait(false);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(ex);
|
||||
}
|
||||
}
|
||||
|
||||
[LocalizedCommand, LocalizedRemarks, LocalizedSummary, LocalizedAlias]
|
||||
|
16
src/NadekoBot/Services/Database/Models/MusicPlaylist.cs
Normal file
16
src/NadekoBot/Services/Database/Models/MusicPlaylist.cs
Normal file
@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NadekoBot.Services.Database.Models
|
||||
{
|
||||
public class MusicPlaylist : DbEntity
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string Author { get; set; }
|
||||
public ulong AuthorId { get; set; }
|
||||
public List<PlaylistSong> Songs { get; set; }
|
||||
}
|
||||
}
|
18
src/NadekoBot/Services/Database/Models/PlaylistSong.cs
Normal file
18
src/NadekoBot/Services/Database/Models/PlaylistSong.cs
Normal file
@ -0,0 +1,18 @@
|
||||
using NadekoBot.Modules.Music.Classes;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NadekoBot.Services.Database.Models
|
||||
{
|
||||
public class PlaylistSong : DbEntity
|
||||
{
|
||||
public string Provider { get; set; }
|
||||
public MusicType ProviderType { get; set; }
|
||||
public string Title { get; set; }
|
||||
public string Uri { get; set; }
|
||||
public string Query { get; set; }
|
||||
}
|
||||
}
|
@ -187,7 +187,7 @@ namespace NadekoBot.Services.Database
|
||||
permissionEntity
|
||||
.HasOne(p => p.Next)
|
||||
.WithOne(p => p.Previous);
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region LogSettings
|
||||
@ -203,6 +203,17 @@ namespace NadekoBot.Services.Database
|
||||
// .HasMany(ls => ls.IgnoredVoicePresenceChannelIds)
|
||||
// .WithOne(ls => ls.LogSetting);
|
||||
#endregion
|
||||
|
||||
#region MusicPlaylists
|
||||
var musicPlaylistEntity = modelBuilder.Entity<MusicPlaylist>();
|
||||
|
||||
musicPlaylistEntity
|
||||
.HasMany<PlaylistSong>(p => p.Songs)
|
||||
.WithOne()
|
||||
.OnDelete(Microsoft.EntityFrameworkCore.Metadata.DeleteBehavior.Cascade);
|
||||
|
||||
|
||||
#endregion
|
||||
}
|
||||
protected abstract override void OnConfiguring(DbContextOptionsBuilder optionsBuilder);
|
||||
}
|
||||
|
@ -0,0 +1,15 @@
|
||||
using NadekoBot.Services.Database.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NadekoBot.Services.Database.Repositories
|
||||
{
|
||||
public interface IMusicPlaylistRepository : IRepository<MusicPlaylist>
|
||||
{
|
||||
List<MusicPlaylist> GetPlaylistsOnPage(int num);
|
||||
MusicPlaylist GetWithSongs(int id);
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
using NadekoBot.Services.Database.Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace NadekoBot.Services.Database.Repositories.Impl
|
||||
{
|
||||
public class MusicPlaylistRepository : Repository<MusicPlaylist>, IMusicPlaylistRepository
|
||||
{
|
||||
public MusicPlaylistRepository(DbContext context) : base(context)
|
||||
{
|
||||
}
|
||||
|
||||
public List<MusicPlaylist> GetPlaylistsOnPage(int num)
|
||||
{
|
||||
if (num < 1)
|
||||
throw new IndexOutOfRangeException();
|
||||
|
||||
return _set.Skip((num - 1) * 20)
|
||||
.Take(20)
|
||||
.Include(pl => pl.Songs)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public MusicPlaylist GetWithSongs(int id) =>
|
||||
_set.Include(mpl => mpl.Songs)
|
||||
.FirstOrDefault(mpl => mpl.Id == id);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user