feat: able to view messages on dashboard (close #32)

This commit is contained in:
JustSong
2023-04-16 12:50:01 +08:00
parent c16530cf6e
commit 26a3c76f3f
8 changed files with 426 additions and 3 deletions
+33
View File
@@ -134,12 +134,26 @@ func pushMessageHelper(c *gin.Context, message *model.Message) {
"success": false,
"message": err.Error(),
})
// Update the status of the message
if common.MessagePersistenceEnabled {
err := message.UpdateStatus(common.MessageSendStatusFailed)
if err != nil {
common.SysError("failed to update the status of the message: " + err.Error())
}
}
return
}
c.JSON(http.StatusOK, gin.H{
"success": true,
"message": "ok",
})
// Update the status of the message
if common.MessagePersistenceEnabled {
err := message.UpdateStatus(common.MessageSendStatusSent)
if err != nil {
common.SysError("failed to update the status of the message: " + err.Error())
}
}
return
}
@@ -235,6 +249,25 @@ func GetMessage(c *gin.Context) {
return
}
func SearchMessages(c *gin.Context) {
// TODO: improve the search algorithm
keyword := c.Query("keyword")
messages, err := model.SearchMessages(keyword)
if err != nil {
c.JSON(http.StatusOK, gin.H{
"success": false,
"message": err.Error(),
})
return
}
c.JSON(http.StatusOK, gin.H{
"success": true,
"message": "",
"data": messages,
})
return
}
func DeleteMessage(c *gin.Context) {
messageId, _ := strconv.Atoi(c.Param("id"))
userId := c.GetInt("id")