Initial
This commit is contained in:
50
LehrerApp.Api/PlainEventStore.cs
Normal file
50
LehrerApp.Api/PlainEventStore.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
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,
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user