Skip to content

Commit

Permalink
T #98 added paginator reminder implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
HueByte committed Oct 9, 2022
1 parent 4daf945 commit 7f16552
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
3 changes: 0 additions & 3 deletions src/Huppy/Huppy.Core/Services/Reminder/ReminderService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@
using Discord.Interactions;
using Discord.WebSocket;
using Huppy.Core.Entities;
using Huppy.Core.Interfaces.IRepositories;
using Huppy.Core.Interfaces.IServices;
using Huppy.Core.Utilities;
using Huppy.Kernel.Constants;
using HuppyService.Service.Protos;
using HuppyService.Service.Protos.Models;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Internal;
using Microsoft.Extensions.Logging;

namespace Huppy.Core.Services.Reminder;
Expand Down
39 changes: 24 additions & 15 deletions src/HuppyService/HuppyService.Service/Services/ReminderService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using HuppyService.Core.Interfaces.IRepositories;
using HuppyService.Core.Models;
using HuppyService.Core.Utilities;
using HuppyService.Infrastructure.Repositories;
using HuppyService.Service.Protos;
using HuppyService.Service.Protos.Models;
using Microsoft.EntityFrameworkCore;
Expand All @@ -18,6 +19,28 @@ public ReminderService(IReminderRepository reminderRepository, ILogger<ReminderS
_logger = logger;
}

public override async Task<ReminderModelCollection> GetSortedUserReminders(SortedUserRemindersInput request, ServerCallContext context)
{
var query = await _reminderRepository.GetAllAsync();
var reminders = await query
.Where(reminder => reminder.UserId == request.UserId)
.OrderBy(e => e.RemindDate)
.Skip(request.Skip)
.Take(request.Take)
.ToListAsync();

ReminderModelCollection? result = new();
result.ReminderModels.AddRange(reminders.Select(reminder => new ReminderModel
{
Id = reminder.Id,
Message = reminder.Message,
UserId = reminder.UserId,
UnixTime = Miscellaneous.DateTimeToUnixTimeStamp(reminder.RemindDate)
}).ToList());

return result;
}

public override async Task<GetReminderCountResponse> GetRemindersCount(GetReminderCountInput request, ServerCallContext context)
{
var query = await _reminderRepository.GetAllAsync();
Expand Down Expand Up @@ -55,22 +78,8 @@ public override async Task<ReminderModel> AddReminder(ReminderModel request, Ser

if (!result) throw new Exception("Failed to create reminder");

//ReminderInput reminderInput = new() { User = user, Message = reminder.Message };

_logger.LogInformation("Added reminder for [{user}] at [{date}] UTC", request.UserId, reminder.RemindDate);

//if (date < FetchingDate)
//{
// await _eventService.AddEvent(date, reminder.Id.ToString()!, reminderInput, async (input) =>
// {
// if (input is ReminderInput data)
// {
// data.Message ??= "";
// await StandardReminder(data.User, data.Message);
// }
// });
//}

return new ReminderModel() { Id = reminder.Id, Message = reminder.Message, UnixTime = request.UnixTime, UserId = reminder.UserId };
}

Expand All @@ -88,7 +97,7 @@ public override async Task<ReminderModel> AddReminder(ReminderModel request, Ser
.Where(reminder => remindDateStart < remindDateEnd)
.ToListAsync();

if (!reminders.Any()) return null;
if (!reminders.Any()) return new();

ReminderModelCollection? result = new();
result.ReminderModels.AddRange(reminders.Select(reminder => new ReminderModel
Expand Down

0 comments on commit 7f16552

Please sign in to comment.