-
Notifications
You must be signed in to change notification settings - Fork 0
/
answer.go
85 lines (67 loc) · 1.75 KB
/
answer.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package db
import (
"../../common"
"../../logger"
"github.com/jmoiron/sqlx"
)
func GetAnswerIdList(questionId int64, offset, limit int64) (answerIdList []int64, err error) {
sqlstr := `select
answer_id
from
question_answer_rel
where question_id=?
limit ?, ?`
err = DB.Select(&answerIdList, sqlstr, questionId, offset, limit)
if err != nil {
logger.Error("get answer list failed, err:%v", err)
return
}
return
}
func MGetAnswer(answerIds []int64) (answerList []*common.Answer, err error) {
sqlstr := `select
answer_id, content, comment_count,
voteup_count, author_id, status, can_comment,
create_time, update_time
from
answer where answer_id in(?)`
var interfaceSlice []interface{}
for _, c := range answerIds {
interfaceSlice = append(interfaceSlice, c)
}
insqlStr, params, err := sqlx.In(sqlstr, interfaceSlice)
if err != nil {
logger.Error("sqlx.in failed, sqlstr:%v, err:%v", sqlstr, err)
return
}
err = DB.Select(&answerList, insqlStr, params...)
if err != nil {
logger.Error("MGetAnswer failed, insqlStr:%v, category_ids:%v, err:%v",
insqlStr, answerIds, err)
return
}
return
}
func GetAnswerCount(questionId int64) (answerCount int64, err error) {
sqlstr := `select
count(answer_id)
from
question_answer_rel
where question_id=?`
err = DB.Get(&answerCount, sqlstr, questionId)
if err != nil {
logger.Error("get GetAnswerCount failed, err:%v", err)
return
}
return
}
func UpdateAnswerLikeCount(answerId int64) (err error) {
sqlstr := `update answer set voteup_count=voteup_count+1
where answer_id=?`
_, err = DB.Exec(sqlstr, answerId)
if err != nil {
logger.Error("UpdateAnswerLikeCount failed, err:%v", err)
return
}
return
}