diff --git a/modules/structs/status.go b/modules/structs/status.go new file mode 100644 index 0000000..562f3bd --- /dev/null +++ b/modules/structs/status.go @@ -0,0 +1,6 @@ +package structs + +// swagger:model StatusResponse +type StatusResponse struct { + Status bool +} diff --git a/modules/structs/verifycode.go b/modules/structs/verifycode.go index ae73349..accce00 100644 --- a/modules/structs/verifycode.go +++ b/modules/structs/verifycode.go @@ -8,7 +8,7 @@ type VerifiedUser struct { CreatedAt time.Time } -type VerifyCodeParams struct { +type UserIdParam struct { UserId string } diff --git a/public/qrcode.png b/public/qrcode.png new file mode 100644 index 0000000..ff5c466 Binary files /dev/null and b/public/qrcode.png differ diff --git a/routers/api/v1/status/status.go b/routers/api/v1/status/status.go new file mode 100644 index 0000000..25043eb --- /dev/null +++ b/routers/api/v1/status/status.go @@ -0,0 +1,48 @@ +package status + +import ( + "jannex/telegram-bot-manager/modules/database" + "jannex/telegram-bot-manager/modules/structs" + + "git.ex.umbach.dev/Alex/roese-utils/rsutils" + "github.com/gofiber/fiber/v2" + "github.com/rs/zerolog/log" +) + +func UserVerified(c *fiber.Ctx) error { + // swagger:operation GET /v1/status/{userId} status userVerified + // --- + // summary: Check if user is verified + // consumes: + // - application/json + // produces: + // - application/json + // parameters: + // - name: userId + // in: params + // description: User ID + // required: true + // type: string + // responses: + // '200': + // description: OK + // schema: + // "$ref": "#/definitions/StatusResponse" + // '400': + // description: Bad request + + var params structs.UserIdParam + + if err := rsutils.ParamsParserHelper(c, ¶ms); err != nil { + return c.SendStatus(fiber.StatusBadRequest) + } + + var foundVerifiedUser structs.VerifiedUser + + // get verified user by userId + database.DB.Where("user_id = ?", params.UserId).First(&foundVerifiedUser) + + log.Info().Msgf("Found verified user: %v", foundVerifiedUser) + + return c.JSON(structs.StatusResponse{Status: foundVerifiedUser.UserId != ""}) +} diff --git a/routers/api/v1/verifycode/verifycode.go b/routers/api/v1/verifycode/verifycode.go index 11f1c56..768036c 100644 --- a/routers/api/v1/verifycode/verifycode.go +++ b/routers/api/v1/verifycode/verifycode.go @@ -36,7 +36,7 @@ func GetVerifyCode(c *fiber.Ctx) error { // '500': // description: Internal server error - var params structs.VerifyCodeParams + var params structs.UserIdParam if err := rsutils.ParamsParserHelper(c, ¶ms); err != nil { return c.SendStatus(fiber.StatusBadRequest) diff --git a/routers/router/router.go b/routers/router/router.go index 81248cf..31ae276 100644 --- a/routers/router/router.go +++ b/routers/router/router.go @@ -2,6 +2,7 @@ package router import ( "jannex/telegram-bot-manager/routers/api/v1/notification" + "jannex/telegram-bot-manager/routers/api/v1/status" "jannex/telegram-bot-manager/routers/api/v1/verifycode" "github.com/gofiber/fiber/v2" @@ -16,5 +17,8 @@ func SetupRoutes(app *fiber.App) { n := v1.Group("/notification") n.Post("/", notification.SendNotification) + s := v1.Group("/status") + s.Get("/:userId", status.UserVerified) + app.Static("/", "./public/") }