feat(accounts): improve account creation

This commit is contained in:
2021-11-12 00:38:44 +01:00
parent 78071a6a91
commit 7bf8db8050
5 changed files with 24 additions and 19 deletions

View File

@@ -1,7 +1,10 @@
package account
import (
"fmt"
"nos-comptes/internal/storage/dao"
"nos-comptes/internal/storage/dao/postgresql"
"nos-comptes/internal/utils"
"github.com/lib/pq"
)
@@ -41,13 +44,22 @@ func (db *Database) GetAccountWithNameForUser(name string, id string) (*Account,
WHERE a.user_id = $1
AND a.name = $2
`
row := db.Session.QueryRow(q, id, name)
row, err := db.Session.Query(q, id, name)
if !row.Next() {
return nil, dao.NewDAOError(dao.ErrTypeNotFound, fmt.Errorf("No row found"))
}
a := Account{}
err := row.Scan(&a.ID, &a.UserId, &a.Name, &a.Provider, &a.CreatedAt, &a.UpdatedAt)
row.Scan(&a.ID, &a.UserId, &a.Name, &a.Provider, &a.CreatedAt, &a.UpdatedAt)
if row.Next() {
return nil, fmt.Errorf("Impossibru")
}
if errPq, ok := err.(*pq.Error); ok {
return nil, postgresql.HandlePgError(errPq)
}
if err != nil {
utils.GetLogger().Info(err)
return nil, err
}
return &a, nil
}