mirror of
https://github.com/nkanaev/yarr.git
synced 2026-06-24 17:15:17 +00:00
storage test fixes
This commit is contained in:
@@ -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),
|
||||
|
||||
Reference in New Issue
Block a user