You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

91 lines
2.5 KiB

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"`
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) {
if update.LoggedTime != nil {
log.LoggedTime = update.LoggedTime.UTC()
}
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"`
ItemAmount *int `json:"itemAmount"`
SecondaryItemID *string `json:"secondaryItemId"`
SecondaryItemAmount *int `json:"secondaryItemAmount"`
ClearSecondaryItem bool `json:"clearSecondaryItemId"`
}
type LogResult struct {
Log
Task *TaskWithProject `json:"task"`
Item *Item `json:"item"`
SecondaryItem *Item `json:"secondaryItem"`
}
type LogWithSecondaryItem struct {
Log
SecondaryItem *Item `json:"secondaryItem,omitempty"`
}
type LogFilter struct {
UserID string
ProjectGroupIDs []string
ProjectIDs []string
TaskIDs []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
}