posts

package
v0.0.0-...-014da05 Latest Latest
Warning

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

Go to latest
Published: Jan 4, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound        = errors.New("post not found")
	ErrCommentNotFound = errors.New("post comment not found")
	ErrDuplicate       = errors.New("post already exists")
	ErrNotAllowed      = errors.New("user is not allowed to perform this operation")
	ErrAlreadyLiked    = errors.New("user already like this post")
)

Functions

This section is empty.

Types

type Comment

type Comment struct {
	ID        int64     `json:"id"`
	Comment   string    `json:"comment"`
	Author    string    `json:"author"`
	UserID    int64     `json:"user_id"`
	PostID    int64     `json:"post_id"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

type CreateCommentParams

type CreateCommentParams struct {
	User    *auth.User `json:"-" validate:"required"`
	PostID  int64      `json:"-" validate:"required"`
	Comment string     `json:"comment" validate:"required,max=60"`
}

type CreatePostParams

type CreatePostParams struct {
	User    *auth.User `json:"-" validate:"required"`
	Title   string     `json:"title" validate:"required,min=2,max=50"`
	Content string     `json:"content" validate:"required,max=250"`
}

type DeletePostParams

type DeletePostParams struct {
	User      *auth.User
	PostID    int64
	CommentID int64
}

type Post

type Post struct {
	ID        int64     `json:"id"`
	Title     string    `json:"title"`
	Content   string    `json:"content"`
	Likes     int64     `json:"likes"`
	Author    string    `json:"author"`
	UserID    int64     `json:"user_id"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

type Service

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

func NewService

func NewService(storer Storer) Service

func (Service) CreateComment

func (s Service) CreateComment(params CreateCommentParams) (*Comment, error)

func (Service) CreatePost

func (s Service) CreatePost(params CreatePostParams) (*Post, error)

func (Service) DeleteComment

func (s Service) DeleteComment(params DeletePostParams) error

Post owners can delete comments.

func (Service) DeletePost

func (s Service) DeletePost(user *auth.User, postId int64) error

func (Service) DislikePost

func (s Service) DislikePost(userId, postId int64) error

func (Service) GetPost

func (s Service) GetPost(id int64) (*Post, error)

func (Service) LikePost

func (s Service) LikePost(userId, postId int64) error

func (Service) ListComments

func (s Service) ListComments(postId int64, p pagination.Pagination) (*pagination.Paginated[*Comment], error)

func (Service) ListPosts

func (Service) UpdateComment

func (s Service) UpdateComment(params UpdateCommentParams) error

func (Service) UpdatePost

func (s Service) UpdatePost(params UpdatePostParams) error

type Storer

type Storer interface {
	InsertPost(*Post) error
	GetPost(int64) (*Post, error)
	ListPosts(limit, offset int) ([]*Post, error)
	DeletePost(int64) error
	UpdatePost(*Post) error
	CountPosts() (int, error)

	InsertPostLike(userId int64, postId int64) error
	DeletePostLike(userId int64, postId int64) error

	GetComment(postId, commentId int64) (*Comment, error)
	InsertPostComment(*Comment) error
	ListPostComments(postId int64, limit int, offset int) ([]*Comment, error)
	DeletePostComment(int64) error
	UpdatePostComment(*Comment) error
	CountPostComments(postId int64) (int, error)
}

type UpdateCommentParams

type UpdateCommentParams struct {
	User      *auth.User `json:"-" validate:"required"`
	PostID    int64      `json:"-" validate:"required"`
	CommentID int64      `json:"-" validate:"required"`
	Comment   string     `json:"comment" validate:"required,max=60"`
}

type UpdatePostParams

type UpdatePostParams struct {
	User    *auth.User `json:"-" validate:"required"`
	PostID  int64      `json:"-" validate:"required"`
	Title   string     `json:"title" validate:"required,min=2,max=50"`
	Content string     `json:"content" validate:"required,max=250"`
}

Jump to

Keyboard shortcuts

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