Revision history: change sets + revisions + revert — the undo substrate (#48) (#61)
Build image / build-and-push (push) Successful in 5s

Co-authored-by: Steve Dudenhoeffer <[email protected]>
This commit was merged in pull request #61.
This commit is contained in:
2026-07-21 05:07:30 +00:00
committed by steve
parent 653f381c4b
commit f208da94d6
16 changed files with 2169 additions and 19 deletions
+29 -4
View File
@@ -72,7 +72,7 @@ type PlantingPatch struct {
// CreatePlanting places a plop in a plantable object the actor can edit.
func (s *Service) CreatePlanting(ctx context.Context, actorID, objectID int64, in PlantingInput) (*domain.Planting, error) {
o, _, err := s.objectForRole(ctx, actorID, objectID, roleEditor)
o, g, err := s.objectForRole(ctx, actorID, objectID, roleEditor)
if err != nil {
return nil, err
}
@@ -105,6 +105,8 @@ func (s *Service) CreatePlanting(ctx context.Context, actorID, objectID int64, i
if err != nil {
return nil, err
}
s.record(ctx, g.ID, actorID, "Planted "+plant.Name+" in "+objectLabel(o),
changeCreate(domain.EntityPlanting, created.ID, created))
created.DerivedCount = derivedCount(created.RadiusCM, plant.SpacingCM)
return created, nil
}
@@ -116,11 +118,12 @@ func (s *Service) UpdatePlanting(ctx context.Context, actorID, plantingID int64,
if err != nil {
return nil, err // ErrNotFound
}
o, _, err := s.objectForRole(ctx, actorID, pl.ObjectID, roleEditor)
o, g, err := s.objectForRole(ctx, actorID, pl.ObjectID, roleEditor)
if err != nil {
return nil, err
}
before := *pl // GetPlanting returns the current row, and the patch mutates it
originalPlantID := pl.PlantID
applyPlantingPatch(pl, patch)
// Fetch the plop's plant for the derived count. Only when the actor is
@@ -155,10 +158,26 @@ func (s *Service) UpdatePlanting(ctx context.Context, actorID, plantingID int64,
}
return updated, err
}
s.record(ctx, g.ID, actorID, plantingEditSummary(&before, updated, plant, o),
changeUpdate(domain.EntityPlanting, updated.ID, &before, updated))
updated.DerivedCount = derivedCount(updated.RadiusCM, plant.SpacingCM)
return updated, nil
}
// plantingEditSummary describes a plop edit for the history list. Soft-removal
// ("clear bed", harvested) is the one edit worth naming specifically — it reads
// as a removal to the person who did it, not as an edit.
func plantingEditSummary(before, after *domain.Planting, plant *domain.Plant, o *domain.GardenObject) string {
switch {
case before.RemovedAt == nil && after.RemovedAt != nil:
return "Removed " + plant.Name + " from " + objectLabel(o)
case before.RemovedAt != nil && after.RemovedAt == nil:
return "Restored " + plant.Name + " in " + objectLabel(o)
default:
return "Edited " + plant.Name + " in " + objectLabel(o)
}
}
// DeletePlanting hard-deletes a plop in an object the actor can edit. (Soft
// removal — "clear bed" / harvested — sets removed_at via UpdatePlanting.)
func (s *Service) DeletePlanting(ctx context.Context, actorID, plantingID int64) error {
@@ -166,10 +185,16 @@ func (s *Service) DeletePlanting(ctx context.Context, actorID, plantingID int64)
if err != nil {
return err
}
if _, _, err := s.objectForRole(ctx, actorID, pl.ObjectID, roleEditor); err != nil {
o, g, err := s.objectForRole(ctx, actorID, pl.ObjectID, roleEditor)
if err != nil {
return err
}
return s.store.DeletePlanting(ctx, plantingID)
if err := s.store.DeletePlanting(ctx, plantingID); err != nil {
return err
}
s.record(ctx, g.ID, actorID, "Deleted a planting from "+objectLabel(o),
changeDelete(domain.EntityPlanting, pl.ID, pl))
return nil
}
// visiblePlant loads a plant the actor may reference in a planting: a built-in or