Skip to content

Commit

Permalink
✨ Add report category feature
Browse files Browse the repository at this point in the history
  • Loading branch information
펜타곤 authored and 펜타곤 committed Apr 1, 2024
1 parent c455f18 commit 60dd3c6
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
11 changes: 11 additions & 0 deletions config/constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,14 @@ var LocationList = []string{
"실외 공간",
"기타 장소",
}

var ReportCategoryList = []string{
"욕설/비방/명예훼손",
"음란물/선정성",
"개인정보 유출",
"혐오 표현",
"폭력/자해/자살",
"도배/스팸",
"저작권 침해",
"기타",
}
15 changes: 15 additions & 0 deletions controllers/reportctrl/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/log"
"github.com/kamva/mgm/v3"
"pentag.kr/dimimonster/config"
"pentag.kr/dimimonster/middleware"
"pentag.kr/dimimonster/models"
"pentag.kr/dimimonster/utils/crypt"
Expand All @@ -12,6 +13,7 @@ import (

type ReportRequest struct {
TargetID string `json:"target-id" validate:"required"`
Category string `json:"category" validate:"required,max=50"`
Reason string `json:"reason" validate:"required,max=300"`
Token string `json:"token" validate:"required"`
}
Expand All @@ -23,6 +25,18 @@ func SendReportCtrl(c *fiber.Ctx) error {
"error": errArr,
})
}
exist := func() bool {
for _, l := range config.ReportCategoryList {
if body.Category == l {
return true
}
}
return false
}
if !exist() {
return c.Status(400).SendString("Bad Request")
}

userID := middleware.GetUserIDFromMiddleware(c)

if !validator.IsHex(body.TargetID) {
Expand All @@ -35,6 +49,7 @@ func SendReportCtrl(c *fiber.Ctx) error {
newReport, err := models.NewReport(
body.TargetID,
userID,
body.Category,
body.Reason,
)
if err != nil {
Expand Down
4 changes: 3 additions & 1 deletion models/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ type Report struct {
TargetImageID string `json:"target_image_id" bson:"target_image_id"`
TargetOwnerID string `json:"target_owner_id" bson:"target_owner_id"`
ReporterID string `json:"reporter_id" bson:"reporter_id"`
Category string `json:"category" bson:"category"`
Reason string `json:"reason" bson:"reason"`
Status string `json:"status" bson:"status"`
Secret string `json:"secret" bson:"secret"`
}

func NewReport(targetImageID string, reporterID string, reason string) (*Report, error) {
func NewReport(targetImageID string, reporterID string, category string, reason string) (*Report, error) {
foundImage := &Image{}
err := mgm.Coll(foundImage).FindByID(targetImageID, foundImage)
if err != nil {
Expand All @@ -26,6 +27,7 @@ func NewReport(targetImageID string, reporterID string, reason string) (*Report,
TargetImageID: targetImageID,
TargetOwnerID: foundImage.OwnerID,
ReporterID: reporterID,
Category: category,
Reason: reason,
Status: "pending",
Secret: random.RandString(32),
Expand Down

0 comments on commit 60dd3c6

Please sign in to comment.