storage

package
v0.0.0-...-9f38a2f Latest Latest
Warning

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

Go to latest
Published: May 3, 2025 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Contains

func Contains(s, substr string) bool

Helper function for string contains search

func FilterTasks

func FilterTasks(tasks []*models.Task, options FilterOptions) []*models.Task

FilterTasks applies filtering options to a slice of tasks

func SortTasks

func SortTasks(tasks []*models.Task, options SortOptions) []*models.Task

SortTasks sorts a slice of tasks according to the given sort options

Types

type BoltDBStorage

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

BoltDBStorage implements Storage using BoltDB

func NewBoltDBStorage

func NewBoltDBStorage(dbPath string) (*BoltDBStorage, error)

NewBoltDBStorage creates a new BoltDB storage

func (*BoltDBStorage) Add

func (s *BoltDBStorage) Add(task *models.Task) error

Add saves a new task

func (*BoltDBStorage) BatchComplete

func (s *BoltDBStorage) BatchComplete(ids []int) error

BatchComplete marks multiple tasks as completed

func (*BoltDBStorage) BatchCreate

func (s *BoltDBStorage) BatchCreate(tasks []*models.Task) error

BatchCreate creates multiple tasks at once

func (*BoltDBStorage) BatchDelete

func (s *BoltDBStorage) BatchDelete(ids []int) error

BatchDelete deletes multiple tasks at once

func (*BoltDBStorage) BatchUpdate

func (s *BoltDBStorage) BatchUpdate(tasks []*models.Task) error

BatchUpdate updates multiple tasks at once

func (*BoltDBStorage) Close

func (s *BoltDBStorage) Close() error

Close closes the database

func (*BoltDBStorage) Delete

func (s *BoltDBStorage) Delete(id int) error

Delete removes a task by ID

func (*BoltDBStorage) DeleteAttachment

func (s *BoltDBStorage) DeleteAttachment(taskID int, attachmentID int) error

DeleteAttachment removes a file attachment from a task

func (*BoltDBStorage) Filter

func (s *BoltDBStorage) Filter(options FilterOptions) ([]*models.Task, error)

Filter returns tasks matching the given filter options

func (*BoltDBStorage) Get

func (s *BoltDBStorage) Get(id int) (*models.Task, error)

Get retrieves a task by ID

func (*BoltDBStorage) GetAll

func (s *BoltDBStorage) GetAll() ([]*models.Task, error)

GetAll returns all tasks

func (*BoltDBStorage) GetAttachment

func (s *BoltDBStorage) GetAttachment(taskID int, attachmentID int) (*models.Attachment, []byte, error)

GetAttachment retrieves a file attachment from a task

func (*BoltDBStorage) GetCategories

func (s *BoltDBStorage) GetCategories() ([]string, error)

GetCategories returns all unique categories

func (*BoltDBStorage) GetPaginated

func (s *BoltDBStorage) GetPaginated(page, perPage int, sortOptions SortOptions) ([]*models.Task, int, error)

GetPaginated retrieves paginated tasks with sorting

func (*BoltDBStorage) GetSharedTasks

func (s *BoltDBStorage) GetSharedTasks(username string) ([]*models.Task, error)

GetSharedTasks returns tasks shared with a user

func (*BoltDBStorage) GetStats

func (s *BoltDBStorage) GetStats() (map[string]interface{}, error)

GetStats returns statistics about tasks

func (*BoltDBStorage) GetTags

func (s *BoltDBStorage) GetTags() ([]string, error)

GetTags returns all unique tags

func (*BoltDBStorage) GetTaskAnalytics

func (s *BoltDBStorage) GetTaskAnalytics() (map[string]interface{}, error)

GetTaskAnalytics returns detailed analytics about tasks

func (*BoltDBStorage) GetTasksByUser

func (s *BoltDBStorage) GetTasksByUser(username string) ([]*models.Task, error)

GetTasksByUser returns tasks assigned to or created by a user

