Initial commit: Open sourcing all of the Maple Open Technologies code.
This commit is contained in:
commit
755d54a99d
2010 changed files with 448675 additions and 0 deletions
47
cloud/maplefile-backend/internal/repo/user/check.go
Normal file
47
cloud/maplefile-backend/internal/repo/user/check.go
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
// codeberg.org/mapleopentech/monorepo/cloud/maplefile-backend/internal/repo/user/check.go
|
||||
package user
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/gocql/gocql"
|
||||
"go.uber.org/zap"
|
||||
|
||||
"codeberg.org/mapleopentech/monorepo/cloud/maplefile-backend/pkg/validation"
|
||||
)
|
||||
|
||||
func (r *userStorerImpl) CheckIfExistsByID(ctx context.Context, id gocql.UUID) (bool, error) {
|
||||
query := `SELECT id FROM users_by_id WHERE id = ? LIMIT 1`
|
||||
err := r.session.Query(query, id).WithContext(ctx).Scan(&id)
|
||||
|
||||
if err == gocql.ErrNotFound {
|
||||
return false, nil
|
||||
}
|
||||
if err != nil {
|
||||
r.logger.Error("Failed to check if user exists by id",
|
||||
zap.String("id", id.String()),
|
||||
zap.Error(err))
|
||||
return false, err
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func (r *userStorerImpl) CheckIfExistsByEmail(ctx context.Context, email string) (bool, error) {
|
||||
var id gocql.UUID
|
||||
|
||||
query := `SELECT id FROM users_by_email WHERE email = ? LIMIT 1`
|
||||
err := r.session.Query(query, email).WithContext(ctx).Scan(&id)
|
||||
|
||||
if err == gocql.ErrNotFound {
|
||||
return false, nil
|
||||
}
|
||||
if err != nil {
|
||||
r.logger.Error("Failed to check if user exists by email",
|
||||
zap.String("email", validation.MaskEmail(email)),
|
||||
zap.Error(err))
|
||||
return false, err
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue