|
|
|
@@ -14,12 +14,12 @@ import (
|
|
|
|
"log"
|
|
|
|
"log"
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
type SqliteRepository struct {
|
|
|
|
type SqliteNKodeRepo struct {
|
|
|
|
Queue *sqlc.Queue
|
|
|
|
Queue *sqlc.Queue
|
|
|
|
ctx context.Context
|
|
|
|
ctx context.Context
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func NewSqliteRepository(ctx context.Context, dbPath string) (*SqliteRepository, error) {
|
|
|
|
func NewSqliteNKodeRepo(ctx context.Context, dbPath string) (*SqliteNKodeRepo, error) {
|
|
|
|
sqliteDb, err := sqlc.OpenSqliteDb(dbPath)
|
|
|
|
sqliteDb, err := sqlc.OpenSqliteDb(dbPath)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
return nil, err
|
|
|
|
@@ -28,21 +28,21 @@ func NewSqliteRepository(ctx context.Context, dbPath string) (*SqliteRepository,
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return &SqliteRepository{
|
|
|
|
return &SqliteNKodeRepo{
|
|
|
|
Queue: queue,
|
|
|
|
Queue: queue,
|
|
|
|
ctx: ctx,
|
|
|
|
ctx: ctx,
|
|
|
|
}, nil
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (d *SqliteRepository) Start() {
|
|
|
|
func (d *SqliteNKodeRepo) Start() {
|
|
|
|
d.Queue.Start()
|
|
|
|
d.Queue.Start()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (d *SqliteRepository) Stop() error {
|
|
|
|
func (d *SqliteNKodeRepo) Stop() error {
|
|
|
|
return d.Queue.Stop()
|
|
|
|
return d.Queue.Stop()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (d *SqliteRepository) CreateCustomer(c entities.Customer) error {
|
|
|
|
func (d *SqliteNKodeRepo) CreateCustomer(c entities.Customer) error {
|
|
|
|
queryFunc := func(q *sqlc.Queries, ctx context.Context, args any) error {
|
|
|
|
queryFunc := func(q *sqlc.Queries, ctx context.Context, args any) error {
|
|
|
|
params, ok := args.(sqlc.CreateCustomerParams)
|
|
|
|
params, ok := args.(sqlc.CreateCustomerParams)
|
|
|
|
if !ok {
|
|
|
|
if !ok {
|
|
|
|
@@ -54,7 +54,7 @@ func (d *SqliteRepository) CreateCustomer(c entities.Customer) error {
|
|
|
|
return d.Queue.EnqueueWriteTx(queryFunc, c.ToSqlcCreateCustomerParams())
|
|
|
|
return d.Queue.EnqueueWriteTx(queryFunc, c.ToSqlcCreateCustomerParams())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (d *SqliteRepository) WriteNewUser(u entities.User) error {
|
|
|
|
func (d *SqliteNKodeRepo) WriteNewUser(u entities.User) error {
|
|
|
|
queryFunc := func(q *sqlc.Queries, ctx context.Context, args any) error {
|
|
|
|
queryFunc := func(q *sqlc.Queries, ctx context.Context, args any) error {
|
|
|
|
params, ok := args.(sqlc.CreateUserParams)
|
|
|
|
params, ok := args.(sqlc.CreateUserParams)
|
|
|
|
if !ok {
|
|
|
|
if !ok {
|
|
|
|
@@ -92,7 +92,7 @@ func (d *SqliteRepository) WriteNewUser(u entities.User) error {
|
|
|
|
return d.Queue.EnqueueWriteTx(queryFunc, params)
|
|
|
|
return d.Queue.EnqueueWriteTx(queryFunc, params)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (d *SqliteRepository) UpdateUserNKode(u entities.User) error {
|
|
|
|
func (d *SqliteNKodeRepo) UpdateUserNKode(u entities.User) error {
|
|
|
|
queryFunc := func(q *sqlc.Queries, ctx context.Context, args any) error {
|
|
|
|
queryFunc := func(q *sqlc.Queries, ctx context.Context, args any) error {
|
|
|
|
params, ok := args.(sqlc.UpdateUserParams)
|
|
|
|
params, ok := args.(sqlc.UpdateUserParams)
|
|
|
|
if !ok {
|
|
|
|
if !ok {
|
|
|
|
@@ -126,7 +126,7 @@ func (d *SqliteRepository) UpdateUserNKode(u entities.User) error {
|
|
|
|
return d.Queue.EnqueueWriteTx(queryFunc, params)
|
|
|
|
return d.Queue.EnqueueWriteTx(queryFunc, params)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (d *SqliteRepository) UpdateUserInterface(id entities.UserId, ui entities.UserInterface) error {
|
|
|
|
func (d *SqliteNKodeRepo) UpdateUserInterface(id entities.UserId, ui entities.UserInterface) error {
|
|
|
|
queryFunc := func(q *sqlc.Queries, ctx context.Context, args any) error {
|
|
|
|
queryFunc := func(q *sqlc.Queries, ctx context.Context, args any) error {
|
|
|
|
params, ok := args.(sqlc.UpdateUserInterfaceParams)
|
|
|
|
params, ok := args.(sqlc.UpdateUserInterfaceParams)
|
|
|
|
if !ok {
|
|
|
|
if !ok {
|
|
|
|
@@ -143,7 +143,7 @@ func (d *SqliteRepository) UpdateUserInterface(id entities.UserId, ui entities.U
|
|
|
|
return d.Queue.EnqueueWriteTx(queryFunc, params)
|
|
|
|
return d.Queue.EnqueueWriteTx(queryFunc, params)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (d *SqliteRepository) UpdateUserRefreshToken(id entities.UserId, refreshToken string) error {
|
|
|
|
func (d *SqliteNKodeRepo) UpdateUserRefreshToken(id entities.UserId, refreshToken string) error {
|
|
|
|
queryFunc := func(q *sqlc.Queries, ctx context.Context, args any) error {
|
|
|
|
queryFunc := func(q *sqlc.Queries, ctx context.Context, args any) error {
|
|
|
|
params, ok := args.(sqlc.UpdateUserRefreshTokenParams)
|
|
|
|
params, ok := args.(sqlc.UpdateUserRefreshTokenParams)
|
|
|
|
if !ok {
|
|
|
|
if !ok {
|
|
|
|
@@ -161,7 +161,7 @@ func (d *SqliteRepository) UpdateUserRefreshToken(id entities.UserId, refreshTok
|
|
|
|
return d.Queue.EnqueueWriteTx(queryFunc, params)
|
|
|
|
return d.Queue.EnqueueWriteTx(queryFunc, params)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (d *SqliteRepository) RenewCustomer(renewParams sqlc.RenewCustomerParams) error {
|
|
|
|
func (d *SqliteNKodeRepo) RenewCustomer(renewParams sqlc.RenewCustomerParams) error {
|
|
|
|
queryFunc := func(q *sqlc.Queries, ctx context.Context, args any) error {
|
|
|
|
queryFunc := func(q *sqlc.Queries, ctx context.Context, args any) error {
|
|
|
|
params, ok := args.(sqlc.RenewCustomerParams)
|
|
|
|
params, ok := args.(sqlc.RenewCustomerParams)
|
|
|
|
if !ok {
|
|
|
|
if !ok {
|
|
|
|
@@ -172,7 +172,7 @@ func (d *SqliteRepository) RenewCustomer(renewParams sqlc.RenewCustomerParams) e
|
|
|
|
return d.Queue.EnqueueWriteTx(queryFunc, renewParams)
|
|
|
|
return d.Queue.EnqueueWriteTx(queryFunc, renewParams)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (d *SqliteRepository) Renew(id entities.CustomerId) error {
|
|
|
|
func (d *SqliteNKodeRepo) Renew(id entities.CustomerId) error {
|
|
|
|
setXor, attrXor, err := d.renewCustomer(id)
|
|
|
|
setXor, attrXor, err := d.renewCustomer(id)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
@@ -224,7 +224,7 @@ func (d *SqliteRepository) Renew(id entities.CustomerId) error {
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (d *SqliteRepository) renewCustomer(id entities.CustomerId) ([]uint64, []uint64, error) {
|
|
|
|
func (d *SqliteNKodeRepo) renewCustomer(id entities.CustomerId) ([]uint64, []uint64, error) {
|
|
|
|
customer, err := d.GetCustomer(id)
|
|
|
|
customer, err := d.GetCustomer(id)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
return nil, nil, err
|
|
|
|
@@ -253,7 +253,7 @@ func (d *SqliteRepository) renewCustomer(id entities.CustomerId) ([]uint64, []ui
|
|
|
|
return setXor, attrXor, nil
|
|
|
|
return setXor, attrXor, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (d *SqliteRepository) RefreshUserPasscode(user entities.User, passcodeIdx []int, customerAttr entities.CustomerAttributes) error {
|
|
|
|
func (d *SqliteNKodeRepo) RefreshUserPasscode(user entities.User, passcodeIdx []int, customerAttr entities.CustomerAttributes) error {
|
|
|
|
if err := user.RefreshPasscode(passcodeIdx, customerAttr); err != nil {
|
|
|
|
if err := user.RefreshPasscode(passcodeIdx, customerAttr); err != nil {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@@ -278,7 +278,7 @@ func (d *SqliteRepository) RefreshUserPasscode(user entities.User, passcodeIdx [
|
|
|
|
return d.Queue.EnqueueWriteTx(queryFunc, params)
|
|
|
|
return d.Queue.EnqueueWriteTx(queryFunc, params)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (d *SqliteRepository) AddSvg(svg string) error {
|
|
|
|
func (d *SqliteNKodeRepo) AddSvg(svg string) error {
|
|
|
|
queryFunc := func(q *sqlc.Queries, ctx context.Context, args any) error {
|
|
|
|
queryFunc := func(q *sqlc.Queries, ctx context.Context, args any) error {
|
|
|
|
params, ok := args.(string)
|
|
|
|
params, ok := args.(string)
|
|
|
|
if !ok {
|
|
|
|
if !ok {
|
|
|
|
@@ -289,7 +289,7 @@ func (d *SqliteRepository) AddSvg(svg string) error {
|
|
|
|
return d.Queue.EnqueueWriteTx(queryFunc, svg)
|
|
|
|
return d.Queue.EnqueueWriteTx(queryFunc, svg)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (d *SqliteRepository) GetCustomer(id entities.CustomerId) (*entities.Customer, error) {
|
|
|
|
func (d *SqliteNKodeRepo) GetCustomer(id entities.CustomerId) (*entities.Customer, error) {
|
|
|
|
customer, err := d.Queue.Queries.GetCustomer(d.ctx, uuid.UUID(id).String())
|
|
|
|
customer, err := d.Queue.Queries.GetCustomer(d.ctx, uuid.UUID(id).String())
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
return nil, err
|
|
|
|
@@ -309,7 +309,7 @@ func (d *SqliteRepository) GetCustomer(id entities.CustomerId) (*entities.Custom
|
|
|
|
}, nil
|
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (d *SqliteRepository) GetUser(email entities.UserEmail, customerId entities.CustomerId) (*entities.User, error) {
|
|
|
|
func (d *SqliteNKodeRepo) GetUser(email entities.UserEmail, customerId entities.CustomerId) (*entities.User, error) {
|
|
|
|
userRow, err := d.Queue.Queries.GetUser(d.ctx, sqlc.GetUserParams{
|
|
|
|
userRow, err := d.Queue.Queries.GetUser(d.ctx, sqlc.GetUserParams{
|
|
|
|
Email: string(email),
|
|
|
|
Email: string(email),
|
|
|
|
CustomerID: uuid.UUID(customerId).String(),
|
|
|
|
CustomerID: uuid.UUID(customerId).String(),
|
|
|
|
@@ -359,7 +359,7 @@ func (d *SqliteRepository) GetUser(email entities.UserEmail, customerId entities
|
|
|
|
return &user, nil
|
|
|
|
return &user, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (d *SqliteRepository) RandomSvgInterface(kp entities.KeypadDimension) ([]string, error) {
|
|
|
|
func (d *SqliteNKodeRepo) RandomSvgInterface(kp entities.KeypadDimension) ([]string, error) {
|
|
|
|
ids, err := d.getRandomIds(kp.TotalAttrs())
|
|
|
|
ids, err := d.getRandomIds(kp.TotalAttrs())
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
return nil, err
|
|
|
|
@@ -367,16 +367,16 @@ func (d *SqliteRepository) RandomSvgInterface(kp entities.KeypadDimension) ([]st
|
|
|
|
return d.getSvgsById(ids)
|
|
|
|
return d.getSvgsById(ids)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (d *SqliteRepository) RandomSvgIdxInterface(kp entities.KeypadDimension) (entities.SvgIdInterface, error) {
|
|
|
|
func (d *SqliteNKodeRepo) RandomSvgIdxInterface(kp entities.KeypadDimension) (entities.SvgIdInterface, error) {
|
|
|
|
return d.getRandomIds(kp.TotalAttrs())
|
|
|
|
return d.getRandomIds(kp.TotalAttrs())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (d *SqliteRepository) GetSvgStringInterface(idxs entities.SvgIdInterface) ([]string, error) {
|
|
|
|
func (d *SqliteNKodeRepo) GetSvgStringInterface(idxs entities.SvgIdInterface) ([]string, error) {
|
|
|
|
return d.getSvgsById(idxs)
|
|
|
|
return d.getSvgsById(idxs)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Is this even useful?
|
|
|
|
// Is this even useful?
|
|
|
|
func (d *SqliteRepository) AddUserPermission(userEmail entities.UserEmail, customerId entities.CustomerId, permission entities.UserPermission) error {
|
|
|
|
func (d *SqliteNKodeRepo) AddUserPermission(userEmail entities.UserEmail, customerId entities.CustomerId, permission entities.UserPermission) error {
|
|
|
|
user, err := d.GetUser(userEmail, customerId)
|
|
|
|
user, err := d.GetUser(userEmail, customerId)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
@@ -395,7 +395,7 @@ func (d *SqliteRepository) AddUserPermission(userEmail entities.UserEmail, custo
|
|
|
|
return d.Queue.EnqueueWriteTx(queryFunc, params)
|
|
|
|
return d.Queue.EnqueueWriteTx(queryFunc, params)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (d *SqliteRepository) getSvgsById(ids []int) ([]string, error) {
|
|
|
|
func (d *SqliteNKodeRepo) getSvgsById(ids []int) ([]string, error) {
|
|
|
|
svgs := make([]string, len(ids))
|
|
|
|
svgs := make([]string, len(ids))
|
|
|
|
for idx, id := range ids {
|
|
|
|
for idx, id := range ids {
|
|
|
|
svg, err := d.Queue.Queries.GetSvgId(d.ctx, int64(id))
|
|
|
|
svg, err := d.Queue.Queries.GetSvgId(d.ctx, int64(id))
|
|
|
|
@@ -407,7 +407,7 @@ func (d *SqliteRepository) getSvgsById(ids []int) ([]string, error) {
|
|
|
|
return svgs, nil
|
|
|
|
return svgs, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func (d *SqliteRepository) getRandomIds(count int) ([]int, error) {
|
|
|
|
func (d *SqliteNKodeRepo) getRandomIds(count int) ([]int, error) {
|
|
|
|
totalRows, err := d.Queue.Queries.GetSvgCount(d.ctx)
|
|
|
|
totalRows, err := d.Queue.Queries.GetSvgCount(d.ctx)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
log.Print(err)
|
|
|
|
log.Print(err)
|