35 lines
1.3 KiB
C#
35 lines
1.3 KiB
C#
using LehrerApp.Sync.Models;
|
|
|
|
namespace LehrerApp.Api;
|
|
|
|
public class PlainEventStore(EventStore eventStore)
|
|
{
|
|
private static readonly HashSet<string> Allowed =
|
|
["Grade", "ExamResult", "WorkTask", "Lesson"];
|
|
|
|
public PlainPushResponse Push(string userId, List<PlainSyncEvent> events)
|
|
{
|
|
var permitted = events.Where(e => Allowed.Contains(e.EntityType)).ToList();
|
|
var rejected = events.Where(e => !Allowed.Contains(e.EntityType))
|
|
.Select(e => e.EventId).ToList();
|
|
if (permitted.Count == 0) return new() { Success = true, RejectedEventIds = rejected };
|
|
|
|
var syncEvents = permitted.Select(e => new SyncEvent
|
|
{
|
|
EventId = e.EventId, DeviceId = e.DeviceId,
|
|
DeviceType = DeviceType.Companion,
|
|
Timestamp = e.Timestamp, SequenceNr = 0,
|
|
EntityType = e.EntityType, EntityId = e.EntityId,
|
|
Operation = e.Operation, Payload = e.Payload,
|
|
}).ToList();
|
|
|
|
var result = eventStore.Push(userId, syncEvents);
|
|
return new()
|
|
{
|
|
Success = result.Success,
|
|
ServerSequenceNr = result.ServerSequenceNr,
|
|
RejectedEventIds = [.. result.ConflictingEventIds, .. rejected],
|
|
};
|
|
}
|
|
}
|