gogmagog/models/action.go
2021-01-30 12:40:58 -06:00

40 lines
1.3 KiB
Go

package models
import (
"time"
)
// Action represents a single action item.
type Action struct {
ActionID int64 `json:"action_id"`
ActionDescription string `json:"action_description"`
UserID int64 `json:"user_id"`
EstimatedChunks int `json:"estimated_chunks"`
CompletedChunks int `json:"completed_chunks"`
CompletedOn *time.Time `json:"completed_on,omitempty"`
PlanID int `json:"plan_id"`
CreatedAt *time.Time `json:"created_at,omitempty"`
UpdatedAt *time.Time `json:"updated_at,omitempty"`
}
// Actions returns all actions from the model.
func (m *Model) Actions(userID int) ([]*Action, error) {
return m.SelectActions(userID)
}
// Action returns a single action from its ID
func (m *Model) Action(id int, userID int) (*Action, error) {
act, err := m.SelectActionByID(id, userID)
return act, wrapNotFound(err)
}
// AddAction inserts a given action into the store, returning the generated ActionID. The provided ActionID is ignored.
func (m *Model) AddAction(action *Action, userID int) (int, error) {
return m.InsertAction(action, userID)
}
// SaveAction saves and updates an action.
func (m *Model) SaveAction(action *Action, userID int) error {
return m.UpdateAction(action, userID)
}