bluesky viewer in the terminal
at main 88 lines 2.8 kB view raw
1package store 2 3import ( 4 "context" 5 "time" 6 7 "github.com/google/uuid" 8) 9 10// Repository defines a generic persistence contract. 11type Repository interface { 12 Init(ctx context.Context) error 13 Close() error 14 Get(ctx context.Context, id string) (Model, error) 15 List(ctx context.Context) ([]Model, error) 16 Save(ctx context.Context, feed Model) error 17 Delete(ctx context.Context, id string) error 18} 19 20// Model is the base interface for any persisted domain object. 21type Model interface { 22 ID() string 23 CreatedAt() time.Time 24 UpdatedAt() time.Time 25} 26 27// Generates a new v4 [uuid.UUID] and converts it to a string 28func GenerateUUID() string { 29 return uuid.New().String() 30} 31 32// FeedModel represents a logical feed (local or remote). 33type FeedModel struct { 34 id string 35 createdAt time.Time 36 updatedAt time.Time 37 Name string 38 Source string 39 Params map[string]string 40 IsLocal bool 41} 42 43func (m *FeedModel) ID() string { return m.id } 44func (m *FeedModel) CreatedAt() time.Time { return m.createdAt } 45func (m *FeedModel) UpdatedAt() time.Time { return m.updatedAt } 46func (m *FeedModel) SetID(id string) { m.id = id } 47func (m *FeedModel) SetCreatedAt(t time.Time) { m.createdAt = t } 48func (m *FeedModel) SetUpdatedAt(t time.Time) { m.updatedAt = t } 49func (m *FeedModel) TouchUpdatedAt() { m.updatedAt = time.Now() } 50 51// PostModel represents a single cached or fetched post. 52type PostModel struct { 53 id string 54 createdAt time.Time 55 updatedAt time.Time 56 URI string 57 AuthorDID string 58 Text string 59 FeedID string 60 IndexedAt time.Time 61} 62 63func (m *PostModel) ID() string { return m.id } 64func (m *PostModel) CreatedAt() time.Time { return m.createdAt } 65func (m *PostModel) UpdatedAt() time.Time { return m.updatedAt } 66func (m *PostModel) SetID(id string) { m.id = id } 67func (m *PostModel) SetCreatedAt(t time.Time) { m.createdAt = t } 68func (m *PostModel) SetUpdatedAt(t time.Time) { m.updatedAt = t } 69func (m *PostModel) TouchUpdatedAt() { m.updatedAt = time.Now() } 70 71// SessionModel represents a user session and API context. 72type SessionModel struct { 73 id string 74 createdAt time.Time 75 updatedAt time.Time 76 Handle string 77 Token string 78 ServiceURL string 79 IsValid bool 80} 81 82func (m *SessionModel) ID() string { return m.id } 83func (m *SessionModel) CreatedAt() time.Time { return m.createdAt } 84func (m *SessionModel) UpdatedAt() time.Time { return m.updatedAt } 85func (m *SessionModel) SetID(id string) { m.id = id } 86func (m *SessionModel) SetCreatedAt(t time.Time) { m.createdAt = t } 87func (m *SessionModel) SetUpdatedAt(t time.Time) { m.updatedAt = t } 88func (m *SessionModel) TouchUpdatedAt() { m.updatedAt = time.Now() }