add fix for bearer token
This commit is contained in:
parent
4403934c71
commit
5dae651d29
@ -61,33 +61,40 @@ func CreateDonat(donatService model.DonatService) echo.HandlerFunc {
|
|||||||
// @Tags Donate
|
// @Tags Donate
|
||||||
// @Accept json
|
// @Accept json
|
||||||
// @Produce json
|
// @Produce json
|
||||||
|
// @Security BearerAuth
|
||||||
// @Param streamer-login path string true "Login стримера"
|
// @Param streamer-login path string true "Login стримера"
|
||||||
// @Param request body model.CreateDonatBody true "Create donat body json"
|
// @Param request body model.CreateDonatBody true "Create donat body json"
|
||||||
// @Success 200 {object} model.CreateDonatResponse "Donat page updated successfully"
|
// @Success 200 {object} model.CreateDonatResponse "Donat page updated successfully"
|
||||||
// @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 422 {object} echo.HTTPError "Validation error"
|
// @Failure 422 {object} echo.HTTPError "Validation error"
|
||||||
// @Router /test-donat/{streamer-login} [post]
|
// @Router /test-donat [post]
|
||||||
func CreateTestDonat(donatService model.DonatService) echo.HandlerFunc {
|
func CreateTestDonat(donatService model.DonatService) echo.HandlerFunc {
|
||||||
return func(request echo.Context) error {
|
return func(request echo.Context) error {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
var body model.CreateDonatBody
|
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 {
|
if err != nil {
|
||||||
slog.Error(err.Error())
|
slog.Error(err.Error())
|
||||||
return echo.NewHTTPError(http.StatusUnprocessableEntity, "Unprocessable Entity")
|
return echo.NewHTTPError(http.StatusUnprocessableEntity, "Unprocessable Entity")
|
||||||
}
|
}
|
||||||
|
|
||||||
streamerLogin := request.Param("streamer-login")
|
|
||||||
err = donatService.CreateTestDonat(
|
err = donatService.CreateTestDonat(
|
||||||
ctx,
|
ctx,
|
||||||
streamerLogin,
|
authData.AccountID,
|
||||||
body.Text,
|
body.Text,
|
||||||
body.DonatUser,
|
body.DonatUser,
|
||||||
body.TargetID,
|
body.TargetID,
|
||||||
body.Amount,
|
body.Amount,
|
||||||
)
|
)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return request.JSON(http.StatusInternalServerError, err.Error())
|
return request.JSON(http.StatusInternalServerError, err.Error())
|
||||||
}
|
}
|
||||||
|
@ -80,7 +80,7 @@ func IncludeDonatHandlers(
|
|||||||
server.POST(PREFIX+"/init-streamer", InitNewStreamer(donatService))
|
server.POST(PREFIX+"/init-streamer", InitNewStreamer(donatService))
|
||||||
|
|
||||||
server.POST(PREFIX+"/donat/:streamer-login", CreateDonat(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+"/inner-donate-page", GetInnerDonatePage(donatService))
|
||||||
server.GET(PREFIX+"/outer-donate-page/:streamer-login", GetOuterDonatePage(donatService))
|
server.GET(PREFIX+"/outer-donate-page/:streamer-login", GetOuterDonatePage(donatService))
|
||||||
|
@ -1111,8 +1111,13 @@ const docTemplate = `{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"/test-donat/{streamer-login}": {
|
"/test-donat": {
|
||||||
"post": {
|
"post": {
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"BearerAuth": []
|
||||||
|
}
|
||||||
|
],
|
||||||
"description": "Create donat",
|
"description": "Create donat",
|
||||||
"consumes": [
|
"consumes": [
|
||||||
"application/json"
|
"application/json"
|
||||||
|
@ -1104,8 +1104,13 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"/test-donat/{streamer-login}": {
|
"/test-donat": {
|
||||||
"post": {
|
"post": {
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"BearerAuth": []
|
||||||
|
}
|
||||||
|
],
|
||||||
"description": "Create donat",
|
"description": "Create donat",
|
||||||
"consumes": [
|
"consumes": [
|
||||||
"application/json"
|
"application/json"
|
||||||
|
@ -1269,7 +1269,7 @@ paths:
|
|||||||
summary: Get outer donate page info
|
summary: Get outer donate page info
|
||||||
tags:
|
tags:
|
||||||
- Donate
|
- Donate
|
||||||
/test-donat/{streamer-login}:
|
/test-donat:
|
||||||
post:
|
post:
|
||||||
consumes:
|
consumes:
|
||||||
- application/json
|
- application/json
|
||||||
@ -1305,6 +1305,8 @@ paths:
|
|||||||
description: Validation error
|
description: Validation error
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/echo.HTTPError'
|
$ref: '#/definitions/echo.HTTPError'
|
||||||
|
security:
|
||||||
|
- BearerAuth: []
|
||||||
summary: Create donat
|
summary: Create donat
|
||||||
tags:
|
tags:
|
||||||
- Donate
|
- Donate
|
||||||
|
@ -76,7 +76,7 @@ type DonatService interface {
|
|||||||
CreateDonat(ctx context.Context, streamerLogin, text, donatUser string, targetID *int, amount int) (CreateDonatResponse, error)
|
CreateDonat(ctx context.Context, streamerLogin, text, donatUser string, targetID *int, amount int) (CreateDonatResponse, error)
|
||||||
CreateTestDonat(
|
CreateTestDonat(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
streamerLogin string,
|
streamerID int,
|
||||||
text string,
|
text string,
|
||||||
donatUser string,
|
donatUser string,
|
||||||
targetID *int,
|
targetID *int,
|
||||||
|
@ -149,25 +149,19 @@ func (donatService *ServiceDonat) CreateDonat(
|
|||||||
|
|
||||||
func (donatService *ServiceDonat) CreateTestDonat(
|
func (donatService *ServiceDonat) CreateTestDonat(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
streamerLogin string,
|
streamerID int,
|
||||||
text string,
|
text string,
|
||||||
donatUser string,
|
donatUser string,
|
||||||
targetID *int,
|
targetID *int,
|
||||||
amount int,
|
amount int,
|
||||||
) error {
|
) 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()
|
orderID := uuid.New()
|
||||||
|
|
||||||
widgetID := donatService.defaultWidgetID
|
widgetID := donatService.defaultWidgetID
|
||||||
|
|
||||||
err = donatService.donatRepo.CreateDonat(
|
err := donatService.donatRepo.CreateDonat(
|
||||||
ctx,
|
ctx,
|
||||||
donatePage.StreamerID,
|
streamerID,
|
||||||
targetID,
|
targetID,
|
||||||
widgetID,
|
widgetID,
|
||||||
orderID,
|
orderID,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user