comment

package
v0.0.0-...-40cf777 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2022 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package comment provides an example of a core business API. Right now these calls are just wrapping the data/data layer. But at some point you will want auditing or something that isn't specific to the data/store layer.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound              = errors.New("comment not found")
	ErrInvalidID             = errors.New("ID is not in its proper form")
	ErrAuthenticationFailure = errors.New("authentication failed")
)

Set of error variables for CRUD operations.

Functions

This section is empty.

Types

type Comment

type Comment struct {
	ID          string    `json:"id"`
	Description string    `json:"description"`
	UserID      string    `json:"user_id"`
	PostID      string    `json:"post_id"`
	DateCreated time.Time `json:"date_created"`
	DateUpdated time.Time `json:"date_updated"`
}

Comment represents an individual comment.

type Core

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

Core manages the set of API's for comment access.

func NewCore

func NewCore(log *zap.SugaredLogger, sqlxDB *sqlx.DB, nats *nats.NATS) Core

NewCore constructs a core for comment api access.

func (Core) Create

func (c Core) Create(ctx context.Context, nc NewComment, now time.Time) (Comment, error)

Create inserts a new comment into the database.

func (Core) Delete

func (c Core) Delete(ctx context.Context, commentID string) error

Delete removes a comment from the database.

func (Core) Query

func (c Core) Query(ctx context.Context, pageNumber int, rowsPerPage int) ([]Comment, error)

Query retrieves a list of existing comments from the database.

func (Core) QueryByID

func (c Core) QueryByID(ctx context.Context, commentID string) (Comment, error)

QueryByID gets the specified comment from the database.

func (Core) QueryByPostID

func (c Core) QueryByPostID(ctx context.Context, postID string) ([]Comment, error)

func (Core) QueryByUserID

func (c Core) QueryByUserID(ctx context.Context, userID string) ([]Comment, error)

func (Core) QueryPostsByPostID

func (c Core) QueryPostsByPostID(ctx context.Context, postID string) (interface{}, error)

func (Core) Update

func (c Core) Update(ctx context.Context, commentID string, uc UpdateComment, now time.Time) error

Update replaces a comment document in the database.

type Listener

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

func (Listener) PostCreated

func (l Listener) PostCreated() error

func (Listener) PostDeleted

func (l Listener) PostDeleted() error

func (Listener) PostUpdated

func (l Listener) PostUpdated() error

type NewComment

type NewComment struct {
	Description string `json:"description" validate:"required"`
	UserID      string `json:"user_id" validate:"required"`
	PostID      string `json:"post_id" validate:"required"`
}

NewComment contains information needed to create a new Comment.

type Post

type Post struct {
	ID          string    `json:"id"`
	Title       string    `json:"title"`
	Description string    `json:"description"`
	UserID      string    `json:"user_id"`
	DateCreated time.Time `json:"date_created"`
	DateUpdated time.Time `json:"date_updated"`
}

type PostComment

type PostComment struct {
	ID                 string    `json:"id"`
	Title              string    `json:"title"`
	Description        string    `json:"description"`
	UserID             string    `json:"user_id"`
	DateCreated        time.Time `json:"date_created"`
	DateUpdated        time.Time `json:"date_updated"`
	CommentID          string    `json:"comment_id"`
	CommentDescription string    `json:"comment_description"`
	CommentUserID      string    `json:"comment_user_id"`
	CommentDateCreated time.Time `json:"comment_date_created"`
	CommentDateUpdated time.Time `json:"comment_date_updated"`
}

type UpdateComment

type UpdateComment struct {
	Description *string `json:"description"`
}

UpdateComment defines what information may be provided to modify an existing Comment. All fields are optional so clients can send just the fields they want changed. It uses pointer fields so we can differentiate between a field that was not provided and a field that was provided as explicitly blank. Normally we do not want to use pointers to basic types but we make exceptions around marshalling/unmarshalling.

Directories

Path Synopsis
Package db contains comment related CRUD functionality.
Package db contains comment related CRUD functionality.

Jump to

Keyboard shortcuts

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