rename structs

This commit is contained in:
2025-02-09 09:38:02 -06:00
parent 75d8250f72
commit 4e61d7714e
7 changed files with 35 additions and 36 deletions

View File

@@ -5,7 +5,6 @@ import (
"git.infra.nkode.tech/dkelly/nkode-core/config"
"git.infra.nkode.tech/dkelly/nkode-core/email"
"git.infra.nkode.tech/dkelly/nkode-core/entities"
"git.infra.nkode.tech/dkelly/nkode-core/memCache"
"git.infra.nkode.tech/dkelly/nkode-core/repository"
"git.infra.nkode.tech/dkelly/nkode-core/security"
"github.com/google/uuid"
@@ -24,7 +23,7 @@ type NKodeAPI struct {
repo repository.CustomerUserRepository
signupSessionCache *cache.Cache
emailQueue *email.Queue
forgotNkodeCache memCache.ForgotNKodeCache
forgotNkodeCache mem_cache.ForgotNKodeCache
}
func NewNKodeAPI(repo repository.CustomerUserRepository, queue *email.Queue) NKodeAPI {
@@ -32,7 +31,7 @@ func NewNKodeAPI(repo repository.CustomerUserRepository, queue *email.Queue) NKo
repo: repo,
emailQueue: queue,
signupSessionCache: cache.New(sessionExpiration, sessionCleanupInterval),
forgotNkodeCache: memCache.NewForgotNKodeCache(),
forgotNkodeCache: mem_cache.NewForgotNKodeCache(),
}
}

View File

