task

package
v0.0.0-...-1e8201c Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2024 License: GPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const DBLocation = "tasks.json"

Variables

View Source
var ErrCouldntGetTasks = errors.New("couln't get tasks")
View Source
var ErrEmptyJson = errors.New("empty json")

Functions

func DeleteTask

func DeleteTask(id uint64) error

func Initialise

func Initialise()

Types

type ProgressStatus

type ProgressStatus string
const (
	NotStarted ProgressStatus = "Not Started"
	InProgress ProgressStatus = "In Progress"
	Done       ProgressStatus = "Done"
)

type Task

type Task struct {
	Id          uint64         `json:"id"`
	Description string         `json:"description"`
	Status      ProgressStatus `json:"status"`
	CreatedAt   time.Time      `json:"createdAt"`
	UpdatedAt   time.Time      `json:"updatedAt"`
}

func AddTask

func AddTask(description string) (*Task, error)

AddTask adds a new task with the given description to the task list.

Parameters:

description (string): The description of the new task.

Returns:

*Task: A pointer to the newly created Task.
error: An error if the task could not be added, or nil if the task was added successfully.

func GetTasks

func GetTasks(filters ...ProgressStatus) ([]Task, error)

GetTasks retrieves the list of tasks from the database file specified by DBLocation. It reads the file content, unmarshals the JSON data into a slice of Task structs, and returns it. If the file is empty, it returns an ErrEmptyJson error. If there is an error reading the file or unmarshalling the JSON data, it returns the respective error.

Returns:

  • []Task: A slice of Task structs representing the tasks.
  • error: An error if there is an issue reading the file or unmarshalling the JSON data, or if the file is empty.

func UpdateTask

func UpdateTask(id uint64, newTask Task) (*Task, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