add fix for bearer token

This commit is contained in:
harold 2025-07-04 11:11:45 +05:00
parent 4403934c71
commit 5dae651d29
7 changed files with 31 additions and 18 deletions

View File

@ -61,33 +61,40 @@ func CreateDonat(donatService model.DonatService) echo.HandlerFunc {
// @Tags Donate
// @Accept json
// @Produce json
// @Security BearerAuth
// @Param streamer-login path string true "Login стримера"
// @Param request body model.CreateDonatBody true "Create donat body json"
// @Success 200 {object} model.CreateDonatResponse "Donat page updated successfully"
// @Failure 400 {object} echo.HTTPError "Bad request"
// @Failure 401 {object} echo.HTTPError "Unauthorized or expired token"
// @Failure 422 {object} echo.HTTPError "Validation error"
// @Router /test-donat/{streamer-login} [post]
// @Router /test-donat [post]
func CreateTestDonat(donatService model.DonatService) echo.HandlerFunc {
return func(request echo.Context) error {
ctx := context.Background()
var body model.CreateDonatBody
err := validator.ParseAndValidate(&body, request)
authData, err := donatService.CheckToken(request)
if err != nil {
slog.Error("Unauthorized")
return echo.NewHTTPError(http.StatusUnauthorized, err.Error())
}
err = validator.ParseAndValidate(&body, request)
if err != nil {
slog.Error(err.Error())
return echo.NewHTTPError(http.StatusUnprocessableEntity, "Unprocessable Entity")
}
streamerLogin := request.Param("streamer-login")
err = donatService.CreateTestDonat(
ctx,
streamerLogin,
authData.AccountID,
body.Text,
body.DonatUser,
body.TargetID,
body.Amount,
)
if err != nil {
return request.JSON(http.StatusInternalServerError, err.Error())
}

View File

@ -80,7 +80,7 @@ func IncludeDonatHandlers(
server.POST(PREFIX+"/init-streamer", InitNewStreamer(donatService))
server.POST(PREFIX+"/donat/:streamer-login", CreateDonat(donatService))
server.POST(PREFIX+"/test-donat/:streamer-login", CreateTestDonat(donatService))
server.POST(PREFIX+"/test-donat", CreateTestDonat(donatService))
server.GET(PREFIX+"/inner-donate-page", GetInnerDonatePage(donatService))
server.GET(PREFIX+"/outer-donate-page/:streamer-login", GetOuterDonatePage(donatService))

View File

@ -1111,8 +1111,13 @@ const docTemplate = `{
}
}
},
"/test-donat/{streamer-login}": {
"/test-donat": {
"post": {
"security": [
{
"BearerAuth": []
}
],
"description": "Create donat",
"consumes": [
"application/json"

View File

@ -1104,8 +1104,13 @@
}
}
},
"/test-donat/{streamer-login}": {
"/test-donat": {
"post": {
"security": [
{
"BearerAuth": []
}
],
"description": "Create donat",
"consumes": [
"application/json"

View File

@ -1269,7 +1269,7 @@ paths:
summary: Get outer donate page info
tags:
- Donate
/test-donat/{streamer-login}:
/test-donat:
post:
consumes:
- application/json
@ -1305,6 +1305,8 @@ paths:
description: Validation error
schema:
$ref: '#/definitions/echo.HTTPError'
security:
- BearerAuth: []
summary: Create donat
tags:
- Donate

View File

@ -76,7 +76,7 @@ type DonatService interface {
CreateDonat(ctx context.Context, streamerLogin, text, donatUser string, targetID *int, amount int) (CreateDonatResponse, error)
CreateTestDonat(
ctx context.Context,
streamerLogin string,
streamerID int,
text string,
donatUser string,
targetID *int,

View File

@ -149,25 +149,19 @@ func (donatService *ServiceDonat) CreateDonat(
func (donatService *ServiceDonat) CreateTestDonat(
ctx context.Context,
streamerLogin string,
streamerID int,
text string,
donatUser string,
targetID *int,
amount int,
) error {
donatePage, err := donatService.donatRepo.GetDonatPageByLogin(ctx, streamerLogin)
if err != nil {
slog.Error("Failed to get donate page", "error", err.Error())
return err
}
orderID := uuid.New()
widgetID := donatService.defaultWidgetID
err = donatService.donatRepo.CreateDonat(
err := donatService.donatRepo.CreateDonat(
ctx,
donatePage.StreamerID,
streamerID,
targetID,
widgetID,
orderID,