api

package
v0.0.0-...-0a31f76 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 24, 2023 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateAnswer

func CreateAnswer(c *gin.Context)

func CreateQuestion

func CreateQuestion(c *gin.Context)

func DeleteAnswer

func DeleteAnswer(c *gin.Context)

func DeleteQuestion

func DeleteQuestion(c *gin.Context)

func EmailLogin

func EmailLogin(c *gin.Context)

func InitRouter

func InitRouter()

func ModifyAnswer

func ModifyAnswer(c *gin.Context)

func ModifyQuestion

func ModifyQuestion(c *gin.Context)

func PhoneNumberLogin

func PhoneNumberLogin(c *gin.Context)

func UserNameLogin

func UserNameLogin(c *gin.Context)

func UserRegister

func UserRegister(c *gin.Context)

func ViewOwnAnswers

func ViewOwnAnswers(c *gin.Context)

func ViewOwnQuestions

func ViewOwnQuestions(c *gin.Context)
func CreateComment(c *gin.Context) {
	//接收前端发来的数据
	var comment model.Comment
	err := c.ShouldBindJSON(&comment)
	if err != nil {
		checkresponse.ResFail(c, "参数绑定失败")
		return
	}
	//通过c.Get方法获取的值的类型是interface{},因此需要根据实际情况进行类型断言或转换,以便正确使用该值。
	usernameRaw, exists := c.Get("username")

	if !exists {
		checkresponse.ResFail(c, "无法获取用户名")
		return
	}

	username, ok := usernameRaw.(string)

	if !ok {
		checkresponse.ResFail(c, "用户名类型断言失败")
		return
	}

	//存入数据库
	depositcomment := model.Comment{
		Commenter: username,
		AnswerID:  comment.AnswerID,
		Content:   comment.Content,
	}
	global.GlobalDb.Model(&model.Question{}).Create(&depositcomment)
}

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL