coder13 / coder13/LetsCube

Centralize room, RaceSession, attempt, and solve persistence

Aperta
#204 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
area: data area: platform area: results enhancement priority: P1
Lingua principale
JavaScript
Stelle
30
Fork
9
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

Part of #199.

## Goal

Stop Socket.IO handlers and Mongoose document methods from directly owning room/session/result persistence behavior. Put the aggregate behind a single tested service/repository boundary that can use PostgreSQL authoritatively.

## Scope

Create explicit operations for at least:

- create room and initial race session;
- load room and active/selected session;
- join, leave, ban, and unban;
- assign owner/admin and session control roles;
- create, start, pause, end, and switch race sessions;
- create the next attempt;
- submit and edit an idempotent solve;
- hide, archive, or delete a room according to the retention contract.

Socket handlers should authorize and translate protocol messages, then call these operations. They should not directly mutate embedded attempts, result maps, or room event state.

## Requirements

- Preserve the current Socket.IO protocol during the first phase where practical.
- Preserve idempotent submission IDs and immutable attempt keys.
- Use PostgreSQL transactions wherever one user action changes room, session, attempt, participant, and solve state together.
- Keep authorization inside or immediately adjacent to the domain operation so alternate callers cannot bypass it.
- Define repository implementations or feature flags needed for migration comparison and rollback.
- Emit realtime events only after durable writes succeed.
- Keep chat transport outside this persistence scope unless required by the contract.

## Acceptance criteria

- [ ] All room/session/attempt/solve mutations have explicit service operations.
- [ ] Socket handlers no longer directly mutate the persisted aggregate.
- [ ] Result submission remains idempotent across reconnects and retries.
- [ ] Event changes end/create sessions without deleting history.
- [ ] Transactions prevent partially-created sessions, attempts, or solves.
- [ ] Authorization tests cover owner, admin, participant, banned, anonymous, and stale-session cases.
- [ ] Existing normal-room client behavior and protocol tests continue passing.
- [ ] The persistence boundary supports shadow comparison and an authoritative PostgreSQL mode.

## Dependencies

- Domain contract and PostgreSQL expansion schema from this initiative.
- Preserve the ownership/admin contract established by #195.

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Individua gli handler Socket.IO e i metodi dei documenti Mongoose che attualmente modificano rooms, sessions, attempts e solves, quindi leggi i test del protocollo correlati e lo schema di espansione PostgreSQL. Il lavoro è completato quando operazioni di servizio esplicite gestiscono queste mutazioni, transazioni e autorizzazione sono coperte dai test, gli eventi realtime seguono le scritture persistenti e il comportamento del protocollo per le stanze normali continua a superare i test.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
javascript, mongodb, nodejs, postgresql
Ambito
backend, databases
Tipo di issue
Refactoring
Difficoltà
5/5
Tempo stimato
Più di una settimana
Stato di attività
Tranquilla
Chiarezza
Abbastanza chiara
Idoneità per principianti
25/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.