wip
This commit is contained in:
@@ -4,6 +4,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"spend-sparrow/internal/handler/middleware"
|
"spend-sparrow/internal/handler/middleware"
|
||||||
"spend-sparrow/internal/template"
|
"spend-sparrow/internal/template"
|
||||||
|
"spend-sparrow/internal/template/dashboard"
|
||||||
|
|
||||||
"github.com/a-h/templ"
|
"github.com/a-h/templ"
|
||||||
)
|
)
|
||||||
@@ -41,7 +42,7 @@ func (handler IndexImpl) handleRootAnd404() http.HandlerFunc {
|
|||||||
status = http.StatusNotFound
|
status = http.StatusNotFound
|
||||||
} else {
|
} else {
|
||||||
if user != nil {
|
if user != nil {
|
||||||
comp = template.Dashboard()
|
comp = dashboard.Dashboard()
|
||||||
} else {
|
} else {
|
||||||
comp = template.Index()
|
comp = template.Index()
|
||||||
}
|
}
|
||||||
|
|||||||
59
internal/service/dashboard.go
Normal file
59
internal/service/dashboard.go
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
package service
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"spend-sparrow/internal/types"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/jmoiron/sqlx"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Dashboard struct {
|
||||||
|
db *sqlx.DB
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewDashboard(db *sqlx.DB) TreasureChest {
|
||||||
|
return TreasureChestImpl{
|
||||||
|
db: db,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s Dashboard) Summary(ctx context.Context, user *types.User, month time.Time) (*types.DashboardSummary, error) {
|
||||||
|
if user == nil {
|
||||||
|
return nil, ErrUnauthorized
|
||||||
|
}
|
||||||
|
|
||||||
|
var summary types.DashboardSummary
|
||||||
|
|
||||||
|
s.db.SelectContext(ctx, &summary.Expenses, `
|
||||||
|
SELECT
|
||||||
|
FROM "transaction"
|
||||||
|
WHERE user_id = $1
|
||||||
|
AND value < 0
|
||||||
|
AND account_id IS NOT NULL
|
||||||
|
AND error IS NULL
|
||||||
|
AND date_trunc('month', date) = date_trund('month', $2)`,
|
||||||
|
user.Id, month)
|
||||||
|
|
||||||
|
s.db.SelectContext(ctx, &summary.Income, `
|
||||||
|
SELECT
|
||||||
|
FROM "transaction"
|
||||||
|
WHERE user_id = $1
|
||||||
|
AND value > 0
|
||||||
|
AND account_id IS NOT NULL
|
||||||
|
AND error IS NULL
|
||||||
|
AND date_trunc('month', date) = date_trund('month', $2)`,
|
||||||
|
user.Id, month)
|
||||||
|
|
||||||
|
s.db.SelectContext(ctx, &summary.Savings, `
|
||||||
|
SELECT
|
||||||
|
FROM "transaction"
|
||||||
|
WHERE user_id = $1
|
||||||
|
AND value > 0
|
||||||
|
AND treasure_chest_id IS NOT NULL
|
||||||
|
AND error IS NULL
|
||||||
|
AND date_trunc('month', date) = date_trund('month', $2)`,
|
||||||
|
user.Id, month)
|
||||||
|
|
||||||
|
return &summary, nil
|
||||||
|
}
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
package template
|
|
||||||
|
|
||||||
templ Dashboard() {
|
|
||||||
<div>
|
|
||||||
<h1 class="text-8xl">
|
|
||||||
Dashboard
|
|
||||||
</h1>
|
|
||||||
</div>
|
|
||||||
}
|
|
||||||
23
internal/template/dashboard/dashboard.templ
Normal file
23
internal/template/dashboard/dashboard.templ
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
package dashboard
|
||||||
|
|
||||||
|
templ Dashboard() {
|
||||||
|
<div class="mt-10">
|
||||||
|
<label for="month">Select Month:</label>
|
||||||
|
<input name="month" type="date" class="input"/>
|
||||||
|
@summaryCard()
|
||||||
|
</div>
|
||||||
|
}
|
||||||
|
|
||||||
|
templ summaryCard() {
|
||||||
|
<section class="grid grid-cols-[auto_auto_auto_auto_1fr] gap-4">
|
||||||
|
<span>Einnahmen</span>
|
||||||
|
<span>Gespart</span>
|
||||||
|
<span>Ausgaben</span>
|
||||||
|
<span>Gesamt</span>
|
||||||
|
<span></span>
|
||||||
|
<span>4,005.15 €</span>
|
||||||
|
<span>4,005.15 €</span>
|
||||||
|
<span>3,805.15 €</span>
|
||||||
|
<span>200€</span>
|
||||||
|
</section>
|
||||||
|
}
|
||||||
2
internal/template/dashboard/default.go
Normal file
2
internal/template/dashboard/default.go
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
package dashboard
|
||||||
|
|
||||||
8
internal/types/dashboard.go
Normal file
8
internal/types/dashboard.go
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
package types
|
||||||
|
|
||||||
|
type DashboardSummary struct {
|
||||||
|
Income int64
|
||||||
|
Savings int64
|
||||||
|
Expenses int64
|
||||||
|
Total int64
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user