feat: db regular and transactional helpers to reduce boilerplate
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user