-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
펜타곤
authored and
펜타곤
committed
Apr 1, 2024
1 parent
aec7acc
commit 29d4eb7
Showing
12 changed files
with
103 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,51 @@ | ||
package reportctrl | ||
|
||
import "github.com/gofiber/fiber/v2" | ||
import ( | ||
"github.com/gofiber/fiber/v2" | ||
"github.com/gofiber/fiber/v2/log" | ||
"github.com/kamva/mgm/v3" | ||
"pentag.kr/dimimonster/middleware" | ||
"pentag.kr/dimimonster/models" | ||
"pentag.kr/dimimonster/utils/validator" | ||
) | ||
|
||
type ReportRequest struct { | ||
TargetID string `json:"target-id" validate:"required"` | ||
Category int `json:"category" validate:"required"` | ||
Reason string `json:"reason" validate:"required"` | ||
Reason string `json:"reason" validate:"required, max=300"` | ||
Token string `json:"token" validate:"required"` | ||
} | ||
|
||
func SendReportCtrl(c *fiber.Ctx) error { | ||
body := ReportRequest{} | ||
if errArr := validator.ParseAndValidate(c, body); errArr != nil { | ||
return c.Status(400).JSON(fiber.Map{ | ||
"error": errArr, | ||
}) | ||
} | ||
userID := middleware.GetUserIDFromMiddleware(c) | ||
|
||
if !validator.IsHex(body.TargetID) { | ||
return c.Status(400).SendString("Bad Request") | ||
} | ||
// if !crypt.RecaptchaCheck(body.Token, "image_report") { | ||
// return c.Status(425).SendString("Recaptcha Failed") | ||
// } | ||
|
||
newReport, err := models.NewReport( | ||
body.TargetID, | ||
userID, | ||
body.Reason, | ||
) | ||
if err != nil { | ||
log.Error(err) | ||
return c.Status(500).SendString("Internal Server Error") | ||
} | ||
|
||
err = mgm.Coll(newReport).Create(newReport) | ||
if err != nil { | ||
log.Error(err) | ||
return c.Status(500).SendString("Internal Server Error") | ||
} | ||
|
||
return c.SendString("Send Report") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package routers | ||
|
||
import ( | ||
"github.com/gofiber/fiber/v2" | ||
"pentag.kr/dimimonster/controllers/reportctrl" | ||
"pentag.kr/dimimonster/middleware" | ||
) | ||
|
||
func initReportRouter(router fiber.Router) { | ||
reportRouter := router.Group("/report") | ||
reportRouter.Use(middleware.AuthMiddleware) | ||
|
||
reportRouter.Post("/send", | ||
func(c *fiber.Ctx) error { | ||
return reportctrl.SendReportCtrl(c) | ||
}, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package validator | ||
|
||
func IsHex(s string) bool { | ||
for _, c := range s { | ||
if !((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f')) { | ||
return false | ||
} | ||
} | ||
return true | ||
} |