forked from tangled.org/core
Monorepo for Tangled — https://tangled.org

appview/models: move db.PunchCard into models

Signed-off-by: oppiliappan <me@oppi.li>

oppi.li a2979381 775ea4d7

verified
Changed files
+23 -18
appview
+7 -16
appview/db/punchcard.go
···
"fmt"
"strings"
"time"
+
+
"tangled.org/core/appview/models"
)
-
type Punch struct {
-
Did string
-
Date time.Time
-
Count int
-
}
-
// this adds to the existing count
-
func AddPunch(e Execer, punch Punch) error {
+
func AddPunch(e Execer, punch models.Punch) error {
_, err := e.Exec(`
insert into punchcard (did, date, count)
values (?, ?, ?)
···
return err
}
-
type Punchcard struct {
-
Total int
-
Punches []Punch
-
}
-
-
func MakePunchcard(e Execer, filters ...filter) (*Punchcard, error) {
-
punchcard := &Punchcard{}
+
func MakePunchcard(e Execer, filters ...filter) (*models.Punchcard, error) {
+
punchcard := &models.Punchcard{}
now := time.Now()
startOfYear := time.Date(now.Year(), 1, 1, 0, 0, 0, 0, time.UTC)
endOfYear := time.Date(now.Year(), 12, 31, 0, 0, 0, 0, time.UTC)
for d := startOfYear; d.Before(endOfYear) || d.Equal(endOfYear); d = d.AddDate(0, 0, 1) {
-
punchcard.Punches = append(punchcard.Punches, Punch{
+
punchcard.Punches = append(punchcard.Punches, models.Punch{
Date: d,
Count: 0,
})
···
defer rows.Close()
for rows.Next() {
-
var punch Punch
+
var punch models.Punch
var date string
var count sql.NullInt64
if err := rows.Scan(&date, &count); err != nil {
+14
appview/models/punchcard.go
···
+
package models
+
+
import "time"
+
+
type Punch struct {
+
Did string
+
Date time.Time
+
Count int
+
}
+
+
type Punchcard struct {
+
Total int
+
Punches []Punch
+
}
+1 -1
appview/pages/pages.go
···
UserDid string
UserHandle string
FollowStatus models.FollowStatus
-
Punchcard *db.Punchcard
+
Punchcard *models.Punchcard
Profile *models.Profile
Stats ProfileStats
Active string
+1 -1
appview/state/knotstream.go
···
}
}
-
punch := db.Punch{
+
punch := models.Punch{
Did: record.CommitterDid,
Date: time.Now(),
Count: count,