@@ -18,12 +18,12 @@ func TestNKodeAPI(t *testing.T) {
dbPath := os.Getenv("TEST_DB")
ctx := context.Background()
sqlitedb, err := repository.NewSqliteRepository(ctx, dbPath)
sqlitedb, err := repository.NewSqliteNKodeRepo(ctx, dbPath)
if err != nil {
log.Fatal(err)
}
sqlitedb.Start()
defer func(sqldb *repository.SqliteRepository) {
defer func(sqldb *repository.SqliteNKodeRepo) {
if err := sqldb.Stop(); err != nil {
log.Fatal(err)
}

View File

@@ -29,9 +29,9 @@ func main() {
log.Fatal(err)
}
ctx := context.Background()
sqliteRepo, err := repository.NewSqliteRepository(ctx, *dbPath)
sqliteRepo, err := repository.NewSqliteNKodeRepo(ctx, *dbPath)
sqliteRepo.Start()
defer func(sqliteRepo *repository.SqliteRepository) {
defer func(sqliteRepo *repository.SqliteNKodeRepo) {
if err := sqliteRepo.Stop(); err != nil {
log.Fatal(err)
}
@@ -41,7 +41,7 @@ func main() {
log.Println(fmt.Sprintf("Successfully added all SVGs in %s to the database at %s\n", *svgPath, *dbPath))
}
func FlaticonToSqlite(repo *repository.SqliteRepository, svgDir string) {
func FlaticonToSqlite(repo *repository.SqliteNKodeRepo, svgDir string) {
files, err := os.ReadDir(svgDir)
if err != nil {
log.Fatal(err)

View File

@@ -133,7 +133,7 @@ func TestNKodeAPI(t *testing.T) {
type TestRouter struct {
router *gin.Engine
emailQueue *email.Queue
repo *repository.SqliteRepository
repo *repository.SqliteNKodeRepo
handler *NkodeHandler
}
@@ -143,7 +143,7 @@ func NewTestRouter() *TestRouter {
logger := log.Default()
ctx := context.Background()
dbPath := os.Getenv("TEST_DB")
repo, err := repository.NewSqliteRepository(ctx, dbPath)
repo, err := repository.NewSqliteNKodeRepo(ctx, dbPath)
if err != nil {
log.Fatal(err)
}

View File

@@ -1,4 +1,4 @@
package memCache
package mem_cache
import (
"git.infra.nkode.tech/dkelly/nkode-core/entities"

View File

@@ -14,12 +14,12 @@ import (
"log"
)
type SqliteRepository struct {
type SqliteNKodeRepo struct {
Queue *sqlc.Queue
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)
if err != nil {
return nil, err
@@ -28,21 +28,21 @@ func NewSqliteRepository(ctx context.Context, dbPath string) (*SqliteRepository,
if err != nil {
return nil, err
}
return &SqliteRepository{
return &SqliteNKodeRepo{
Queue: queue,
ctx: ctx,
}, nil
}
func (d *SqliteRepository) Start() {
func (d *SqliteNKodeRepo) Start() {
d.Queue.Start()
}
func (d *SqliteRepository) Stop() error {
func (d *SqliteNKodeRepo) Stop() error {
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 {
params, ok := args.(sqlc.CreateCustomerParams)
if !ok {
@@ -54,7 +54,7 @@ func (d *SqliteRepository) CreateCustomer(c entities.Customer) error {
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 {
params, ok := args.(sqlc.CreateUserParams)
if !ok {
@@ -92,7 +92,7 @@ func (d *SqliteRepository) WriteNewUser(u entities.User) error {
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 {
params, ok := args.(sqlc.UpdateUserParams)
if !ok {
@@ -126,7 +126,7 @@ func (d *SqliteRepository) UpdateUserNKode(u entities.User) error {
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 {
params, ok := args.(sqlc.UpdateUserInterfaceParams)
if !ok {
@@ -143,7 +143,7 @@ func (d *SqliteRepository) UpdateUserInterface(id entities.UserId, ui entities.U
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 {
params, ok := args.(sqlc.UpdateUserRefreshTokenParams)
if !ok {
@@ -161,7 +161,7 @@ func (d *SqliteRepository) UpdateUserRefreshToken(id entities.UserId, refreshTok
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 {
params, ok := args.(sqlc.RenewCustomerParams)
if !ok {
@@ -172,7 +172,7 @@ func (d *SqliteRepository) RenewCustomer(renewParams sqlc.RenewCustomerParams) e
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)
if err != nil {
return err
@@ -224,7 +224,7 @@ func (d *SqliteRepository) Renew(id entities.CustomerId) error {
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)
if err != nil {
return nil, nil, err
@@ -253,7 +253,7 @@ func (d *SqliteRepository) renewCustomer(id entities.CustomerId) ([]uint64, []ui
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 {
return err
}
@@ -278,7 +278,7 @@ func (d *SqliteRepository) RefreshUserPasscode(user entities.User, passcodeIdx [
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 {
params, ok := args.(string)
if !ok {
@@ -289,7 +289,7 @@ func (d *SqliteRepository) AddSvg(svg string) error {
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())
if err != nil {
return nil, err
@@ -309,7 +309,7 @@ func (d *SqliteRepository) GetCustomer(id entities.CustomerId) (*entities.Custom
}, 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{
Email: string(email),
CustomerID: uuid.UUID(customerId).String(),
@@ -359,7 +359,7 @@ func (d *SqliteRepository) GetUser(email entities.UserEmail, customerId entities
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())
if err != nil {
return nil, err
@@ -367,16 +367,16 @@ func (d *SqliteRepository) RandomSvgInterface(kp entities.KeypadDimension) ([]st
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())
}
func (d *SqliteRepository) GetSvgStringInterface(idxs entities.SvgIdInterface) ([]string, error) {
func (d *SqliteNKodeRepo) GetSvgStringInterface(idxs entities.SvgIdInterface) ([]string, error) {
return d.getSvgsById(idxs)
}
// 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)
if err != nil {
return err
@@ -395,7 +395,7 @@ func (d *SqliteRepository) AddUserPermission(userEmail entities.UserEmail, custo
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))
for idx, id := range ids {
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
}
func (d *SqliteRepository) getRandomIds(count int) ([]int, error) {
func (d *SqliteNKodeRepo) getRandomIds(count int) ([]int, error) {
totalRows, err := d.Queue.Queries.GetSvgCount(d.ctx)
if err != nil {
log.Print(err)

View File

@@ -11,10 +11,10 @@ import (
func TestNewSqliteDB(t *testing.T) {
dbPath := os.Getenv("TEST_DB")
ctx := context.Background()
sqliteDb, err := NewSqliteRepository(ctx, dbPath)
sqliteDb, err := NewSqliteNKodeRepo(ctx, dbPath)
assert.NoError(t, err)
sqliteDb.Start()
defer func(t *testing.T, sqliteDb *SqliteRepository) {
defer func(t *testing.T, sqliteDb *SqliteNKodeRepo) {
err := sqliteDb.Stop()
assert.NoError(t, err)
}(t, sqliteDb)