From 5104b0ba1047546065af6e6516e1333ba61ce00a Mon Sep 17 00:00:00 2001 From: Hopertz Date: Sun, 1 Sep 2024 12:57:00 +0300 Subject: [PATCH] sqlc gen --- internal/db/sqlc/models.go | 2 +- internal/db/sqlc/querier.go | 2 +- internal/db/sqlc/users.sql.go | 105 +++++++++++++++++++--------------- 3 files changed, 60 insertions(+), 49 deletions(-) diff --git a/internal/db/sqlc/models.go b/internal/db/sqlc/models.go index cbb11e2..740d264 100644 --- a/internal/db/sqlc/models.go +++ b/internal/db/sqlc/models.go @@ -32,7 +32,7 @@ type User struct { ChesscomUsername string `json:"chesscom_username"` PhoneNumber string `json:"phone_number"` PasswordHash []byte `json:"password_hash"` - Passcode int32 `json:"passcode"` + Passcode []byte `json:"passcode"` Activated bool `json:"activated"` Enabled bool `json:"enabled"` Photo string `json:"photo"` diff --git a/internal/db/sqlc/querier.go b/internal/db/sqlc/querier.go index a9e3d45..dc8d152 100644 --- a/internal/db/sqlc/querier.go +++ b/internal/db/sqlc/querier.go @@ -17,10 +17,10 @@ type Querier interface { DeleteUserById(ctx context.Context, id uuid.UUID) error GetLichessTeamMembers(ctx context.Context) ([]Lichess, error) GetUserById(ctx context.Context, id uuid.UUID) (GetUserByIdRow, error) - GetUserByPasscode(ctx context.Context, passcode int32) (GetUserByPasscodeRow, error) GetUserByToken(ctx context.Context, arg GetUserByTokenParams) (GetUserByTokenRow, error) GetUserByUsername(ctx context.Context, username string) (GetUserByUsernameRow, error) GetUserByUsernameOrPhone(ctx context.Context, arg GetUserByUsernameOrPhoneParams) (User, error) + GetUserForResetOrActivation(ctx context.Context, arg GetUserForResetOrActivationParams) (GetUserForResetOrActivationRow, error) UpdateUserById(ctx context.Context, arg UpdateUserByIdParams) error } diff --git a/internal/db/sqlc/users.sql.go b/internal/db/sqlc/users.sql.go index e800a95..9efd033 100644 --- a/internal/db/sqlc/users.sql.go +++ b/internal/db/sqlc/users.sql.go @@ -36,7 +36,7 @@ type CreateUserParams struct { ChesscomUsername string `json:"chesscom_username"` PhoneNumber string `json:"phone_number"` Photo string `json:"photo"` - Passcode int32 `json:"passcode"` + Passcode []byte `json:"passcode"` PasswordHash []byte `json:"password_hash"` Activated bool `json:"activated"` Enabled bool `json:"enabled"` @@ -89,7 +89,7 @@ type GetUserByIdRow struct { ChesscomUsername string `json:"chesscom_username"` PhoneNumber string `json:"phone_number"` Photo string `json:"photo"` - Passcode int32 `json:"passcode"` + Passcode []byte `json:"passcode"` PasswordHash []byte `json:"password_hash"` Enabled bool `json:"enabled"` Activated bool `json:"activated"` @@ -116,48 +116,6 @@ func (q *Queries) GetUserById(ctx context.Context, id uuid.UUID) (GetUserByIdRow return i, err } -const getUserByPasscode = `-- name: GetUserByPasscode :one -SELECT id, username, full_name, lichess_username, chesscom_username, -phone_number, photo, passcode, password_hash, enabled, activated, created_at -FROM users -WHERE passcode = $1 -` - -type GetUserByPasscodeRow struct { - ID uuid.UUID `json:"id"` - Username string `json:"username"` - FullName string `json:"full_name"` - LichessUsername string `json:"lichess_username"` - ChesscomUsername string `json:"chesscom_username"` - PhoneNumber string `json:"phone_number"` - Photo string `json:"photo"` - Passcode int32 `json:"passcode"` - PasswordHash []byte `json:"password_hash"` - Enabled bool `json:"enabled"` - Activated bool `json:"activated"` - CreatedAt time.Time `json:"created_at"` -} - -func (q *Queries) GetUserByPasscode(ctx context.Context, passcode int32) (GetUserByPasscodeRow, error) { - row := q.db.QueryRowContext(ctx, getUserByPasscode, passcode) - var i GetUserByPasscodeRow - err := row.Scan( - &i.ID, - &i.Username, - &i.FullName, - &i.LichessUsername, - &i.ChesscomUsername, - &i.PhoneNumber, - &i.Photo, - &i.Passcode, - &i.PasswordHash, - &i.Enabled, - &i.Activated, - &i.CreatedAt, - ) - return i, err -} - const getUserByToken = `-- name: GetUserByToken :one SELECT users.id, users.username, users.full_name, users.lichess_username, users.chesscom_username, users.phone_number,users.photo, users.passcode, users.password_hash, users.activated,users.enabled, users.created_at @@ -183,7 +141,7 @@ type GetUserByTokenRow struct { ChesscomUsername string `json:"chesscom_username"` PhoneNumber string `json:"phone_number"` Photo string `json:"photo"` - Passcode int32 `json:"passcode"` + Passcode []byte `json:"passcode"` PasswordHash []byte `json:"password_hash"` Activated bool `json:"activated"` Enabled bool `json:"enabled"` @@ -225,7 +183,7 @@ type GetUserByUsernameRow struct { ChesscomUsername string `json:"chesscom_username"` PhoneNumber string `json:"phone_number"` Photo string `json:"photo"` - Passcode int32 `json:"passcode"` + Passcode []byte `json:"passcode"` PasswordHash []byte `json:"password_hash"` Enabled bool `json:"enabled"` Activated bool `json:"activated"` @@ -285,6 +243,59 @@ func (q *Queries) GetUserByUsernameOrPhone(ctx context.Context, arg GetUserByUse return i, err } +const getUserForResetOrActivation = `-- name: GetUserForResetOrActivation :one +SELECT id, username, full_name, lichess_username, chesscom_username, +phone_number, photo, passcode, password_hash, enabled, activated, created_at +FROM users +WHERE + (phone_number = $1 OR $1 = '' ) + AND + (username = $2 OR $2 = '') + AND + (passcode = $3) +` + +type GetUserForResetOrActivationParams struct { + PhoneNumber string `json:"phone_number"` + Username string `json:"username"` + Passcode []byte `json:"passcode"` +} + +type GetUserForResetOrActivationRow struct { + ID uuid.UUID `json:"id"` + Username string `json:"username"` + FullName string `json:"full_name"` + LichessUsername string `json:"lichess_username"` + ChesscomUsername string `json:"chesscom_username"` + PhoneNumber string `json:"phone_number"` + Photo string `json:"photo"` + Passcode []byte `json:"passcode"` + PasswordHash []byte `json:"password_hash"` + Enabled bool `json:"enabled"` + Activated bool `json:"activated"` + CreatedAt time.Time `json:"created_at"` +} + +func (q *Queries) GetUserForResetOrActivation(ctx context.Context, arg GetUserForResetOrActivationParams) (GetUserForResetOrActivationRow, error) { + row := q.db.QueryRowContext(ctx, getUserForResetOrActivation, arg.PhoneNumber, arg.Username, arg.Passcode) + var i GetUserForResetOrActivationRow + err := row.Scan( + &i.ID, + &i.Username, + &i.FullName, + &i.LichessUsername, + &i.ChesscomUsername, + &i.PhoneNumber, + &i.Photo, + &i.Passcode, + &i.PasswordHash, + &i.Enabled, + &i.Activated, + &i.CreatedAt, + ) + return i, err +} + const updateUserById = `-- name: UpdateUserById :exec UPDATE users SET @@ -309,7 +320,7 @@ type UpdateUserByIdParams struct { ChesscomUsername string `json:"chesscom_username"` PhoneNumber string `json:"phone_number"` Photo string `json:"photo"` - Passcode int32 `json:"passcode"` + Passcode []byte `json:"passcode"` PasswordHash []byte `json:"password_hash"` Activated bool `json:"activated"` Enabled bool `json:"enabled"`