feat: started to make things work

This commit is contained in:
didier committed 2026-06-07 12:30:08 -04:00
1 parent 9e21732d00
commit de6480ba4e
8 files changed
+157 -106

No files matched your search

+18 -9
View File
@@ -171,31 +171,40 @@ func (s *sqliteStore) getLatestByPublicID(ctx context.Context, publicID int64) (
return &e, nil
}
func (s *sqliteStore) listAllPublicIDs(ctx context.Context) ([]int64, error) {
func (s *sqliteStore) listAll(ctx context.Context) ([]flashcardSummary, error) {
rows, err := s.db.QueryContext(ctx,
`SELECT f.public_id FROM flashcard f
`SELECT f.public_id, f.version, f.note, f.host, f.user, f.tags, f.repos, f.created
FROM flashcard f
WHERE f.version = (SELECT MAX(f2.version) FROM flashcard f2 WHERE f2.public_id = f.public_id)
AND f.delete_timestamp IS NULL
AND f.public_id != 0
ORDER BY f.public_id`,
)
if err != nil {
return nil, fmt.Errorf("list ids: %w", err)
return nil, fmt.Errorf("list: %w", err)
}
defer rows.Close()
var ids []int64
var summaries []flashcardSummary
for rows.Next() {
var id int64
if err := rows.Scan(&id); err != nil {
return nil, fmt.Errorf("scan id: %w", err)
var s flashcardSummary
var tagsJSON, reposJSON *string
if err := rows.Scan(&s.PublicID, &s.Version, &s.Note, &s.Host, &s.User, &tagsJSON, &reposJSON, &s.Created); err != nil {
return nil, fmt.Errorf("scan: %w", err)
}
ids = append(ids, id)
if tagsJSON != nil {
json.Unmarshal([]byte(*tagsJSON), &s.Tags)
}
if reposJSON != nil {
json.Unmarshal([]byte(*reposJSON), &s.Repos)
}
s.URL = fmt.Sprintf("/api/v1/flashcards/%d", s.PublicID)
summaries = append(summaries, s)
}
if err := rows.Err(); err != nil {
return nil, fmt.Errorf("rows: %w", err)
}
return ids, nil
return summaries, nil
}
func (s *sqliteStore) getByPublicIDAndVersion(ctx context.Context, publicID int64, version int) (*entry, error) {