feat: revision-check material writes

- add jz_bm_materials.revision (default 1), read-only for GORM
- bump it only on content changes (models.ReviseMaterial)
- PUT /materials/{id} locks the row and answers 409 to a stale revision
- management answers carry revision and updated_at, the student detail
  carries revision
This commit is contained in:
Jakub Zych
2026-11-08 23:33:34 +01:00
parent 94ca257c6f
commit 237069c827
12 changed files with 611 additions and 17 deletions

View File

@@ -36,6 +36,11 @@ type Material struct {
AuthorUserID *uint `gorm:"column:author_user_id"`
CreatedAt time.Time `gorm:"column:created_at"`
UpdatedAt time.Time `gorm:"column:updated_at"`
// Revision goes up by one on every content change (ReviseMaterial).
// It is read-only for GORM, so a full-row Save of a stale in-memory
// model never writes an old revision back; only ReviseMaterial changes
// it.
Revision uint `gorm:"column:revision;->"`
Tags []Tag `gorm:"many2many:jz_bm_material_tag;joinForeignKey:material_id;joinReferences:tag_id"`
}