diff --git a/cmd/main.go b/cmd/main.go index 28f8c71..a12d752 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -4,6 +4,7 @@ import ( "context" "donat-widget/internal/app/http" "donat-widget/internal/config" + "donat-widget/internal/docs" "donat-widget/pkg/logger" ) @@ -23,9 +24,18 @@ import ( WidgetService "donat-widget/internal/service/widget" ) +// @title Donate Auth Documentation +// @version 3.0 +// @description Donate auth service docs. +// @BasePath /api/donat-wiget +// @securityDefinitions.apikey BearerAuth +// @in header +// @name Authorization + func main() { logger.New() cfg := config.Init() + docs.SwaggerInfo.Host = cfg.HOST // INFRASTRUCTURE db := pg.NewPgPool(context.Background(), cfg.Db.Username, cfg.Db.Password, cfg.Db.Host, cfg.Db.Port, cfg.Db.DBName) diff --git a/internal/api/http/handlers/donat/donat.go b/internal/api/http/handlers/donat/donat.go index b7eb735..a684e1a 100644 --- a/internal/api/http/handlers/donat/donat.go +++ b/internal/api/http/handlers/donat/donat.go @@ -129,6 +129,19 @@ func GetOuterDonatePage(donatService model.DonatService) echo.HandlerFunc { } } +// UpdateDonatePage godoc +// @Summary Update personal streamer donate page. +// @Description Update personal streamer donate page. +// @Tags Donate +// @Accept json +// @Produce json +// @Param request body model.UpdateDonatPage true "Update fields" +// @Param background formData file false "Background image" +// @Success 200 {string} string "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 /donat-page [patch] func UpdateDonatePage(donatService model.DonatService) echo.HandlerFunc { return func(c echo.Context) error { return nil diff --git a/internal/app/http/app.go b/internal/app/http/app.go index df40b0c..6a45540 100644 --- a/internal/app/http/app.go +++ b/internal/app/http/app.go @@ -2,6 +2,7 @@ package http import ( "context" + "github.com/labstack/echo/v4/middleware" "donat-widget/internal/model/sql" "github.com/labstack/echo/v4" @@ -30,8 +31,21 @@ func NewApp( authClient model.AuthClient, ) { server := echo.New() + + server.Use( + middleware.CORSWithConfig( + middleware.CORSConfig{ + AllowOrigins: []string{"*"}, // Разрешить все домены + AllowMethods: []string{"*"}, + AllowHeaders: []string{"*"}, + }, + ), + ) + server.Validator = validator.NewValidator() + server.GET(PREFIX+"/docs/*", echoSwagger.WrapHandler) + server.GET(PREFIX+"/docs/*", echoSwagger.WrapHandler) server.GET(PREFIX+"/table/create", CreateTale(db)) server.GET(PREFIX+"/table/drop", DropTale(db)) diff --git a/internal/docs/docs.go b/internal/docs/docs.go new file mode 100644 index 0000000..3c14b94 --- /dev/null +++ b/internal/docs/docs.go @@ -0,0 +1,127 @@ +// Package docs Code generated by swaggo/swag. DO NOT EDIT +package docs + +import "github.com/swaggo/swag" + +const docTemplate = `{ + "schemes": {{ marshal .Schemes }}, + "swagger": "2.0", + "info": { + "description": "{{escape .Description}}", + "title": "{{.Title}}", + "contact": {}, + "version": "{{.Version}}" + }, + "host": "{{.Host}}", + "basePath": "{{.BasePath}}", + "paths": { + "/donat-page": { + "patch": { + "description": "Update personal streamer donate page.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Donate" + ], + "summary": "Update personal streamer donate page.", + "parameters": [ + { + "description": "Update fields", + "name": "request", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/donat-widget_internal_model.UpdateDonatPage" + } + }, + { + "type": "file", + "description": "Background image", + "name": "background", + "in": "formData" + } + ], + "responses": { + "200": { + "description": "Donat page updated successfully", + "schema": { + "type": "string" + } + }, + "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" + } + } + } + } + } + }, + "definitions": { + "donat-widget_internal_model.UpdateDonatPage": { + "type": "object", + "properties": { + "description": { + "type": "string" + }, + "pageBackground": { + "type": "string" + }, + "profileAvatar": { + "type": "boolean" + }, + "textAfterDonat": { + "type": "string" + } + } + }, + "echo.HTTPError": { + "type": "object", + "properties": { + "message": {} + } + } + }, + "securityDefinitions": { + "BearerAuth": { + "type": "apiKey", + "name": "Authorization", + "in": "header" + } + } +}` + +// SwaggerInfo holds exported Swagger Info so clients can modify it +var SwaggerInfo = &swag.Spec{ + Version: "3.0", + Host: "", + BasePath: "/api/donat-wiget", + Schemes: []string{}, + Title: "Donate Auth Documentation", + Description: "Donate auth service docs.", + InfoInstanceName: "swagger", + SwaggerTemplate: docTemplate, + LeftDelim: "{{", + RightDelim: "}}", +} + +func init() { + swag.Register(SwaggerInfo.InstanceName(), SwaggerInfo) +} diff --git a/internal/docs/swagger.json b/internal/docs/swagger.json new file mode 100644 index 0000000..5d75654 --- /dev/null +++ b/internal/docs/swagger.json @@ -0,0 +1,102 @@ +{ + "swagger": "2.0", + "info": { + "description": "Donate auth service docs.", + "title": "Donate Auth Documentation", + "contact": {}, + "version": "3.0" + }, + "basePath": "/api/donat-wiget", + "paths": { + "/donat-page": { + "patch": { + "description": "Update personal streamer donate page.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Donate" + ], + "summary": "Update personal streamer donate page.", + "parameters": [ + { + "description": "Update fields", + "name": "request", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/donat-widget_internal_model.UpdateDonatPage" + } + }, + { + "type": "file", + "description": "Background image", + "name": "background", + "in": "formData" + } + ], + "responses": { + "200": { + "description": "Donat page updated successfully", + "schema": { + "type": "string" + } + }, + "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" + } + } + } + } + } + }, + "definitions": { + "donat-widget_internal_model.UpdateDonatPage": { + "type": "object", + "properties": { + "description": { + "type": "string" + }, + "pageBackground": { + "type": "string" + }, + "profileAvatar": { + "type": "boolean" + }, + "textAfterDonat": { + "type": "string" + } + } + }, + "echo.HTTPError": { + "type": "object", + "properties": { + "message": {} + } + } + }, + "securityDefinitions": { + "BearerAuth": { + "type": "apiKey", + "name": "Authorization", + "in": "header" + } + } +} \ No newline at end of file diff --git a/internal/docs/swagger.yaml b/internal/docs/swagger.yaml new file mode 100644 index 0000000..8fd9b01 --- /dev/null +++ b/internal/docs/swagger.yaml @@ -0,0 +1,67 @@ +basePath: /api/donat-wiget +definitions: + donat-widget_internal_model.UpdateDonatPage: + properties: + description: + type: string + pageBackground: + type: string + profileAvatar: + type: boolean + textAfterDonat: + type: string + type: object + echo.HTTPError: + properties: + message: {} + type: object +info: + contact: {} + description: Donate auth service docs. + title: Donate Auth Documentation + version: "3.0" +paths: + /donat-page: + patch: + consumes: + - application/json + description: Update personal streamer donate page. + parameters: + - description: Update fields + in: body + name: request + required: true + schema: + $ref: '#/definitions/donat-widget_internal_model.UpdateDonatPage' + - description: Background image + in: formData + name: background + type: file + produces: + - application/json + responses: + "200": + description: Donat page updated successfully + schema: + type: string + "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: Update personal streamer donate page. + tags: + - Donate +securityDefinitions: + BearerAuth: + in: header + name: Authorization + type: apiKey +swagger: "2.0" diff --git a/internal/model/models.go b/internal/model/models.go index 7182085..3f32dac 100644 --- a/internal/model/models.go +++ b/internal/model/models.go @@ -52,6 +52,13 @@ type Target struct { UpdatedAt time.Time `db:"updated_at"` } +type UpdateDonatPage struct { + ProfileAvatar bool `json:"profileAvatar"` + Description string `json:"description"` + TextAfterDonat string `json:"textAfterDonat"` + PageBackground string `json:"pageBackground"` +} + type DonatAndWidget struct { Widget *Widget Donat *Donat