This commit is contained in:
2026-03-29 23:47:31 +02:00
commit 216d5d2280
75 changed files with 5702 additions and 0 deletions

View 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,
};
}
}