A community based topic aggregation platform built on atproto
1package votes
2
3import (
4 "context"
5
6 oauthlib "github.com/bluesky-social/indigo/atproto/auth/oauth"
7)
8
9// Service defines the business logic interface for vote operations
10// Implements write-forward pattern: validates requests, then forwards to user's PDS
11//
12// Architecture:
13// - Service validates input and checks authorization
14// - Queries user's PDS directly via com.atproto.repo.listRecords to check existing votes
15// (avoids eventual consistency issues with AppView database)
16// - Creates/deletes vote records via com.atproto.repo.createRecord/deleteRecord
17// - AppView indexes resulting records from Jetstream firehose for aggregate counts
18type Service interface {
19 // CreateVote creates a new vote or toggles off an existing vote
20 // Returns URI and CID of created vote, or empty strings if toggled off
21 //
22 // Validation:
23 // - Direction must be "up" or "down" (returns ErrInvalidDirection)
24 // - Subject URI must be valid AT-URI (returns ErrInvalidSubject)
25 // - Subject must exist (returns ErrSubjectNotFound)
26 //
27 // Behavior:
28 // - If no vote exists: creates new vote with given direction
29 // - If vote exists with same direction: deletes vote (toggle off)
30 // - If vote exists with different direction: updates to new direction
31 CreateVote(ctx context.Context, session *oauthlib.ClientSessionData, req CreateVoteRequest) (*CreateVoteResponse, error)
32
33 // DeleteVote removes a vote on the specified subject
34 //
35 // Validation:
36 // - Subject URI must be valid AT-URI (returns ErrInvalidSubject)
37 // - Vote must exist (returns ErrVoteNotFound)
38 //
39 // Behavior:
40 // - Deletes the user's vote record from their PDS
41 // - AppView will soft-delete via Jetstream consumer
42 DeleteVote(ctx context.Context, session *oauthlib.ClientSessionData, req DeleteVoteRequest) error
43}
44
45// CreateVoteRequest contains the parameters for creating a vote
46type CreateVoteRequest struct {
47 // Subject is the post or comment being voted on
48 Subject StrongRef `json:"subject"`
49
50 // Direction is either "up" or "down"
51 Direction string `json:"direction"`
52}
53
54// CreateVoteResponse contains the result of creating a vote
55type CreateVoteResponse struct {
56 // URI is the AT-URI of the created vote record
57 // Empty string if vote was toggled off (deleted)
58 URI string `json:"uri"`
59
60 // CID is the content identifier of the created vote record
61 // Empty string if vote was toggled off (deleted)
62 CID string `json:"cid"`
63}
64
65// DeleteVoteRequest contains the parameters for deleting a vote
66type DeleteVoteRequest struct {
67 // Subject is the post or comment whose vote should be removed
68 Subject StrongRef `json:"subject"`
69}