Report status update with a message

This commit is contained in:
LittleSheep 2024-09-19 21:06:35 +08:00
parent 817c60c4e0
commit 02bffc062f
2 changed files with 7 additions and 4 deletions

View File

@ -37,7 +37,8 @@ func updateAbuseReportStatus(c *fiber.Ctx) error {
} }
var data struct { 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 { if err := exts.BindAndValidate(c, &data); err != nil {
@ -46,7 +47,7 @@ func updateAbuseReportStatus(c *fiber.Ctx) error {
id, _ := c.ParamsInt("id") 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()) return fiber.NewError(fiber.StatusBadRequest, err.Error())
} }

View File

@ -5,6 +5,7 @@ import (
"git.solsynth.dev/hydrogen/passport/pkg/internal/database" "git.solsynth.dev/hydrogen/passport/pkg/internal/database"
"git.solsynth.dev/hydrogen/passport/pkg/internal/models" "git.solsynth.dev/hydrogen/passport/pkg/internal/models"
"github.com/samber/lo"
) )
func ListAbuseReport(account models.Account) ([]models.AbuseReport, error) { func ListAbuseReport(account models.Account) ([]models.AbuseReport, error) {
@ -23,7 +24,7 @@ func GetAbuseReport(id uint) (models.AbuseReport, error) {
return report, err return report, err
} }
func UpdateAbuseReportStatus(id uint, status string) error { func UpdateAbuseReportStatus(id uint, status, message string) error {
var report models.AbuseReport var report models.AbuseReport
err := database.C. err := database.C.
Where("id = ?", id). Where("id = ?", id).
@ -44,7 +45,8 @@ func UpdateAbuseReportStatus(id uint, status string) error {
NewNotification(models.Notification{ NewNotification(models.Notification{
Topic: "reports.feedback", Topic: "reports.feedback",
Title: "Abuse report status has been changed.", 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, Account: account,
AccountID: account.ID, AccountID: account.ID,
}) })