feat: 徽章api
This commit is contained in:
@@ -4,18 +4,36 @@ import (
|
||||
"sundynix-go/global"
|
||||
"sundynix-go/model/plant"
|
||||
plantReq "sundynix-go/model/plant/request"
|
||||
"sundynix-go/model/system"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
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
|
||||
|
||||
return global.DB.Transaction(func(tx *gorm.DB) error {
|
||||
//1.更新profile
|
||||
updateMap := map[string]interface{}{
|
||||
"nick_name": req.Nickname,
|
||||
"avatar_id": req.AvatarId,
|
||||
}
|
||||
err := tx.Model(&plant.UserProfile{}).Where("user_id = ?", userId).Updates(updateMap).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
//2.更新user表
|
||||
updateMap = map[string]interface{}{
|
||||
"name": req.Nickname,
|
||||
"avatar_id": req.AvatarId,
|
||||
}
|
||||
err = tx.Model(&system.User{}).Where("id = ?", userId).Updates(updateMap).Error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
// ProfileDetail 获取用户详情
|
||||
|
||||
Reference in New Issue
Block a user