posts

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2021 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// TableName is the database table name for posts.
	TableName = "posts"
)

Variables

View Source
var (
	// ErrPostsExists is returned by validate when
	// a post already exists.
	ErrPostsExists = errors.New("post already exists")
	// ErrNoPageTemplate is returned by validate when
	// no page template has been matched with the
	// one passed.
	ErrNoPageTemplate = errors.New("no page template matched")
	// ErrNoPageLayout is returned by validate when
	// no page layout has been matched with the
	// one passed.
	ErrNoPageLayout = errors.New("no page layout matched")
)

Functions

This section is empty.

Types

type ListConfig

type ListConfig struct {
	Resource string
	Status   string
}

ListConfig defines the configuration for obtaining posts for Selects. Posts can be filtered by resource and status.

type Repository

type Repository interface {
	List(meta params.Params, layout bool, cfg ListConfig) (domain.PostData, int, error)
	Find(id int, layout bool) (domain.PostDatum, error)
	FindBySlug(slug string) (domain.PostDatum, error)
	Create(p domain.PostCreate) (domain.PostDatum, error)
	Update(p domain.PostCreate) (domain.PostDatum, error)
	Delete(id int) error
	Exists(id int) bool
	ExistsBySlug(slug string) bool
}

Repository defines methods for posts to interact with the database.

type Store

type Store struct {
	*config.Config
	// contains filtered or unexported fields
}

Store defines the data layer for posts.

func New

func New(cfg *config.Config) *Store

New

Creates a new posts store.

func (*Store) Create

func (s *Store) Create(p domain.PostCreate) (domain.PostDatum, error)

Create

Returns a new post upon creation. Returns errors.CONFLICT if the the category (name) already exists. Returns errors.INTERNAL if the SQL query was invalid or the function could not get the newly created ID.

func (*Store) Delete

func (s *Store) Delete(id int) error

Delete

Returns nil if the category was successfully deleted. Returns errors.INTERNAL if the SQL query was invalid. Returns errors.NOTFOUND if the category was not found.

func (*Store) Exists

func (s *Store) Exists(id int) bool

Exists

Returns a bool indicating if the post exists by ID. Logs errors.INTERNAL if there was an error executing the query.

func (*Store) ExistsBySlug

func (s *Store) ExistsBySlug(slug string) bool

ExistsBySlug

Returns a bool indicating if the post exists by slug. Logs errors.INTERNAL if there was an error executing the query.

func (*Store) Find

func (s *Store) Find(id int, layout bool) (domain.PostDatum, error)

Find

Returns a post by searching with the given ID. Returns errors.INTERNAL if there was an error executing the query. Returns errors.NOTFOUND if the post was not found by the given ID.

func (*Store) FindBySlug

func (s *Store) FindBySlug(slug string) (domain.PostDatum, error)

FindBySlug

Returns a post by searching with the given slug. Returns errors.INTERNAL if there was an error executing the query. Returns errors.NOTFOUND if the post was not found by the given slug.

func (*Store) List

func (s *Store) List(meta params.Params, layout bool, cfg ListConfig) (domain.PostData, int, error)

List

Returns a slice of posts with the total amount. Returns errors.INTERNAL if the SQL query was invalid. Returns errors.NOTFOUND if there are no posts available.

func (*Store) Update

func (s *Store) Update(p domain.PostCreate) (domain.PostDatum, error)

Update

Returns an updated post. Returns errors.CONFLICT if the validation failed. Returns errors.INTERNAL if the SQL query was invalid or the function could not obtain the newly created ID.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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