From 97938545966c7bae4a084e01f6a404a2cc3eb9f8 Mon Sep 17 00:00:00 2001 From: Yared Yemane Date: Fri, 23 May 2025 20:37:29 +0300 Subject: [PATCH] authmiddleware fix --- docs/docs.go | 63 ---------------------- docs/swagger.json | 63 ---------------------- docs/swagger.yaml | 42 --------------- internal/web_server/handlers/alea_games.go | 10 +--- internal/web_server/routes.go | 4 +- 5 files changed, 4 insertions(+), 178 deletions(-) diff --git a/docs/docs.go b/docs/docs.go index 235d7ff..875d103 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -200,33 +200,6 @@ const docTemplate = `{ ] } } - }, - "400": { - "description": "Invalid request parameters", - "schema": { - "type": "object", - "additionalProperties": { - "type": "string" - } - } - }, - "401": { - "description": "Unauthorized", - "schema": { - "type": "object", - "additionalProperties": { - "type": "string" - } - } - }, - "500": { - "description": "Internal server error", - "schema": { - "type": "object", - "additionalProperties": { - "type": "string" - } - } } } } @@ -465,42 +438,6 @@ const docTemplate = `{ ] } } - }, - "400": { - "description": "Invalid callback format", - "schema": { - "type": "object", - "additionalProperties": { - "type": "string" - } - } - }, - "401": { - "description": "Invalid signature", - "schema": { - "type": "object", - "additionalProperties": { - "type": "string" - } - } - }, - "409": { - "description": "Duplicate transaction", - "schema": { - "type": "object", - "additionalProperties": { - "type": "string" - } - } - }, - "500": { - "description": "Internal processing error", - "schema": { - "type": "object", - "additionalProperties": { - "type": "string" - } - } } } } diff --git a/docs/swagger.json b/docs/swagger.json index 1b046b1..4c54116 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -192,33 +192,6 @@ ] } } - }, - "400": { - "description": "Invalid request parameters", - "schema": { - "type": "object", - "additionalProperties": { - "type": "string" - } - } - }, - "401": { - "description": "Unauthorized", - "schema": { - "type": "object", - "additionalProperties": { - "type": "string" - } - } - }, - "500": { - "description": "Internal server error", - "schema": { - "type": "object", - "additionalProperties": { - "type": "string" - } - } } } } @@ -457,42 +430,6 @@ ] } } - }, - "400": { - "description": "Invalid callback format", - "schema": { - "type": "object", - "additionalProperties": { - "type": "string" - } - } - }, - "401": { - "description": "Invalid signature", - "schema": { - "type": "object", - "additionalProperties": { - "type": "string" - } - } - }, - "409": { - "description": "Duplicate transaction", - "schema": { - "type": "object", - "additionalProperties": { - "type": "string" - } - } - }, - "500": { - "description": "Internal processing error", - "schema": { - "type": "object", - "additionalProperties": { - "type": "string" - } - } } } } diff --git a/docs/swagger.yaml b/docs/swagger.yaml index cc038bf..33afae3 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -1440,24 +1440,6 @@ paths: type: string type: object type: object - "400": - description: Invalid request parameters - schema: - additionalProperties: - type: string - type: object - "401": - description: Unauthorized - schema: - additionalProperties: - type: string - type: object - "500": - description: Internal server error - schema: - additionalProperties: - type: string - type: object security: - BearerAuth: [] summary: Launch an Alea Play virtual game @@ -1613,30 +1595,6 @@ paths: type: string type: object type: object - "400": - description: Invalid callback format - schema: - additionalProperties: - type: string - type: object - "401": - description: Invalid signature - schema: - additionalProperties: - type: string - type: object - "409": - description: Duplicate transaction - schema: - additionalProperties: - type: string - type: object - "500": - description: Internal processing error - schema: - additionalProperties: - type: string - type: object summary: Process Alea Play game callback tags: - Alea Virtual Games diff --git a/internal/web_server/handlers/alea_games.go b/internal/web_server/handlers/alea_games.go index 01e4bb6..0fc8ea3 100644 --- a/internal/web_server/handlers/alea_games.go +++ b/internal/web_server/handlers/alea_games.go @@ -16,12 +16,9 @@ import ( // @Param currency query string false "Currency code (ISO 4217)" Enums(USD, EUR, GBP) default(USD) // @Param mode query string false "Game mode" Enums(real, demo) default(real) // @Success 200 {object} map[string]string{launch_url=string} "Returns authenticated game launch URL" -// @Failure 400 {object} map[string]string "Invalid request parameters" -// @Failure 401 {object} map[string]string "Unauthorized" -// @Failure 500 {object} map[string]string "Internal server error" // @Router /api/v1/alea-games/launch [get] func (h *Handler) LaunchAleaGame(c *fiber.Ctx) error { - userID := c.Locals("userID").(int64) + userID := c.Locals("user_id").(int64) gameID := c.Query("game_id") currency := c.Query("currency", "USD") mode := c.Query("mode", "real") // real or demo @@ -36,6 +33,7 @@ func (h *Handler) LaunchAleaGame(c *fiber.Ctx) error { return c.JSON(fiber.Map{ "launch_url": launchURL, + "message": "Game launched successfully", }) } @@ -47,10 +45,6 @@ func (h *Handler) LaunchAleaGame(c *fiber.Ctx) error { // @Produce json // @Param callback body domain.AleaPlayCallback true "Callback payload" // @Success 200 {object} map[string]string{status=string} "Callback processed successfully" -// @Failure 400 {object} map[string]string "Invalid callback format" -// @Failure 401 {object} map[string]string "Invalid signature" -// @Failure 409 {object} map[string]string "Duplicate transaction" -// @Failure 500 {object} map[string]string "Internal processing error" // @Router /api/v1/webhooks/alea [post] func (h *Handler) HandleAleaCallback(c *fiber.Ctx) error { var cb domain.AleaPlayCallback diff --git a/internal/web_server/routes.go b/internal/web_server/routes.go index fad2586..7a18943 100644 --- a/internal/web_server/routes.go +++ b/internal/web_server/routes.go @@ -174,8 +174,8 @@ func (a *App) initAppRoutes() { a.fiber.Get("/api/v1/chapa/transfers/verify/:transfer_ref", h.VerifyTransfer) //Alea Play Virtual Game Routes - a.fiber.Get("/api/v1/alea-games/launch", h.LaunchAleaGame) - a.fiber.Post("/api/v1/webhooks/alea", h.HandleAleaCallback) + a.fiber.Get("/api/v1/alea-games/launch", a.authMiddleware, h.LaunchAleaGame) + a.fiber.Post("/api/v1/webhooks/alea", a.authMiddleware, h.HandleAleaCallback) // a.fiber.Post("/webhooks/alea", middleware.AleaWebhookMiddleware(a.cfg.AleaPlay.SecretKey), h.HandleAleaCallback) // Transactions /transactions