refactor: updates delete method to return affected rows count

This commit is contained in:
2025-11-01 20:29:39 -03:00
parent e06c30635e
commit af511203a4
2 changed files with 7 additions and 4 deletions

View File

@@ -69,8 +69,11 @@ func (r *baseRepository[T]) GetAll() ([]T, error) {
return entities, nil return entities, nil
} }
func (r *baseRepository[T]) Delete(id int) error { func (r *baseRepository[T]) Delete(id int) (int64, error) {
query := r.BuildQuery("DELETE %s WHERE id = ? LIMIT 1") query := r.BuildQuery("DELETE %s WHERE id = ? LIMIT 1")
_, err := r.db.Exec(query, id) res, err := r.db.Exec(query, id)
return err if err != nil {
return 0, err
}
return res.RowsAffected()
} }

View File

@@ -4,5 +4,5 @@ type Repository[T any] interface {
BuildQuery(s string) string BuildQuery(s string) string
GetByID(id int) (*T, error) GetByID(id int) (*T, error)
GetAll() ([]T, error) GetAll() ([]T, error)
Delete(id int) error Delete(id int) (int64, error)
} }