/
food_comment_info.go
46 lines (42 loc) · 1.21 KB
/
food_comment_info.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package database
import (
"github.com/TateYdq/DietRegimen/DietRegimenServer/utils"
"github.com/sirupsen/logrus"
)
type FoodCommentInfo struct{
ID int `json:"id"`
FoodID int `json:"food_id"`
UserID int `json:"user_id"`
UserName string `json:"user_name"`
Comment string `json:"comment"`
RecordTime string `json:"record_time"`
}
func GetCommentByFoodID(foodID int)(foodComments[] FoodCommentInfo,err error){
err = DrDatabase.Model(FoodCommentInfo{}).Where("food_id = ?",foodID).Find(&foodComments).Error
if err != nil{
logrus.WithError(err).Errorf("GetFoodInfoByID err,foodID:%v",foodID)
}
return foodComments,err
}
func CreateFoodComment(foodID int,userID int, content string)(err error){
name,err := GetUserNameByID(userID)
if err != nil{
return err
}
fc := FoodCommentInfo{
FoodID:foodID,
UserID:userID,
UserName:name,
Comment:content,
RecordTime:utils.GetCurTime(),
}
err = DrDatabase.Model(FoodCommentInfo{}).Create(&fc).Error
if err != nil{
logrus.WithError(err).Errorf("CreateFoodComment err,foodID:%v,userID:%v",foodID,userID)
return err
}
//奖励积分,加相关度
go AddUserAndFoodScore(userID,foodID,utils.ScoreFoodComment)
go AddUserScore(userID,utils.ScoreUserComment)
return err
}