From 1a55855aaa59f6c4a974d77696a4974b7366b472 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Tue, 1 Jul 2025 04:30:20 -0700 Subject: [PATCH] submissions: check rows affected --- pkg/datastore/gormstore/mapfixes.go | 11 ++++++++--- pkg/datastore/gormstore/submissions.go | 11 ++++++++--- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/pkg/datastore/gormstore/mapfixes.go b/pkg/datastore/gormstore/mapfixes.go index 50f4a05..ee4f0ad 100644 --- a/pkg/datastore/gormstore/mapfixes.go +++ b/pkg/datastore/gormstore/mapfixes.go @@ -55,11 +55,16 @@ func (env *Mapfixes) Update(ctx context.Context, id int64, values datastore.Opti // the update can only occur if the status matches one of the provided values. func (env *Mapfixes) IfStatusThenUpdate(ctx context.Context, id int64, statuses []model.MapfixStatus, values datastore.OptionalMap) error { - if err := env.db.Model(&model.Mapfix{}).Where("id = ?", id).Where("status_id IN ?", statuses).Updates(values.Map()).Error; err != nil { - if err == gorm.ErrRecordNotFound { + result := env.db.Model(&model.Mapfix{}).Where("id = ?", id).Where("status_id IN ?", statuses).Updates(values.Map()) + if result.Error != nil { + if result.Error == gorm.ErrRecordNotFound { return datastore.ErrNotExist } - return err + return result.Error + } + + if result.RowsAffected == 0 { + return datastore.ErroNoRowsAffected } return nil diff --git a/pkg/datastore/gormstore/submissions.go b/pkg/datastore/gormstore/submissions.go index 5791819..9f4d149 100644 --- a/pkg/datastore/gormstore/submissions.go +++ b/pkg/datastore/gormstore/submissions.go @@ -55,11 +55,16 @@ func (env *Submissions) Update(ctx context.Context, id int64, values datastore.O // the update can only occur if the status matches one of the provided values. func (env *Submissions) IfStatusThenUpdate(ctx context.Context, id int64, statuses []model.SubmissionStatus, values datastore.OptionalMap) error { - if err := env.db.Model(&model.Submission{}).Where("id = ?", id).Where("status_id IN ?", statuses).Updates(values.Map()).Error; err != nil { - if err == gorm.ErrRecordNotFound { + result := env.db.Model(&model.Submission{}).Where("id = ?", id).Where("status_id IN ?", statuses).Updates(values.Map()) + if result.Error != nil { + if result.Error == gorm.ErrRecordNotFound { return datastore.ErrNotExist } - return err + return result.Error + } + + if result.RowsAffected == 0 { + return datastore.ErroNoRowsAffected } return nil -- 2.49.1