more refactoring
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"github.com/google/uuid"
|
||||
_ "github.com/mattn/go-sqlite3" // Import the SQLite3 driver
|
||||
"go-nkode/config"
|
||||
"go-nkode/internal/entities"
|
||||
"go-nkode/internal/models"
|
||||
"go-nkode/internal/security"
|
||||
"log"
|
||||
@@ -60,7 +61,7 @@ func (d *SqliteDB) CloseDb() {
|
||||
}
|
||||
}
|
||||
|
||||
func (d *SqliteDB) WriteNewCustomer(c models.Customer) error {
|
||||
func (d *SqliteDB) WriteNewCustomer(c entities.Customer) error {
|
||||
query := `
|
||||
INSERT INTO customer (
|
||||
id
|
||||
@@ -85,7 +86,7 @@ VALUES (?,?,?,?,?,?,?,?,?,?,?)
|
||||
return d.addWriteTx(query, args)
|
||||
}
|
||||
|
||||
func (d *SqliteDB) WriteNewUser(u models.User) error {
|
||||
func (d *SqliteDB) WriteNewUser(u entities.User) error {
|
||||
query := `
|
||||
INSERT INTO user (
|
||||
id
|
||||
@@ -128,7 +129,7 @@ VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
|
||||
return d.addWriteTx(query, args)
|
||||
}
|
||||
|
||||
func (d *SqliteDB) UpdateUserNKode(u models.User) error {
|
||||
func (d *SqliteDB) UpdateUserNKode(u entities.User) error {
|
||||
query := `
|
||||
UPDATE user
|
||||
SET renew = ?
|
||||
@@ -158,7 +159,7 @@ WHERE email = ? AND customer_id = ?
|
||||
return d.addWriteTx(query, args)
|
||||
}
|
||||
|
||||
func (d *SqliteDB) UpdateUserInterface(id models.UserId, ui models.UserInterface) error {
|
||||
func (d *SqliteDB) UpdateUserInterface(id models.UserId, ui entities.UserInterface) error {
|
||||
query := `
|
||||
UPDATE user SET idx_interface = ?, last_login = ? WHERE id = ?
|
||||
`
|
||||
@@ -219,20 +220,20 @@ WHERE customer_id = ?
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
user := models.User{
|
||||
user := entities.User{
|
||||
Id: models.UserId{},
|
||||
CustomerId: models.CustomerId{},
|
||||
Email: "",
|
||||
EncipheredPasscode: models.EncipheredNKode{},
|
||||
Kp: models.KeypadDimension{
|
||||
Kp: entities.KeypadDimension{
|
||||
AttrsPerKey: attrsPerKey,
|
||||
NumbOfKeys: numbOfKeys,
|
||||
},
|
||||
CipherKeys: models.UserCipherKeys{
|
||||
CipherKeys: entities.UserCipherKeys{
|
||||
AlphaKey: security.ByteArrToUint64Arr(alphaBytes),
|
||||
SetKey: security.ByteArrToUint64Arr(setBytes),
|
||||
},
|
||||
Interface: models.UserInterface{},
|
||||
Interface: entities.UserInterface{},
|
||||
Renew: false,
|
||||
}
|
||||
err = user.RenewKeys(setXor, attrXor)
|
||||
@@ -255,7 +256,7 @@ WHERE id = ?;
|
||||
return d.addWriteTx(renewQuery, renewArgs)
|
||||
}
|
||||
|
||||
func (d *SqliteDB) RefreshUserPasscode(user models.User, passcodeIdx []int, customerAttr models.CustomerAttributes) error {
|
||||
func (d *SqliteDB) RefreshUserPasscode(user entities.User, passcodeIdx []int, customerAttr entities.CustomerAttributes) error {
|
||||
err := user.RefreshPasscode(passcodeIdx, customerAttr)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -276,7 +277,7 @@ WHERE id = ?;
|
||||
args := []any{user.RefreshToken, 0, user.EncipheredPasscode.Code, user.EncipheredPasscode.Mask, security.Uint64ArrToByteArr(user.CipherKeys.AlphaKey), security.Uint64ArrToByteArr(user.CipherKeys.SetKey), security.Uint64ArrToByteArr(user.CipherKeys.PassKey), security.Uint64ArrToByteArr(user.CipherKeys.MaskKey), user.CipherKeys.Salt, uuid.UUID(user.Id).String()}
|
||||
return d.addWriteTx(query, args)
|
||||
}
|
||||
func (d *SqliteDB) GetCustomer(id models.CustomerId) (*models.Customer, error) {
|
||||
func (d *SqliteDB) GetCustomer(id models.CustomerId) (*entities.Customer, error) {
|
||||
tx, err := d.db.Begin()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -324,7 +325,7 @@ WHERE id = ?
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
customer := models.Customer{
|
||||
customer := entities.Customer{
|
||||
Id: id,
|
||||
NKodePolicy: models.NKodePolicy{
|
||||
MaxNkodeLen: maxNKodeLen,
|
||||
@@ -334,7 +335,7 @@ WHERE id = ?
|
||||
LockOut: lockOut,
|
||||
Expiration: expiration,
|
||||
},
|
||||
Attributes: models.NewCustomerAttributesFromBytes(attributeValues, setValues),
|
||||
Attributes: entities.NewCustomerAttributesFromBytes(attributeValues, setValues),
|
||||
}
|
||||
if err = tx.Commit(); err != nil {
|
||||
return nil, err
|
||||
@@ -342,7 +343,7 @@ WHERE id = ?
|
||||
return &customer, nil
|
||||
}
|
||||
|
||||
func (d *SqliteDB) GetUser(email models.UserEmail, customerId models.CustomerId) (*models.User, error) {
|
||||
func (d *SqliteDB) GetUser(email models.UserEmail, customerId models.CustomerId) (*entities.User, error) {
|
||||
tx, err := d.db.Begin()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -401,7 +402,7 @@ WHERE user.email = ? AND user.customer_id = ?
|
||||
renew = true
|
||||
}
|
||||
|
||||
user := models.User{
|
||||
user := entities.User{
|
||||
Id: models.UserId(userId),
|
||||
CustomerId: customerId,
|
||||
Email: email,
|
||||
@@ -409,11 +410,11 @@ WHERE user.email = ? AND user.customer_id = ?
|
||||
Code: code,
|
||||
Mask: mask,
|
||||
},
|
||||
Kp: models.KeypadDimension{
|
||||
Kp: entities.KeypadDimension{
|
||||
AttrsPerKey: attrsPerKey,
|
||||
NumbOfKeys: numbOfKeys,
|
||||
},
|
||||
CipherKeys: models.UserCipherKeys{
|
||||
CipherKeys: entities.UserCipherKeys{
|
||||
AlphaKey: security.ByteArrToUint64Arr(alphaKey),
|
||||
SetKey: security.ByteArrToUint64Arr(setKey),
|
||||
PassKey: security.ByteArrToUint64Arr(passKey),
|
||||
@@ -422,7 +423,7 @@ WHERE user.email = ? AND user.customer_id = ?
|
||||
MaxNKodeLen: maxNKodeLen,
|
||||
Kp: nil,
|
||||
},
|
||||
Interface: models.UserInterface{
|
||||
Interface: entities.UserInterface{
|
||||
IdxInterface: security.ByteArrToIntArr(idxInterface),
|
||||
SvgId: security.ByteArrToIntArr(svgIdInterface),
|
||||
Kp: nil,
|
||||
@@ -438,7 +439,7 @@ WHERE user.email = ? AND user.customer_id = ?
|
||||
return &user, nil
|
||||
}
|
||||
|
||||
func (d *SqliteDB) RandomSvgInterface(kp models.KeypadDimension) ([]string, error) {
|
||||
func (d *SqliteDB) RandomSvgInterface(kp entities.KeypadDimension) ([]string, error) {
|
||||
ids, err := d.getRandomIds(kp.TotalAttrs())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -446,7 +447,7 @@ func (d *SqliteDB) RandomSvgInterface(kp models.KeypadDimension) ([]string, erro
|
||||
return d.getSvgsById(ids)
|
||||
}
|
||||
|
||||
func (d *SqliteDB) RandomSvgIdxInterface(kp models.KeypadDimension) (models.SvgIdInterface, error) {
|
||||
func (d *SqliteDB) RandomSvgIdxInterface(kp entities.KeypadDimension) (models.SvgIdInterface, error) {
|
||||
return d.getRandomIds(kp.TotalAttrs())
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user