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
- Variables
- func Module() fx.Option
- type Comment
- type CommentInput
- type CommentUpdate
- type Repository
- func (r *Repository) Create(ctx context.Context, input CommentInput) (*Comment, error)
- func (r *Repository) Delete(ctx context.Context, id int64) error
- func (r *Repository) GetByID(ctx context.Context, id int64) (*Comment, error)
- func (r *Repository) Import(ctx context.Context, input Comment) (*Comment, error)
- func (r *Repository) List(ctx context.Context, taskID int64) ([]Comment, error)
- func (r *Repository) Update(ctx context.Context, id int64, content string) error
- type Service
- func (s *Service) Create(ctx context.Context, input CommentInput) (*Comment, error)
- func (s *Service) Delete(ctx context.Context, userID int64, taskID, id int64) error
- func (s *Service) GetByID(ctx context.Context, id int64) (*Comment, error)
- func (s *Service) Import(ctx context.Context, input Comment) (*Comment, error)
- func (s *Service) ListByTask(ctx context.Context, taskID int64) ([]Comment, error)
- func (s *Service) Update(ctx context.Context, userID int64, taskID, id int64, update CommentUpdate) (*Comment, error)
Constants ¶
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 )
const (
// MaxContentLength is the maximum length of comment content.
MaxContentLength = 10000
)
Variables ¶
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 = errors.New("unauthorized") )
Module-specific error definitions. These errors can be checked using errors.Is(err, ErrXXX).
Functions ¶
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 ¶
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.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service implements the business logic for comment management.
func NewService ¶
NewService creates a new Service instance with the given dependencies.
func (*Service) Delete ¶
Delete soft-deletes a comment. Returns an error if the comment is not found, validation fails, or the user is not authorized.
func (*Service) ListByTask ¶
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.