Documentation
¶
Index ¶
- Constants
- type Link
- type LinkDataStore
- type LinkQueryParams
- func (l LinkQueryParams) SortByNewest() LinkQueryParams
- func (l LinkQueryParams) SortByTop() LinkQueryParams
- func (l LinkQueryParams) WithCreatedTimeCursor(t int64) LinkQueryParams
- func (l LinkQueryParams) WithLimit(limit int) LinkQueryParams
- func (l LinkQueryParams) WithScoreCursor(score int) LinkQueryParams
- type LinkReturnFields
- type LinkService
- type LinkWithRating
- type Rating
- type SortOrder
- type User
- type UserLinkRating
Constants ¶
const SortOrderNewest = "newest"
const SortOrderTop = "top"
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Link ¶
type LinkDataStore ¶
type LinkDataStore interface { CreateLink(ctx context.Context, boardId string, link Link) error DeleteLink(ctx context.Context, boardId string, linkId string) error UpdateRating(ctx context.Context, boardId string, linkId string, rating UserLinkRating) error // Return a single link, possibly with a rating summary and the rating for a particular user, depending on the LinkReturnFields value. Link(ctx context.Context, boardId string, linkId string, rf LinkReturnFields) (LinkWithRating, error) Links(ctx context.Context, boardId string, rf LinkReturnFields, qp LinkQueryParams) ([]LinkWithRating, error) }
Any type implementing this interface can be used as the link and rating data store for this application.
Note that we do not aggregate the user ratings in the domain layer. Instead we expect that the data store implementation is capable of computing a Rating value that aggregates all the user ratings. How this is done is up to the implementation. One could e.g. store the aggregate explicitly and update it every time a user rating changes or it could be computed from all the user ratings and cached.
type LinkQueryParams ¶
type LinkQueryParams struct { // Should be either newest or top, defaults to newest SortOrder SortOrder // Maximum number of links to return. // Valid values are between 1 and 100, defaults to 20. Limit int // Query cursors that can be used for pagination. // When sort order is "newest", just provide CursorCreatedTime. // When sort order is "top", provide both values, // since there can possibly be many links with the same score. // // Return only links with less than or equal to score. // Use a pointer here to distinguish the case where no value is set, since 0 would be a valid cursor value. CursorScore *int // Return only links that were created at or before the given time. CursorCreatedTime int64 }
func NewLinkQueryParams ¶
func NewLinkQueryParams() LinkQueryParams
func (LinkQueryParams) SortByNewest ¶
func (l LinkQueryParams) SortByNewest() LinkQueryParams
func (LinkQueryParams) SortByTop ¶
func (l LinkQueryParams) SortByTop() LinkQueryParams
func (LinkQueryParams) WithCreatedTimeCursor ¶
func (l LinkQueryParams) WithCreatedTimeCursor(t int64) LinkQueryParams
func (LinkQueryParams) WithLimit ¶
func (l LinkQueryParams) WithLimit(limit int) LinkQueryParams
func (LinkQueryParams) WithScoreCursor ¶
func (l LinkQueryParams) WithScoreCursor(score int) LinkQueryParams
type LinkReturnFields ¶
type LinkReturnFields struct { // Wether or not to include the rating of the link IncludeRating bool // Whether or not to include the rating of the user with the given userId (if not empty) IncludeUserRatingFor string }
Defines what data a LinkDataStore query result should contain
type LinkService ¶
type LinkService struct {
// contains filtered or unexported fields
}
func NewLinkService ¶
func NewLinkService(ds LinkDataStore) *LinkService
func (*LinkService) CreateLink ¶
func (*LinkService) UpdateUserRating ¶
func (ls *LinkService) UpdateUserRating(ctx context.Context, boardId string, linkId string, rating int, user User) (UserLinkRating, error)
Creates or changes the rating of a user for a link.
type LinkWithRating ¶
type LinkWithRating struct { Link Link // Rating of the link, might be empty Rating Rating // Rating of the link from a user, might be empty UserRating UserLinkRating }
For convenience, LinkDataStore should be able to return a link with its rating (i.e. the summary/aggregate of all user ratings) and possibly the individual rating of a given user. A LinkReturnFields value can be used to configure what a LinkDataStore method should return.
type Rating ¶
type Rating struct { // Score = Upvotes + Downvotes Score int // Total of positive ratings, must be >= 0 Upvotes int // Total of negative ratings, must be <= 0 Downvotes int }
A summary/aggregate of all the ratings for a link
type UserLinkRating ¶
type UserLinkRating struct { UserId string // +1 for upvote, -1 for downvote Rating int ModifiedTime int64 }
The rating of a user for a link.
func NewUserLinkRating ¶
func NewUserLinkRating(rating int, userId string) (UserLinkRating, error)