Documentation ¶
Index ¶
- Variables
- func ConvertPaginationToSQLExpression(pagination service.Pagination) string
- func MakeCreateSnippetEndpoint(s Service) endpoint.Endpoint
- func MakeDeleteSnippetEndpoint(s Service) endpoint.Endpoint
- func MakeGetSnippetEndpoint(s Service) endpoint.Endpoint
- func MakeListSnippetsEndpoint(s Service) endpoint.Endpoint
- func MakeSnippetsHandler(s Service, l log.Logger) chi.Router
- func NewPagination(limit uint, offset uint, total uint) service.Pagination
- type ListSnippetsRequest
- type PGStorage
- func (pg *PGStorage) Create(ctx context.Context, snippet Snippet) (uint, error)
- func (pg *PGStorage) Get(ctx context.Context, id uint) (Snippet, error)
- func (pg *PGStorage) List(ctx context.Context, pagination service.Pagination) ([]Snippet, error)
- func (pg *PGStorage) SoftDelete(ctx context.Context, id uint) error
- func (pg *PGStorage) Total(ctx context.Context) (uint, error)
- type Service
- type Snippet
- type SnippetService
- func (s *SnippetService) Create(ctx context.Context, snippet Snippet) (Snippet, *service.Error)
- func (s *SnippetService) Get(ctx context.Context, id uint) (Snippet, *service.Error)
- func (s *SnippetService) List(ctx context.Context, limit uint, offset uint) ([]Snippet, service.Pagination, *service.Error)
- func (s *SnippetService) SoftDelete(ctx context.Context, id uint) *service.Error
- type Storage
Constants ¶
This section is empty.
Variables ¶
var ErrNotFound = errors.New("not found")
ErrNotFound error used to signal higher level about sql.ErrNoRows error
Functions ¶
func ConvertPaginationToSQLExpression ¶
func ConvertPaginationToSQLExpression(pagination service.Pagination) string
ConvertPaginationToSQLExpression converts service.Pagination to SQL expression
func MakeCreateSnippetEndpoint ¶
MakeCreateSnippetEndpoint creates a new go-kit Endpoint for POST /snippets method
func MakeDeleteSnippetEndpoint ¶
MakeDeleteSnippetEndpoint creates a new go-kit Endpoint for DELETE /snippets/{snippet_id} method
func MakeGetSnippetEndpoint ¶
MakeGetSnippetEndpoint creates a new go-kit Endpoint for GET /snippets/{snippet_id} method
func MakeListSnippetsEndpoint ¶
MakeListSnippetsEndpoint creates a new go-kit Endpoint for GET /snippets method
func MakeSnippetsHandler ¶
MakeSnippetsHandler initialize all endpoints for route /snippets
func NewPagination ¶
func NewPagination(limit uint, offset uint, total uint) service.Pagination
NewPagination creates new service.Pagination with default maximum limit
Types ¶
type ListSnippetsRequest ¶
ListSnippetsRequest represents a request struct for GET /snippets?limit=<x>&offset=<y> method
type PGStorage ¶
type PGStorage struct {
// contains filtered or unexported fields
}
PGStorage implements storage interface and provides methods to manipulate data in PostgreSQL storage
func NewPGStorage ¶
NewPGStorage returns a new instance of PGStorage
func (*PGStorage) SoftDelete ¶
SoftDelete set `expires_at` to `now()`, so snippet is considered deleted
type Service ¶
type Service interface { Get(ctx context.Context, id uint) (Snippet, *service.Error) Create(ctx context.Context, snippet Snippet) (Snippet, *service.Error) List(ctx context.Context, limit uint, offset uint) ([]Snippet, service.Pagination, *service.Error) SoftDelete(ctx context.Context, id uint) *service.Error }
Service is used to manipulate data over snippets
type Snippet ¶
type Snippet struct { ID uint Title string Content string CreatedAt time.Time UpdatedAt time.Time ExpiresAt time.Time }
Snippet model struct
type SnippetService ¶
type SnippetService struct {
// contains filtered or unexported fields
}
SnippetService represents service struct. It holds storage and logger.
func NewService ¶
func NewService(storage Storage, logger log.Logger) *SnippetService
NewService returns new instance of SnippetService
func (*SnippetService) List ¶
func (s *SnippetService) List(ctx context.Context, limit uint, offset uint) ([]Snippet, service.Pagination, *service.Error)
List returns a list of snippets and a pagination struct
func (*SnippetService) SoftDelete ¶
SoftDelete mark a single snippet as deleted
type Storage ¶
type Storage interface { Get(ctx context.Context, id uint) (Snippet, error) Create(ctx context.Context, snippet Snippet) (uint, error) List(ctx context.Context, pagination service.Pagination) ([]Snippet, error) SoftDelete(ctx context.Context, id uint) error Total(ctx context.Context) (uint, error) }
Storage is used to manipulate data in DB