mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-10 09: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.Extensions;
|
||||
using NadekoBot.Modules.Administration.Services;
|
||||
using NadekoBot.Modules.Utility.Common;
|
||||
using NadekoBot.Modules.Utility.Services;
|
||||
|
||||
namespace NadekoBot.Modules.Utility
|
||||
@@ -92,7 +93,7 @@ namespace NadekoBot.Modules.Utility
|
||||
List<Reminder> rems;
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
rems = uow.Reminders.RemindersFor(ctx.User.Id, page)
|
||||
rems = uow._context.Reminders.RemindersFor(ctx.User.Id, page)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
@@ -130,13 +131,13 @@ namespace NadekoBot.Modules.Utility
|
||||
Reminder rem = null;
|
||||
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();
|
||||
var pageIndex = index % 10;
|
||||
if (rems.Count > pageIndex)
|
||||
{
|
||||
rem = rems[pageIndex];
|
||||
uow.Reminders.Remove(rem);
|
||||
uow._context.Reminders.Remove(rem);
|
||||
uow.SaveChanges();
|
||||
}
|
||||
}
|
||||
@@ -179,7 +180,7 @@ namespace NadekoBot.Modules.Utility
|
||||
|
||||
using (var uow = _db.GetDbContext())
|
||||
{
|
||||
uow.Reminders.Add(rem);
|
||||
uow._context.Reminders.Add(rem);
|
||||
await uow.SaveChangesAsync();
|
||||
}
|
||||
|
||||
|
@@ -10,7 +10,6 @@ namespace NadekoBot.Core.Services.Database
|
||||
|
||||
IQuoteRepository Quotes { get; }
|
||||
IGuildConfigRepository GuildConfigs { get; }
|
||||
IReminderRepository Reminders { get; }
|
||||
ICustomReactionRepository CustomReactions { get; }
|
||||
IMusicPlaylistRepository MusicPlaylists { 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.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)
|
||||
{
|
||||
return _set.AsQueryable().Where(x => guildIds.Contains(x.ServerId) || x.ServerId == 0).ToList();
|
||||
}
|
||||
|
||||
public IEnumerable<Reminder> RemindersFor(ulong userId, int page)
|
||||
{
|
||||
return _set.AsQueryable()
|
||||
public static IEnumerable<Reminder> RemindersFor(this DbSet<Reminder> reminders, ulong userId, int page)
|
||||
=> reminders.AsQueryable()
|
||||
.Where(x => x.UserId == userId)
|
||||
.OrderBy(x => x.DateAdded)
|
||||
.Skip(page * 10)
|
||||
.Take(10);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -15,9 +15,6 @@ namespace NadekoBot.Core.Services.Database
|
||||
private IGuildConfigRepository _guildConfigs;
|
||||
public IGuildConfigRepository GuildConfigs => _guildConfigs ?? (_guildConfigs = new GuildConfigRepository(_context));
|
||||
|
||||
private IReminderRepository _reminders;
|
||||
public IReminderRepository Reminders => _reminders ?? (_reminders = new ReminderRepository(_context));
|
||||
|
||||
private IMusicPlaylistRepository _musicPlaylists;
|
||||
public IMusicPlaylistRepository MusicPlaylists => _musicPlaylists ?? (_musicPlaylists = new MusicPlaylistRepository(_context));
|
||||
|
||||
|
Reference in New Issue
Block a user