Documentation
¶
Index ¶
- Variables
- type AuthorIDFilter
- type BoardIDFilter
- type IDFilter
- type MongoStore
- func (s *MongoStore) Delete(id bson.ObjectId) error
- func (s *MongoStore) GetAll() ([]*Post, error)
- func (s *MongoStore) GetByAuthorID(id bson.ObjectId) ([]*Post, error)
- func (s *MongoStore) GetByBoardID(id bson.ObjectId) ([]*Post, error)
- func (s *MongoStore) GetByID(id bson.ObjectId) (*Post, error)
- func (s *MongoStore) GetLastN(n int) ([]*Post, error)
- func (s *MongoStore) Insert(np *NewPost) (*Post, error)
- func (s *MongoStore) PostUpdate(id bson.ObjectId, update *PostUpdate) error
- func (s *MongoStore) PostVotes(id bson.ObjectId, update *PostVote) (*Post, error)
- type NewPost
- type Post
- type PostUpdate
- type PostVote
- type Store
- type VoteInjector
Constants ¶
This section is empty.
Variables ¶
var AllPostLimit = 1000
AllPostLimit is a Limit for user queries
var ErrPostNotFound = errors.New("post not found")
ErrPostNotFound is returned when the user can't be found
Functions ¶
This section is empty.
Types ¶
type AuthorIDFilter ¶
AuthorIDFilter filters by author id
type BoardIDFilter ¶
BoardIDFilter filters by board id
type MongoStore ¶
type MongoStore struct {
// contains filtered or unexported fields
}
MongoStore outlines the storage struct for mongo db
func NewMongoStore ¶
func NewMongoStore(sess *mgo.Session, dbName string, collectionName string) *MongoStore
NewMongoStore constructs a new MongoStore
func (*MongoStore) Delete ¶
func (s *MongoStore) Delete(id bson.ObjectId) error
Delete removes a post from the database
func (*MongoStore) GetAll ¶
func (s *MongoStore) GetAll() ([]*Post, error)
GetAll gets every post from the store
func (*MongoStore) GetByAuthorID ¶
func (s *MongoStore) GetByAuthorID(id bson.ObjectId) ([]*Post, error)
GetByAuthorID gets all posts by the given author (via id)
func (*MongoStore) GetByBoardID ¶
func (s *MongoStore) GetByBoardID(id bson.ObjectId) ([]*Post, error)
GetByBoardID gets all posts from a given board (via id)
func (*MongoStore) GetByID ¶
func (s *MongoStore) GetByID(id bson.ObjectId) (*Post, error)
GetByID gets all posts by the given ID
func (*MongoStore) GetLastN ¶
func (s *MongoStore) GetLastN(n int) ([]*Post, error)
GetLastN gets the last N posts inserted into the store
func (*MongoStore) Insert ¶
func (s *MongoStore) Insert(np *NewPost) (*Post, error)
Insert inserts a new post into the store
func (*MongoStore) PostUpdate ¶
func (s *MongoStore) PostUpdate(id bson.ObjectId, update *PostUpdate) error
PostUpdate updates the post with general information
type NewPost ¶
type NewPost struct {
Title string `json:"title"`
ImageURL string `json:"image_url"`
Caption string `json:"caption"`
AuthorID bson.ObjectId `json:"author_id"`
BoardID bson.ObjectId `json:"board_id"`
}
NewPost is a new post
type Post ¶
type Post struct {
ID bson.ObjectId `json:"id" bson:"_id"`
Title string `json:"title"`
ImageURL string `json:"image_url"`
Caption string `json:"caption"`
AuthorID bson.ObjectId `json:"author_id"`
Comments []bson.ObjectId `json:"comments"`
BoardID bson.ObjectId `json:"board_id"`
Upvotes int `json:"upvotes"`
Downvotes int `json:"downvotes"`
TimeCreated time.Time `json:"time_created"`
TimeEdited time.Time `json:"time_edited"`
}
Post is a post
func (*Post) AddComment ¶
AddComment adds comment IDs to the Post change to "reply"? also can i just lump this into PostUpdate?
func (*Post) ApplyUpdates ¶
func (p *Post) ApplyUpdates(updates *PostUpdate) error
ApplyUpdates applies the post updates to the post
func (*Post) ApplyVotes ¶
ApplyVotes takes care of applying the votes later
type PostUpdate ¶
type PostUpdate struct {
Title string `json:"title"`
Caption string `json:"caption"`
ImageURL string `json:"image_url"`
}
PostUpdate represents allowed updates to a post
type Store ¶
type Store interface {
// Insert converts the NewPost to a Post, inserts
// it into the database, and returns it
Insert(newPost *NewPost) (*Post, error)
//GetByID returns the Post with the given ID
GetByID(id bson.ObjectId) (*Post, error)
//GetByAuthorID returns all Posts by a given author by ID
GetByAuthorID(id bson.ObjectId) ([]*Post, error)
//GetByBoardID returns all Posts for a given board by ID
GetByBoardID(id bson.ObjectId) ([]*Post, error)
//Delete deletes the post with the given ID
Delete(id bson.ObjectId) error
//PostUpdate applies a PostUpdate to a given post ID
PostUpdate(id bson.ObjectId, update *PostUpdate) error
// Get all posts returns all posts
GetAll() ([]*Post, error)
// GetLastN gets the last N posts
GetLastN(n int) ([]*Post, error)
}
Store represents a store for Posts
type VoteInjector ¶
VoteInjector is used by the change in mgo to update the votes in a post object