Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
46 lines
1.3 KiB
Go
46 lines
1.3 KiB
Go
package recomapi
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
"strconv"
|
|
"time"
|
|
"videoweb/pub/common/log"
|
|
"videoweb/pub/common/srvdef"
|
|
"videoweb/pub/common/utils"
|
|
)
|
|
|
|
// AddOneFeedback 添加一个推荐反馈
|
|
func AddOneFeedback(url string, key string,
|
|
userId int64, mediaId int64, fbType string, comment string) (
|
|
int64, *srvdef.SrvErr) {
|
|
feedBack := &FeedbackInfo{
|
|
UserId: strconv.FormatInt(userId, 10),
|
|
ItemId: strconv.FormatInt(mediaId, 10),
|
|
FeedbackType: fbType,
|
|
Comment: comment,
|
|
Timestamp: time.Now(),
|
|
}
|
|
return AddManyFeedbacks(url, key, FeedbackInfoList{feedBack})
|
|
}
|
|
|
|
func AddManyFeedbacks(url string, key string, feedbacks FeedbackInfoList) (
|
|
int64, *srvdef.SrvErr) {
|
|
reqUrl := url + "/api/feedback"
|
|
resp := &APIResult{}
|
|
reqBody, _ := json.Marshal(feedbacks)
|
|
header := map[string]string{"X-API-Key": key}
|
|
code, err := utils.POSTJsonWithJResp(resp, reqUrl, header, reqBody)
|
|
if err != nil {
|
|
log.Error("recomapi:AddManyFeedbacks POSTJsonWithJResp failed",
|
|
log.Any("reqUrl", reqUrl), log.E(err))
|
|
return 0, srvdef.New(srvdef.Err, "", "")
|
|
}
|
|
if code != http.StatusOK {
|
|
log.Error("recomapi:AddManyFeedbacks POSTJsonWithJResp code error.",
|
|
log.Any("reqUrl", reqUrl), log.Any("code", code))
|
|
return 0, srvdef.New(srvdef.Err, "", "")
|
|
}
|
|
return resp.RowAffected, nil
|
|
}
|