storage test fixes

This commit is contained in:
nkanaev
2026-06-18 12:07:52 +01:00
parent 5110fbd596
commit 4dc266d3d3
5 changed files with 84 additions and 2 deletions

View File

@@ -242,6 +242,35 @@ func (s *SQLiteStorage) GetItem(id int64) *model.Item {
return i
}
func (s *SQLiteStorage) UpdateItem(id int64, params model.UpdateItemParams) bool {
sets := make([]string, 0)
args := make([]any, 0)
if params.Title != nil {
sets = append(sets, "title = :title")
args = append(args, sql.Named("title", *params.Title))
}
if params.Status != nil {
sets = append(sets, "status = :status")
args = append(args, sql.Named("status", *params.Status))
}
if params.LastArrived != nil {
sets = append(sets, "last_arrived = :last_arrived")
args = append(args, sql.Named("last_arrived", *params.LastArrived))
}
if len(sets) == 0 {
return true
}
args = append(args, sql.Named("id", id))
query := fmt.Sprintf("update items set %s where id = :id", strings.Join(sets, ", "))
_, err := s.db.Exec(query, args...)
return err == nil
}
func (s *SQLiteStorage) DeleteItem(id int64) bool {
_, err := s.db.Exec(`delete from items where id = :id`, sql.Named("id", id))
return err == nil
}
func (s *SQLiteStorage) UpdateItemStatus(item_id int64, status model.ItemStatus) bool {
_, err := s.db.Exec(`update items set status = :status where id = :id`,
sql.Named("status", status),