feat: db regular and transactional helpers to reduce boilerplate

This commit is contained in:
2025-06-21 20:04:20 +03:00
parent e1df58b434
commit 613deae8e2
2 changed files with 82 additions and 4 deletions

View File

@@ -1,7 +1,6 @@
package services
import (
"context"
"easywish/internal/database"
errs "easywish/internal/errors"
"easywish/internal/logger"
@@ -29,9 +28,9 @@ func NewAuthService(_log logger.Logger, _dbctx database.DbContext) AuthService {
func (a *authServiceImpl) RegistrationBegin(request models.RegistrationBeginRequest) (bool, error) {
ctx := context.Background()
queries := database.New(a.dbctx)
user, err := queries.CreateUser(ctx, request.Username) // TODO: validation
helper, db, _ := database.NewDbHelperTransaction(a.dbctx)
user, err := db.TXQueries.CreateUser(db.CTX, request.Username) // TODO: validation
if err != nil {
a.log.Get().Error("Failed to add user to database", zap.Error(err))
@@ -39,6 +38,8 @@ func (a *authServiceImpl) RegistrationBegin(request models.RegistrationBeginRequ
}
a.log.Get().Info("Registered a new user", zap.String("username", user.Username))
helper.Commit()
// TODO: Send verification email
return true, nil