func (*BoltDBStorage) SaveAttachment

func (s *BoltDBStorage) SaveAttachment(taskID int, filename string, data []byte, contentType string) (*models.Attachment, error)

SaveAttachment stores a file attachment for a task

func (*BoltDBStorage) Search

func (s *BoltDBStorage) Search(query string) ([]*models.Task, error)

Search searches tasks by title, description, or category

func (*BoltDBStorage) Update

func (s *BoltDBStorage) Update(task *models.Task) error

Update modifies an existing task

type FilterOptions

type FilterOptions struct {
	Completed     *bool             `json:"completed,omitempty"`     // Filter by completion status
	Category      string            `json:"category,omitempty"`      // Filter by category
	Priority      models.Priority   `json:"priority,omitempty"`      // Filter by priority
	Tag           string            `json:"tag,omitempty"`           // Filter by tag
	DueBefore     time.Time         `json:"dueBefore,omitempty"`     // Filter by due date before
	DueAfter      time.Time         `json:"dueAfter,omitempty"`      // Filter by due date after
	CreatedAfter  time.Time         `json:"createdAfter,omitempty"`  // Filter by creation date after
	AssignedTo    string            `json:"assignedTo,omitempty"`    // Filter by assignee
	CreatedBy     string            `json:"createdBy,omitempty"`     // Filter by creator
	SearchTerm    string            `json:"searchTerm,omitempty"`    // Search term to match against title and description
	CustomFilters map[string]string `json:"customFilters,omitempty"` // Additional custom filters
}

FilterOptions defines options for filtering tasks

type PaginationOptions

type PaginationOptions struct {
	Page    int `json:"page"`
	PerPage int `json:"perPage"`
}

PaginationOptions defines pagination parameters for list queries

type SortOptions

type SortOptions struct {
	Field     string `json:"field"`     // Field to sort by
	Direction string `json:"direction"` // Sort direction ("asc" or "desc")
}

SortOptions defines options for sorting tasks

type TaskStorage

type TaskStorage interface {
	// Basic CRUD operations
	Add(task *models.Task) error
	Get(id int) (*models.Task, error)
	GetAll() ([]*models.Task, error)
	Update(task *models.Task) error
	Delete(id int) error
	Close() error

	// Search and filtering
	Search(query string) ([]*models.Task, error)
	Filter(options FilterOptions) ([]*models.Task, error)
	GetCategories() ([]string, error)
	GetTags() ([]string, error)

	// Pagination and sorting
	GetPaginated(page, perPage int, sortOptions SortOptions) ([]*models.Task, int, error)

	// Statistics and analytics
	GetStats() (map[string]interface{}, error)
	GetTaskAnalytics() (map[string]interface{}, error)

	// Batch operations
	BatchCreate(tasks []*models.Task) error
	BatchUpdate(tasks []*models.Task) error
	BatchDelete(ids []int) error
	BatchComplete(ids []int) error

	// User-specific operations
	GetTasksByUser(username string) ([]*models.Task, error)
	GetSharedTasks(username string) ([]*models.Task, error)

	// Attachments
	SaveAttachment(taskID int, filename string, data []byte, contentType string) (*models.Attachment, error)
	GetAttachment(taskID int, attachmentID int) (*models.Attachment, []byte, error)
	DeleteAttachment(taskID int, attachmentID int) error
}

TaskStorage defines the interface for task storage

type UserStorage

type UserStorage interface {
	// User operations
	AddUser(user *models.User) error
	GetUser(id int) (*models.User, error)
	GetUserByUsername(username string) (*models.User, error)
	GetUserByEmail(email string) (*models.User, error)
	UpdateUser(user *models.User) error
	DeleteUser(id int) error
	ListUsers() ([]*models.User, error)

	// Authentication
	Authenticate(username, password string) (*models.User, error)
	ResetPassword(userID int, newPassword string) error

	// Close connection
	Close() error
}

UserStorage defines the interface for user storage

Jump to

Keyboard shortcuts

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