Added transactions and improved error handling #35
@@ -3,7 +3,6 @@ package domain
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"log/slog"
|
"log/slog"
|
||||||
"time"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type RegistrationService struct {
|
type RegistrationService struct {
|
||||||
@@ -23,13 +22,6 @@ func (s *RegistrationService) Register(ctx context.Context, inviteCode string, e
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if invite.ConsumedAt != nil {
|
|
||||||
return nil, ErrInviteConsumed
|
|
||||||
}
|
|
||||||
if invite.ExpiresAt.Before(time.Now()) {
|
|
||||||
return nil, ErrInviteExpired
|
|
||||||
}
|
|
||||||
|
|
||||||
var user *User
|
var user *User
|
||||||
err = s.tx.WithinTx(ctx, func(ctx context.Context) error {
|
err = s.tx.WithinTx(ctx, func(ctx context.Context) error {
|
||||||
user, err = s.UserService.CreateUser(ctx, email, username, password)
|
user, err = s.UserService.CreateUser(ctx, email, username, password)
|
||||||
|
|||||||
Reference in New Issue
Block a user