fix(store): return ErrRecordNotFound when updating non-existent template

RowsAffected == 0 now returns gorm.ErrRecordNotFound so the handler can respond with 404 instead of silently returning 200.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
This commit is contained in:
dailz
2026-04-10 09:21:03 +08:00
parent 4ff02d4a80
commit 1359730300
2 changed files with 15 additions and 2 deletions

View File

@@ -100,7 +100,13 @@ func (s *TemplateStore) Update(ctx context.Context, id int64, req *model.UpdateT
}
result := s.db.WithContext(ctx).Model(&model.JobTemplate{}).Where("id = ?", id).Updates(updates)
return result.Error
if result.Error != nil {
return result.Error
}
if result.RowsAffected == 0 {
return gorm.ErrRecordNotFound
}
return nil
}
// Delete removes a job template by ID. Idempotent — returns nil even if the row doesn't exist.