Files
stufflog2/models/item.go
T
2020-12-31 17:49:54 +01:00

51 lines
1.2 KiB
Go

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
}