Add create from email
This commit is contained in:
+12
-6
@@ -333,14 +333,14 @@ func (r *UserRepository) jsonToString(jsonData any) string {
|
||||
return string(bytes)
|
||||
}
|
||||
|
||||
func (u *UserRepository) DoesUserEmailExist(email string) (bool, error) {
|
||||
sql, args, _ := u.dialect.From("user").
|
||||
func (r *UserRepository) DoesUserEmailExist(email string) (bool, error) {
|
||||
sql, args, _ := r.dialect.From("user").
|
||||
Prepared(true).
|
||||
Select(goqu.COUNT("email")).
|
||||
Where(goqu.Ex{"email": email}).
|
||||
ToSQL()
|
||||
|
||||
rows, err := u.connPool.Query(context.Background(), sql, args...)
|
||||
rows, err := r.connPool.Query(context.Background(), sql, args...)
|
||||
if err != nil {
|
||||
ersteller_lib.LogError("failed to run sql query: %v", err)
|
||||
return false, err
|
||||
@@ -357,14 +357,14 @@ func (u *UserRepository) DoesUserEmailExist(email string) (bool, error) {
|
||||
return false, nil
|
||||
}
|
||||
|
||||
func (u *UserRepository) GetUserId(email string) (int, error) {
|
||||
sql, args, _ := u.dialect.From("user").
|
||||
func (r *UserRepository) GetUserId(email string) (int, error) {
|
||||
sql, args, _ := r.dialect.From("user").
|
||||
Prepared(true).
|
||||
Select("id").
|
||||
Where(goqu.Ex{"email": email}).
|
||||
ToSQL()
|
||||
|
||||
rows, err := u.connPool.Query(context.Background(), sql, args...)
|
||||
rows, err := r.connPool.Query(context.Background(), sql, args...)
|
||||
if err != nil {
|
||||
ersteller_lib.LogError("failed to run sql query: %v", err)
|
||||
return -1, err
|
||||
@@ -381,6 +381,12 @@ func (u *UserRepository) GetUserId(email string) (int, error) {
|
||||
return -1, errors.New("did not find user with email " + email)
|
||||
}
|
||||
|
||||
func (r *UserRepository) CreateFromEmail(email string) (int, error) {
|
||||
return r.Create(User{
|
||||
Email: email,
|
||||
})
|
||||
}
|
||||
|
||||
func (r *UserRepository) VerifyPassword(email string, password string) (bool, int, error) {
|
||||
userId, err := r.GetUserId(email)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user