package handler import ( "nCovTrack-Backend/models" "nCovTrack-Backend/service/notify" "nCovTrack-Backend/utils" "strconv" "time" "github.com/gin-gonic/gin" ) //InsertNotificationHandler for test func InsertNotificationHandler(c *gin.Context) { sendNotify := models.SendInfo{Region: []string{"江苏 徐州"}, Channel: []int{1, 0}, Notification: models.BackNotification{Time: time.Now(), Kind: "测试", Content: "Test"}} notify.SendNotify(sendNotify) } //CountNotificationHandler count the notification // @Tags Notification // @Produce json // @Summary count the notification // @Success 200 {object} utils.GinResponse // @Router /notify/count/ [get] // @Param Token header string true "token" func CountNotificationHandler(c *gin.Context) { claims := utils.ClaimsFromHeader(c) count := notify.QueryNotificationLen(claims.Region) utils.Succ(c, map[string]interface{}{"count": count}) } //ListNotificationHandler list the notifications in the range // @Tags Notification // @Produce json // @Summary list the notification in the range // @Success 200 {object} utils.GinResponse{data=[]models.BackNotification} // @Router /notify/{start}/{end} [get] // @Param Token header string true "token" // @Param start path int true "start" // @Param end path int true "end" func ListNotificationHandler(c *gin.Context) { claims := utils.ClaimsFromHeader(c) start, _ := strconv.Atoi(c.Param("start")) end, _ := strconv.Atoi(c.Param("end")) notifications := notify.ListNotifycation(claims.Region, start, end) utils.Succ(c, notifications) } //DeleteNotificationHandler delete the notify by index // @Tags Notification // @Produce json // @Summary delete the notify by index, if -1 delete all // @Success 200 {object} utils.GinResponse // @Router /notify/{index} [delete] // @Param Token header string true "token" // @Param index path int true "index" func DeleteNotificationHandler(c *gin.Context) { claims := utils.ClaimsFromHeader(c) index, _ := strconv.Atoi(c.Param("index")) if index == -1 { notify.CleanNotification(claims.Region) } notify.DeleteNotification(claims.Region, index) utils.Succ(c, nil) }