first commit

This commit is contained in:
2020-12-31 17:49:54 +01:00
commit 2240985aa1
120 changed files with 11574 additions and 0 deletions
+73
View File
@@ -0,0 +1,73 @@
package models
import (
"context"
"time"
)
type Goal struct {
ID string `json:"id" db:"goal_id"`
UserID string `json:"-" db:"user_id"`
GroupID string `json:"groupId" db:"group_id"`
StartTime time.Time `json:"startTime" db:"start_time"`
EndTime time.Time `json:"endTime" db:"end_time"`
Amount int `json:"amount" db:"amount"`
Name string `json:"name" db:"name"`
Description string `json:"description" db:"description"`
}
func (goal *Goal) Update(update GoalUpdate) {
if update.Amount != nil {
goal.Amount = *update.Amount
}
if update.StartTime != nil {
goal.StartTime = *update.StartTime
}
if update.EndTime != nil {
goal.EndTime = *update.EndTime
}
if update.Name != nil {
goal.Name = *update.Name
}
if update.Description != nil {
goal.Description = *update.Description
}
}
type GoalUpdate struct {
StartTime *time.Time `json:"startTime"`
EndTime *time.Time `json:"endTime"`
Amount *int `json:"amount"`
Name *string `json:"name"`
Description *string `json:"description"`
}
type GoalResult struct {
Goal
Group *Group `json:"group"`
Items []*GoalResultItem `json:"items"`
Logs []*LogResult `json:"logs"`
CompletedAmount int `json:"completedAmount"`
}
type GoalResultItem struct {
Item
CompletedAmount int `json:"completedAmount"`
}
type GoalFilter struct {
UserID string
GroupIDs []string
IncludesTime *time.Time
MinTime *time.Time
MaxTime *time.Time
IDs []string
}
type GoalRepository interface {
Find(ctx context.Context, id string) (*Goal, error)
List(ctx context.Context, filter GoalFilter) ([]*Goal, error)
Insert(ctx context.Context, goal Goal) error
Update(ctx context.Context, goal Goal) error
Delete(ctx context.Context, goal Goal) error
}
+47
View File
@@ -0,0 +1,47 @@
package models
import "context"
type Group struct {
ID string `json:"id" db:"group_id"`
UserID string `json:"-" db:"user_id"`
Name string `json:"name" db:"name"`
Icon string `json:"icon" db:"icon"`
Description string `json:"description" db:"description"`
}
func (g *Group) Update(update GroupUpdate) {
if update.Name != nil {
g.Name = *update.Name
}
if update.Icon != nil {
g.Icon = *update.Icon
}
if update.Description != nil {
g.Description = *update.Description
}
}
type GroupUpdate struct {
Name *string `json:"name"`
Icon *string `jsoN:"icon"`
Description *string `json:"description"`
}
type GroupResult struct {
Group
Items []*Item `json:"items"`
}
type GroupFilter struct {
UserID string
IDs []string
}
type GroupRepository interface {
Find(ctx context.Context, id string) (*Group, error)
List(ctx context.Context, filter GroupFilter) ([]*Group, error)
Insert(ctx context.Context, group Group) error
Update(ctx context.Context, group Group) error
Delete(ctx context.Context, group Group) error
}
+50
View File
@@ -0,0 +1,50 @@
package models
import "context"
type Item struct {
ID string `json:"id" db:"item_id"`
UserID string `json:"-" db:"user_id"`
GroupID string `json:"groupId" db:"group_id"`
GroupWeight int `json:"groupWeight" db:"group_weight"`
Icon string `json:"icon" db:"icon"`
Name string `json:"name" db:"name"`
Description string `json:"description" db:"description"`
}
func (item *Item) Update(update ItemUpdate) {
if update.GroupWeight != nil {
item.GroupWeight = *update.GroupWeight
}
if update.Name != nil {
item.Name = *update.Name
}
if update.Description != nil {
item.Description = *update.Description
}
}
type ItemUpdate struct {
GroupWeight *int `json:"groupWeight"`
Name *string `json:"name"`
Description *string `json:"description"`
}
type ItemResult struct {
Item
Group *Group `json:"group"`
}
type ItemFilter struct {
UserID string
IDs []string
GroupIDs []string
}
type ItemRepository interface {
Find(ctx context.Context, id string) (*Item, error)
List(ctx context.Context, filter ItemFilter) ([]*Item, error)
Insert(ctx context.Context, item Item) error
Update(ctx context.Context, item Item) error
Delete(ctx context.Context, item Item) error
}
+50
View File
@@ -0,0 +1,50 @@
package models
import (
"context"
"time"
)
type Log struct {
ID string `json:"id" db:"log_id"`
UserID string `json:"-" db:"user_id"`
TaskID string `json:"taskId" db:"task_id"`
ItemID string `json:"itemId" db:"item_id"`
LoggedTime time.Time `json:"loggedTime" db:"logged_time"`
Description string `json:"description" db:"description"`
}
func (log *Log) Update(update LogUpdate) {
if update.LoggedTime != nil {
log.LoggedTime = update.LoggedTime.UTC()
}
if update.Description != nil {
log.Description = *update.Description
}
}
type LogUpdate struct {
LoggedTime *time.Time `json:"loggedTime"`
Description *string `json:"description"`
}
type LogResult struct {
Log
Task *Task `json:"task"`
}
type LogFilter struct {
UserID string
IDs []string
ItemIDs []string
MinTime *time.Time
MaxTime *time.Time
}
type LogRepository interface {
Find(ctx context.Context, id string) (*Log, error)
List(ctx context.Context, filter LogFilter) ([]*Log, error)
Insert(ctx context.Context, log Log) error
Update(ctx context.Context, log Log) error
Delete(ctx context.Context, log Log) error
}
+68
View File
@@ -0,0 +1,68 @@
package models
import (
"context"
"time"
)
type Project struct {
ID string `json:"id" db:"project_id"`
UserID string `json:"-" db:"user_id"`
Name string `json:"name" db:"name"`
Description string `json:"description" db:"description"`
Icon string `json:"icon" db:"icon"`
Active bool `json:"active" db:"active"`
CreatedTime time.Time `json:"createdTime" db:"created_time"`
EndTime *time.Time `json:"endTime" db:"end_time"`
}
func (project *Project) Update(update ProjectUpdate) {
if update.Name != nil {
project.Name = *update.Name
}
if update.Description != nil {
project.Description = *update.Description
}
if update.Icon != nil {
project.Icon = *update.Icon
}
if update.Active != nil {
project.Active = *update.Active
}
if update.EndTime != nil {
endTimeCopy := update.EndTime.UTC()
project.EndTime = &endTimeCopy
}
if update.ClearEndTime {
project.EndTime = nil
}
}
type ProjectUpdate struct {
Name *string `json:"name"`
Description *string `json:"description"`
Icon *string `json:"icon"`
Active *bool `json:"active"`
EndTime *time.Time `json:"endTime"`
ClearEndTime bool `json:"clearEndTime"`
}
type ProjectResult struct {
Project
Tasks []*TaskResult `json:"tasks"`
}
type ProjectFilter struct {
UserID string
Active *bool
Expiring bool
IDs []string
}
type ProjectRepository interface {
Find(ctx context.Context, id string) (*Project, error)
List(ctx context.Context, filter ProjectFilter) ([]*Project, error)
Insert(ctx context.Context, project Project) error
Update(ctx context.Context, project Project) error
Delete(ctx context.Context, project Project) error
}
+74
View File
@@ -0,0 +1,74 @@
package models
import (
"context"
"time"
)
type Task struct {
ID string `json:"id" db:"task_id"`
UserID string `json:"-" db:"user_id"`
ItemID string `json:"itemId" db:"item_id"`
ProjectID string `json:"projectId" db:"project_id"`
ItemAmount int `json:"itemAmount" db:"item_amount"`
Name string `json:"name" db:"name"`
Description string `json:"description" db:"description"`
Icon string `json:"icon" db:"icon"`
Active bool `json:"active" db:"active"`
CreatedTime time.Time `json:"createdTime" db:"created_time"`
EndTime *time.Time `json:"endTime" db:"end_time"`
}
func (task *Task) Update(update TaskUpdate) {
if update.ItemAmount != nil {
task.ItemAmount = *update.ItemAmount
}
if update.Name != nil {
task.Name = *update.Name
}
if update.Description != nil {
task.Description = *update.Description
}
if update.Active != nil {
task.Active = *update.Active
}
if update.EndTime != nil {
endTimeCopy := update.EndTime.UTC()
task.EndTime = &endTimeCopy
}
if update.ClearEndTime {
task.EndTime = nil
}
}
type TaskUpdate struct {
ItemAmount *int `json:"itemAmount"`
Name *string `json:"name"`
Description *string `json:"description"`
Active *bool `json:"active"`
EndTime *time.Time `json:"endTime"`
ClearEndTime bool `json:"clearEndTime"`
}
type TaskResult struct {
Task
Item *Item `json:"item"`
Logs []*Log `json:"logs"`
CompletedAmount int `json:"completedAmount"`
}
type TaskFilter struct {
UserID string
Active *bool
IDs []string
ItemIDs []string
ProjectIDs []string
}
type TaskRepository interface {
Find(ctx context.Context, id string) (*Task, error)
List(ctx context.Context, filter TaskFilter) ([]*Task, error)
Insert(ctx context.Context, task Task) error
Update(ctx context.Context, task Task) error
Delete(ctx context.Context, task Task) error
}