posts

package
v0.0.0-...-c33ccd5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 2, 2018 License: MIT Imports: 6 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AllPostLimit = 1000

AllPostLimit is a Limit for user queries

View Source
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

type AuthorIDFilter struct {
	AuthorID bson.ObjectId `json:"author_id"`
}

AuthorIDFilter filters by author id

type BoardIDFilter

type BoardIDFilter struct {
	BoardID bson.ObjectId `json:"board_id"`
}

BoardIDFilter filters by board id

type IDFilter

type IDFilter struct {
	ID bson.ObjectId
}

IDFilter filters by post 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

func (*MongoStore) PostVotes

func (s *MongoStore) PostVotes(id bson.ObjectId, update *PostVote) (*Post, error)

PostVotes takes care of updating the votes in the post with the given input

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

func (*NewPost) ToPost

func (np *NewPost) ToPost() (*Post, error)

ToPost converts the NewPost to a real Post

func (*NewPost) Validate

func (np *NewPost) Validate() error

Validate confirms that a new post contains a title and at least one of either an image or a caption

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

func (p *Post) AddComment(comment bson.ObjectId)

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

func (p *Post) ApplyVotes(updates *PostVote) error

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 PostVote

type PostVote struct {
	Upvote   int `json:"upvotes"`
	Downvote int `json:"downvotes"`
}

PostVote updater

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

type VoteInjector struct {
	Upvotes   int
	Downvotes int
}

VoteInjector is used by the change in mgo to update the votes in a post object

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL