task.go
go
package models
import "theskyscape.com/repo/skykit"
// Task represents a task within a project
type Task struct {
	skykit.Model
	ProjectID   string
	Title       string
	Description string
	Status      string // "todo", "in_progress", "done"
	Priority    string // "low", "medium", "high"
	Position    int    // Order within the status column
}
// CreateTask creates a new task
func CreateTask(projectID, title, description, status, priority string) (*Task, error) {
	return Tasks.Insert(&Task{
		ProjectID:   projectID,
		Title:       title,
		Description: description,
		Status:      status,
		Priority:    priority,
	})
}
// GetTasksByProjectID retrieves all tasks for a project
func GetTasksByProjectID(projectID string) ([]*Task, error) {
	return Tasks.Search(`
		WHERE ProjectID = ?
		ORDER BY Position ASC, CreatedAt DESC
	`, projectID)
}
// GetTaskByID retrieves a single task by ID
func GetTaskByID(id string) (*Task, error) {
	return Tasks.Get(id)
}
// UpdateTaskStatus updates the status of a task
func (t *Task) UpdateStatus(status string) error {
	t.Status = status
	return Tasks.Update(t)
}
// UpdatePosition updates the position of a task
func (t *Task) UpdatePosition(position int) error {
	t.Position = position
	return Tasks.Update(t)
}
// GetComments retrieves all comments for this task
func (t *Task) GetComments() ([]*Comment, error) {
	return Comments.Search(`
		WHERE TaskID = ?
		ORDER BY CreatedAt ASC
	`, t.ID)
}
No comments yet.