Skip to content

Commit bbf84cc

Browse files
committed
feat:finish task
1 parent 13e1c65 commit bbf84cc

File tree

19 files changed

+105
-194
lines changed

19 files changed

+105
-194
lines changed

sh4ll0t/api/admin/admin.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@ package admin
33
import (
44
"github.com/gin-contrib/sessions"
55
"github.com/gin-gonic/gin"
6-
"hduhelp_text/api/user"
7-
"hduhelp_text/db"
86
"net/http"
7+
"sh4ll0t/db"
98
)
109

1110
func Admin(c *gin.Context) {
@@ -18,7 +17,7 @@ func Admin(c *gin.Context) {
1817
c.JSON(http.StatusUnauthorized, gin.H{"error": "管理员才可以访问!"})
1918
return
2019
}
21-
var questions []user.Question
20+
var questions []db.Question
2221
if err := db.DB.Preload("Answers").Find(&questions).Error; err != nil {
2322
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
2423
return

sh4ll0t/api/admin/check_answer.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import (
44
"github.com/gin-contrib/sessions"
55
"github.com/gin-gonic/gin"
66
"gorm.io/gorm"
7-
"hduhelp_text/db"
87
"net/http"
8+
"sh4ll0t/db"
99
"strconv"
1010
)
1111

@@ -37,9 +37,7 @@ func CheckAnswer(c *gin.Context) {
3737
}
3838
return
3939
}
40-
41-
// 更新审核状态
42-
answer.CheckStatus = checkStatus // 假设你在 Answer 结构体中添加了 CheckStatus 字段
40+
answer.CheckStatus = checkStatus
4341
if err := db.DB.Save(&answer).Error; err != nil {
4442
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
4543
return

sh4ll0t/api/admin/check_question.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import (
44
"github.com/gin-contrib/sessions"
55
"github.com/gin-gonic/gin"
66
"gorm.io/gorm"
7-
"hduhelp_text/db"
87
"net/http"
8+
"sh4ll0t/db"
99
"strconv"
1010
)
1111

sh4ll0t/api/answer/answer.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ package answer
33
import (
44
"github.com/gin-contrib/sessions"
55
"github.com/gin-gonic/gin"
6-
"hduhelp_text/db"
76
"net/http"
7+
"sh4ll0t/db"
88
"strconv"
99
)
1010

@@ -15,18 +15,16 @@ func Answer(c *gin.Context) {
1515
return
1616
}
1717
respondent := session.Get("username").(string)
18-
idStr := c.PostForm("id") // 获取问题 ID
19-
answerText := c.PostForm("Answer")
20-
21-
// 将问题 ID 从 string 转换为 uint
18+
idStr := c.PostForm("id")
19+
answerText := c.PostForm("answer")
2220
questionID, err := strconv.ParseUint(idStr, 10, 32)
2321
if err != nil {
2422
c.JSON(http.StatusBadRequest, gin.H{"error": "无效的问题 ID"})
2523
return
2624
}
2725

2826
answer := db.Answer{
29-
QuestionID: uint(questionID), // 转换为 uint
27+
QuestionID: uint(questionID),
3028
AnswerText: answerText,
3129
Respondent: respondent,
3230
}

sh4ll0t/api/answer/change_answer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ package answer
33
import (
44
"github.com/gin-contrib/sessions"
55
"github.com/gin-gonic/gin"
6-
"hduhelp_text/db"
76
"net/http"
7+
"sh4ll0t/db"
88
)
99

1010
func ChangeAnswer(c *gin.Context) {

sh4ll0t/api/answer/delete_answer.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ package answer
33
import (
44
"github.com/gin-contrib/sessions"
55
"github.com/gin-gonic/gin"
6-
"hduhelp_text/db"
76
"net/http"
7+
"sh4ll0t/db"
88
)
99

1010
func DeleteAnswer(c *gin.Context) {
@@ -15,17 +15,17 @@ func DeleteAnswer(c *gin.Context) {
1515
}
1616

1717
id := c.PostForm("id")
18-
var question db.Question
19-
if err := db.DB.First(&question, id).Error; err != nil {
18+
var answer db.Answer
19+
if err := db.DB.First(&answer, id).Error; err != nil {
2020
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
2121
return
2222
}
23-
if session.Get("username") != question.Questioner {
23+
if session.Get("username") != answer.Respondent {
2424
c.JSON(http.StatusUnauthorized, gin.H{"error": "只有本作者才可以删除!"})
2525
return
2626
}
2727

28-
db.DB.Delete(&db.Answer{}, "question_id = ?", id)
29-
db.DB.Delete(&question)
28+
db.DB.Delete(&db.Answer{}, "id = ?", id)
29+
db.DB.Delete(&answer)
3030
c.JSON(http.StatusOK, gin.H{"message": "删除成功"})
3131
}

sh4ll0t/api/question/ask.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ package question
33
import (
44
"github.com/gin-contrib/sessions"
55
"github.com/gin-gonic/gin"
6-
"hduhelp_text/db"
7-
"hduhelp_text/utils"
86
"net/http"
7+
"sh4ll0t/db"
8+
"sh4ll0t/utils"
99
)
1010

1111
func Ask(c *gin.Context) {
@@ -44,7 +44,7 @@ func Ask(c *gin.Context) {
4444
}
4545

4646
answer := db.Answer{
47-
QuestionID: newQuestion.ID, // 确保这里是 uint 类型
47+
QuestionID: newQuestion.ID,
4848
AnswerText: answerText,
4949
Respondent: "ai",
5050
}

sh4ll0t/api/question/change_question.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ package question
33
import (
44
"github.com/gin-contrib/sessions"
55
"github.com/gin-gonic/gin"
6-
"hduhelp_text/db"
76
"net/http"
7+
"sh4ll0t/db"
88
)
99

1010
func ChangeQuestion(c *gin.Context) {

sh4ll0t/api/question/delete_question.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ package question
33
import (
44
"github.com/gin-contrib/sessions"
55
"github.com/gin-gonic/gin"
6-
"hduhelp_text/db"
76
"net/http"
7+
"sh4ll0t/db"
88
)
99

1010
func DeleteQuestion(c *gin.Context) {

sh4ll0t/api/user/like.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ package user
33
import (
44
"github.com/gin-contrib/sessions"
55
"github.com/gin-gonic/gin"
6-
"hduhelp_text/db"
76
"net/http"
7+
"sh4ll0t/db"
88
)
99

1010
func Like(c *gin.Context) {

0 commit comments

Comments
 (0)