mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-12 10:18:27 -04:00
Removed remind repository
This commit is contained in:
@@ -9,6 +9,7 @@ using NadekoBot.Core.Services;
|
|||||||
using NadekoBot.Core.Services.Database.Models;
|
using NadekoBot.Core.Services.Database.Models;
|
||||||
using NadekoBot.Extensions;
|
using NadekoBot.Extensions;
|
||||||
using NadekoBot.Modules.Administration.Services;
|
using NadekoBot.Modules.Administration.Services;
|
||||||
|
using NadekoBot.Modules.Utility.Common;
|
||||||
using NadekoBot.Modules.Utility.Services;
|
using NadekoBot.Modules.Utility.Services;
|
||||||
|
|
||||||
namespace NadekoBot.Modules.Utility
|
namespace NadekoBot.Modules.Utility
|
||||||
@@ -92,7 +93,7 @@ namespace NadekoBot.Modules.Utility
|
|||||||
List<Reminder> rems;
|
List<Reminder> rems;
|
||||||
using (var uow = _db.GetDbContext())
|
using (var uow = _db.GetDbContext())
|
||||||
{
|
{
|
||||||
rems = uow.Reminders.RemindersFor(ctx.User.Id, page)
|
rems = uow._context.Reminders.RemindersFor(ctx.User.Id, page)
|
||||||
.ToList();
|
.ToList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -130,13 +131,13 @@ namespace NadekoBot.Modules.Utility
|
|||||||
Reminder rem = null;
|
Reminder rem = null;
|
||||||
using (var uow = _db.GetDbContext())
|
using (var uow = _db.GetDbContext())
|
||||||
{
|
{
|
||||||
var rems = uow.Reminders.RemindersFor(ctx.User.Id, index / 10)
|
var rems = uow._context.Reminders.RemindersFor(ctx.User.Id, index / 10)
|
||||||
.ToList();
|
.ToList();
|
||||||
var pageIndex = index % 10;
|
var pageIndex = index % 10;
|
||||||
if (rems.Count > pageIndex)
|
if (rems.Count > pageIndex)
|
||||||
{
|
{
|
||||||
rem = rems[pageIndex];
|
rem = rems[pageIndex];
|
||||||
uow.Reminders.Remove(rem);
|
uow._context.Reminders.Remove(rem);
|
||||||
uow.SaveChanges();
|
uow.SaveChanges();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -179,7 +180,7 @@ namespace NadekoBot.Modules.Utility
|
|||||||
|
|
||||||
using (var uow = _db.GetDbContext())
|
using (var uow = _db.GetDbContext())
|
||||||
{
|
{
|
||||||
uow.Reminders.Add(rem);
|
uow._context.Reminders.Add(rem);
|
||||||
await uow.SaveChangesAsync();
|
await uow.SaveChangesAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -10,7 +10,6 @@ namespace NadekoBot.Core.Services.Database
|
|||||||
|
|
||||||
IQuoteRepository Quotes { get; }
|
IQuoteRepository Quotes { get; }
|
||||||
IGuildConfigRepository GuildConfigs { get; }
|
IGuildConfigRepository GuildConfigs { get; }
|
||||||
IReminderRepository Reminders { get; }
|
|
||||||
ICustomReactionRepository CustomReactions { get; }
|
ICustomReactionRepository CustomReactions { get; }
|
||||||
IMusicPlaylistRepository MusicPlaylists { get; }
|
IMusicPlaylistRepository MusicPlaylists { get; }
|
||||||
IWaifuRepository Waifus { get; }
|
IWaifuRepository Waifus { get; }
|
||||||
|
@@ -1,11 +0,0 @@
|
|||||||
using NadekoBot.Core.Services.Database.Models;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
|
|
||||||
namespace NadekoBot.Core.Services.Database.Repositories
|
|
||||||
{
|
|
||||||
public interface IReminderRepository : IRepository<Reminder>
|
|
||||||
{
|
|
||||||
IEnumerable<Reminder> GetIncludedReminders(IEnumerable<ulong> guildIds);
|
|
||||||
IEnumerable<Reminder> RemindersFor(ulong userId, int page);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -3,26 +3,20 @@ using Microsoft.EntityFrameworkCore;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
namespace NadekoBot.Core.Services.Database.Repositories.Impl
|
namespace NadekoBot.Modules.Utility.Common
|
||||||
{
|
{
|
||||||
public class ReminderRepository : Repository<Reminder>, IReminderRepository
|
public static class ReminderExtensions
|
||||||
{
|
{
|
||||||
public ReminderRepository(DbContext context) : base(context)
|
public static IEnumerable<Reminder> GetIncludedReminders(this DbSet<Reminder> reminders, IEnumerable<ulong> guildIds)
|
||||||
{
|
=> reminders.AsQueryable()
|
||||||
}
|
.Where(x => guildIds.Contains(x.ServerId) || x.ServerId == 0)
|
||||||
|
.ToList();
|
||||||
|
|
||||||
public IEnumerable<Reminder> GetIncludedReminders(IEnumerable<ulong> guildIds)
|
public static IEnumerable<Reminder> RemindersFor(this DbSet<Reminder> reminders, ulong userId, int page)
|
||||||
{
|
=> reminders.AsQueryable()
|
||||||
return _set.AsQueryable().Where(x => guildIds.Contains(x.ServerId) || x.ServerId == 0).ToList();
|
|
||||||
}
|
|
||||||
|
|
||||||
public IEnumerable<Reminder> RemindersFor(ulong userId, int page)
|
|
||||||
{
|
|
||||||
return _set.AsQueryable()
|
|
||||||
.Where(x => x.UserId == userId)
|
.Where(x => x.UserId == userId)
|
||||||
.OrderBy(x => x.DateAdded)
|
.OrderBy(x => x.DateAdded)
|
||||||
.Skip(page * 10)
|
.Skip(page * 10)
|
||||||
.Take(10);
|
.Take(10);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -15,9 +15,6 @@ namespace NadekoBot.Core.Services.Database
|
|||||||
private IGuildConfigRepository _guildConfigs;
|
private IGuildConfigRepository _guildConfigs;
|
||||||
public IGuildConfigRepository GuildConfigs => _guildConfigs ?? (_guildConfigs = new GuildConfigRepository(_context));
|
public IGuildConfigRepository GuildConfigs => _guildConfigs ?? (_guildConfigs = new GuildConfigRepository(_context));
|
||||||
|
|
||||||
private IReminderRepository _reminders;
|
|
||||||
public IReminderRepository Reminders => _reminders ?? (_reminders = new ReminderRepository(_context));
|
|
||||||
|
|
||||||
private IMusicPlaylistRepository _musicPlaylists;
|
private IMusicPlaylistRepository _musicPlaylists;
|
||||||
public IMusicPlaylistRepository MusicPlaylists => _musicPlaylists ?? (_musicPlaylists = new MusicPlaylistRepository(_context));
|
public IMusicPlaylistRepository MusicPlaylists => _musicPlaylists ?? (_musicPlaylists = new MusicPlaylistRepository(_context));
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user