attachments

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: 19 Imported by: 0

Documentation

Overview

Package attachments provides domain, repository and service logic for task attachments.

Index

Constants

View Source
const (
	DefaultMaxFileSizeBytes uint64 = 104857600
	MaxFileNameLength       int    = 255
)

Variables

View Source
var (
	ErrNotFound         = errors.New("attachment not found")
	ErrValidationFailed = errors.New("validation failed")
	ErrTaskNotFound     = errors.New("task not found")
	ErrUnauthorized     = errors.New("unauthorized")
	ErrFileTooLarge     = errors.New("file exceeds maximum allowed size")
	ErrNotUploaded      = errors.New("attachment is not yet uploaded")
)

Functions

func Module

func Module() fx.Option

Types

type Attachment

type Attachment struct {
	ID         int64
	TaskID     int64
	FileName   string
	StorageKey string
	SizeBytes  uint64
	Status     AttachmentStatus
	UploadedBy int64
	UploadedAt time.Time
	DeletedAt  *time.Time
}

type AttachmentInput

type AttachmentInput struct {
	TaskID     int64
	FileName   string
	SizeBytes  uint64
	UploaderID int64
}

func (AttachmentInput) Validate

func (i AttachmentInput) Validate(maxFileSize uint64) error

type AttachmentStatus

type AttachmentStatus string
const (
	StatusPending  AttachmentStatus = "pending"
	StatusUploaded AttachmentStatus = "uploaded"
)

type AttachmentWithURL

type AttachmentWithURL struct {
	Attachment

	DownloadURL string
}

type Config

type Config struct {
	MaxSize uint64
}

type Repository

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

func NewRepository

func NewRepository(db *bun.DB) *Repository

func (*Repository) Confirm

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

func (*Repository) Create

func (r *Repository) Create(ctx context.Context, input AttachmentInput, storageKey string) (*Attachment, error)

func (*Repository) Delete

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

func (*Repository) GetByID

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

func (*Repository) Import added in v0.2.0

func (r *Repository) Import(ctx context.Context, model *attachmentModel) (*Attachment, error)

func (*Repository) ListByTask

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

type Service

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

func NewService

func NewService(
	config Config,
	attachments *Repository,
	tasksSvc *tasks.Service,
	storageSvc *storage.Service,
	logger *zap.Logger,
) *Service

func (*Service) ConfirmUpload

func (s *Service) ConfirmUpload(ctx context.Context, id int64, uploaderID int64) (*Attachment, error)

func (*Service) Delete

func (s *Service) Delete(ctx context.Context, user *users.User, id int64) error

func (*Service) GetDownloadURL

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

func (*Service) Import added in v0.2.0

func (s *Service) Import(
	ctx context.Context,
	taskID int64,
	fileName, localFilePath string,
	uploadedBy int64,
) (*Attachment, error)

func (*Service) InitUpload

func (s *Service) InitUpload(ctx context.Context, input AttachmentInput) (*UploadResult, error)

func (*Service) ListByTask

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

type UploadResult

type UploadResult struct {
	Attachment *Attachment
	UploadURL  string
}

Jump to

Keyboard shortcuts

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