Monorepo for Tangled tangled.org

appview/models: move db.Email into models

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

oppi.li fde77b9f ea02bd91

verified
Changed files
+37 -28
appview
db
models
pages
settings
signup
+16 -25
appview/db/email.go
··· 3 3 import ( 4 4 "strings" 5 5 "time" 6 + 7 + "tangled.org/core/appview/models" 6 8 ) 7 9 8 - type Email struct { 9 - ID int64 10 - Did string 11 - Address string 12 - Verified bool 13 - Primary bool 14 - VerificationCode string 15 - LastSent *time.Time 16 - CreatedAt time.Time 17 - } 18 - 19 - func GetPrimaryEmail(e Execer, did string) (Email, error) { 10 + func GetPrimaryEmail(e Execer, did string) (models.Email, error) { 20 11 query := ` 21 12 select id, did, email, verified, is_primary, verification_code, last_sent, created 22 13 from emails 23 14 where did = ? and is_primary = true 24 15 ` 25 - var email Email 16 + var email models.Email 26 17 var createdStr string 27 18 var lastSent string 28 19 err := e.QueryRow(query, did).Scan(&email.ID, &email.Did, &email.Address, &email.Verified, &email.Primary, &email.VerificationCode, &lastSent, &createdStr) 29 20 if err != nil { 30 - return Email{}, err 21 + return models.Email{}, err 31 22 } 32 23 email.CreatedAt, err = time.Parse(time.RFC3339, createdStr) 33 24 if err != nil { 34 - return Email{}, err 25 + return models.Email{}, err 35 26 } 36 27 parsedTime, err := time.Parse(time.RFC3339, lastSent) 37 28 if err != nil { 38 - return Email{}, err 29 + return models.Email{}, err 39 30 } 40 31 email.LastSent = &parsedTime 41 32 return email, nil 42 33 } 43 34 44 - func GetEmail(e Execer, did string, em string) (Email, error) { 35 + func GetEmail(e Execer, did string, em string) (models.Email, error) { 45 36 query := ` 46 37 select id, did, email, verified, is_primary, verification_code, last_sent, created 47 38 from emails 48 39 where did = ? and email = ? 49 40 ` 50 - var email Email 41 + var email models.Email 51 42 var createdStr string 52 43 var lastSent string 53 44 err := e.QueryRow(query, did, em).Scan(&email.ID, &email.Did, &email.Address, &email.Verified, &email.Primary, &email.VerificationCode, &lastSent, &createdStr) 54 45 if err != nil { 55 - return Email{}, err 46 + return models.Email{}, err 56 47 } 57 48 email.CreatedAt, err = time.Parse(time.RFC3339, createdStr) 58 49 if err != nil { 59 - return Email{}, err 50 + return models.Email{}, err 60 51 } 61 52 parsedTime, err := time.Parse(time.RFC3339, lastSent) 62 53 if err != nil { 63 - return Email{}, err 54 + return models.Email{}, err 64 55 } 65 56 email.LastSent = &parsedTime 66 57 return email, nil ··· 187 178 return count > 0, nil 188 179 } 189 180 190 - func AddEmail(e Execer, email Email) error { 181 + func AddEmail(e Execer, email models.Email) error { 191 182 // Check if this is the first email for this DID 192 183 countQuery := ` 193 184 select count(*) ··· 254 245 return err 255 246 } 256 247 257 - func GetAllEmails(e Execer, did string) ([]Email, error) { 248 + func GetAllEmails(e Execer, did string) ([]models.Email, error) { 258 249 query := ` 259 250 select did, email, verified, is_primary, verification_code, last_sent, created 260 251 from emails ··· 266 257 } 267 258 defer rows.Close() 268 259 269 - var emails []Email 260 + var emails []models.Email 270 261 for rows.Next() { 271 - var email Email 262 + var email models.Email 272 263 var createdStr string 273 264 var lastSent string 274 265 err := rows.Scan(&email.Did, &email.Address, &email.Verified, &email.Primary, &email.VerificationCode, &lastSent, &createdStr)
+16
appview/models/email.go
··· 1 + package models 2 + 3 + import ( 4 + "time" 5 + ) 6 + 7 + type Email struct { 8 + ID int64 9 + Did string 10 + Address string 11 + Verified bool 12 + Primary bool 13 + VerificationCode string 14 + LastSent *time.Time 15 + CreatedAt time.Time 16 + }
+1 -1
appview/pages/pages.go
··· 314 314 315 315 type UserEmailsSettingsParams struct { 316 316 LoggedInUser *oauth.User 317 - Emails []db.Email 317 + Emails []models.Email 318 318 Tabs []map[string]any 319 319 Tab string 320 320 }
+2 -1
appview/settings/settings.go
··· 16 16 "tangled.org/core/appview/db" 17 17 "tangled.org/core/appview/email" 18 18 "tangled.org/core/appview/middleware" 19 + "tangled.org/core/appview/models" 19 20 "tangled.org/core/appview/oauth" 20 21 "tangled.org/core/appview/pages" 21 22 "tangled.org/core/tid" ··· 185 186 } 186 187 defer tx.Rollback() 187 188 188 - if err := db.AddEmail(tx, db.Email{ 189 + if err := db.AddEmail(tx, models.Email{ 189 190 Did: did, 190 191 Address: emAddr, 191 192 Verified: false,
+2 -1
appview/signup/signup.go
··· 14 14 "tangled.org/core/appview/db" 15 15 "tangled.org/core/appview/dns" 16 16 "tangled.org/core/appview/email" 17 + "tangled.org/core/appview/models" 17 18 "tangled.org/core/appview/pages" 18 19 "tangled.org/core/appview/state/userutil" 19 20 "tangled.org/core/appview/xrpcclient" ··· 229 230 return 230 231 } 231 232 232 - err = db.AddEmail(s.db, db.Email{ 233 + err = db.AddEmail(s.db, models.Email{ 233 234 Did: did, 234 235 Address: email, 235 236 Verified: true,