946 lines
27 KiB
Go
946 lines
27 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.30.0
|
|
// source: user.sql
|
|
|
|
package dbgen
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
const CheckPhoneEmailExist = `-- name: CheckPhoneEmailExist :one
|
|
SELECT
|
|
EXISTS (
|
|
SELECT 1 FROM users u1 WHERE u1.phone_number = $1
|
|
) AS phone_exists,
|
|
EXISTS (
|
|
SELECT 1 FROM users u2 WHERE u2.email = $2
|
|
) AS email_exists
|
|
`
|
|
|
|
type CheckPhoneEmailExistParams struct {
|
|
PhoneNumber pgtype.Text `json:"phone_number"`
|
|
Email pgtype.Text `json:"email"`
|
|
}
|
|
|
|
type CheckPhoneEmailExistRow struct {
|
|
PhoneExists bool `json:"phone_exists"`
|
|
EmailExists bool `json:"email_exists"`
|
|
}
|
|
|
|
func (q *Queries) CheckPhoneEmailExist(ctx context.Context, arg CheckPhoneEmailExistParams) (CheckPhoneEmailExistRow, error) {
|
|
row := q.db.QueryRow(ctx, CheckPhoneEmailExist, arg.PhoneNumber, arg.Email)
|
|
var i CheckPhoneEmailExistRow
|
|
err := row.Scan(&i.PhoneExists, &i.EmailExists)
|
|
return i, err
|
|
}
|
|
|
|
const CreateUser = `-- name: CreateUser :one
|
|
INSERT INTO users (
|
|
first_name,
|
|
last_name,
|
|
user_name,
|
|
email,
|
|
phone_number,
|
|
role,
|
|
password,
|
|
age,
|
|
education_level,
|
|
country,
|
|
region,
|
|
|
|
nick_name,
|
|
occupation,
|
|
learning_goal,
|
|
language_goal,
|
|
language_challange,
|
|
favoutite_topic,
|
|
|
|
initial_assessment_completed,
|
|
email_verified,
|
|
phone_verified,
|
|
status,
|
|
profile_completed,
|
|
profile_picture_url,
|
|
preferred_language,
|
|
updated_at
|
|
)
|
|
VALUES (
|
|
$1, -- first_name
|
|
$2, -- last_name
|
|
$3, -- user_name
|
|
$4, -- email
|
|
$5, -- phone_number
|
|
$6, -- role
|
|
$7, -- password
|
|
$8, -- age
|
|
$9, -- education_level
|
|
$10, -- country
|
|
$11, -- region
|
|
|
|
$12, -- nick_name
|
|
$13, -- occupation
|
|
$14, -- learning_goal
|
|
$15, -- language_goal
|
|
$16, -- language_challange
|
|
$17, -- favoutite_topic
|
|
|
|
$18, -- initial_assessment_completed
|
|
$19, -- email_verified
|
|
$20, -- phone_verified
|
|
$21, -- status
|
|
$22, -- profile_completed
|
|
$23, -- profile_picture_url
|
|
$24, -- preferred_language
|
|
CURRENT_TIMESTAMP
|
|
)
|
|
RETURNING
|
|
id,
|
|
first_name,
|
|
last_name,
|
|
user_name,
|
|
email,
|
|
phone_number,
|
|
role,
|
|
age,
|
|
education_level,
|
|
country,
|
|
region,
|
|
|
|
nick_name,
|
|
occupation,
|
|
learning_goal,
|
|
language_goal,
|
|
language_challange,
|
|
favoutite_topic,
|
|
|
|
initial_assessment_completed,
|
|
email_verified,
|
|
phone_verified,
|
|
status,
|
|
profile_completed,
|
|
profile_picture_url,
|
|
preferred_language,
|
|
created_at,
|
|
updated_at
|
|
`
|
|
|
|
type CreateUserParams struct {
|
|
FirstName string `json:"first_name"`
|
|
LastName string `json:"last_name"`
|
|
UserName string `json:"user_name"`
|
|
Email pgtype.Text `json:"email"`
|
|
PhoneNumber pgtype.Text `json:"phone_number"`
|
|
Role string `json:"role"`
|
|
Password []byte `json:"password"`
|
|
Age pgtype.Int4 `json:"age"`
|
|
EducationLevel pgtype.Text `json:"education_level"`
|
|
Country pgtype.Text `json:"country"`
|
|
Region pgtype.Text `json:"region"`
|
|
NickName pgtype.Text `json:"nick_name"`
|
|
Occupation pgtype.Text `json:"occupation"`
|
|
LearningGoal pgtype.Text `json:"learning_goal"`
|
|
LanguageGoal pgtype.Text `json:"language_goal"`
|
|
LanguageChallange pgtype.Text `json:"language_challange"`
|
|
FavoutiteTopic pgtype.Text `json:"favoutite_topic"`
|
|
InitialAssessmentCompleted bool `json:"initial_assessment_completed"`
|
|
EmailVerified bool `json:"email_verified"`
|
|
PhoneVerified bool `json:"phone_verified"`
|
|
Status string `json:"status"`
|
|
ProfileCompleted bool `json:"profile_completed"`
|
|
ProfilePictureUrl pgtype.Text `json:"profile_picture_url"`
|
|
PreferredLanguage pgtype.Text `json:"preferred_language"`
|
|
}
|
|
|
|
type CreateUserRow struct {
|
|
ID int64 `json:"id"`
|
|
FirstName string `json:"first_name"`
|
|
LastName string `json:"last_name"`
|
|
UserName string `json:"user_name"`
|
|
Email pgtype.Text `json:"email"`
|
|
PhoneNumber pgtype.Text `json:"phone_number"`
|
|
Role string `json:"role"`
|
|
Age pgtype.Int4 `json:"age"`
|
|
EducationLevel pgtype.Text `json:"education_level"`
|
|
Country pgtype.Text `json:"country"`
|
|
Region pgtype.Text `json:"region"`
|
|
NickName pgtype.Text `json:"nick_name"`
|
|
Occupation pgtype.Text `json:"occupation"`
|
|
LearningGoal pgtype.Text `json:"learning_goal"`
|
|
LanguageGoal pgtype.Text `json:"language_goal"`
|
|
LanguageChallange pgtype.Text `json:"language_challange"`
|
|
FavoutiteTopic pgtype.Text `json:"favoutite_topic"`
|
|
InitialAssessmentCompleted bool `json:"initial_assessment_completed"`
|
|
EmailVerified bool `json:"email_verified"`
|
|
PhoneVerified bool `json:"phone_verified"`
|
|
Status string `json:"status"`
|
|
ProfileCompleted bool `json:"profile_completed"`
|
|
ProfilePictureUrl pgtype.Text `json:"profile_picture_url"`
|
|
PreferredLanguage pgtype.Text `json:"preferred_language"`
|
|
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
|
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
|
}
|
|
|
|
func (q *Queries) CreateUser(ctx context.Context, arg CreateUserParams) (CreateUserRow, error) {
|
|
row := q.db.QueryRow(ctx, CreateUser,
|
|
arg.FirstName,
|
|
arg.LastName,
|
|
arg.UserName,
|
|
arg.Email,
|
|
arg.PhoneNumber,
|
|
arg.Role,
|
|
arg.Password,
|
|
arg.Age,
|
|
arg.EducationLevel,
|
|
arg.Country,
|
|
arg.Region,
|
|
arg.NickName,
|
|
arg.Occupation,
|
|
arg.LearningGoal,
|
|
arg.LanguageGoal,
|
|
arg.LanguageChallange,
|
|
arg.FavoutiteTopic,
|
|
arg.InitialAssessmentCompleted,
|
|
arg.EmailVerified,
|
|
arg.PhoneVerified,
|
|
arg.Status,
|
|
arg.ProfileCompleted,
|
|
arg.ProfilePictureUrl,
|
|
arg.PreferredLanguage,
|
|
)
|
|
var i CreateUserRow
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.FirstName,
|
|
&i.LastName,
|
|
&i.UserName,
|
|
&i.Email,
|
|
&i.PhoneNumber,
|
|
&i.Role,
|
|
&i.Age,
|
|
&i.EducationLevel,
|
|
&i.Country,
|
|
&i.Region,
|
|
&i.NickName,
|
|
&i.Occupation,
|
|
&i.LearningGoal,
|
|
&i.LanguageGoal,
|
|
&i.LanguageChallange,
|
|
&i.FavoutiteTopic,
|
|
&i.InitialAssessmentCompleted,
|
|
&i.EmailVerified,
|
|
&i.PhoneVerified,
|
|
&i.Status,
|
|
&i.ProfileCompleted,
|
|
&i.ProfilePictureUrl,
|
|
&i.PreferredLanguage,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const DeleteUser = `-- name: DeleteUser :exec
|
|
DELETE FROM users
|
|
WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) DeleteUser(ctx context.Context, id int64) error {
|
|
_, err := q.db.Exec(ctx, DeleteUser, id)
|
|
return err
|
|
}
|
|
|
|
const GetAllUsers = `-- name: GetAllUsers :many
|
|
SELECT
|
|
COUNT(*) OVER () AS total_count,
|
|
id,
|
|
first_name,
|
|
last_name,
|
|
user_name,
|
|
email,
|
|
phone_number,
|
|
role,
|
|
age,
|
|
education_level,
|
|
country,
|
|
region,
|
|
nick_name,
|
|
occupation,
|
|
learning_goal,
|
|
language_goal,
|
|
language_challange,
|
|
favoutite_topic,
|
|
initial_assessment_completed,
|
|
profile_picture_url,
|
|
preferred_language,
|
|
email_verified,
|
|
phone_verified,
|
|
status,
|
|
profile_completed,
|
|
created_at,
|
|
updated_at
|
|
FROM users
|
|
WHERE ($1 IS NULL OR role = $1)
|
|
AND ($2 IS NULL OR first_name ILIKE '%' || $2 || '%'
|
|
OR last_name ILIKE '%' || $2 || '%'
|
|
OR phone_number ILIKE '%' || $2 || '%'
|
|
OR email ILIKE '%' || $2 || '%')
|
|
AND ($3 IS NULL OR created_at >= $3)
|
|
AND ($4 IS NULL OR created_at <= $4)
|
|
LIMIT $5
|
|
OFFSET $6
|
|
`
|
|
|
|
type GetAllUsersParams struct {
|
|
Column1 interface{} `json:"column_1"`
|
|
Column2 interface{} `json:"column_2"`
|
|
Column3 interface{} `json:"column_3"`
|
|
Column4 interface{} `json:"column_4"`
|
|
Limit int32 `json:"limit"`
|
|
Offset int32 `json:"offset"`
|
|
}
|
|
|
|
type GetAllUsersRow struct {
|
|
TotalCount int64 `json:"total_count"`
|
|
ID int64 `json:"id"`
|
|
FirstName string `json:"first_name"`
|
|
LastName string `json:"last_name"`
|
|
UserName string `json:"user_name"`
|
|
Email pgtype.Text `json:"email"`
|
|
PhoneNumber pgtype.Text `json:"phone_number"`
|
|
Role string `json:"role"`
|
|
Age pgtype.Int4 `json:"age"`
|
|
EducationLevel pgtype.Text `json:"education_level"`
|
|
Country pgtype.Text `json:"country"`
|
|
Region pgtype.Text `json:"region"`
|
|
NickName pgtype.Text `json:"nick_name"`
|
|
Occupation pgtype.Text `json:"occupation"`
|
|
LearningGoal pgtype.Text `json:"learning_goal"`
|
|
LanguageGoal pgtype.Text `json:"language_goal"`
|
|
LanguageChallange pgtype.Text `json:"language_challange"`
|
|
FavoutiteTopic pgtype.Text `json:"favoutite_topic"`
|
|
InitialAssessmentCompleted bool `json:"initial_assessment_completed"`
|
|
ProfilePictureUrl pgtype.Text `json:"profile_picture_url"`
|
|
PreferredLanguage pgtype.Text `json:"preferred_language"`
|
|
EmailVerified bool `json:"email_verified"`
|
|
PhoneVerified bool `json:"phone_verified"`
|
|
Status string `json:"status"`
|
|
ProfileCompleted bool `json:"profile_completed"`
|
|
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
|
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
|
}
|
|
|
|
func (q *Queries) GetAllUsers(ctx context.Context, arg GetAllUsersParams) ([]GetAllUsersRow, error) {
|
|
rows, err := q.db.Query(ctx, GetAllUsers,
|
|
arg.Column1,
|
|
arg.Column2,
|
|
arg.Column3,
|
|
arg.Column4,
|
|
arg.Limit,
|
|
arg.Offset,
|
|
)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []GetAllUsersRow
|
|
for rows.Next() {
|
|
var i GetAllUsersRow
|
|
if err := rows.Scan(
|
|
&i.TotalCount,
|
|
&i.ID,
|
|
&i.FirstName,
|
|
&i.LastName,
|
|
&i.UserName,
|
|
&i.Email,
|
|
&i.PhoneNumber,
|
|
&i.Role,
|
|
&i.Age,
|
|
&i.EducationLevel,
|
|
&i.Country,
|
|
&i.Region,
|
|
&i.NickName,
|
|
&i.Occupation,
|
|
&i.LearningGoal,
|
|
&i.LanguageGoal,
|
|
&i.LanguageChallange,
|
|
&i.FavoutiteTopic,
|
|
&i.InitialAssessmentCompleted,
|
|
&i.ProfilePictureUrl,
|
|
&i.PreferredLanguage,
|
|
&i.EmailVerified,
|
|
&i.PhoneVerified,
|
|
&i.Status,
|
|
&i.ProfileCompleted,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const GetTotalUsers = `-- name: GetTotalUsers :one
|
|
SELECT COUNT(*)
|
|
FROM users
|
|
WHERE (role = $1 OR $1 IS NULL)
|
|
`
|
|
|
|
func (q *Queries) GetTotalUsers(ctx context.Context, role string) (int64, error) {
|
|
row := q.db.QueryRow(ctx, GetTotalUsers, role)
|
|
var count int64
|
|
err := row.Scan(&count)
|
|
return count, err
|
|
}
|
|
|
|
const GetUserByEmailPhone = `-- name: GetUserByEmailPhone :one
|
|
SELECT
|
|
id,
|
|
first_name,
|
|
last_name,
|
|
user_name,
|
|
email,
|
|
phone_number,
|
|
role,
|
|
password,
|
|
age,
|
|
education_level,
|
|
country,
|
|
region,
|
|
|
|
nick_name,
|
|
occupation,
|
|
learning_goal,
|
|
language_goal,
|
|
language_challange,
|
|
favoutite_topic,
|
|
|
|
medium,
|
|
email_verified,
|
|
phone_verified,
|
|
status,
|
|
profile_completed,
|
|
last_login,
|
|
profile_picture_url,
|
|
preferred_language,
|
|
created_at,
|
|
updated_at
|
|
FROM users
|
|
WHERE (email = $1 AND $1 IS NOT NULL)
|
|
OR (phone_number = $2 AND $2 IS NOT NULL)
|
|
LIMIT 1
|
|
`
|
|
|
|
type GetUserByEmailPhoneParams struct {
|
|
Email pgtype.Text `json:"email"`
|
|
PhoneNumber pgtype.Text `json:"phone_number"`
|
|
}
|
|
|
|
type GetUserByEmailPhoneRow struct {
|
|
ID int64 `json:"id"`
|
|
FirstName string `json:"first_name"`
|
|
LastName string `json:"last_name"`
|
|
UserName string `json:"user_name"`
|
|
Email pgtype.Text `json:"email"`
|
|
PhoneNumber pgtype.Text `json:"phone_number"`
|
|
Role string `json:"role"`
|
|
Password []byte `json:"password"`
|
|
Age pgtype.Int4 `json:"age"`
|
|
EducationLevel pgtype.Text `json:"education_level"`
|
|
Country pgtype.Text `json:"country"`
|
|
Region pgtype.Text `json:"region"`
|
|
NickName pgtype.Text `json:"nick_name"`
|
|
Occupation pgtype.Text `json:"occupation"`
|
|
LearningGoal pgtype.Text `json:"learning_goal"`
|
|
LanguageGoal pgtype.Text `json:"language_goal"`
|
|
LanguageChallange pgtype.Text `json:"language_challange"`
|
|
FavoutiteTopic pgtype.Text `json:"favoutite_topic"`
|
|
Medium string `json:"medium"`
|
|
EmailVerified bool `json:"email_verified"`
|
|
PhoneVerified bool `json:"phone_verified"`
|
|
Status string `json:"status"`
|
|
ProfileCompleted bool `json:"profile_completed"`
|
|
LastLogin pgtype.Timestamptz `json:"last_login"`
|
|
ProfilePictureUrl pgtype.Text `json:"profile_picture_url"`
|
|
PreferredLanguage pgtype.Text `json:"preferred_language"`
|
|
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
|
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
|
}
|
|
|
|
func (q *Queries) GetUserByEmailPhone(ctx context.Context, arg GetUserByEmailPhoneParams) (GetUserByEmailPhoneRow, error) {
|
|
row := q.db.QueryRow(ctx, GetUserByEmailPhone, arg.Email, arg.PhoneNumber)
|
|
var i GetUserByEmailPhoneRow
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.FirstName,
|
|
&i.LastName,
|
|
&i.UserName,
|
|
&i.Email,
|
|
&i.PhoneNumber,
|
|
&i.Role,
|
|
&i.Password,
|
|
&i.Age,
|
|
&i.EducationLevel,
|
|
&i.Country,
|
|
&i.Region,
|
|
&i.NickName,
|
|
&i.Occupation,
|
|
&i.LearningGoal,
|
|
&i.LanguageGoal,
|
|
&i.LanguageChallange,
|
|
&i.FavoutiteTopic,
|
|
&i.Medium,
|
|
&i.EmailVerified,
|
|
&i.PhoneVerified,
|
|
&i.Status,
|
|
&i.ProfileCompleted,
|
|
&i.LastLogin,
|
|
&i.ProfilePictureUrl,
|
|
&i.PreferredLanguage,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const GetUserByID = `-- name: GetUserByID :one
|
|
SELECT id, first_name, last_name, user_name, email, phone_number, role, password, age, education_level, country, region, medium, knowledge_level, nick_name, occupation, learning_goal, language_goal, language_challange, favoutite_topic, initial_assessment_completed, email_verified, phone_verified, status, last_login, profile_completed, profile_picture_url, preferred_language, created_at, updated_at
|
|
FROM users
|
|
WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) GetUserByID(ctx context.Context, id int64) (User, error) {
|
|
row := q.db.QueryRow(ctx, GetUserByID, id)
|
|
var i User
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.FirstName,
|
|
&i.LastName,
|
|
&i.UserName,
|
|
&i.Email,
|
|
&i.PhoneNumber,
|
|
&i.Role,
|
|
&i.Password,
|
|
&i.Age,
|
|
&i.EducationLevel,
|
|
&i.Country,
|
|
&i.Region,
|
|
&i.Medium,
|
|
&i.KnowledgeLevel,
|
|
&i.NickName,
|
|
&i.Occupation,
|
|
&i.LearningGoal,
|
|
&i.LanguageGoal,
|
|
&i.LanguageChallange,
|
|
&i.FavoutiteTopic,
|
|
&i.InitialAssessmentCompleted,
|
|
&i.EmailVerified,
|
|
&i.PhoneVerified,
|
|
&i.Status,
|
|
&i.LastLogin,
|
|
&i.ProfileCompleted,
|
|
&i.ProfilePictureUrl,
|
|
&i.PreferredLanguage,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const GetUserByUserName = `-- name: GetUserByUserName :one
|
|
SELECT
|
|
id,
|
|
first_name,
|
|
last_name,
|
|
user_name,
|
|
email,
|
|
phone_number,
|
|
role,
|
|
password,
|
|
age,
|
|
education_level,
|
|
country,
|
|
region,
|
|
|
|
nick_name,
|
|
occupation,
|
|
learning_goal,
|
|
language_goal,
|
|
language_challange,
|
|
favoutite_topic,
|
|
|
|
email_verified,
|
|
phone_verified,
|
|
status,
|
|
profile_completed,
|
|
last_login,
|
|
profile_picture_url,
|
|
preferred_language,
|
|
created_at,
|
|
updated_at
|
|
FROM users
|
|
WHERE user_name = $1 AND $1 IS NOT NULL
|
|
LIMIT 1
|
|
`
|
|
|
|
type GetUserByUserNameRow struct {
|
|
ID int64 `json:"id"`
|
|
FirstName string `json:"first_name"`
|
|
LastName string `json:"last_name"`
|
|
UserName string `json:"user_name"`
|
|
Email pgtype.Text `json:"email"`
|
|
PhoneNumber pgtype.Text `json:"phone_number"`
|
|
Role string `json:"role"`
|
|
Password []byte `json:"password"`
|
|
Age pgtype.Int4 `json:"age"`
|
|
EducationLevel pgtype.Text `json:"education_level"`
|
|
Country pgtype.Text `json:"country"`
|
|
Region pgtype.Text `json:"region"`
|
|
NickName pgtype.Text `json:"nick_name"`
|
|
Occupation pgtype.Text `json:"occupation"`
|
|
LearningGoal pgtype.Text `json:"learning_goal"`
|
|
LanguageGoal pgtype.Text `json:"language_goal"`
|
|
LanguageChallange pgtype.Text `json:"language_challange"`
|
|
FavoutiteTopic pgtype.Text `json:"favoutite_topic"`
|
|
EmailVerified bool `json:"email_verified"`
|
|
PhoneVerified bool `json:"phone_verified"`
|
|
Status string `json:"status"`
|
|
ProfileCompleted bool `json:"profile_completed"`
|
|
LastLogin pgtype.Timestamptz `json:"last_login"`
|
|
ProfilePictureUrl pgtype.Text `json:"profile_picture_url"`
|
|
PreferredLanguage pgtype.Text `json:"preferred_language"`
|
|
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
|
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
|
}
|
|
|
|
func (q *Queries) GetUserByUserName(ctx context.Context, userName string) (GetUserByUserNameRow, error) {
|
|
row := q.db.QueryRow(ctx, GetUserByUserName, userName)
|
|
var i GetUserByUserNameRow
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.FirstName,
|
|
&i.LastName,
|
|
&i.UserName,
|
|
&i.Email,
|
|
&i.PhoneNumber,
|
|
&i.Role,
|
|
&i.Password,
|
|
&i.Age,
|
|
&i.EducationLevel,
|
|
&i.Country,
|
|
&i.Region,
|
|
&i.NickName,
|
|
&i.Occupation,
|
|
&i.LearningGoal,
|
|
&i.LanguageGoal,
|
|
&i.LanguageChallange,
|
|
&i.FavoutiteTopic,
|
|
&i.EmailVerified,
|
|
&i.PhoneVerified,
|
|
&i.Status,
|
|
&i.ProfileCompleted,
|
|
&i.LastLogin,
|
|
&i.ProfilePictureUrl,
|
|
&i.PreferredLanguage,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const IsUserNameUnique = `-- name: IsUserNameUnique :one
|
|
SELECT
|
|
CASE WHEN COUNT(*) = 0 THEN true ELSE false END AS is_unique
|
|
FROM users
|
|
WHERE user_name = $1
|
|
`
|
|
|
|
func (q *Queries) IsUserNameUnique(ctx context.Context, userName string) (bool, error) {
|
|
row := q.db.QueryRow(ctx, IsUserNameUnique, userName)
|
|
var is_unique bool
|
|
err := row.Scan(&is_unique)
|
|
return is_unique, err
|
|
}
|
|
|
|
const IsUserPending = `-- name: IsUserPending :one
|
|
SELECT
|
|
CASE WHEN status = 'PENDING' THEN true ELSE false END AS is_pending
|
|
FROM users
|
|
WHERE user_name = $1
|
|
LIMIT 1
|
|
`
|
|
|
|
func (q *Queries) IsUserPending(ctx context.Context, userName string) (bool, error) {
|
|
row := q.db.QueryRow(ctx, IsUserPending, userName)
|
|
var is_pending bool
|
|
err := row.Scan(&is_pending)
|
|
return is_pending, err
|
|
}
|
|
|
|
const SearchUserByNameOrPhone = `-- name: SearchUserByNameOrPhone :many
|
|
SELECT
|
|
id,
|
|
first_name,
|
|
last_name,
|
|
user_name,
|
|
email,
|
|
phone_number,
|
|
role,
|
|
age,
|
|
education_level,
|
|
country,
|
|
region,
|
|
|
|
nick_name,
|
|
occupation,
|
|
learning_goal,
|
|
language_goal,
|
|
language_challange,
|
|
favoutite_topic,
|
|
|
|
initial_assessment_completed,
|
|
profile_picture_url,
|
|
preferred_language,
|
|
email_verified,
|
|
phone_verified,
|
|
status,
|
|
profile_completed,
|
|
created_at,
|
|
updated_at
|
|
FROM users
|
|
WHERE (
|
|
first_name ILIKE '%' || $1 || '%'
|
|
OR last_name ILIKE '%' || $1 || '%'
|
|
OR phone_number ILIKE '%' || $1 || '%'
|
|
OR email ILIKE '%' || $1 || '%'
|
|
)
|
|
AND (
|
|
role = $2
|
|
OR $2 IS NULL
|
|
)
|
|
`
|
|
|
|
type SearchUserByNameOrPhoneParams struct {
|
|
Column1 pgtype.Text `json:"column_1"`
|
|
Role pgtype.Text `json:"role"`
|
|
}
|
|
|
|
type SearchUserByNameOrPhoneRow struct {
|
|
ID int64 `json:"id"`
|
|
FirstName string `json:"first_name"`
|
|
LastName string `json:"last_name"`
|
|
UserName string `json:"user_name"`
|
|
Email pgtype.Text `json:"email"`
|
|
PhoneNumber pgtype.Text `json:"phone_number"`
|
|
Role string `json:"role"`
|
|
Age pgtype.Int4 `json:"age"`
|
|
EducationLevel pgtype.Text `json:"education_level"`
|
|
Country pgtype.Text `json:"country"`
|
|
Region pgtype.Text `json:"region"`
|
|
NickName pgtype.Text `json:"nick_name"`
|
|
Occupation pgtype.Text `json:"occupation"`
|
|
LearningGoal pgtype.Text `json:"learning_goal"`
|
|
LanguageGoal pgtype.Text `json:"language_goal"`
|
|
LanguageChallange pgtype.Text `json:"language_challange"`
|
|
FavoutiteTopic pgtype.Text `json:"favoutite_topic"`
|
|
InitialAssessmentCompleted bool `json:"initial_assessment_completed"`
|
|
ProfilePictureUrl pgtype.Text `json:"profile_picture_url"`
|
|
PreferredLanguage pgtype.Text `json:"preferred_language"`
|
|
EmailVerified bool `json:"email_verified"`
|
|
PhoneVerified bool `json:"phone_verified"`
|
|
Status string `json:"status"`
|
|
ProfileCompleted bool `json:"profile_completed"`
|
|
CreatedAt pgtype.Timestamptz `json:"created_at"`
|
|
UpdatedAt pgtype.Timestamptz `json:"updated_at"`
|
|
}
|
|
|
|
func (q *Queries) SearchUserByNameOrPhone(ctx context.Context, arg SearchUserByNameOrPhoneParams) ([]SearchUserByNameOrPhoneRow, error) {
|
|
rows, err := q.db.Query(ctx, SearchUserByNameOrPhone, arg.Column1, arg.Role)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []SearchUserByNameOrPhoneRow
|
|
for rows.Next() {
|
|
var i SearchUserByNameOrPhoneRow
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.FirstName,
|
|
&i.LastName,
|
|
&i.UserName,
|
|
&i.Email,
|
|
&i.PhoneNumber,
|
|
&i.Role,
|
|
&i.Age,
|
|
&i.EducationLevel,
|
|
&i.Country,
|
|
&i.Region,
|
|
&i.NickName,
|
|
&i.Occupation,
|
|
&i.LearningGoal,
|
|
&i.LanguageGoal,
|
|
&i.LanguageChallange,
|
|
&i.FavoutiteTopic,
|
|
&i.InitialAssessmentCompleted,
|
|
&i.ProfilePictureUrl,
|
|
&i.PreferredLanguage,
|
|
&i.EmailVerified,
|
|
&i.PhoneVerified,
|
|
&i.Status,
|
|
&i.ProfileCompleted,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const UpdatePassword = `-- name: UpdatePassword :exec
|
|
UPDATE users
|
|
SET
|
|
password = $1,
|
|
updated_at = CURRENT_TIMESTAMP
|
|
WHERE user_name = $2
|
|
`
|
|
|
|
type UpdatePasswordParams struct {
|
|
Password []byte `json:"password"`
|
|
UserName string `json:"user_name"`
|
|
}
|
|
|
|
func (q *Queries) UpdatePassword(ctx context.Context, arg UpdatePasswordParams) error {
|
|
_, err := q.db.Exec(ctx, UpdatePassword, arg.Password, arg.UserName)
|
|
return err
|
|
}
|
|
|
|
const UpdateUser = `-- name: UpdateUser :exec
|
|
UPDATE users
|
|
SET
|
|
first_name = COALESCE($1, first_name),
|
|
last_name = COALESCE($2, last_name),
|
|
user_name = COALESCE($3, user_name),
|
|
knowledge_level = COALESCE($4, knowledge_level),
|
|
age = COALESCE($5, age),
|
|
education_level = COALESCE($6, education_level),
|
|
country = COALESCE($7, country),
|
|
region = COALESCE($8, region),
|
|
nick_name = COALESCE($9, nick_name),
|
|
occupation = COALESCE($10, occupation),
|
|
learning_goal = COALESCE($11, learning_goal),
|
|
language_goal = COALESCE($12, language_goal),
|
|
language_challange = COALESCE($13, language_challange),
|
|
favoutite_topic = COALESCE($14, favoutite_topic),
|
|
initial_assessment_completed = COALESCE($15, initial_assessment_completed),
|
|
email_verified = COALESCE($16, email_verified),
|
|
phone_verified = COALESCE($17, phone_verified),
|
|
status = COALESCE($18, status),
|
|
profile_completed = COALESCE($19, profile_completed),
|
|
profile_picture_url = COALESCE($20, profile_picture_url),
|
|
preferred_language = COALESCE($21, preferred_language),
|
|
updated_at = CURRENT_TIMESTAMP
|
|
WHERE id = $22
|
|
`
|
|
|
|
type UpdateUserParams struct {
|
|
FirstName string `json:"first_name"`
|
|
LastName string `json:"last_name"`
|
|
UserName string `json:"user_name"`
|
|
KnowledgeLevel pgtype.Text `json:"knowledge_level"`
|
|
Age pgtype.Int4 `json:"age"`
|
|
EducationLevel pgtype.Text `json:"education_level"`
|
|
Country pgtype.Text `json:"country"`
|
|
Region pgtype.Text `json:"region"`
|
|
NickName pgtype.Text `json:"nick_name"`
|
|
Occupation pgtype.Text `json:"occupation"`
|
|
LearningGoal pgtype.Text `json:"learning_goal"`
|
|
LanguageGoal pgtype.Text `json:"language_goal"`
|
|
LanguageChallange pgtype.Text `json:"language_challange"`
|
|
FavoutiteTopic pgtype.Text `json:"favoutite_topic"`
|
|
InitialAssessmentCompleted bool `json:"initial_assessment_completed"`
|
|
EmailVerified bool `json:"email_verified"`
|
|
PhoneVerified bool `json:"phone_verified"`
|
|
Status string `json:"status"`
|
|
ProfileCompleted bool `json:"profile_completed"`
|
|
ProfilePictureUrl pgtype.Text `json:"profile_picture_url"`
|
|
PreferredLanguage pgtype.Text `json:"preferred_language"`
|
|
ID int64 `json:"id"`
|
|
}
|
|
|
|
func (q *Queries) UpdateUser(ctx context.Context, arg UpdateUserParams) error {
|
|
_, err := q.db.Exec(ctx, UpdateUser,
|
|
arg.FirstName,
|
|
arg.LastName,
|
|
arg.UserName,
|
|
arg.KnowledgeLevel,
|
|
arg.Age,
|
|
arg.EducationLevel,
|
|
arg.Country,
|
|
arg.Region,
|
|
arg.NickName,
|
|
arg.Occupation,
|
|
arg.LearningGoal,
|
|
arg.LanguageGoal,
|
|
arg.LanguageChallange,
|
|
arg.FavoutiteTopic,
|
|
arg.InitialAssessmentCompleted,
|
|
arg.EmailVerified,
|
|
arg.PhoneVerified,
|
|
arg.Status,
|
|
arg.ProfileCompleted,
|
|
arg.ProfilePictureUrl,
|
|
arg.PreferredLanguage,
|
|
arg.ID,
|
|
)
|
|
return err
|
|
}
|
|
|
|
const UpdateUserKnowledgeLevel = `-- name: UpdateUserKnowledgeLevel :exec
|
|
UPDATE users
|
|
SET
|
|
knowledge_level = $1,
|
|
updated_at = CURRENT_TIMESTAMP
|
|
WHERE id = $2
|
|
`
|
|
|
|
type UpdateUserKnowledgeLevelParams struct {
|
|
KnowledgeLevel pgtype.Text `json:"knowledge_level"`
|
|
ID int64 `json:"id"`
|
|
}
|
|
|
|
func (q *Queries) UpdateUserKnowledgeLevel(ctx context.Context, arg UpdateUserKnowledgeLevelParams) error {
|
|
_, err := q.db.Exec(ctx, UpdateUserKnowledgeLevel, arg.KnowledgeLevel, arg.ID)
|
|
return err
|
|
}
|
|
|
|
const UpdateUserStatus = `-- name: UpdateUserStatus :exec
|
|
UPDATE users
|
|
SET
|
|
status = $1,
|
|
updated_at = CURRENT_TIMESTAMP
|
|
WHERE id = $2
|
|
`
|
|
|
|
type UpdateUserStatusParams struct {
|
|
Status string `json:"status"`
|
|
ID int64 `json:"id"`
|
|
}
|
|
|
|
func (q *Queries) UpdateUserStatus(ctx context.Context, arg UpdateUserStatusParams) error {
|
|
_, err := q.db.Exec(ctx, UpdateUserStatus, arg.Status, arg.ID)
|
|
return err
|
|
}
|