mirror of
https://github.com/pushbits/server.git
synced 2025-05-09 23:17:00 +02:00
add endpoint for delete
This commit is contained in:
parent
3834e90527
commit
b392ea1b44
6 changed files with 65 additions and 34 deletions
|
@ -18,8 +18,8 @@ type NotificationDatabase interface {
|
|||
|
||||
// The NotificationDispatcher interface for relaying notifications.
|
||||
type NotificationDispatcher interface {
|
||||
SendNotification(a *model.Application, n *model.Notification) error
|
||||
SendDeleteNotification(a *model.Application, n *model.DeleteNotification) error
|
||||
SendNotification(a *model.Application, n *model.Notification) (id string, err error)
|
||||
DeleteNotification(a *model.Application, n *model.DeleteNotification) error
|
||||
}
|
||||
|
||||
// NotificationHandler holds information for processing requests about notifications.
|
||||
|
@ -39,24 +39,36 @@ func (h *NotificationHandler) CreateNotification(ctx *gin.Context) {
|
|||
application := authentication.GetApplication(ctx)
|
||||
log.Printf("Sending notification for application %s.", application.Name)
|
||||
|
||||
notification.ID = 0
|
||||
notification.ApplicationID = application.ID
|
||||
if strings.TrimSpace(notification.Title) == "" {
|
||||
notification.Title = application.Name
|
||||
}
|
||||
notification.Date = time.Now()
|
||||
|
||||
if success := successOrAbort(ctx, http.StatusInternalServerError, h.DP.SendNotification(application, ¬ification)); !success {
|
||||
messageID, err := h.DP.SendNotification(application, ¬ification)
|
||||
|
||||
if success := successOrAbort(ctx, http.StatusInternalServerError, err); !success {
|
||||
return
|
||||
}
|
||||
|
||||
notification.ID = messageID
|
||||
|
||||
ctx.JSON(http.StatusOK, ¬ification)
|
||||
}
|
||||
|
||||
// DeleteNotification is used to delete (or mark as deleted) a notification for a user
|
||||
func (h *NotificationHandler) DeleteNotification(ctx *gin.Context) {
|
||||
application := authentication.GetApplication(ctx)
|
||||
id, err := getMessageID(ctx)
|
||||
|
||||
n := model.DeleteNotification{}
|
||||
if success := successOrAbort(ctx, http.StatusUnprocessableEntity, err); !success {
|
||||
return
|
||||
}
|
||||
|
||||
h.DP.SendDeleteNotification(application, &n)
|
||||
n := model.DeleteNotification{
|
||||
ID: id,
|
||||
Date: time.Now(),
|
||||
}
|
||||
|
||||
h.DP.DeleteNotification(application, &n)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue