article

package
v0.0.0-...-8ba40cc Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2021 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Length of random string appended to slug to make it unique
	SlugRandLen = 4
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ArticleRequest

type ArticleRequest struct {
	Title       string `json:"title"`
	Description string `json:"description"`
	Body        string `json:"body"`
}

type CreateRequest

type CreateRequest struct {
	Article ArticleRequest `json:"article"`
}

func (*CreateRequest) Validate

func (r *CreateRequest) Validate() error

type ProfilesStore

type ProfilesStore interface {
	GetProfile(username string, follower *app.Profile) (*app.Profile, error)
}

ProfilesStore provides helper to get author with all its fields (like id) by username

type ResponseMulti

type ResponseMulti struct {
	Articles []*app.Article `json:"articles"`
	Count    int            `json:"articlesCount"`
}

type ResponseSingle

type ResponseSingle struct {
	Article app.Article `json:"article"`
}

type Server

type Server struct {
	// contains filtered or unexported fields
}

func NewHTTP

func NewHTTP(store Store, profilesStore ProfilesStore, secret []byte) (*Server, error)

func (*Server) HandleCreate

func (s *Server) HandleCreate(w http.ResponseWriter, r *http.Request) error

func (*Server) HandleDelete

func (s *Server) HandleDelete(w http.ResponseWriter, r *http.Request) error

func (*Server) HandleFeed

func (s *Server) HandleFeed(w http.ResponseWriter, r *http.Request) error

func (*Server) HandleGet

func (s *Server) HandleGet(w http.ResponseWriter, r *http.Request) error

func (*Server) HandleList

func (s *Server) HandleList(w http.ResponseWriter, r *http.Request) error

func (*Server) HandleUpdate

func (s *Server) HandleUpdate(w http.ResponseWriter, r *http.Request) error

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements http.handler interface and uses router ServeHTTP method

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service provides methods for articles

func NewService

func NewService(store Store, profileStore ProfilesStore) *Service

NewService creates new instance of the service with provided store

func (*Service) Create

func (s *Service) Create(req *CreateRequest, author *app.Profile) (*app.Article, error)

Create creates new article in the articles store

func (*Service) Delete

func (s *Service) Delete(slug string, author *app.Profile) error

func (*Service) Get

func (s *Service) Get(slug string) (*app.Article, error)

func (*Service) List

func (s *Service) List(filter *app.ArticleListFilter) ([]*app.Article, error)

func (*Service) Update

func (s *Service) Update(slug string, author *app.Profile, req *UpdateRequest) (*app.Article, error)

Update modifies article found by slug with the new data in req. Returns updated article.

type Store

type Store interface {
	CreateArticle(a *app.Article) error
	GetArticle(slug string) (*app.Article, error)
	ListArticles(f *app.ArticleListFilter) ([]*app.Article, error)
	UpdateArticle(a *app.Article) error
	DeleteArticle(id int) error
}

ArticleStore defines an interface to work with articles

type UpdateArticle

type UpdateArticle struct {
	Title       string `json:"title,omitempty"`
	Description string `json:"description,omitempty"`
	Body        string `json:"body,omitempty"`
}

type UpdateRequest

type UpdateRequest struct {
	Article UpdateArticle `json:"article"`
}

func (*UpdateRequest) Validate

func (r *UpdateRequest) Validate() error

Jump to

Keyboard shortcuts

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