Merge remote-tracking branch 'origin' into ticket-bet
This commit is contained in:
commit
32ce4e2509
|
|
@ -34,7 +34,6 @@ import (
|
|||
// @name Authorization
|
||||
// @BasePath /
|
||||
func main() {
|
||||
|
||||
cfg, err := config.NewConfig()
|
||||
if err != nil {
|
||||
slog.Error(err.Error())
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
-- name: CreateOtp :exec
|
||||
INSERT INTO otps (sent_to, medium, otp_for, otp, used, created_at, expires_at)
|
||||
VALUES ($1, $2, $3, $4, FALSE, CURRENT_TIMESTAMP, $5);
|
||||
VALUES ($1, $2, $3, $4, FALSE, $5, $6);
|
||||
|
||||
-- name: GetOtp :one
|
||||
SELECT id, sent_to, medium, otp_for, otp, used, used_at, created_at, expires_at
|
||||
|
|
@ -10,5 +10,5 @@ ORDER BY created_at DESC LIMIT 1;
|
|||
|
||||
-- name: MarkOtpAsUsed :exec
|
||||
UPDATE otps
|
||||
SET used = TRUE, used_at = CURRENT_TIMESTAMP
|
||||
SET used = TRUE, used_at = $2
|
||||
WHERE id = $1;
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
-- name: CreateUser :one
|
||||
|
||||
INSERT INTO users (first_name, last_name, email, phone_number, role, password, email_verified, phone_verified, created_at, updated_at)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)
|
||||
RETURNING id, first_name, last_name, email, phone_number, role, email_verified, phone_verified, created_at, updated_at;
|
||||
|
||||
-- name: GetUserByID :one
|
||||
|
|
@ -15,8 +15,8 @@ FROM users;
|
|||
|
||||
-- name: UpdateUser :exec
|
||||
UPDATE users
|
||||
SET first_name = $1, last_name = $2, email = $3, phone_number = $4, role = $5, updated_at = CURRENT_TIMESTAMP
|
||||
WHERE id = $6;
|
||||
SET first_name = $1, last_name = $2, email = $3, phone_number = $4, role = $5, updated_at = $6
|
||||
WHERE id = $7;
|
||||
|
||||
-- name: DeleteUser :exec
|
||||
DELETE FROM users
|
||||
|
|
@ -38,5 +38,5 @@ WHERE phone_number = $1;
|
|||
|
||||
-- name: UpdatePassword :exec
|
||||
UPDATE users
|
||||
SET password = $1, updated_at = CURRENT_TIMESTAMP
|
||||
SET password = $1, updated_at = $4
|
||||
WHERE (email = $2 OR phone_number = $3);
|
||||
|
|
@ -13,7 +13,7 @@ import (
|
|||
|
||||
const CreateOtp = `-- name: CreateOtp :exec
|
||||
INSERT INTO otps (sent_to, medium, otp_for, otp, used, created_at, expires_at)
|
||||
VALUES ($1, $2, $3, $4, FALSE, CURRENT_TIMESTAMP, $5)
|
||||
VALUES ($1, $2, $3, $4, FALSE, $5, $6)
|
||||
`
|
||||
|
||||
type CreateOtpParams struct {
|
||||
|
|
@ -21,6 +21,7 @@ type CreateOtpParams struct {
|
|||
Medium string
|
||||
OtpFor string
|
||||
Otp string
|
||||
CreatedAt pgtype.Timestamptz
|
||||
ExpiresAt pgtype.Timestamptz
|
||||
}
|
||||
|
||||
|
|
@ -30,6 +31,7 @@ func (q *Queries) CreateOtp(ctx context.Context, arg CreateOtpParams) error {
|
|||
arg.Medium,
|
||||
arg.OtpFor,
|
||||
arg.Otp,
|
||||
arg.CreatedAt,
|
||||
arg.ExpiresAt,
|
||||
)
|
||||
return err
|
||||
|
|
@ -67,11 +69,16 @@ func (q *Queries) GetOtp(ctx context.Context, arg GetOtpParams) (Otp, error) {
|
|||
|
||||
const MarkOtpAsUsed = `-- name: MarkOtpAsUsed :exec
|
||||
UPDATE otps
|
||||
SET used = TRUE, used_at = CURRENT_TIMESTAMP
|
||||
SET used = TRUE, used_at = $2
|
||||
WHERE id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) MarkOtpAsUsed(ctx context.Context, id int64) error {
|
||||
_, err := q.db.Exec(ctx, MarkOtpAsUsed, id)
|
||||
type MarkOtpAsUsedParams struct {
|
||||
ID int64
|
||||
UsedAt pgtype.Timestamptz
|
||||
}
|
||||
|
||||
func (q *Queries) MarkOtpAsUsed(ctx context.Context, arg MarkOtpAsUsedParams) error {
|
||||
_, err := q.db.Exec(ctx, MarkOtpAsUsed, arg.ID, arg.UsedAt)
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ func (q *Queries) CheckPhoneEmailExist(ctx context.Context, arg CheckPhoneEmailE
|
|||
const CreateUser = `-- name: CreateUser :one
|
||||
|
||||
INSERT INTO users (first_name, last_name, email, phone_number, role, password, email_verified, phone_verified, created_at, updated_at)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP)
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10)
|
||||
RETURNING id, first_name, last_name, email, phone_number, role, email_verified, phone_verified, created_at, updated_at
|
||||
`
|
||||
|
||||
|
|
@ -50,6 +50,8 @@ type CreateUserParams struct {
|
|||
Password []byte
|
||||
EmailVerified bool
|
||||
PhoneVerified bool
|
||||
CreatedAt pgtype.Timestamptz
|
||||
UpdatedAt pgtype.Timestamptz
|
||||
}
|
||||
|
||||
type CreateUserRow struct {
|
||||
|
|
@ -75,6 +77,8 @@ func (q *Queries) CreateUser(ctx context.Context, arg CreateUserParams) (CreateU
|
|||
arg.Password,
|
||||
arg.EmailVerified,
|
||||
arg.PhoneVerified,
|
||||
arg.CreatedAt,
|
||||
arg.UpdatedAt,
|
||||
)
|
||||
var i CreateUserRow
|
||||
err := row.Scan(
|
||||
|
|
@ -254,7 +258,7 @@ func (q *Queries) GetUserByPhone(ctx context.Context, phoneNumber pgtype.Text) (
|
|||
|
||||
const UpdatePassword = `-- name: UpdatePassword :exec
|
||||
UPDATE users
|
||||
SET password = $1, updated_at = CURRENT_TIMESTAMP
|
||||
SET password = $1, updated_at = $4
|
||||
WHERE (email = $2 OR phone_number = $3)
|
||||
`
|
||||
|
||||
|
|
@ -262,17 +266,23 @@ type UpdatePasswordParams struct {
|
|||
Password []byte
|
||||
Email pgtype.Text
|
||||
PhoneNumber pgtype.Text
|
||||
UpdatedAt pgtype.Timestamptz
|
||||
}
|
||||
|
||||
func (q *Queries) UpdatePassword(ctx context.Context, arg UpdatePasswordParams) error {
|
||||
_, err := q.db.Exec(ctx, UpdatePassword, arg.Password, arg.Email, arg.PhoneNumber)
|
||||
_, err := q.db.Exec(ctx, UpdatePassword,
|
||||
arg.Password,
|
||||
arg.Email,
|
||||
arg.PhoneNumber,
|
||||
arg.UpdatedAt,
|
||||
)
|
||||
return err
|
||||
}
|
||||
|
||||
const UpdateUser = `-- name: UpdateUser :exec
|
||||
UPDATE users
|
||||
SET first_name = $1, last_name = $2, email = $3, phone_number = $4, role = $5, updated_at = CURRENT_TIMESTAMP
|
||||
WHERE id = $6
|
||||
SET first_name = $1, last_name = $2, email = $3, phone_number = $4, role = $5, updated_at = $6
|
||||
WHERE id = $7
|
||||
`
|
||||
|
||||
type UpdateUserParams struct {
|
||||
|
|
@ -281,6 +291,7 @@ type UpdateUserParams struct {
|
|||
Email pgtype.Text
|
||||
PhoneNumber pgtype.Text
|
||||
Role string
|
||||
UpdatedAt pgtype.Timestamptz
|
||||
ID int64
|
||||
}
|
||||
|
||||
|
|
@ -291,6 +302,7 @@ func (q *Queries) UpdateUser(ctx context.Context, arg UpdateUserParams) error {
|
|||
arg.Email,
|
||||
arg.PhoneNumber,
|
||||
arg.Role,
|
||||
arg.UpdatedAt,
|
||||
arg.ID,
|
||||
)
|
||||
return err
|
||||
|
|
|
|||
|
|
@ -3,9 +3,9 @@ package domain
|
|||
type Role string
|
||||
|
||||
const (
|
||||
RoleAdmin Role = "admin"
|
||||
RoleCustomer Role = "customer"
|
||||
RoleSuperAdmin Role = "super_admin"
|
||||
RoleAdmin Role = "admin"
|
||||
RoleBranchManager Role = "branch_manager"
|
||||
RoleCustomer Role = "customer"
|
||||
RoleCashier Role = "cashier"
|
||||
)
|
||||
|
|
|
|||
|
|
@ -19,6 +19,10 @@ func (s *Store) CreateOtp(ctx context.Context, otp domain.Otp) error {
|
|||
Time: otp.ExpiresAt,
|
||||
Valid: true,
|
||||
},
|
||||
CreatedAt: pgtype.Timestamptz{
|
||||
Time: otp.CreatedAt,
|
||||
Valid: true,
|
||||
},
|
||||
})
|
||||
}
|
||||
func (s *Store) GetOtp(ctx context.Context, sentTo string, sentfor domain.OtpFor, medium domain.OtpMedium) (domain.Otp, error) {
|
||||
|
|
@ -46,5 +50,11 @@ func (s *Store) GetOtp(ctx context.Context, sentTo string, sentfor domain.OtpFor
|
|||
}, nil
|
||||
}
|
||||
func (s *Store) MarkOtpAsUsed(ctx context.Context, otp domain.Otp) error {
|
||||
return s.queries.MarkOtpAsUsed(ctx, otp.ID)
|
||||
return s.queries.MarkOtpAsUsed(ctx, dbgen.MarkOtpAsUsedParams{
|
||||
ID: otp.ID,
|
||||
UsedAt: pgtype.Timestamptz{
|
||||
Time: otp.UsedAt,
|
||||
Valid: true,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ import (
|
|||
"context"
|
||||
"database/sql"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
dbgen "github.com/SamuelTariku/FortuneBet-Backend/gen/db"
|
||||
"github.com/SamuelTariku/FortuneBet-Backend/internal/domain"
|
||||
|
|
@ -12,7 +12,13 @@ import (
|
|||
)
|
||||
|
||||
func (s *Store) CreateUser(ctx context.Context, user domain.User, usedOtpId int64) (domain.User, error) {
|
||||
err := s.queries.MarkOtpAsUsed(ctx, usedOtpId)
|
||||
err := s.queries.MarkOtpAsUsed(ctx, dbgen.MarkOtpAsUsedParams{
|
||||
ID: usedOtpId,
|
||||
UsedAt: pgtype.Timestamptz{
|
||||
Time: time.Now(),
|
||||
Valid: true,
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
return domain.User{}, err
|
||||
}
|
||||
|
|
@ -31,6 +37,14 @@ func (s *Store) CreateUser(ctx context.Context, user domain.User, usedOtpId int6
|
|||
Role: string(user.Role),
|
||||
EmailVerified: user.EmailVerified,
|
||||
PhoneVerified: user.PhoneVerified,
|
||||
CreatedAt: pgtype.Timestamptz{
|
||||
Time: time.Now(),
|
||||
Valid: true,
|
||||
},
|
||||
UpdatedAt: pgtype.Timestamptz{
|
||||
Time: time.Now(),
|
||||
Valid: true,
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
return domain.User{}, err
|
||||
|
|
@ -93,6 +107,7 @@ func (s *Store) UpdateUser(ctx context.Context, user domain.UpdateUserReq) error
|
|||
// LastName: user.LastName,
|
||||
// Email: user.Email,
|
||||
// PhoneNumber: user.PhoneNumber,
|
||||
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
@ -107,7 +122,7 @@ func (s *Store) DeleteUser(ctx context.Context, id int64) error {
|
|||
return nil
|
||||
}
|
||||
func (s *Store) CheckPhoneEmailExist(ctx context.Context, phoneNum, email string) (bool, bool, error) {
|
||||
fmt.Printf("phoneNum: %s, email: %s\n", phoneNum, email)
|
||||
|
||||
row, err := s.queries.CheckPhoneEmailExist(ctx, dbgen.CheckPhoneEmailExistParams{
|
||||
PhoneNumber: pgtype.Text{
|
||||
String: phoneNum,
|
||||
|
|
@ -119,7 +134,7 @@ func (s *Store) CheckPhoneEmailExist(ctx context.Context, phoneNum, email string
|
|||
Valid: email != "",
|
||||
},
|
||||
})
|
||||
fmt.Printf("row: %+v\n", row)
|
||||
|
||||
if err != nil {
|
||||
return false, false, err
|
||||
}
|
||||
|
|
@ -168,7 +183,13 @@ func (s *Store) GetUserByPhone(ctx context.Context, phoneNum string) (domain.Use
|
|||
}
|
||||
|
||||
func (s *Store) UpdatePassword(ctx context.Context, identifier string, password []byte, usedOtpId int64) error {
|
||||
err := s.queries.MarkOtpAsUsed(ctx, usedOtpId)
|
||||
err := s.queries.MarkOtpAsUsed(ctx, dbgen.MarkOtpAsUsedParams{
|
||||
ID: usedOtpId,
|
||||
UsedAt: pgtype.Timestamptz{
|
||||
Time: time.Now(),
|
||||
Valid: true,
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
1
internal/services/sportsbook/events.go
Normal file
1
internal/services/sportsbook/events.go
Normal file
|
|
@ -0,0 +1 @@
|
|||
package sportsbook
|
||||
1
internal/services/sportsbook/odds.go
Normal file
1
internal/services/sportsbook/odds.go
Normal file
|
|
@ -0,0 +1 @@
|
|||
package sportsbook
|
||||
1
internal/services/sportsbook/service.go
Normal file
1
internal/services/sportsbook/service.go
Normal file
|
|
@ -0,0 +1 @@
|
|||
package sportsbook
|
||||
|
|
@ -2,7 +2,6 @@ package user
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/SamuelTariku/FortuneBet-Backend/internal/domain"
|
||||
|
|
@ -31,7 +30,7 @@ func (s *Service) SendRegisterCode(ctx context.Context, medium domain.OtpMedium,
|
|||
}
|
||||
func (s *Service) RegisterUser(ctx context.Context, registerReq domain.RegisterUserReq) (domain.User, error) { // normal
|
||||
// get otp
|
||||
fmt.Printf("registerReq: %+v\n", registerReq)
|
||||
|
||||
var sentTo string
|
||||
if registerReq.OtpMedium == domain.OtpMediumEmail {
|
||||
sentTo = registerReq.Email
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user