reportbug is "finished"

just need to update database!

Co-authored-by: haraldnilsen <harald_998@hotmail.com>
Signed-off-by: Sindre Kjelsrud <kjelsrudsindre@gmail.com>
This commit is contained in:
Sindre Kjelsrud 2024-01-10 13:05:58 +01:00
parent deb7d05b98
commit 113b0fb4b7
Signed by untrusted user who does not match committer: sidski
GPG key ID: D2BBDF3EDE6BA9A6
6 changed files with 135 additions and 17 deletions

View file

@ -23,6 +23,10 @@ type FormData struct {
RespondentId int `json:"respondentID"`
}
type BugReport struct {
BugText string `json:"bugText"`
}
func main() {
router := gin.Default()
router.Use(cors.Default())
@ -89,6 +93,28 @@ func main() {
c.JSON(http.StatusOK, "Successfully inserted formdata!")
})
router.POST("/submitbug", func(c *gin.Context) {
var requestBody BugReport
// Bind JSON to the requestBody struct
if err := c.BindJSON(&requestBody); err != nil {
fmt.Print(err)
c.JSON(http.StatusBadRequest, gin.H{"error": "Invalid request"})
return
}
// Here, you'd insert the bug text into your database
err := db.InsertBugReport(requestBody.BugText)
if err != nil {
fmt.Print(err)
c.JSON(http.StatusInternalServerError, gin.H{"error": "Unable to insert bug report"})
return
}
// Respond with a success message
c.JSON(http.StatusOK, "Successfully submitted bug report!")
})
// Run the server on port 8080
router.Run(":8080")
//db.SetupDb()