sqlx: add get user profile data logic implement

r/paopao-ce-plus
Michael Li 1 year ago
parent 5861c3d503
commit 05230212f2
No known key found for this signature in database

@ -187,6 +187,7 @@ const (
_UserManage_GetUsersByIds = `SELECT * FROM @user WHERE id IN (?) AND is_del=0`
_UserManage_GetUsersByKeyword = `SELECT * FROM @user WHERE username LIKE ? AND is_del=0 limit 6`
_UserManage_UpdateUser = `UPDATE @user SET username=:username, nickname=:nickname, phone=:phone, password=:password, salt=:salt, status=:status, avatar=:avatar, balance=:balance, is_admin=:is_admin, modified_on=:modified_on WHERE id=? AND is_del=0`
_UserManage_UserProfileByName = `SELECT u.id, u.username, u.nickname, u.phone, u.status, u.avatar, u.balance, u.is_admin, u.created_on, m.tweets_count FROM @user u LEFT JOIN @user_metric m ON u.id=m.user_id WHERE u.username=? AND u.is_del=0`
_UserMetrics_AddUserMetric = `INSERT INTO @user_metric (user_id, created_on) VALUES (?, ?)`
_UserMetrics_DeleteUserMetric = `UPDATE @user_metric SET is_del=1, deleted_on=? WHERE user_id=? AND is_del=0`
_UserMetrics_GetTweetsCount = `SELECT tweets_count FROM @user_metric WHERE user_id=? AND is_del=0`
@ -457,6 +458,7 @@ type UserManage struct {
GetUserByPhone *sqlx.Stmt `yesql:"get_user_by_phone"`
GetUserByUsername *sqlx.Stmt `yesql:"get_user_by_username"`
GetUsersByKeyword *sqlx.Stmt `yesql:"get_users_by_keyword"`
UserProfileByName *sqlx.Stmt `yesql:"user_profile_by_name"`
CreateUser *sqlx.NamedStmt `yesql:"create_user"`
UpdateUser *sqlx.NamedStmt `yesql:"update_user"`
}
@ -1124,6 +1126,9 @@ func BuildUserManage(p PreparexBuilder, ctx ...context.Context) (obj *UserManage
if obj.GetUsersByKeyword, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserManage_GetUsersByKeyword))); err != nil {
return nil, fmt.Errorf("prepare _UserManage_GetUsersByKeyword error: %w", err)
}
if obj.UserProfileByName, err = p.PreparexContext(c, p.Rebind(p.QueryHook(_UserManage_UserProfileByName))); err != nil {
return nil, fmt.Errorf("prepare _UserManage_UserProfileByName error: %w", err)
}
if obj.CreateUser, err = p.PrepareNamedContext(c, p.Rebind(p.QueryHook(_UserManage_CreateUser))); err != nil {
return nil, fmt.Errorf("prepare _UserManage_CreateUser error: %w", err)
}

@ -12,6 +12,7 @@ import (
"github.com/bitbus/sqlx"
"github.com/bitbus/sqlx/db"
"github.com/rocboss/paopao-ce/internal/core"
"github.com/rocboss/paopao-ce/internal/core/cs"
"github.com/rocboss/paopao-ce/internal/core/ms"
"github.com/rocboss/paopao-ce/internal/dao/sakila/auto/cc"
"github.com/rocboss/paopao-ce/internal/dao/sakila/auto/pgc"
@ -40,6 +41,10 @@ func (s *userManageSrv) GetUserByUsername(username string) (*ms.User, error) {
return db.Get[ms.User](s.q.GetUserByUsername, username)
}
func (s *userManageSrv) UserProfileByName(username string) (*cs.UserProfile, error) {
return db.Get[cs.UserProfile](s.q.UserProfileByName, username)
}
func (s *userManageSrv) GetUserByPhone(phone string) (*ms.User, error) {
return db.Get[ms.User](s.q.GetUserByPhone, phone)
}

@ -1403,6 +1403,23 @@ SELECT * FROM @user WHERE id=? AND is_del=0;
-- prepare: stmt
SELECT * FROM @user WHERE username=? AND is_del=0;
-- name: user_profile_by_name@user_manage
-- prepare: stmt
SELECT u.id,
u.username,
u.nickname,
u.phone,
u.status,
u.avatar,
u.balance,
u.is_admin,
u.created_on,
m.tweets_count
FROM @user u
LEFT JOIN @user_metric m
ON u.id=m.user_id
WHERE u.username=? AND u.is_del=0;
-- name: get_user_by_phone@user_manage
-- prepare: stmt
SELECT * FROM @user WHERE phone=? AND is_del=0;

Loading…
Cancel
Save