comments

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2026 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package comments provides functionality for managing comments on tasks.

The comments module supports:

  • Creating comments with Markdown content
  • Editing comments (author or admin only)
  • Soft deleting comments (author or admin only)
  • Retrieving comments by task

Usage

Create a new comment:

svc := comments.NewService(repo, tasksSvc, logger)
input := comments.CommentInput{
    TaskID:   123,
    AuthorID: 456,
    Content:  "This is a comment",
}
comment, err := svc.Create(ctx, input)

List comments for a task:

pagination := &db.Pagination{}
comments, err := svc.ListByTask(ctx, taskID, pagination)

Update a comment:

update := comments.CommentUpdate{Content: "Updated content"}
err := svc.Update(ctx, userID, commentID, update)

Delete a comment (soft delete):

err := svc.Delete(ctx, userID, commentID)

Index

Constants

View Source
const (
	// DefaultLimit is the default number of comments to return per page.
	DefaultLimit = 20
	// MaxLimit is the maximum number of comments to return per page.
	MaxLimit = 100
)
View Source
const (
	// MaxContentLength is the maximum length of comment content.
	MaxContentLength = 10000
)

Variables

View Source
var (
	// ErrNotFound indicates the requested comment does not exist.
	ErrNotFound = errors.New("comment not found")

	// ErrValidationFailed indicates input validation failed.
	ErrValidationFailed = errors.New("validation failed")

	// ErrUnauthorized indicates the user lacks permission for this action.
	ErrUnauthorized = errors.New("unauthorized")
)

Module-specific error definitions. These errors can be checked using errors.Is(err, ErrXXX).

Functions

func Module

func Module() fx.Option

Module creates and returns an FX module for the comments package.

The module provides:

  • comments.Service (public) - for use by HTTP handlers and other modules
  • comments.Repository (private) - internal data access layer
  • Named logger "comments" for structured logging

Types

type Comment

type Comment struct {
	ID        int64
	TaskID    int64
	AuthorID  int64
	Content   string
	CreatedAt time.Time
	UpdatedAt time.Time
	DeletedAt *time.Time
}

Comment represents a complete comment entity with all fields.

type CommentInput

type CommentInput struct {
	TaskID   int64
	AuthorID int64
	Content  string
}

CommentInput contains the data required to create a new comment.

func (CommentInput) Validate

func (i CommentInput) Validate() error

Validate checks that the input data is valid for comment creation.

type CommentUpdate

type CommentUpdate struct {
	Content string
}

CommentUpdate represents the data that can be updated for a comment.

func (CommentUpdate) Validate

func (u CommentUpdate) Validate() error

Validate checks that the update data is valid.

type Repository

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

Repository handles data access operations for comments.

func NewRepository

func NewRepository(db *bun.DB) *Repository

NewRepository creates a new Repository instance with the given database connection.

func (*Repository) Create

func (r *Repository) Create(ctx context.Context, input CommentInput) (*Comment, error)

Create inserts a new comment.

func (*Repository) Delete

func (r *Repository) Delete(ctx context.Context, id int64) error

Delete soft-deletes a comment by setting the deleted_at timestamp.

func (*Repository) GetByID

func (r *Repository) GetByID(ctx context.Context, id int64) (*Comment, error)

GetByID retrieves a comment by its ID.

func (*Repository) Import

func (r *Repository) Import(
	ctx context.Context,
	input Comment,
) (*Comment, error)

Import creates a comment with explicit timestamps for import.

func (*Repository) List

func (r *Repository) List(ctx context.Context, taskID int64) ([]Comment, error)

List retrieves all comments for a specific task.

func (*Repository) Update

func (r *Repository) Update(ctx context.Context, id int64, content string) error

Update modifies an existing comment with the provided content.

type Service

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

Service implements the business logic for comment management.

func NewService

func NewService(comments *Repository, usersSvc *users.Service, logger *zap.Logger) *Service

NewService creates a new Service instance with the given dependencies.

func (*Service) Create

func (s *Service) Create(ctx context.Context, input CommentInput) (*Comment, error)

Create validates input and creates a new comment.

func (*Service) Delete

func (s *Service) Delete(ctx context.Context, userID int64, taskID, id int64) error

Delete soft-deletes a comment. Returns an error if the comment is not found, validation fails, or the user is not authorized.

func (*Service) GetByID

func (s *Service) GetByID(ctx context.Context, id int64) (*Comment, error)

GetByID retrieves a comment by its ID.

func (*Service) Import

func (s *Service) Import(
	ctx context.Context,
	input Comment,
) (*Comment, error)

Import creates a comment with explicit timestamps for import.

func (*Service) ListByTask

func (s *Service) ListByTask(ctx context.Context, taskID int64) ([]Comment, error)

ListByTask retrieves all comments for a specific task.

func (*Service) Update

func (s *Service) Update(ctx context.Context, userID int64, taskID, id int64, update CommentUpdate) (*Comment, error)

Update modifies an existing comment with the provided content. Returns an error if the comment is not found, validation fails, or the user is not authorized.

Jump to

Keyboard shortcuts

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