models

package
v0.0.0-...-8cb9352 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2025 License: GPL-3.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Project

type Project struct {
	ID               int       `gorm:"primaryKey"                 json:"id"`
	Name             string    `gorm:"unique;not null"            json:"name"`
	Description      string    `                                  json:"description"`
	CreationDate     time.Time `gorm:"not null"                   json:"creation_date"`
	LastModifiedDate time.Time `gorm:"not null"                   json:"last_modified_date"`
	ParentProjectID  *int      `                                  json:"parent_project_id,omitempty"`
	ParentProject    *Project  `gorm:"foreignKey:ParentProjectID" json:"-"`
	SubProjects      []Project `gorm:"foreignKey:ParentProjectID" json:"-"`
	Tasks            []Task    `gorm:"foreignKey:ProjectID"       json:"-"`
}

Project represents a project entity in the to-do list system. It supports hierarchical relationships, where a project can have a parent project and multiple subprojects. Each project can also have associated tasks.

Fields:

  • ID: The unique identifier for the project.
  • Name: The name of the project, which must be unique and non-null.
  • Description: A description of the project (optional).
  • CreationDate: The date and time when the project was created (automatically set).
  • LastModifiedDate: The date and time when the project was last updated (automatically set).
  • ParentProjectID: The ID of the parent project, if this project is a subproject (optional).
  • ParentProject: A reference to the parent project (not serialized to JSON).
  • SubProjects: A list of subprojects belonging to this project (not serialized to JSON).
  • Tasks: A list of tasks associated with this project (not serialized to JSON).

func (*Project) BeforeCreate

func (p *Project) BeforeCreate(_ *gorm.DB) error

BeforeCreate is a GORM hook that sets the CreationDate and LastModifiedDate fields to the current time before a new project is inserted into the database.

func (*Project) BeforeUpdate

func (p *Project) BeforeUpdate(_ *gorm.DB) error

BeforeUpdate is a GORM hook that updates the LastModifiedDate field to the current time before an existing project is updated in the database.

type Task

type Task struct {
	ID              int        `gorm:"primaryKey"              json:"id"`
	Name            string     `gorm:"not null"                json:"name"`
	Description     string     `                               json:"description"`
	ProjectID       int        `gorm:"not null"                json:"project_id"`
	Project         Project    `gorm:"foreignKey:ProjectID"    json:"-"`
	TaskCompleted   bool       `gorm:"not null"                json:"task_completed"`
	DueDate         *time.Time `                               json:"due_date,omitempty"`
	CompletionDate  *time.Time `                               json:"completion_date,omitempty"`
	CreationDate    time.Time  `gorm:"not null"                json:"creation_date"`
	LastUpdatedDate time.Time  `gorm:"not null"                json:"last_updated_date"`
	Priority        int        `gorm:"not null;default:4"      json:"priority"`
	ParentTaskID    *int       `                               json:"parent_task_id,omitempty"`
	ParentTask      *Task      `gorm:"foreignKey:ParentTaskID" json:"-"`
	SubTasks        []Task     `gorm:"foreignKey:ParentTaskID" json:"-"`
}

Task represents a task entity in the to-do list system. Each task belongs to a project and can have a parent task (for subtasks) and multiple subtasks. The task tracks its completion status, priority, and relevant timestamps.

Fields:

  • ID: The unique identifier for the task.
  • Name: The name of the task, which is required.
  • Description: A description of the task (optional).
  • ProjectID: The ID of the project to which the task belongs (required).
  • Project: A reference to the project this task belongs to (not serialized to JSON).
  • TaskCompleted: A boolean indicating whether the task is completed (required).
  • DueDate: The due date for the task (optional).
  • CompletionDate: The date when the task was completed (optional, set when TaskCompleted is true).
  • CreationDate: The date and time when the task was created (automatically set).
  • LastUpdatedDate: The date and time when the task was last updated (automatically set).
  • Priority: The priority level of the task, represented by an integer (1: High, 2: Medium, 3: Low, 4: None).
  • ParentTaskID: The ID of the parent task, if this task is a subtask (optional).
  • ParentTask: A reference to the parent task (not serialized to JSON).
  • SubTasks: A list of subtasks belonging to this task (not serialized to JSON).

func (*Task) BeforeCreate

func (t *Task) BeforeCreate(_ *gorm.DB) error

BeforeCreate is a GORM hook that sets the CreationDate and LastUpdatedDate fields to the current time before a new task is inserted into the database.

func (*Task) BeforeUpdate

func (t *Task) BeforeUpdate(_ *gorm.DB) error

BeforeUpdate is a GORM hook that updates the LastUpdatedDate field to the current time before an existing task is updated in the database.

Jump to

Keyboard shortcuts

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