From 775ea4d7921af4411574544840b10577f44501a5 Mon Sep 17 00:00:00 2001 From: oppiliappan Date: Tue, 23 Sep 2025 11:01:45 +0100 Subject: [PATCH] appview/models: move db.PublicKey into models Signed-off-by: oppiliappan --- appview/commitverify/verify.go | 3 ++- appview/db/pubkeys.go | 33 +++++++-------------------------- appview/models/pubkey.go | 25 +++++++++++++++++++++++++ appview/pages/pages.go | 2 +- 4 files changed, 35 insertions(+), 28 deletions(-) create mode 100644 appview/models/pubkey.go diff --git a/appview/commitverify/verify.go b/appview/commitverify/verify.go index 233ad918..3c04495d 100644 --- a/appview/commitverify/verify.go +++ b/appview/commitverify/verify.go @@ -5,6 +5,7 @@ import ( "github.com/go-git/go-git/v5/plumbing/object" "tangled.org/core/appview/db" + "tangled.org/core/appview/models" "tangled.org/core/crypto" "tangled.org/core/types" ) @@ -45,7 +46,7 @@ func GetVerifiedObjectCommits(e db.Execer, emailToDid map[string]string, commits func GetVerifiedCommits(e db.Execer, emailToDid map[string]string, ndCommits []types.NiceDiff) (VerifiedCommits, error) { vcs := VerifiedCommits{} - didPubkeyCache := make(map[string][]db.PublicKey) + didPubkeyCache := make(map[string][]models.PublicKey) for _, commit := range ndCommits { c := commit.Commit diff --git a/appview/db/pubkeys.go b/appview/db/pubkeys.go index e4d30a20..c62525f2 100644 --- a/appview/db/pubkeys.go +++ b/appview/db/pubkeys.go @@ -1,7 +1,7 @@ package db import ( - "encoding/json" + "tangled.org/core/appview/models" "time" ) @@ -29,27 +29,8 @@ func DeletePublicKeyByRkey(e Execer, did, rkey string) error { return err } -type PublicKey struct { - Did string `json:"did"` - Key string `json:"key"` - Name string `json:"name"` - Rkey string `json:"rkey"` - Created *time.Time -} - -func (p PublicKey) MarshalJSON() ([]byte, error) { - type Alias PublicKey - return json.Marshal(&struct { - Created string `json:"created"` - *Alias - }{ - Created: p.Created.Format(time.RFC3339), - Alias: (*Alias)(&p), - }) -} - -func GetAllPublicKeys(e Execer) ([]PublicKey, error) { - var keys []PublicKey +func GetAllPublicKeys(e Execer) ([]models.PublicKey, error) { + var keys []models.PublicKey rows, err := e.Query(`select key, name, did, rkey, created from public_keys`) if err != nil { @@ -58,7 +39,7 @@ func GetAllPublicKeys(e Execer) ([]PublicKey, error) { defer rows.Close() for rows.Next() { - var publicKey PublicKey + var publicKey models.PublicKey var createdAt string if err := rows.Scan(&publicKey.Key, &publicKey.Name, &publicKey.Did, &publicKey.Rkey, &createdAt); err != nil { return nil, err @@ -75,8 +56,8 @@ func GetAllPublicKeys(e Execer) ([]PublicKey, error) { return keys, nil } -func GetPublicKeysForDid(e Execer, did string) ([]PublicKey, error) { - var keys []PublicKey +func GetPublicKeysForDid(e Execer, did string) ([]models.PublicKey, error) { + var keys []models.PublicKey rows, err := e.Query(`select did, key, name, rkey, created from public_keys where did = ?`, did) if err != nil { @@ -85,7 +66,7 @@ func GetPublicKeysForDid(e Execer, did string) ([]PublicKey, error) { defer rows.Close() for rows.Next() { - var publicKey PublicKey + var publicKey models.PublicKey var createdAt string if err := rows.Scan(&publicKey.Did, &publicKey.Key, &publicKey.Name, &publicKey.Rkey, &createdAt); err != nil { return nil, err diff --git a/appview/models/pubkey.go b/appview/models/pubkey.go new file mode 100644 index 00000000..c2d64e26 --- /dev/null +++ b/appview/models/pubkey.go @@ -0,0 +1,25 @@ +package models + +import ( + "encoding/json" + "time" +) + +type PublicKey struct { + Did string `json:"did"` + Key string `json:"key"` + Name string `json:"name"` + Rkey string `json:"rkey"` + Created *time.Time +} + +func (p PublicKey) MarshalJSON() ([]byte, error) { + type Alias PublicKey + return json.Marshal(&struct { + Created string `json:"created"` + *Alias + }{ + Created: p.Created.Format(time.RFC3339), + Alias: (*Alias)(&p), + }) +} diff --git a/appview/pages/pages.go b/appview/pages/pages.go index bf990080..6a29603d 100644 --- a/appview/pages/pages.go +++ b/appview/pages/pages.go @@ -303,7 +303,7 @@ func (p *Pages) UserProfileSettings(w io.Writer, params UserProfileSettingsParam type UserKeysSettingsParams struct { LoggedInUser *oauth.User - PubKeys []db.PublicKey + PubKeys []models.PublicKey Tabs []map[string]any Tab string } -- 2.51.2