1
1
package handlers
2
2
3
3
import (
4
+ "strconv"
5
+
4
6
"github.com/gofiber/fiber/v2"
5
7
6
8
"github.com/ghostsecurity/reaper/internal/database/models"
@@ -16,7 +18,16 @@ func (h *Handler) GetReports(c *fiber.Ctx) error {
16
18
17
19
func (h * Handler ) GetReport (c * fiber.Ctx ) error {
18
20
report := models.Report {}
19
- err := h .db .First (& report , c .Params ("id" )).Error
21
+ id := c .Params ("id" )
22
+ if id == "" {
23
+ return c .Status (fiber .StatusBadRequest ).JSON (fiber.Map {"error" : "report id is required" })
24
+ }
25
+
26
+ if _ , err := strconv .Atoi (id ); err != nil {
27
+ return c .Status (fiber .StatusBadRequest ).JSON (fiber.Map {"error" : "invalid report id" })
28
+ }
29
+
30
+ err := h .db .First (& report , id ).Error
20
31
if err != nil {
21
32
return c .Status (fiber .StatusNotFound ).JSON (fiber.Map {"error" : err .Error ()})
22
33
}
@@ -56,7 +67,16 @@ func (h *Handler) CreateReport(c *fiber.Ctx) error {
56
67
57
68
func (h * Handler ) DeleteReport (c * fiber.Ctx ) error {
58
69
report := models.Report {}
59
- res := h .db .Delete (& report , c .Params ("id" ))
70
+ id := c .Params ("id" )
71
+ if id == "" {
72
+ return c .Status (fiber .StatusBadRequest ).JSON (fiber.Map {"error" : "report id is required" })
73
+ }
74
+
75
+ if _ , err := strconv .Atoi (id ); err != nil {
76
+ return c .Status (fiber .StatusBadRequest ).JSON (fiber.Map {"error" : "invalid report id" })
77
+ }
78
+
79
+ res := h .db .Delete (& report , id )
60
80
if res .RowsAffected == 0 {
61
81
return c .Status (fiber .StatusNotFound ).JSON (fiber.Map {"error" : "report not found" })
62
82
}
0 commit comments