From 02bffc062fb371a48c69e3ba674ee4cf802d2cbd Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Thu, 19 Sep 2024 21:06:35 +0800 Subject: [PATCH] :sparkles: Report status update with a message --- pkg/internal/server/api/reports.go | 5 +++-- pkg/internal/services/reports.go | 6 ++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/pkg/internal/server/api/reports.go b/pkg/internal/server/api/reports.go index 60deec6..856daf0 100644 --- a/pkg/internal/server/api/reports.go +++ b/pkg/internal/server/api/reports.go @@ -37,7 +37,8 @@ func updateAbuseReportStatus(c *fiber.Ctx) error { } var data struct { - Status string `json:"status" validate:"required"` + Status string `json:"status" validate:"required"` + Message string `json:"message" validate:"required,max=4096"` } if err := exts.BindAndValidate(c, &data); err != nil { @@ -46,7 +47,7 @@ func updateAbuseReportStatus(c *fiber.Ctx) error { id, _ := c.ParamsInt("id") - if err := services.UpdateAbuseReportStatus(uint(id), data.Status); err != nil { + if err := services.UpdateAbuseReportStatus(uint(id), data.Status, data.Message); err != nil { return fiber.NewError(fiber.StatusBadRequest, err.Error()) } diff --git a/pkg/internal/services/reports.go b/pkg/internal/services/reports.go index 2467711..369bf94 100644 --- a/pkg/internal/services/reports.go +++ b/pkg/internal/services/reports.go @@ -5,6 +5,7 @@ import ( "git.solsynth.dev/hydrogen/passport/pkg/internal/database" "git.solsynth.dev/hydrogen/passport/pkg/internal/models" + "github.com/samber/lo" ) func ListAbuseReport(account models.Account) ([]models.AbuseReport, error) { @@ -23,7 +24,7 @@ func GetAbuseReport(id uint) (models.AbuseReport, error) { return report, err } -func UpdateAbuseReportStatus(id uint, status string) error { +func UpdateAbuseReportStatus(id uint, status, message string) error { var report models.AbuseReport err := database.C. Where("id = ?", id). @@ -44,7 +45,8 @@ func UpdateAbuseReportStatus(id uint, status string) error { NewNotification(models.Notification{ Topic: "reports.feedback", Title: "Abuse report status has been changed.", - Body: fmt.Sprintf("The report created by you with ID #%d's status has been changed to %s", id, status), + Subtitle: lo.ToPtr(fmt.Sprintf("The report #%d's status updated", id)), + Body: fmt.Sprintf("The report created by you with ID #%d's status has been changed to %s. Moderator message: %s", id, status, message), Account: account, AccountID: account.ID, })