A community based topic aggregation platform built on atproto
1package votes 2 3import "context" 4 5// Service defines the business logic interface for votes 6// Coordinates between Repository, user PDS, and vote validation 7type Service interface { 8 // CreateVote creates a new vote or toggles an existing vote 9 // Flow: Validate -> Check existing vote -> Handle toggle logic -> Write to user's PDS -> Return URI/CID 10 // AppView indexing happens asynchronously via Jetstream consumer 11 // Toggle logic: 12 // - No vote -> Create vote 13 // - Same direction -> Delete vote (toggle off) 14 // - Different direction -> Delete old + Create new (toggle direction) 15 CreateVote(ctx context.Context, voterDID string, userAccessToken string, req CreateVoteRequest) (*CreateVoteResponse, error) 16 17 // DeleteVote removes a vote from a post/comment 18 // Flow: Find vote -> Verify ownership -> Delete from user's PDS 19 // AppView decrements vote count asynchronously via Jetstream consumer 20 DeleteVote(ctx context.Context, voterDID string, userAccessToken string, req DeleteVoteRequest) error 21 22 // GetVote retrieves a user's vote on a specific subject 23 // Used to check vote state before creating/toggling 24 GetVote(ctx context.Context, voterDID string, subjectURI string) (*Vote, error) 25} 26 27// Repository defines the data access interface for votes 28// Used by Jetstream consumer to index votes from firehose 29type Repository interface { 30 // Create inserts a new vote into the AppView database 31 // Called by Jetstream consumer after vote is created on PDS 32 // Idempotent: ON CONFLICT DO NOTHING for duplicate URIs 33 Create(ctx context.Context, vote *Vote) error 34 35 // GetByURI retrieves a vote by its AT-URI 36 // Used for Jetstream DELETE operations 37 GetByURI(ctx context.Context, uri string) (*Vote, error) 38 39 // GetByVoterAndSubject retrieves a user's vote on a specific subject 40 // Used to check existing vote state 41 GetByVoterAndSubject(ctx context.Context, voterDID string, subjectURI string) (*Vote, error) 42 43 // Delete soft-deletes a vote (sets deleted_at) 44 // Called by Jetstream consumer after vote is deleted from PDS 45 Delete(ctx context.Context, uri string) error 46 47 // ListBySubject retrieves all votes on a specific post/comment 48 // Future: Used for vote detail views 49 ListBySubject(ctx context.Context, subjectURI string, limit, offset int) ([]*Vote, error) 50 51 // ListByVoter retrieves all votes by a specific user 52 // Future: Used for user voting history 53 ListByVoter(ctx context.Context, voterDID string, limit, offset int) ([]*Vote, error) 54}