Documentation
¶
Index ¶
- Variables
- func ConvertPaginationToSQLExpression(pagination service.Pagination) string
- func NewPagination(limit uint, offset uint, total uint) service.Pagination
- type CreateSnippetRequest
- type ListSnippetsRequest
- type ListSnippetsResponse
- 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 SnippetResponse
- 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
- type Transport
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 NewPagination ¶
func NewPagination(limit uint, offset uint, total uint) service.Pagination
NewPagination creates new service.Pagination with default maximum limit
Types ¶
type CreateSnippetRequest ¶
type CreateSnippetRequest struct {
Title string `json:"title"`
Content string `json:"content"`
ExpiresAt time.Time `json:"expires_at"`
}
CreateSnippetRequest represents a request struct for POST /snippets method
func (*CreateSnippetRequest) Validate ¶
func (r *CreateSnippetRequest) Validate() error
Validate implements ozzo-validation.Validatable interface and used to check user request
type ListSnippetsRequest ¶
ListSnippetsRequest represents a request struct for GET /snippets?limit=<x>&offset=<y> method
type ListSnippetsResponse ¶
type ListSnippetsResponse struct {
Snippets []SnippetResponse `json:"snippets,omitempty"`
Pagination service.Pagination `json:"pagination"`
}
ListSnippetsResponse represents a response 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 SnippetResponse ¶
type SnippetResponse struct {
ID uint `json:"id"`
Title string `json:"title"`
Content string `json:"content"`
CreatedAt time.Time `json:"created_at"`
ExpiresAt time.Time `json:"expires_at"`
}
SnippetResponse represents a common snippet-response struct
type SnippetService ¶
type SnippetService struct {
// contains filtered or unexported fields
}
SnippetService represents service struct. It holds storage and logger.
func NewService ¶
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
type Transport ¶
type Transport struct {
// contains filtered or unexported fields
}
Transport is a struct that holds all endpoints for snippets
func NewTransport ¶
NewTransport creates a new Transport instance