Monorepo for Tangled 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
··· 5 "fmt" 6 "strings" 7 "time" 8 ) 9 10 - type Punch struct { 11 - Did string 12 - Date time.Time 13 - Count int 14 - } 15 - 16 // this adds to the existing count 17 - func AddPunch(e Execer, punch Punch) error { 18 _, err := e.Exec(` 19 insert into punchcard (did, date, count) 20 values (?, ?, ?) ··· 24 return err 25 } 26 27 - type Punchcard struct { 28 - Total int 29 - Punches []Punch 30 - } 31 - 32 - func MakePunchcard(e Execer, filters ...filter) (*Punchcard, error) { 33 - punchcard := &Punchcard{} 34 now := time.Now() 35 startOfYear := time.Date(now.Year(), 1, 1, 0, 0, 0, 0, time.UTC) 36 endOfYear := time.Date(now.Year(), 12, 31, 0, 0, 0, 0, time.UTC) 37 for d := startOfYear; d.Before(endOfYear) || d.Equal(endOfYear); d = d.AddDate(0, 0, 1) { 38 - punchcard.Punches = append(punchcard.Punches, Punch{ 39 Date: d, 40 Count: 0, 41 }) ··· 68 defer rows.Close() 69 70 for rows.Next() { 71 - var punch Punch 72 var date string 73 var count sql.NullInt64 74 if err := rows.Scan(&date, &count); err != nil {
··· 5 "fmt" 6 "strings" 7 "time" 8 + 9 + "tangled.org/core/appview/models" 10 ) 11 12 // this adds to the existing count 13 + func AddPunch(e Execer, punch models.Punch) error { 14 _, err := e.Exec(` 15 insert into punchcard (did, date, count) 16 values (?, ?, ?) ··· 20 return err 21 } 22 23 + func MakePunchcard(e Execer, filters ...filter) (*models.Punchcard, error) { 24 + punchcard := &models.Punchcard{} 25 now := time.Now() 26 startOfYear := time.Date(now.Year(), 1, 1, 0, 0, 0, 0, time.UTC) 27 endOfYear := time.Date(now.Year(), 12, 31, 0, 0, 0, 0, time.UTC) 28 for d := startOfYear; d.Before(endOfYear) || d.Equal(endOfYear); d = d.AddDate(0, 0, 1) { 29 + punchcard.Punches = append(punchcard.Punches, models.Punch{ 30 Date: d, 31 Count: 0, 32 }) ··· 59 defer rows.Close() 60 61 for rows.Next() { 62 + var punch models.Punch 63 var date string 64 var count sql.NullInt64 65 if err := rows.Scan(&date, &count); err != nil {
+14
appview/models/punchcard.go
···
··· 1 + package models 2 + 3 + import "time" 4 + 5 + type Punch struct { 6 + Did string 7 + Date time.Time 8 + Count int 9 + } 10 + 11 + type Punchcard struct { 12 + Total int 13 + Punches []Punch 14 + }
+1 -1
appview/pages/pages.go
··· 412 UserDid string 413 UserHandle string 414 FollowStatus models.FollowStatus 415 - Punchcard *db.Punchcard 416 Profile *models.Profile 417 Stats ProfileStats 418 Active string
··· 412 UserDid string 413 UserHandle string 414 FollowStatus models.FollowStatus 415 + Punchcard *models.Punchcard 416 Profile *models.Profile 417 Stats ProfileStats 418 Active string
+1 -1
appview/state/knotstream.go
··· 125 } 126 } 127 128 - punch := db.Punch{ 129 Did: record.CommitterDid, 130 Date: time.Now(), 131 Count: count,
··· 125 } 126 } 127 128 + punch := models.Punch{ 129 Did: record.CommitterDid, 130 Date: time.Now(), 131 Count: count,