diff --git a/internal/api/http/handlers/donat/donat.go b/internal/api/http/handlers/donat/donat.go index de6bf2e..1ef3a28 100644 --- a/internal/api/http/handlers/donat/donat.go +++ b/internal/api/http/handlers/donat/donat.go @@ -702,27 +702,23 @@ func GetDonatForPlaying(donatService model.DonatService) echo.HandlerFunc { // @Tags Donate // @Accept json // @Produce json -// @Param streamer-id query string true "Login стримера" -// @Security BearerAuth +// @Param request body model.UpdateLoginBody true "Update data" // @Success 200 {object} string "Successfully updated streamer login" // @Failure 400 {object} echo.HTTPError "Bad request" // @Failure 401 {object} echo.HTTPError "Unauthorized or expired token" // @Failure 500 {object} echo.HTTPError "Internal server error" -// @Router /update-login-donate [patch] +// @Router /update-login-donate [post] func UpdateLoginDonatePage(donatService model.DonatService) echo.HandlerFunc { return func(request echo.Context) error { ctx := context.Background() - streamerLogin := request.QueryParam("streamer-id") - if streamerLogin == "" { - return echo.NewHTTPError(http.StatusBadRequest, "streamer-id is required") - } - authData, err := donatService.CheckToken(request) - if err != nil { - slog.Error("Unauthorized") - return echo.NewHTTPError(http.StatusUnauthorized, "Incorrect token") + + var body model.UpdateLoginBody + if err := validator.ParseAndValidate(&body, request); err != nil { + slog.Error("Validation error", "error", err) + return echo.NewHTTPError(http.StatusUnprocessableEntity, "Invalid request body") } - err = donatService.UpdateStreamerLogin(ctx, streamerLogin, authData.AccountID) + err := donatService.UpdateStreamerLogin(ctx, body.Login, body.AccountID) if err != nil { slog.Error("Failed to update streamer login", "error", err) return echo.NewHTTPError(http.StatusInternalServerError, "Failed to update streamer login") diff --git a/internal/app/http/app.go b/internal/app/http/app.go index de32e20..69b576f 100644 --- a/internal/app/http/app.go +++ b/internal/app/http/app.go @@ -97,7 +97,7 @@ func IncludeDonatHandlers( server.PATCH(PREFIX+"/donat-moderate/:donat-id", ModerateDonat(donatService)) server.GET(PREFIX+"/get-donat-for-playing/:streamer-id", GetDonatForPlaying(donatService)) - server.PATCH(PREFIX+"/update-login-donate", UpdateLoginDonatePage(donatService)) + server.POST(PREFIX+"/update-login-donate", UpdateLoginDonatePage(donatService)) } func IncludeWidgetHandlers( diff --git a/internal/docs/docs.go b/internal/docs/docs.go index 4a31872..c0c1df0 100644 --- a/internal/docs/docs.go +++ b/internal/docs/docs.go @@ -1087,12 +1087,7 @@ const docTemplate = `{ } }, "/update-login-donate": { - "patch": { - "security": [ - { - "BearerAuth": [] - } - ], + "post": { "description": "Updates the streamer login associated with the donate page", "consumes": [ "application/json" @@ -1106,11 +1101,13 @@ const docTemplate = `{ "summary": "Update streamer login", "parameters": [ { - "type": "string", - "description": "Login стримера", - "name": "streamer-id", - "in": "query", - "required": true + "description": "Update data", + "name": "request", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/donat-widget_internal_model.UpdateLoginBody" + } } ], "responses": { @@ -2062,6 +2059,17 @@ const docTemplate = `{ } } }, + "donat-widget_internal_model.UpdateLoginBody": { + "type": "object", + "properties": { + "account_id": { + "type": "integer" + }, + "login": { + "type": "string" + } + } + }, "donat-widget_internal_model.UpdateModeration": { "type": "object", "properties": { diff --git a/internal/docs/swagger.json b/internal/docs/swagger.json index 0478942..4106a7f 100644 --- a/internal/docs/swagger.json +++ b/internal/docs/swagger.json @@ -1080,12 +1080,7 @@ } }, "/update-login-donate": { - "patch": { - "security": [ - { - "BearerAuth": [] - } - ], + "post": { "description": "Updates the streamer login associated with the donate page", "consumes": [ "application/json" @@ -1099,11 +1094,13 @@ "summary": "Update streamer login", "parameters": [ { - "type": "string", - "description": "Login стримера", - "name": "streamer-id", - "in": "query", - "required": true + "description": "Update data", + "name": "request", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/donat-widget_internal_model.UpdateLoginBody" + } } ], "responses": { @@ -2055,6 +2052,17 @@ } } }, + "donat-widget_internal_model.UpdateLoginBody": { + "type": "object", + "properties": { + "account_id": { + "type": "integer" + }, + "login": { + "type": "string" + } + } + }, "donat-widget_internal_model.UpdateModeration": { "type": "object", "properties": { diff --git a/internal/docs/swagger.yaml b/internal/docs/swagger.yaml index f1c1822..8e2305c 100644 --- a/internal/docs/swagger.yaml +++ b/internal/docs/swagger.yaml @@ -420,6 +420,13 @@ definitions: type: string type: array type: object + donat-widget_internal_model.UpdateLoginBody: + properties: + account_id: + type: integer + login: + type: string + type: object donat-widget_internal_model.UpdateModeration: properties: duration: @@ -1212,16 +1219,17 @@ paths: tags: - Donate /update-login-donate: - patch: + post: consumes: - application/json description: Updates the streamer login associated with the donate page parameters: - - description: Login стримера - in: query - name: streamer-id + - description: Update data + in: body + name: request required: true - type: string + schema: + $ref: '#/definitions/donat-widget_internal_model.UpdateLoginBody' produces: - application/json responses: @@ -1241,8 +1249,6 @@ paths: description: Internal server error schema: $ref: '#/definitions/echo.HTTPError' - security: - - BearerAuth: [] summary: Update streamer login tags: - Donate diff --git a/internal/model/models.go b/internal/model/models.go index 0f4a77b..ad7a488 100644 --- a/internal/model/models.go +++ b/internal/model/models.go @@ -333,3 +333,8 @@ type PlayingDonat struct { Amount int `json:"amount"` OrderID string `json:"order_id"` } + +type UpdateLoginBody struct { + AccountID int `json:"account_id"` + Login string `json:"login"` +}