fmt plus name support on time series data

This commit is contained in:
Hayden 2022-12-05 12:32:26 -09:00
parent d2b8c96d76
commit 386885b115
No known key found for this signature in database
GPG key ID: 17CF79474E257545

View file

@ -58,6 +58,7 @@ type (
ValueOverTimeEntry struct {
Date time.Time `json:"date"`
Value float64 `json:"value"`
Name string `json:"name"`
}
ValueOverTime struct {
@ -136,11 +137,8 @@ func (r *GroupRepository) StatsLabelsByPurchasePrice(ctx context.Context, GID uu
Aggregate(func(sq *sql.Selector) string {
itemTable := sql.Table(item.Table)
// item to label is a many to many relation
// so we need to join the junction table
jt := sql.Table(label.ItemsTable)
// join the junction table to the item table
sq.Join(jt).On(sq.C(label.FieldID), jt.C(label.ItemsPrimaryKey[0]))
sq.Join(itemTable).On(jt.C(label.ItemsPrimaryKey[1]), itemTable.C(item.FieldID))
@ -188,17 +186,25 @@ func (r *GroupRepository) StatsPurchasePrice(ctx context.Context, GID uuid.UUID,
stats.PriceAtEnd = orDefault(maybeEnd, 0)
var v []struct {
Name string `json:"name"`
CreatedAt time.Time `json:"created_at"`
PurchasePrice float64 `json:"purchase_price"`
}
// Get Created Date and Price of all items between start and end
err = r.db.Item.Query().Where(
item.HasGroupWith(group.ID(GID)),
item.CreatedAtGTE(start),
item.CreatedAtLTE(end),
item.Archived(false)).
Select(item.FieldCreatedAt, item.FieldPurchasePrice).Scan(ctx, &v)
err = r.db.Item.Query().
Where(
item.HasGroupWith(group.ID(GID)),
item.CreatedAtGTE(start),
item.CreatedAtLTE(end),
item.Archived(false),
).
Select(
item.FieldName,
item.FieldCreatedAt,
item.FieldPurchasePrice,
).
Scan(ctx, &v)
if err != nil {
return nil, err