improve documentation
This commit is contained in:
parent
232463e1db
commit
0826963742
16 changed files with 80 additions and 28 deletions
|
|
@ -5,16 +5,19 @@ import (
|
|||
"github.com/go-pg/pg"
|
||||
)
|
||||
|
||||
// AccountStore implements database operations for account management by user.
|
||||
type AccountStore struct {
|
||||
db *pg.DB
|
||||
}
|
||||
|
||||
// NewAccountStore returns an AccountStore.
|
||||
func NewAccountStore(db *pg.DB) *AccountStore {
|
||||
return &AccountStore{
|
||||
db: db,
|
||||
}
|
||||
}
|
||||
|
||||
// Get an account by ID.
|
||||
func (s *AccountStore) Get(id int) (*models.Account, error) {
|
||||
a := models.Account{ID: id}
|
||||
err := s.db.Model(&a).
|
||||
|
|
@ -24,6 +27,7 @@ func (s *AccountStore) Get(id int) (*models.Account, error) {
|
|||
return &a, err
|
||||
}
|
||||
|
||||
// Update an account.
|
||||
func (s *AccountStore) Update(a *models.Account) error {
|
||||
_, err := s.db.Model(a).
|
||||
Column("email", "name").
|
||||
|
|
@ -31,6 +35,7 @@ func (s *AccountStore) Update(a *models.Account) error {
|
|||
return err
|
||||
}
|
||||
|
||||
// Delete an account.
|
||||
func (s *AccountStore) Delete(a *models.Account) error {
|
||||
err := s.db.RunInTransaction(func(tx *pg.Tx) error {
|
||||
if _, err := tx.Model(&models.Token{}).
|
||||
|
|
@ -48,6 +53,7 @@ func (s *AccountStore) Delete(a *models.Account) error {
|
|||
return err
|
||||
}
|
||||
|
||||
// UpdateToken updates a jwt refresh token.
|
||||
func (s *AccountStore) UpdateToken(t *models.Token) error {
|
||||
_, err := s.db.Model(t).
|
||||
Column("identifier").
|
||||
|
|
@ -55,11 +61,13 @@ func (s *AccountStore) UpdateToken(t *models.Token) error {
|
|||
return err
|
||||
}
|
||||
|
||||
// DeleteToken deletes a jwt refresh token.
|
||||
func (s *AccountStore) DeleteToken(t *models.Token) error {
|
||||
err := s.db.Delete(t)
|
||||
return err
|
||||
}
|
||||
|
||||
// UpdateProfile updates corresponding account profile.
|
||||
func (s *AccountStore) UpdateProfile(p *models.Profile) error {
|
||||
err := s.db.Update(p)
|
||||
return err
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue