From 82ec8b6080e4c3d4569f23d78b262dc3512a3ad4 Mon Sep 17 00:00:00 2001 From: windpo Date: Fri, 3 Nov 2023 18:59:50 +0800 Subject: [PATCH] fix:cos route, profile org_id --- model/profile.go | 2 +- service/profile.go | 8 ++++---- service/user.go | 1 + 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/model/profile.go b/model/profile.go index 874e7cd..8e7d351 100644 --- a/model/profile.go +++ b/model/profile.go @@ -57,7 +57,7 @@ func SelectProfileByUid(uid string) (*Profile, error) { func UpdateProfile(oldProfile, newProfile *Profile) error { newProfile.ID = oldProfile.ID - if err := Db.Table("profile").Model(&Profile{}).Where("profile.id = ?", oldProfile.ID).Updates(newProfile).Error; err != nil { + if err := Db.Debug().Table("profile").Model(&Profile{}).Where("profile.id = ?", oldProfile.ID).Updates(newProfile).Error; err != nil { profileLogger.Errorln("updateProfile Err", err) return err } diff --git a/service/profile.go b/service/profile.go index 50eaa74..9c9f6a3 100644 --- a/service/profile.go +++ b/service/profile.go @@ -77,7 +77,7 @@ const picSensitiveMsg = `{ func ChangeProfile(profile *model.Profile, uid string) error { // check org_id - if profile.OrgId > 26 || profile.OrgId < 1 { + if profile.OrgId > 26 || profile.OrgId < -1 { serviceLogger.Infof("org_id input Err") return result.OrgIdError } @@ -143,7 +143,7 @@ func GetProfileOrg(OrgId int) (string, string, error) { if OrgId > 26 { serviceLogger.Errorln("org_id input Err,ErrMsg:") return "", "", result.OrgIdError - } else if OrgId == 0 { + } else if OrgId == -1 || OrgId == 0 { return "", "", nil } else { //get dep and org @@ -181,7 +181,7 @@ func UploadAvatar(avatar *multipart.FileHeader, uid string, ctx *gin.Context) (s } //write to database, file url refer:tencent cos bucket file - if dBUpErr := model.UpdateAvatar("https://sast-link-1309205610.cos.ap-shanghai.myqcloud.com"+uploadKey, userInfo.ID); dBUpErr != nil { + if dBUpErr := model.UpdateAvatar("https://sast-link-1309205610.cos.ap-shanghai.myqcloud.com/"+uploadKey, userInfo.ID); dBUpErr != nil { //del cos file if _, cosDelErr := cos.Object.Delete(ctx, uploadKey); cosDelErr != nil { serviceLogger.Errorln("upload avatar to cos fail,ErrMsg:", cosDelErr) @@ -192,7 +192,7 @@ func UploadAvatar(avatar *multipart.FileHeader, uid string, ctx *gin.Context) (s return "", dBUpErr } - return "https://sast-link-1309205610.cos.ap-shanghai.myqcloud.com" + uploadKey, nil + return "https://sast-link-1309205610.cos.ap-shanghai.myqcloud.com/" + uploadKey, nil } func checkHideLegal(hide []string) error { diff --git a/service/user.go b/service/user.go index 382b77f..bff72de 100644 --- a/service/user.go +++ b/service/user.go @@ -42,6 +42,7 @@ func CreateUserAndProfile(email string, password string) error { }, &model.Profile{ Nickname: &uid, Email: &email, + OrgId: -1, }) if err != nil {