add test donat handler
This commit is contained in:
parent
66a546b465
commit
4403934c71
@ -55,6 +55,47 @@ func CreateDonat(donatService model.DonatService) echo.HandlerFunc {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CreateTestDonat godoc
|
||||||
|
// @Summary Create donat
|
||||||
|
// @Description Create donat
|
||||||
|
// @Tags Donate
|
||||||
|
// @Accept json
|
||||||
|
// @Produce json
|
||||||
|
// @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]
|
||||||
|
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)
|
||||||
|
if err != nil {
|
||||||
|
slog.Error(err.Error())
|
||||||
|
return echo.NewHTTPError(http.StatusUnprocessableEntity, "Unprocessable Entity")
|
||||||
|
}
|
||||||
|
|
||||||
|
streamerLogin := request.Param("streamer-login")
|
||||||
|
err = donatService.CreateTestDonat(
|
||||||
|
ctx,
|
||||||
|
streamerLogin,
|
||||||
|
body.Text,
|
||||||
|
body.DonatUser,
|
||||||
|
body.TargetID,
|
||||||
|
body.Amount,
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return request.JSON(http.StatusInternalServerError, err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
return request.JSON(http.StatusCreated, "Test donat has been created!")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// GetDonat godoc
|
// GetDonat godoc
|
||||||
// @Summary Get donats
|
// @Summary Get donats
|
||||||
// @Description Получает список донатов для указанного стримера с пагинацией
|
// @Description Получает список донатов для указанного стримера с пагинацией
|
||||||
|
@ -80,6 +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.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))
|
||||||
|
@ -504,7 +504,7 @@ const docTemplate = `{
|
|||||||
"parameters": [
|
"parameters": [
|
||||||
{
|
{
|
||||||
"type": "file",
|
"type": "file",
|
||||||
"description": "New file to upload",
|
"description": "New file to upload (max 20 MB)",
|
||||||
"name": "new_file",
|
"name": "new_file",
|
||||||
"in": "formData",
|
"in": "formData",
|
||||||
"required": true
|
"required": true
|
||||||
@ -535,6 +535,12 @@ const docTemplate = `{
|
|||||||
"$ref": "#/definitions/echo.HTTPError"
|
"$ref": "#/definitions/echo.HTTPError"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"413": {
|
||||||
|
"description": "File size exceeds 20 MB limit",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/echo.HTTPError"
|
||||||
|
}
|
||||||
|
},
|
||||||
"422": {
|
"422": {
|
||||||
"description": "Validation error (specific cases, might overlap with 400/500)",
|
"description": "Validation error (specific cases, might overlap with 400/500)",
|
||||||
"schema": {
|
"schema": {
|
||||||
@ -1105,6 +1111,65 @@ const docTemplate = `{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"/test-donat/{streamer-login}": {
|
||||||
|
"post": {
|
||||||
|
"description": "Create donat",
|
||||||
|
"consumes": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"tags": [
|
||||||
|
"Donate"
|
||||||
|
],
|
||||||
|
"summary": "Create donat",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"type": "string",
|
||||||
|
"description": "Login стримера",
|
||||||
|
"name": "streamer-login",
|
||||||
|
"in": "path",
|
||||||
|
"required": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"description": "Create donat body json",
|
||||||
|
"name": "request",
|
||||||
|
"in": "body",
|
||||||
|
"required": true,
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/donat-widget_internal_model.CreateDonatBody"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "Donat page updated successfully",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/donat-widget_internal_model.CreateDonatResponse"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"400": {
|
||||||
|
"description": "Bad request",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/echo.HTTPError"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"401": {
|
||||||
|
"description": "Unauthorized or expired token",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/echo.HTTPError"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"422": {
|
||||||
|
"description": "Validation error",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/echo.HTTPError"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"/text-after-donat/{order-id}": {
|
"/text-after-donat/{order-id}": {
|
||||||
"get": {
|
"get": {
|
||||||
"description": "Получает список донатов для указанного стримера с пагинацией",
|
"description": "Получает список донатов для указанного стримера с пагинацией",
|
||||||
|
@ -497,7 +497,7 @@
|
|||||||
"parameters": [
|
"parameters": [
|
||||||
{
|
{
|
||||||
"type": "file",
|
"type": "file",
|
||||||
"description": "New file to upload",
|
"description": "New file to upload (max 20 MB)",
|
||||||
"name": "new_file",
|
"name": "new_file",
|
||||||
"in": "formData",
|
"in": "formData",
|
||||||
"required": true
|
"required": true
|
||||||
@ -528,6 +528,12 @@
|
|||||||
"$ref": "#/definitions/echo.HTTPError"
|
"$ref": "#/definitions/echo.HTTPError"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"413": {
|
||||||
|
"description": "File size exceeds 20 MB limit",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/echo.HTTPError"
|
||||||
|
}
|
||||||
|
},
|
||||||
"422": {
|
"422": {
|
||||||
"description": "Validation error (specific cases, might overlap with 400/500)",
|
"description": "Validation error (specific cases, might overlap with 400/500)",
|
||||||
"schema": {
|
"schema": {
|
||||||
@ -1098,6 +1104,65 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"/test-donat/{streamer-login}": {
|
||||||
|
"post": {
|
||||||
|
"description": "Create donat",
|
||||||
|
"consumes": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"tags": [
|
||||||
|
"Donate"
|
||||||
|
],
|
||||||
|
"summary": "Create donat",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"type": "string",
|
||||||
|
"description": "Login стримера",
|
||||||
|
"name": "streamer-login",
|
||||||
|
"in": "path",
|
||||||
|
"required": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"description": "Create donat body json",
|
||||||
|
"name": "request",
|
||||||
|
"in": "body",
|
||||||
|
"required": true,
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/donat-widget_internal_model.CreateDonatBody"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "Donat page updated successfully",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/donat-widget_internal_model.CreateDonatResponse"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"400": {
|
||||||
|
"description": "Bad request",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/echo.HTTPError"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"401": {
|
||||||
|
"description": "Unauthorized or expired token",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/echo.HTTPError"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"422": {
|
||||||
|
"description": "Validation error",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/echo.HTTPError"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"/text-after-donat/{order-id}": {
|
"/text-after-donat/{order-id}": {
|
||||||
"get": {
|
"get": {
|
||||||
"description": "Получает список донатов для указанного стримера с пагинацией",
|
"description": "Получает список донатов для указанного стримера с пагинацией",
|
||||||
|
@ -870,7 +870,7 @@ paths:
|
|||||||
- multipart/form-data
|
- multipart/form-data
|
||||||
description: Add new File. The entity type defaults to 'widget' if not specified.
|
description: Add new File. The entity type defaults to 'widget' if not specified.
|
||||||
parameters:
|
parameters:
|
||||||
- description: New file to upload
|
- description: New file to upload (max 20 MB)
|
||||||
in: formData
|
in: formData
|
||||||
name: new_file
|
name: new_file
|
||||||
required: true
|
required: true
|
||||||
@ -894,6 +894,10 @@ paths:
|
|||||||
description: Unauthorized or expired token
|
description: Unauthorized or expired token
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/echo.HTTPError'
|
$ref: '#/definitions/echo.HTTPError'
|
||||||
|
"413":
|
||||||
|
description: File size exceeds 20 MB limit
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/echo.HTTPError'
|
||||||
"422":
|
"422":
|
||||||
description: Validation error (specific cases, might overlap with 400/500)
|
description: Validation error (specific cases, might overlap with 400/500)
|
||||||
schema:
|
schema:
|
||||||
@ -1265,6 +1269,45 @@ paths:
|
|||||||
summary: Get outer donate page info
|
summary: Get outer donate page info
|
||||||
tags:
|
tags:
|
||||||
- Donate
|
- Donate
|
||||||
|
/test-donat/{streamer-login}:
|
||||||
|
post:
|
||||||
|
consumes:
|
||||||
|
- application/json
|
||||||
|
description: Create donat
|
||||||
|
parameters:
|
||||||
|
- description: Login стримера
|
||||||
|
in: path
|
||||||
|
name: streamer-login
|
||||||
|
required: true
|
||||||
|
type: string
|
||||||
|
- description: Create donat body json
|
||||||
|
in: body
|
||||||
|
name: request
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/donat-widget_internal_model.CreateDonatBody'
|
||||||
|
produces:
|
||||||
|
- application/json
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: Donat page updated successfully
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/donat-widget_internal_model.CreateDonatResponse'
|
||||||
|
"400":
|
||||||
|
description: Bad request
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/echo.HTTPError'
|
||||||
|
"401":
|
||||||
|
description: Unauthorized or expired token
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/echo.HTTPError'
|
||||||
|
"422":
|
||||||
|
description: Validation error
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/echo.HTTPError'
|
||||||
|
summary: Create donat
|
||||||
|
tags:
|
||||||
|
- Donate
|
||||||
/text-after-donat/{order-id}:
|
/text-after-donat/{order-id}:
|
||||||
get:
|
get:
|
||||||
consumes:
|
consumes:
|
||||||
|
@ -74,6 +74,14 @@ type DonatService interface {
|
|||||||
CheckToken(request echo.Context) (api.CheckTokenResponse, error)
|
CheckToken(request echo.Context) (api.CheckTokenResponse, error)
|
||||||
|
|
||||||
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(
|
||||||
|
ctx context.Context,
|
||||||
|
streamerLogin string,
|
||||||
|
text string,
|
||||||
|
donatUser string,
|
||||||
|
targetID *int,
|
||||||
|
amount int,
|
||||||
|
) error
|
||||||
|
|
||||||
GetDonatsByStreamerID(ctx context.Context, streamerID, page, limit int) ([]*Donat, error)
|
GetDonatsByStreamerID(ctx context.Context, streamerID, page, limit int) ([]*Donat, error)
|
||||||
GetDonatByOrderID(ctx context.Context, orderID string) (*Donat, error)
|
GetDonatByOrderID(ctx context.Context, orderID string) (*Donat, error)
|
||||||
@ -131,6 +139,7 @@ type DonatRepo interface {
|
|||||||
amount int,
|
amount int,
|
||||||
text string,
|
text string,
|
||||||
donatUser string,
|
donatUser string,
|
||||||
|
status string,
|
||||||
) error
|
) error
|
||||||
|
|
||||||
GetDonatsByStreamerID(ctx context.Context, streamerID, page, limit int) ([]*Donat, error)
|
GetDonatsByStreamerID(ctx context.Context, streamerID, page, limit int) ([]*Donat, error)
|
||||||
|
@ -77,6 +77,7 @@ FROM donats
|
|||||||
WHERE streamer_id = @streamer_id
|
WHERE streamer_id = @streamer_id
|
||||||
AND rejected_time IS NULL
|
AND rejected_time IS NULL
|
||||||
AND paid_time IS NOT NULL
|
AND paid_time IS NOT NULL
|
||||||
|
AND status != 'test_donat'
|
||||||
ORDER BY created_at DESC
|
ORDER BY created_at DESC
|
||||||
LIMIT @limit OFFSET @offset;
|
LIMIT @limit OFFSET @offset;
|
||||||
|
|
||||||
@ -580,7 +581,7 @@ FROM widgets AS w
|
|||||||
INNER JOIN
|
INNER JOIN
|
||||||
donats AS d ON d.widget_id = w.id
|
donats AS d ON d.widget_id = w.id
|
||||||
WHERE d.streamer_id = @streamer_id
|
WHERE d.streamer_id = @streamer_id
|
||||||
AND d.status = 'accepted_moderation'
|
AND (d.status = 'accepted_moderation' OR d.status = 'test_donat')
|
||||||
AND d.showed_time IS NULL
|
AND d.showed_time IS NULL
|
||||||
ORDER BY d.accepted_time ASC
|
ORDER BY d.accepted_time ASC
|
||||||
LIMIT 1;
|
LIMIT 1;
|
||||||
|
@ -33,6 +33,7 @@ func (repoDonat *RepoDonat) CreateDonat(
|
|||||||
amount int,
|
amount int,
|
||||||
text string,
|
text string,
|
||||||
donatUser string,
|
donatUser string,
|
||||||
|
status string,
|
||||||
) error {
|
) error {
|
||||||
args := pgx.NamedArgs{
|
args := pgx.NamedArgs{
|
||||||
"streamer_id": streamerID,
|
"streamer_id": streamerID,
|
||||||
@ -41,7 +42,7 @@ func (repoDonat *RepoDonat) CreateDonat(
|
|||||||
"target_id": targetID,
|
"target_id": targetID,
|
||||||
"text": text,
|
"text": text,
|
||||||
"amount": amount,
|
"amount": amount,
|
||||||
"status": "pending",
|
"status": status,
|
||||||
"donat_user": donatUser,
|
"donat_user": donatUser,
|
||||||
}
|
}
|
||||||
_, err := repoDonat.db.Insert(ctx, sql.CreateDonat, args)
|
_, err := repoDonat.db.Insert(ctx, sql.CreateDonat, args)
|
||||||
|
@ -120,7 +120,15 @@ func (donatService *ServiceDonat) CreateDonat(
|
|||||||
}
|
}
|
||||||
|
|
||||||
err = donatService.donatRepo.CreateDonat(
|
err = donatService.donatRepo.CreateDonat(
|
||||||
ctx, donatePage.StreamerID, targetID, widgetID, orderID, amount, text, donatUser,
|
ctx,
|
||||||
|
donatePage.StreamerID,
|
||||||
|
targetID,
|
||||||
|
widgetID,
|
||||||
|
orderID,
|
||||||
|
amount,
|
||||||
|
text,
|
||||||
|
donatUser,
|
||||||
|
"pending",
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
slog.Error(err.Error())
|
slog.Error(err.Error())
|
||||||
@ -139,6 +147,43 @@ func (donatService *ServiceDonat) CreateDonat(
|
|||||||
return createDonatResp, err
|
return createDonatResp, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (donatService *ServiceDonat) CreateTestDonat(
|
||||||
|
ctx context.Context,
|
||||||
|
streamerLogin string,
|
||||||
|
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(
|
||||||
|
ctx,
|
||||||
|
donatePage.StreamerID,
|
||||||
|
targetID,
|
||||||
|
widgetID,
|
||||||
|
orderID,
|
||||||
|
amount,
|
||||||
|
text,
|
||||||
|
donatUser,
|
||||||
|
"test_donat",
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
slog.Error(err.Error())
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (donatService *ServiceDonat) GetDonatsByStreamerID(
|
func (donatService *ServiceDonat) GetDonatsByStreamerID(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
streamerID int,
|
streamerID int,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user