|
|
@@ -689,9 +689,9 @@ func (a *Ab) PeerDel(c *gin.Context) {
|
|
689
|
689
|
// @Router /ab/peer/update/{guid} [put]
|
|
690
|
690
|
// @Security BearerAuth
|
|
691
|
691
|
func (a *Ab) PeerUpdate(c *gin.Context) {
|
|
692
|
|
- //f := &gin.H{}
|
|
693
|
|
- f := &requstform.PersonalAddressBookForm{}
|
|
694
|
|
- err := c.ShouldBindJSON(f)
|
|
|
692
|
+ f := gin.H{}
|
|
|
693
|
+ //f := &requstform.PersonalAddressBookForm{}
|
|
|
694
|
+ err := c.ShouldBindJSON(&f)
|
|
695
|
695
|
if err != nil {
|
|
696
|
696
|
response.Error(c, response.TranslateMsg(c, "ParamsError")+err.Error())
|
|
697
|
697
|
return
|
|
|
@@ -709,17 +709,33 @@ func (a *Ab) PeerUpdate(c *gin.Context) {
|
|
709
|
709
|
response.Error(c, response.TranslateMsg(c, "NoAccess"))
|
|
710
|
710
|
return
|
|
711
|
711
|
}
|
|
712
|
|
-
|
|
713
|
712
|
//fmt.Println(f)
|
|
714
|
|
- //return
|
|
715
|
|
- ab := service.AllService.AddressBookService.InfoByUserIdAndIdAndCid(uid, f.Id, cid)
|
|
|
713
|
+ //判断f["Id"]是否存在
|
|
|
714
|
+ fid, ok := f["id"]
|
|
|
715
|
+ if !ok {
|
|
|
716
|
+ response.Error(c, response.TranslateMsg(c, "ParamsError"))
|
|
|
717
|
+ return
|
|
|
718
|
+ }
|
|
|
719
|
+ fidstr := fid.(string)
|
|
|
720
|
+
|
|
|
721
|
+ ab := service.AllService.AddressBookService.InfoByUserIdAndIdAndCid(uid, fidstr, cid)
|
|
716
|
722
|
if ab == nil || ab.RowId == 0 {
|
|
717
|
723
|
response.Error(c, response.TranslateMsg(c, "ItemNotFound"))
|
|
718
|
724
|
return
|
|
719
|
725
|
}
|
|
720
|
|
- nab := f.ToAddressBook()
|
|
721
|
|
- nab.RowId = ab.RowId
|
|
722
|
|
- err = service.AllService.AddressBookService.Update(nab)
|
|
|
726
|
+ //允许的字段
|
|
|
727
|
+ allowUp := []string{"password", "hash", "tags", "alias"}
|
|
|
728
|
+ //f中的字段如果不在allowUp中,就删除
|
|
|
729
|
+ for k := range f {
|
|
|
730
|
+ if !utils.InArray(k, allowUp) {
|
|
|
731
|
+ delete(f, k)
|
|
|
732
|
+ }
|
|
|
733
|
+ }
|
|
|
734
|
+ //fmt.Println(f)
|
|
|
735
|
+ if tags, _ok := f["tags"]; _ok {
|
|
|
736
|
+ f["tags"], _ = json.Marshal(tags)
|
|
|
737
|
+ }
|
|
|
738
|
+ err = service.AllService.AddressBookService.UpdateByMap(ab, f)
|
|
723
|
739
|
if err != nil {
|
|
724
|
740
|
response.Error(c, response.TranslateMsg(c, "OperationFailed")+err.Error())
|
|
725
|
741
|
return
|