51 lines
1.7 KiB
C#
51 lines
1.7 KiB
C#
using LiteDB;
|
||
using LehrerApp.Sync.Models;
|
||
|
||
namespace LehrerApp.Api;
|
||
|
||
/// <summary>
|
||
/// Speichert Klartext-Events der WebApp/Companion im EventStore.
|
||
/// Diese werden vom Desktop-Client beim nächsten Pull abgeholt
|
||
/// und wie normale Events angewendet – nur ohne Entschlüsselung.
|
||
///
|
||
/// Technisch gesehen ist das nur eine dünne Schicht über dem
|
||
/// bestehenden EventStore – Plain-Events werden einfach mit
|
||
/// DeviceType.Companion markiert und landen im selben Stream.
|
||
/// </summary>
|
||
public class PlainEventStore
|
||
{
|
||
private readonly EventStore _eventStore;
|
||
|
||
public PlainEventStore(EventStore eventStore)
|
||
{
|
||
_eventStore = eventStore;
|
||
}
|
||
|
||
public PlainPushResponse Push(string userId, List<PlainSyncEvent> events)
|
||
{
|
||
// Plain-Events in normale SyncEvents umwandeln
|
||
// DeviceType.Companion → Desktop-Client entschlüsselt nicht
|
||
var syncEvents = events.Select(e => new SyncEvent
|
||
{
|
||
EventId = e.EventId,
|
||
DeviceId = e.DeviceId,
|
||
DeviceType = DeviceType.Companion, // ← Signal: kein Decrypt nötig
|
||
Timestamp = e.Timestamp,
|
||
SequenceNr = 0, // vom EventStore vergeben
|
||
EntityType = e.EntityType,
|
||
EntityId = e.EntityId,
|
||
Operation = e.Operation,
|
||
Payload = e.Payload, // Klartext JSON
|
||
}).ToList();
|
||
|
||
var result = _eventStore.Push(userId, syncEvents);
|
||
|
||
return new PlainPushResponse
|
||
{
|
||
Success = result.Success,
|
||
ServerSequenceNr = result.ServerSequenceNr,
|
||
RejectedEventIds = result.ConflictingEventIds,
|
||
};
|
||
}
|
||
}
|