| | |
| | | import ( |
| | | "errors" |
| | | "gorm.io/gorm" |
| | | "speechAnalysis/constvar" |
| | | "speechAnalysis/models" |
| | | "speechAnalysis/pkg/logx" |
| | | ) |
| | |
| | | } |
| | | return nil |
| | | } |
| | | |
| | | func Follow(audioId uint) (followStatus constvar.BoolType, err error) { |
| | | if audioId == 0 { |
| | | return |
| | | } |
| | | audio, err := models.NewAudioSearch().SetID(audioId).First() |
| | | if err != nil { |
| | | return followStatus, errors.New("DB错误") |
| | | } |
| | | if audio.IsFollowed.Bool() { |
| | | followStatus = constvar.BoolTypeFalse |
| | | } else { |
| | | followStatus = constvar.BoolTypeTrue |
| | | } |
| | | err = models.NewAudioSearch().SetID(audioId).UpdateByMap(map[string]interface{}{ |
| | | "is_followed": followStatus, |
| | | }) |
| | | if err != nil { |
| | | logx.Errorf("follow audio err: %v", err) |
| | | return followStatus, errors.New("DB错误") |
| | | } |
| | | return followStatus, nil |
| | | } |