comment

package
v0.0.0-...-b46d3ee Latest Latest
Warning

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

Go to latest
Published: May 11, 2022 License: BSD-3-Clause Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrFetchingComment = errors.New("failed to fetch comment by id")
	ErrNotImplemented  = errors.New("not implemented")
)

Functions

This section is empty.

Types

type Comment

type Comment struct {
	ID     string
	Slug   string
	Body   string
	Author string
}

Comment - a representation of the comment structure for our service

type Service

type Service struct {
	Store Store
}

Service - is the struct on which all the logic will be built on top of

func NewService

func NewService(store Store) *Service

NewService - returns a pointer to a new service

func (*Service) DeleteComment

func (s *Service) DeleteComment(ctx context.Context, id string) error

func (*Service) GetComment

func (s *Service) GetComment(ctx context.Context, id string) (Comment, error)

func (*Service) PostComment

func (s *Service) PostComment(ctx context.Context, cmt Comment) (Comment, error)

func (*Service) UpdateComment

func (s *Service) UpdateComment(
	ctx context.Context,
	ID string,
	updatedCmt Comment,
) (Comment, error)

type Store

type Store interface {
	GetComment(context.Context, string) (Comment, error)
	PostComment(context.Context, Comment) (Comment, error)
	DeleteComment(context.Context, string) error
	UpdateComment(context.Context, string, Comment) (Comment, error)
}

Store - this interface defines all the methods that the service needs to operate. 1. The benefit of this structure is that the storage interface can reach out to postgress, kasandera, etc 2. the store can be mocked for unit testing

Jump to

Keyboard shortcuts

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