Documentation ¶
Overview ¶
Package post provides an example of a core business API. Right now these calls are just wrapping the data/data layer. But at some point you will want auditing or something that isn't specific to the data/store layer.
Index ¶
- Variables
- type Core
- func (c Core) Create(ctx context.Context, np NewPost, now time.Time) (Post, error)
- func (c Core) Delete(ctx context.Context, postID string) error
- func (c Core) Query(ctx context.Context, pageNumber int, rowsPerPage int) ([]Post, error)
- func (c Core) QueryByID(ctx context.Context, postID string) (Post, error)
- func (c Core) QueryByUserID(ctx context.Context, userID string) ([]Post, error)
- func (c Core) Update(ctx context.Context, postID string, up UpdatePost, now time.Time) error
- type NewPost
- type Post
- type UpdatePost
Constants ¶
This section is empty.
Variables ¶
var ( ErrNotFound = errors.New("post not found") ErrInvalidID = errors.New("ID is not in its proper form") ErrAuthenticationFailure = errors.New("authentication failed") )
Set of error variables for CRUD operations.
Functions ¶
This section is empty.
Types ¶
type Core ¶
type Core struct {
// contains filtered or unexported fields
}
Core manages the set of API's for post access.
func (Core) QueryByUserID ¶
type NewPost ¶
type NewPost struct { Title string `json:"title" validate:"required"` Description string `json:"description" validate:"required"` UserID string `json:"user_id" validate:"required"` }
NewPost contains information needed to create a new Post.
type Post ¶
type Post struct { ID string `json:"id"` Title string `json:"title"` Description string `json:"description"` UserID string `json:"user_id"` DateCreated time.Time `json:"date_created"` DateUpdated time.Time `json:"date_updated"` }
Post represents an individual post.
type UpdatePost ¶
UpdatePost defines what information may be provided to modify an existing Post. All fields are optional so clients can send just the fields they want changed. It uses pointer fields so we can differentiate between a field that was not provided and a field that was provided as explicitly blank. Normally we do not want to use pointers to basic types but we make exceptions around marshalling/unmarshalling.