show last time item was refreshed

This commit is contained in:
2026-02-13 23:20:12 +03:00
parent f43519f7f6
commit a37ed0d902
5 changed files with 42 additions and 7 deletions

View File

@@ -1,6 +1,9 @@
package model
import "fmt"
import (
"fmt"
"time"
)
func (m *Model) GetItems() ([]*Item, error) {
rows, err := m.db.Queryx("SELECT * FROM items")
@@ -19,3 +22,14 @@ func (m *Model) GetItems() ([]*Item, error) {
return items, nil
}
func (m *Model) UpdateRefreshedAt(itemId int64, refreshedAt time.Time) error {
if _, err := m.db.NamedExec("UPDATE items SET refreshed_at = :refreshed_at WHERE id = :item_id", map[string]any{
"refreshed_at": refreshedAt,
"item_id": itemId,
}); err != nil {
return fmt.Errorf("failed to update refreshed_at field: %v", err)
}
return nil
}

View File

@@ -28,11 +28,12 @@ type Torrent struct {
}
type Item struct {
ID int64 `json:"id" db:"id"`
Query string `json:"query" db:"query"`
Category int `json:"category" db:"category"`
CreatedAt time.Time `json:"createdAt" db:"created_at"`
Torrents []Torrent `json:"torrents,omitempty"`
ID int64 `json:"id" db:"id"`
Query string `json:"query" db:"query"`
Category int `json:"category" db:"category"`
CreatedAt time.Time `json:"createdAt" db:"created_at"`
Torrents []Torrent `json:"torrents,omitempty"`
RefreshedAt *time.Time `json:"refreshedAt" db:"refreshed_at"`
}
func (m *Model) Init() {
@@ -59,6 +60,8 @@ func (m *Model) Init() {
item_id integer not null,
FOREIGN KEY (item_id) REFERENCES users(id)
)`)
m.db.Exec(`ALTER TABLE items ADD COLUMN refreshed_at datetime default null`)
}
func New(db *sqlx.DB) *Model {