add handle for donat paid
This commit is contained in:
parent
17d8c25d5f
commit
167a7d5e59
@ -105,23 +105,28 @@ func GetDonat(donatService model.DonatService) echo.HandlerFunc {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MarkDonatPaid godoc
|
||||||
|
// @Summary Mark donat as paid
|
||||||
|
// @Description Mark donat as paid
|
||||||
|
// @Tags Donate
|
||||||
|
// @Accept json
|
||||||
|
// @Produce json
|
||||||
|
// @Param request body model.MarkDonatPaidBody true "order id body"
|
||||||
|
// @Success 200 {string} string "Ok"
|
||||||
|
// @Failure 400 {object} echo.HTTPError "Некорректный формат streamerID"
|
||||||
|
// @Failure 500 {object} echo.HTTPError "Внутренняя ошибка сервера"
|
||||||
|
// @Router /donat/paid [post]
|
||||||
func MarkDonatPaid(donatService model.DonatService) echo.HandlerFunc {
|
func MarkDonatPaid(donatService model.DonatService) echo.HandlerFunc {
|
||||||
type MarkDonatPaidBody struct {
|
|
||||||
OrderID string `json:"orderID"`
|
|
||||||
}
|
|
||||||
return func(request echo.Context) error {
|
return func(request echo.Context) error {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
var body MarkDonatPaidBody
|
var body model.MarkDonatPaidBody
|
||||||
if err := request.Bind(&body); err != nil {
|
err := validator.ParseAndValidate(&body, request)
|
||||||
|
if err != nil {
|
||||||
slog.Error(err.Error())
|
slog.Error(err.Error())
|
||||||
return request.JSON(http.StatusInternalServerError, err.Error())
|
return echo.NewHTTPError(http.StatusUnprocessableEntity, "Unprocessable Entity")
|
||||||
}
|
|
||||||
if err := request.Validate(&body); err != nil {
|
|
||||||
slog.Error(err.Error())
|
|
||||||
return request.JSON(http.StatusInternalServerError, err.Error())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
err := donatService.MarkDonatPaid(ctx, body.OrderID)
|
err = donatService.MarkDonatPaid(ctx, body.OrderID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
slog.Error(err.Error())
|
slog.Error(err.Error())
|
||||||
return request.JSON(http.StatusInternalServerError, err.Error())
|
return request.JSON(http.StatusInternalServerError, err.Error())
|
||||||
|
@ -268,6 +268,52 @@ const docTemplate = `{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"/donat/paid": {
|
||||||
|
"post": {
|
||||||
|
"description": "Mark donat as paid",
|
||||||
|
"consumes": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"tags": [
|
||||||
|
"Donate"
|
||||||
|
],
|
||||||
|
"summary": "Mark donat as paid",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"description": "order id body",
|
||||||
|
"name": "request",
|
||||||
|
"in": "body",
|
||||||
|
"required": true,
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/donat-widget_internal_model.MarkDonatPaidBody"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "Ok",
|
||||||
|
"schema": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"400": {
|
||||||
|
"description": "Некорректный формат streamerID",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/echo.HTTPError"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"500": {
|
||||||
|
"description": "Внутренняя ошибка сервера",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/echo.HTTPError"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"/donat/period-stat": {
|
"/donat/period-stat": {
|
||||||
"get": {
|
"get": {
|
||||||
"security": [
|
"security": [
|
||||||
@ -1559,6 +1605,14 @@ const docTemplate = `{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"donat-widget_internal_model.MarkDonatPaidBody": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"order_id": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"donat-widget_internal_model.ModerationDonat": {
|
"donat-widget_internal_model.ModerationDonat": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
|
@ -261,6 +261,52 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"/donat/paid": {
|
||||||
|
"post": {
|
||||||
|
"description": "Mark donat as paid",
|
||||||
|
"consumes": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"tags": [
|
||||||
|
"Donate"
|
||||||
|
],
|
||||||
|
"summary": "Mark donat as paid",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"description": "order id body",
|
||||||
|
"name": "request",
|
||||||
|
"in": "body",
|
||||||
|
"required": true,
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/donat-widget_internal_model.MarkDonatPaidBody"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"200": {
|
||||||
|
"description": "Ok",
|
||||||
|
"schema": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"400": {
|
||||||
|
"description": "Некорректный формат streamerID",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/echo.HTTPError"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"500": {
|
||||||
|
"description": "Внутренняя ошибка сервера",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/echo.HTTPError"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"/donat/period-stat": {
|
"/donat/period-stat": {
|
||||||
"get": {
|
"get": {
|
||||||
"security": [
|
"security": [
|
||||||
@ -1552,6 +1598,14 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"donat-widget_internal_model.MarkDonatPaidBody": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"order_id": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"donat-widget_internal_model.ModerationDonat": {
|
"donat-widget_internal_model.ModerationDonat": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
|
@ -317,6 +317,11 @@ definitions:
|
|||||||
ru_name:
|
ru_name:
|
||||||
type: string
|
type: string
|
||||||
type: object
|
type: object
|
||||||
|
donat-widget_internal_model.MarkDonatPaidBody:
|
||||||
|
properties:
|
||||||
|
order_id:
|
||||||
|
type: string
|
||||||
|
type: object
|
||||||
donat-widget_internal_model.ModerationDonat:
|
donat-widget_internal_model.ModerationDonat:
|
||||||
properties:
|
properties:
|
||||||
accepted:
|
accepted:
|
||||||
@ -660,6 +665,36 @@ paths:
|
|||||||
summary: Create donat
|
summary: Create donat
|
||||||
tags:
|
tags:
|
||||||
- Donate
|
- Donate
|
||||||
|
/donat/paid:
|
||||||
|
post:
|
||||||
|
consumes:
|
||||||
|
- application/json
|
||||||
|
description: Mark donat as paid
|
||||||
|
parameters:
|
||||||
|
- description: order id body
|
||||||
|
in: body
|
||||||
|
name: request
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/donat-widget_internal_model.MarkDonatPaidBody'
|
||||||
|
produces:
|
||||||
|
- application/json
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: Ok
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
|
"400":
|
||||||
|
description: Некорректный формат streamerID
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/echo.HTTPError'
|
||||||
|
"500":
|
||||||
|
description: Внутренняя ошибка сервера
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/echo.HTTPError'
|
||||||
|
summary: Mark donat as paid
|
||||||
|
tags:
|
||||||
|
- Donate
|
||||||
/donat/period-stat:
|
/donat/period-stat:
|
||||||
get:
|
get:
|
||||||
consumes:
|
consumes:
|
||||||
|
@ -302,6 +302,10 @@ type ModerationDonat struct {
|
|||||||
ShowName *bool `json:"show_name"`
|
ShowName *bool `json:"show_name"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type MarkDonatPaidBody struct {
|
||||||
|
OrderID string `json:"order_id"`
|
||||||
|
}
|
||||||
|
|
||||||
//func (widget *GetWidgetDb) GetMediaUrl(mediaType MediaType) MediaUrl {
|
//func (widget *GetWidgetDb) GetMediaUrl(mediaType MediaType) MediaUrl {
|
||||||
// var mediaUrl MediaUrl
|
// var mediaUrl MediaUrl
|
||||||
// if mediaType == "background_url" {
|
// if mediaType == "background_url" {
|
||||||
|
@ -37,6 +37,7 @@ CREATE TABLE IF NOT EXISTS donats (
|
|||||||
widget_id INTEGER REFERENCES widgets(id) NOT NULL,
|
widget_id INTEGER REFERENCES widgets(id) NOT NULL,
|
||||||
order_id UUID NOT NULL,
|
order_id UUID NOT NULL,
|
||||||
target_id INTEGER,
|
target_id INTEGER,
|
||||||
|
paid_time TIMESTAMP,
|
||||||
|
|
||||||
status VARCHAR(50) NOT NULL DEFAULT 'pending',
|
status VARCHAR(50) NOT NULL DEFAULT 'pending',
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ WHERE id = (@id);
|
|||||||
`
|
`
|
||||||
var MarkDonatPaid = `
|
var MarkDonatPaid = `
|
||||||
UPDATE donats
|
UPDATE donats
|
||||||
SET paid = (@paid)
|
SET paid_time = now(), status = 'moderation'
|
||||||
WHERE order_id = (@order_id);
|
WHERE order_id = (@order_id);
|
||||||
`
|
`
|
||||||
var GetDonatByStreamerID = `
|
var GetDonatByStreamerID = `
|
||||||
|
@ -130,7 +130,6 @@ func (repoDonat *RepoDonat) MarkDonatPaid(
|
|||||||
) error {
|
) error {
|
||||||
args := pgx.NamedArgs{
|
args := pgx.NamedArgs{
|
||||||
"order_id": orderID,
|
"order_id": orderID,
|
||||||
"paid": true,
|
|
||||||
}
|
}
|
||||||
err := repoDonat.db.Update(ctx, sql.MarkDonatPaid, args)
|
err := repoDonat.db.Update(ctx, sql.MarkDonatPaid, args)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user