From 7f91ff9dfa6d6ff8ec35dfea6d5195a20f631127 Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期一, 13 五月 2024 13:58:16 +0800
Subject: [PATCH] 关注和取消关注接口

---
 service/audio.go |   24 ++++++++++++++++++++++++
 1 files changed, 24 insertions(+), 0 deletions(-)

diff --git a/service/audio.go b/service/audio.go
index fa30810..677b695 100644
--- a/service/audio.go
+++ b/service/audio.go
@@ -3,6 +3,7 @@
 import (
 	"errors"
 	"gorm.io/gorm"
+	"speechAnalysis/constvar"
 	"speechAnalysis/models"
 	"speechAnalysis/pkg/logx"
 )
@@ -37,3 +38,26 @@
 	}
 	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
+}

--
Gitblit v1.8.0