feat: 用户中心
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
package plant
|
||||
|
||||
import (
|
||||
"sundynix-go/global"
|
||||
"sundynix-go/model/plant"
|
||||
plantReq "sundynix-go/model/plant/request"
|
||||
)
|
||||
|
||||
type UserProfileService struct{}
|
||||
|
||||
// UpdateProfile 修改用户信息
|
||||
func (s *UserProfileService) UpdateProfile(req plantReq.UpdateProfile, userId string) error {
|
||||
updateMap := map[string]interface{}{
|
||||
"nick_name": req.Nickname,
|
||||
"avatar_id": req.AvatarId,
|
||||
}
|
||||
return global.DB.Model(&plant.UserProfile{}).Where("user_id = ?", userId).Updates(updateMap).Error
|
||||
|
||||
}
|
||||
|
||||
// ProfileDetail 获取用户详情
|
||||
func (s *UserProfileService) ProfileDetail(userId string) (plant.UserProfile, error) {
|
||||
var res plant.UserProfile
|
||||
err := global.DB.Where("user_id = ?", userId).Preload("Avatar").Preload("Level").First(&res).Error
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
Reference in New Issue
Block a user