change post method

This commit is contained in:
harold 2025-04-05 20:49:49 +05:00
parent 004701457c
commit 05e85e077d
6 changed files with 65 additions and 42 deletions

View File

@ -702,27 +702,23 @@ func GetDonatForPlaying(donatService model.DonatService) echo.HandlerFunc {
// @Tags Donate // @Tags Donate
// @Accept json // @Accept json
// @Produce json // @Produce json
// @Param streamer-id query string true "Login стримера" // @Param request body model.UpdateLoginBody true "Update data"
// @Security BearerAuth
// @Success 200 {object} string "Successfully updated streamer login" // @Success 200 {object} string "Successfully updated streamer login"
// @Failure 400 {object} echo.HTTPError "Bad request" // @Failure 400 {object} echo.HTTPError "Bad request"
// @Failure 401 {object} echo.HTTPError "Unauthorized or expired token" // @Failure 401 {object} echo.HTTPError "Unauthorized or expired token"
// @Failure 500 {object} echo.HTTPError "Internal server error" // @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 { func UpdateLoginDonatePage(donatService model.DonatService) echo.HandlerFunc {
return func(request echo.Context) error { return func(request echo.Context) error {
ctx := context.Background() ctx := context.Background()
streamerLogin := request.QueryParam("streamer-id")
if streamerLogin == "" { var body model.UpdateLoginBody
return echo.NewHTTPError(http.StatusBadRequest, "streamer-id is required") if err := validator.ParseAndValidate(&body, request); err != nil {
} slog.Error("Validation error", "error", err)
authData, err := donatService.CheckToken(request) return echo.NewHTTPError(http.StatusUnprocessableEntity, "Invalid request body")
if err != nil {
slog.Error("Unauthorized")
return echo.NewHTTPError(http.StatusUnauthorized, "Incorrect token")
} }
err = donatService.UpdateStreamerLogin(ctx, streamerLogin, authData.AccountID) err := donatService.UpdateStreamerLogin(ctx, body.Login, body.AccountID)
if err != nil { if err != nil {
slog.Error("Failed to update streamer login", "error", err) slog.Error("Failed to update streamer login", "error", err)
return echo.NewHTTPError(http.StatusInternalServerError, "Failed to update streamer login") return echo.NewHTTPError(http.StatusInternalServerError, "Failed to update streamer login")

View File

@ -97,7 +97,7 @@ func IncludeDonatHandlers(
server.PATCH(PREFIX+"/donat-moderate/:donat-id", ModerateDonat(donatService)) server.PATCH(PREFIX+"/donat-moderate/:donat-id", ModerateDonat(donatService))
server.GET(PREFIX+"/get-donat-for-playing/:streamer-id", GetDonatForPlaying(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( func IncludeWidgetHandlers(

View File

@ -1087,12 +1087,7 @@ const docTemplate = `{
} }
}, },
"/update-login-donate": { "/update-login-donate": {
"patch": { "post": {
"security": [
{
"BearerAuth": []
}
],
"description": "Updates the streamer login associated with the donate page", "description": "Updates the streamer login associated with the donate page",
"consumes": [ "consumes": [
"application/json" "application/json"
@ -1106,11 +1101,13 @@ const docTemplate = `{
"summary": "Update streamer login", "summary": "Update streamer login",
"parameters": [ "parameters": [
{ {
"type": "string", "description": "Update data",
"description": "Login стримера", "name": "request",
"name": "streamer-id", "in": "body",
"in": "query", "required": true,
"required": true "schema": {
"$ref": "#/definitions/donat-widget_internal_model.UpdateLoginBody"
}
} }
], ],
"responses": { "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": { "donat-widget_internal_model.UpdateModeration": {
"type": "object", "type": "object",
"properties": { "properties": {

View File

@ -1080,12 +1080,7 @@
} }
}, },
"/update-login-donate": { "/update-login-donate": {
"patch": { "post": {
"security": [
{
"BearerAuth": []
}
],
"description": "Updates the streamer login associated with the donate page", "description": "Updates the streamer login associated with the donate page",
"consumes": [ "consumes": [
"application/json" "application/json"
@ -1099,11 +1094,13 @@
"summary": "Update streamer login", "summary": "Update streamer login",
"parameters": [ "parameters": [
{ {
"type": "string", "description": "Update data",
"description": "Login стримера", "name": "request",
"name": "streamer-id", "in": "body",
"in": "query", "required": true,
"required": true "schema": {
"$ref": "#/definitions/donat-widget_internal_model.UpdateLoginBody"
}
} }
], ],
"responses": { "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": { "donat-widget_internal_model.UpdateModeration": {
"type": "object", "type": "object",
"properties": { "properties": {

View File

@ -420,6 +420,13 @@ definitions:
type: string type: string
type: array type: array
type: object type: object
donat-widget_internal_model.UpdateLoginBody:
properties:
account_id:
type: integer
login:
type: string
type: object
donat-widget_internal_model.UpdateModeration: donat-widget_internal_model.UpdateModeration:
properties: properties:
duration: duration:
@ -1212,16 +1219,17 @@ paths:
tags: tags:
- Donate - Donate
/update-login-donate: /update-login-donate:
patch: post:
consumes: consumes:
- application/json - application/json
description: Updates the streamer login associated with the donate page description: Updates the streamer login associated with the donate page
parameters: parameters:
- description: Login стримера - description: Update data
in: query in: body
name: streamer-id name: request
required: true required: true
type: string schema:
$ref: '#/definitions/donat-widget_internal_model.UpdateLoginBody'
produces: produces:
- application/json - application/json
responses: responses:
@ -1241,8 +1249,6 @@ paths:
description: Internal server error description: Internal server error
schema: schema:
$ref: '#/definitions/echo.HTTPError' $ref: '#/definitions/echo.HTTPError'
security:
- BearerAuth: []
summary: Update streamer login summary: Update streamer login
tags: tags:
- Donate - Donate

View File

@ -333,3 +333,8 @@ type PlayingDonat struct {
Amount int `json:"amount"` Amount int `json:"amount"`
OrderID string `json:"order_id"` OrderID string `json:"order_id"`
} }
type UpdateLoginBody struct {
AccountID int `json:"account_id"`
Login string `json:"login"`
}