Skip to content

Commit

Permalink
feat(styles): add promotions to notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
vednoc committed Jul 17, 2021
1 parent 27a7eca commit c5477ad
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
24 changes: 24 additions & 0 deletions handlers/style/promote.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,15 @@ func Promote(c *fiber.Ctx) error {
})
}

id, err := strconv.Atoi(p)
if err != nil {
log.Println("Couldn't convert %v to int, err: %v", p, err)
return c.Render("err", fiber.Map{
"Title": "Couldn't convert style ID",
"User": u,
})
}

style, err := models.GetStyleByID(p)
if err != nil {
log.Println("Couldn't get the style:", err)
Expand Down Expand Up @@ -90,6 +99,21 @@ func Promote(c *fiber.Ctx) error {
// So we have to reverse check it ;)
if !style.Featured {
go sendPromotionEmail(style.UserID, style, u.Username, c.BaseURL())

// Create a notification.
notification := models.Notification{
Seen: false,
Kind: models.KindStylePromotion,
TargetID: int(style.UserID),
UserID: int(u.ID),
StyleID: id,
}

go func(notification models.Notification) {
if err := notification.Create(); err != nil {
log.Printf("Failed to create a notification for %d, err: %v", id, err)
}
}(notification)
}

return c.Redirect("/style/"+p, fiber.StatusSeeOther)
Expand Down
2 changes: 1 addition & 1 deletion models/notification.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type Notification struct {
StyleID int

Review Review
ReviewID int
ReviewID int `gorm:"default:null"`
}

func (n Notification) Create() error {
Expand Down

0 comments on commit c5477ad

Please sign in to comment.