feat(assets): track selected indices by FIGI
Add the nullable FIGI migration, owner-scoped asset identity operations, and the explicit index search and selection flow. Refs #4 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@ -4,7 +4,6 @@ import (
|
||||
"database/sql"
|
||||
"errors"
|
||||
"github.com/lib/pq"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Repository struct {
|
||||
@ -128,46 +127,6 @@ func (r *Repository) CountAdmins() (int, error) {
|
||||
return count, err
|
||||
}
|
||||
|
||||
// ── User Assets ────────────────────────────────────────────────────────────
|
||||
|
||||
func (r *Repository) GetUserAssets(userID string) ([]UserAsset, error) {
|
||||
rows, err := r.db.Query(`
|
||||
SELECT id, user_id, symbol, name, created_at
|
||||
FROM user_assets WHERE user_id=$1 ORDER BY symbol`, userID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var assets []UserAsset
|
||||
for rows.Next() {
|
||||
var a UserAsset
|
||||
if err := rows.Scan(&a.ID, &a.UserID, &a.Symbol, &a.Name, &a.CreatedAt); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
assets = append(assets, a)
|
||||
}
|
||||
return assets, nil
|
||||
}
|
||||
|
||||
func (r *Repository) AddUserAsset(userID, symbol, name string) (*UserAsset, error) {
|
||||
a := &UserAsset{}
|
||||
err := r.db.QueryRow(`
|
||||
INSERT INTO user_assets (user_id, symbol, name)
|
||||
VALUES ($1, $2, $3)
|
||||
ON CONFLICT (user_id, symbol) DO UPDATE SET name=EXCLUDED.name
|
||||
RETURNING id, user_id, symbol, name, created_at`,
|
||||
userID, strings.ToUpper(symbol), name,
|
||||
).Scan(&a.ID, &a.UserID, &a.Symbol, &a.Name, &a.CreatedAt)
|
||||
return a, err
|
||||
}
|
||||
|
||||
func (r *Repository) RemoveUserAsset(userID, symbol string) error {
|
||||
_, err := r.db.Exec(`
|
||||
DELETE FROM user_assets WHERE user_id=$1 AND symbol=$2`,
|
||||
userID, strings.ToUpper(symbol))
|
||||
return err
|
||||
}
|
||||
|
||||
// ── Sources ────────────────────────────────────────────────────────────────
|
||||
|
||||
func (r *Repository) ListSources() ([]Source, error) {
|
||||
|
||||
Reference in New Issue
Block a user