This commit is contained in:
+32
-13
@@ -6,14 +6,17 @@ import (
|
||||
)
|
||||
|
||||
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"`
|
||||
ID string `json:"id" db:"goal_id"`
|
||||
UserID string `json:"-" db:"user_id"`
|
||||
GroupID string `json:"groupId" db:"group_id"`
|
||||
ItemID *string `json:"itemId" db:"item_id"`
|
||||
StartTime time.Time `json:"startTime" db:"start_time"`
|
||||
EndTime time.Time `json:"endTime" db:"end_time"`
|
||||
Amount int `json:"amount" db:"amount"`
|
||||
Unweighted bool `json:"unweighted" db:"unweighted"`
|
||||
Name string `json:"name" db:"name"`
|
||||
Description string `json:"description" db:"description"`
|
||||
CompositionMode string `json:"compositionMode" db:"composition_mode"`
|
||||
}
|
||||
|
||||
func (goal *Goal) Update(update GoalUpdate) {
|
||||
@@ -32,14 +35,30 @@ func (goal *Goal) Update(update GoalUpdate) {
|
||||
if update.Description != nil {
|
||||
goal.Description = *update.Description
|
||||
}
|
||||
if update.Unweighted != nil {
|
||||
goal.Unweighted = *update.Unweighted
|
||||
}
|
||||
if update.CompositionMode != nil {
|
||||
goal.CompositionMode = *update.CompositionMode
|
||||
}
|
||||
if update.ItemID != nil {
|
||||
goal.ItemID = update.ItemID
|
||||
}
|
||||
if update.ClearItemID {
|
||||
goal.ItemID = nil
|
||||
}
|
||||
}
|
||||
|
||||
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"`
|
||||
StartTime *time.Time `json:"startTime"`
|
||||
EndTime *time.Time `json:"endTime"`
|
||||
Amount *int `json:"amount"`
|
||||
Name *string `json:"name"`
|
||||
Description *string `json:"description"`
|
||||
ItemID *string `json:"itemId"`
|
||||
Unweighted *bool `json:"unweighted"`
|
||||
CompositionMode *string `json:"compositionMode"`
|
||||
ClearItemID bool `json:"clearItemID"`
|
||||
}
|
||||
|
||||
type GoalResult struct {
|
||||
|
||||
+43
-10
@@ -6,12 +6,28 @@ import (
|
||||
)
|
||||
|
||||
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"`
|
||||
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"`
|
||||
ItemAmount int `json:"itemAmount" db:"item_amount"`
|
||||
SecondaryItemID *string `json:"secondaryItemId" db:"secondary_item_id"`
|
||||
SecondaryItemAmount int `json:"secondaryItemAmount" db:"secondary_item_amount"`
|
||||
LoggedTime time.Time `json:"loggedTime" db:"logged_time"`
|
||||
Description string `json:"description" db:"description"`
|
||||
}
|
||||
|
||||
func (log *Log) Amount(itemID string) int {
|
||||
result := 0
|
||||
|
||||
if log.ItemID == itemID {
|
||||
result += log.ItemAmount
|
||||
}
|
||||
if log.SecondaryItemID != nil && *log.SecondaryItemID == itemID {
|
||||
result += log.SecondaryItemAmount
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
func (log *Log) Update(update LogUpdate) {
|
||||
@@ -21,17 +37,34 @@ func (log *Log) Update(update LogUpdate) {
|
||||
if update.Description != nil {
|
||||
log.Description = *update.Description
|
||||
}
|
||||
if update.ItemAmount != nil {
|
||||
log.ItemAmount = *update.ItemAmount
|
||||
}
|
||||
if update.SecondaryItemID != nil {
|
||||
log.SecondaryItemID = update.SecondaryItemID
|
||||
}
|
||||
if update.ClearSecondaryItem {
|
||||
log.SecondaryItemID = nil
|
||||
}
|
||||
if update.SecondaryItemAmount != nil {
|
||||
log.SecondaryItemAmount = *update.SecondaryItemAmount
|
||||
}
|
||||
}
|
||||
|
||||
type LogUpdate struct {
|
||||
LoggedTime *time.Time `json:"loggedTime"`
|
||||
Description *string `json:"description"`
|
||||
LoggedTime *time.Time `json:"loggedTime"`
|
||||
Description *string `json:"description"`
|
||||
ItemAmount *int `json:"itemAmount"`
|
||||
SecondaryItemID *string `json:"secondaryItemId"`
|
||||
SecondaryItemAmount *int `json:"secondaryItemAmount"`
|
||||
ClearSecondaryItem bool `json:"clearSecondaryItem"`
|
||||
}
|
||||
|
||||
type LogResult struct {
|
||||
Log
|
||||
Task *Task `json:"task"`
|
||||
Item *Item `json:"item"`
|
||||
Task *Task `json:"task"`
|
||||
Item *Item `json:"item"`
|
||||
SecondaryItem *Item `json:"secondaryItem"`
|
||||
}
|
||||
|
||||
type LogFilter struct {
|
||||
|
||||
Reference in New Issue
Block a user