From 131acf7182b220279dc0a647904f379336b18cf2 Mon Sep 17 00:00:00 2001 From: harold Date: Thu, 6 Mar 2025 14:02:08 +0500 Subject: [PATCH] add fixes for docs in get all streamers widgets --- internal/api/http/handlers/widget/widget.go | 2 +- internal/docs/docs.go | 99 ++++++++++++++++++++- internal/docs/swagger.json | 99 ++++++++++++++++++++- internal/docs/swagger.yaml | 78 +++++++++++++++- internal/model/models.go | 35 ++++---- internal/model/sql/model.go | 1 + 6 files changed, 287 insertions(+), 27 deletions(-) diff --git a/internal/api/http/handlers/widget/widget.go b/internal/api/http/handlers/widget/widget.go index b94999b..8b4678e 100644 --- a/internal/api/http/handlers/widget/widget.go +++ b/internal/api/http/handlers/widget/widget.go @@ -66,7 +66,7 @@ func CreateWidget(widgetService model.WidgetService) echo.HandlerFunc { // @Accept json // @Produce json // @Security BearerAuth -// @Success 200 {string} string "GetWidgetDb has been created successfully!" +// @Success 200 {array} model.GetWidgetDb "Success widgets response" // @Failure 400 {object} echo.HTTPError "Bad request" // @Failure 401 {object} echo.HTTPError "Unauthorized or expired token" // @Failure 422 {object} echo.HTTPError "Validation error" diff --git a/internal/docs/docs.go b/internal/docs/docs.go index 85a6595..8bc834d 100644 --- a/internal/docs/docs.go +++ b/internal/docs/docs.go @@ -153,7 +153,7 @@ const docTemplate = `{ "summary": "Get a file", "parameters": [ { - "type": "string", + "type": "integer", "description": "File ID", "name": "file_id", "in": "path", @@ -578,9 +578,12 @@ const docTemplate = `{ "summary": "Get all streamer's widgets", "responses": { "200": { - "description": "GetWidgetDb has been created successfully!", + "description": "Success widgets response", "schema": { - "type": "string" + "type": "array", + "items": { + "$ref": "#/definitions/donat-widget_internal_model.GetWidgetDb" + } } }, "400": { @@ -719,6 +722,96 @@ const docTemplate = `{ } } }, + "donat-widget_internal_model.GetWidgetDb": { + "type": "object", + "properties": { + "audio_file_name": { + "type": "string", + "example": "alert.mp3" + }, + "audio_id": { + "description": "Поля для аудио", + "type": "string", + "format": "uuid", + "example": "123e4567-e89b-12d3-a456-426614174000" + }, + "audio_link": { + "type": "string", + "example": "https://cdn.example.com/audio/123e4567-e89b-12d3-a456-426614174000" + }, + "audio_type": { + "type": "string", + "example": "audio/mp3" + }, + "created_at": { + "type": "string", + "format": "date-time", + "example": "2025-03-06T13:37:36Z" + }, + "duration": { + "type": "integer", + "format": "int64", + "example": 30 + }, + "group_id": { + "type": "integer", + "format": "int64", + "example": 2 + }, + "id": { + "type": "integer", + "format": "int64", + "example": 1 + }, + "image_file_name": { + "type": "string", + "example": "background.png" + }, + "image_id": { + "description": "Поля для изображения", + "type": "string", + "format": "uuid", + "example": "550e8400-e29b-41d4-a716-446655440000" + }, + "image_link": { + "type": "string", + "example": "https://cdn.example.com/images/550e8400-e29b-41d4-a716-446655440000" + }, + "image_type": { + "type": "string", + "example": "image/png" + }, + "is_active": { + "type": "boolean", + "example": true + }, + "max_amount": { + "type": "integer", + "format": "int64", + "example": 1000 + }, + "min_amount": { + "type": "integer", + "format": "int64", + "example": 100 + }, + "streamer_id": { + "type": "integer", + "format": "int64", + "example": 1001 + }, + "template_id": { + "type": "integer", + "format": "int64", + "example": 5 + }, + "updated_at": { + "type": "string", + "format": "date-time", + "example": "2025-03-07T10:15:30Z" + } + } + }, "donat-widget_internal_model.InnerDonatePageResponse": { "type": "object", "properties": { diff --git a/internal/docs/swagger.json b/internal/docs/swagger.json index e203e11..cdd8de0 100644 --- a/internal/docs/swagger.json +++ b/internal/docs/swagger.json @@ -146,7 +146,7 @@ "summary": "Get a file", "parameters": [ { - "type": "string", + "type": "integer", "description": "File ID", "name": "file_id", "in": "path", @@ -571,9 +571,12 @@ "summary": "Get all streamer's widgets", "responses": { "200": { - "description": "GetWidgetDb has been created successfully!", + "description": "Success widgets response", "schema": { - "type": "string" + "type": "array", + "items": { + "$ref": "#/definitions/donat-widget_internal_model.GetWidgetDb" + } } }, "400": { @@ -712,6 +715,96 @@ } } }, + "donat-widget_internal_model.GetWidgetDb": { + "type": "object", + "properties": { + "audio_file_name": { + "type": "string", + "example": "alert.mp3" + }, + "audio_id": { + "description": "Поля для аудио", + "type": "string", + "format": "uuid", + "example": "123e4567-e89b-12d3-a456-426614174000" + }, + "audio_link": { + "type": "string", + "example": "https://cdn.example.com/audio/123e4567-e89b-12d3-a456-426614174000" + }, + "audio_type": { + "type": "string", + "example": "audio/mp3" + }, + "created_at": { + "type": "string", + "format": "date-time", + "example": "2025-03-06T13:37:36Z" + }, + "duration": { + "type": "integer", + "format": "int64", + "example": 30 + }, + "group_id": { + "type": "integer", + "format": "int64", + "example": 2 + }, + "id": { + "type": "integer", + "format": "int64", + "example": 1 + }, + "image_file_name": { + "type": "string", + "example": "background.png" + }, + "image_id": { + "description": "Поля для изображения", + "type": "string", + "format": "uuid", + "example": "550e8400-e29b-41d4-a716-446655440000" + }, + "image_link": { + "type": "string", + "example": "https://cdn.example.com/images/550e8400-e29b-41d4-a716-446655440000" + }, + "image_type": { + "type": "string", + "example": "image/png" + }, + "is_active": { + "type": "boolean", + "example": true + }, + "max_amount": { + "type": "integer", + "format": "int64", + "example": 1000 + }, + "min_amount": { + "type": "integer", + "format": "int64", + "example": 100 + }, + "streamer_id": { + "type": "integer", + "format": "int64", + "example": 1001 + }, + "template_id": { + "type": "integer", + "format": "int64", + "example": 5 + }, + "updated_at": { + "type": "string", + "format": "date-time", + "example": "2025-03-07T10:15:30Z" + } + } + }, "donat-widget_internal_model.InnerDonatePageResponse": { "type": "object", "properties": { diff --git a/internal/docs/swagger.yaml b/internal/docs/swagger.yaml index 4302432..ca7e51a 100644 --- a/internal/docs/swagger.yaml +++ b/internal/docs/swagger.yaml @@ -43,6 +43,76 @@ definitions: type: string type: array type: object + donat-widget_internal_model.GetWidgetDb: + properties: + audio_file_name: + example: alert.mp3 + type: string + audio_id: + description: Поля для аудио + example: 123e4567-e89b-12d3-a456-426614174000 + format: uuid + type: string + audio_link: + example: https://cdn.example.com/audio/123e4567-e89b-12d3-a456-426614174000 + type: string + audio_type: + example: audio/mp3 + type: string + created_at: + example: "2025-03-06T13:37:36Z" + format: date-time + type: string + duration: + example: 30 + format: int64 + type: integer + group_id: + example: 2 + format: int64 + type: integer + id: + example: 1 + format: int64 + type: integer + image_file_name: + example: background.png + type: string + image_id: + description: Поля для изображения + example: 550e8400-e29b-41d4-a716-446655440000 + format: uuid + type: string + image_link: + example: https://cdn.example.com/images/550e8400-e29b-41d4-a716-446655440000 + type: string + image_type: + example: image/png + type: string + is_active: + example: true + type: boolean + max_amount: + example: 1000 + format: int64 + type: integer + min_amount: + example: 100 + format: int64 + type: integer + streamer_id: + example: 1001 + format: int64 + type: integer + template_id: + example: 5 + format: int64 + type: integer + updated_at: + example: "2025-03-07T10:15:30Z" + format: date-time + type: string + type: object donat-widget_internal_model.InnerDonatePageResponse: properties: avatar: @@ -231,7 +301,7 @@ paths: in: path name: file_id required: true - type: string + type: integer produces: - application/octet-stream responses: @@ -506,9 +576,11 @@ paths: - application/json responses: "200": - description: GetWidgetDb has been created successfully! + description: Success widgets response schema: - type: string + items: + $ref: '#/definitions/donat-widget_internal_model.GetWidgetDb' + type: array "400": description: Bad request schema: diff --git a/internal/model/models.go b/internal/model/models.go index d29f265..ecce281 100644 --- a/internal/model/models.go +++ b/internal/model/models.go @@ -6,27 +6,28 @@ import ( ) type GetWidgetDb struct { - ID int `db:"id" json:"id"` - StreamerID int `db:"streamer_id" json:"streamer_id"` - TemplateID int `db:"template_id" json:"template_id"` - Duration int `db:"duration" json:"duration"` - MinAmount int `db:"min_amount" json:"min_amount"` - MaxAmount int `db:"max_amount" json:"max_amount"` - CreatedAt time.Time `db:"created_at" json:"created_at"` - UpdatedAt time.Time `db:"updated_at" json:"updated_at"` - GroupID int `db:"group_id" json:"group_id"` + ID int `db:"id" json:"id" example:"1" format:"int64" description:"Unique identifier of the widget"` + StreamerID int `db:"streamer_id" json:"streamer_id" example:"1001" format:"int64" description:"ID of the streamer"` + TemplateID int `db:"template_id" json:"template_id" example:"5" format:"int64" description:"ID of the template"` + Duration int `db:"duration" json:"duration" example:"30" format:"int64" description:"Duration of the widget"` + MinAmount int `db:"min_amount" json:"min_amount" example:"100" format:"int64" description:"Minimum donation amount"` + MaxAmount int `db:"max_amount" json:"max_amount" example:"1000" format:"int64" description:"Maximum donation amount"` + CreatedAt time.Time `db:"created_at" json:"created_at" format:"date-time" example:"2025-03-06T13:37:36Z" description:"Timestamp when the widget was created"` + UpdatedAt time.Time `db:"updated_at" json:"updated_at" format:"date-time" example:"2025-03-07T10:15:30Z" description:"Timestamp when the widget was last updated"` + GroupID int `db:"group_id" json:"group_id" example:"2" format:"int64" description:"Group ID associated with the widget"` + IsActive bool `db:"is_active" json:"is_active" example:"true" description:"Whether or not this widget is active"` // Поля для изображения - ImageFileId uuid.UUID `db:"image_id" json:"image_id"` - ImageFileName string `db:"image_file_name" json:"image_file_name"` - ImageType string `db:"image_type" json:"image_type"` - ImageLink string `json:"image_link"` + ImageFileId uuid.UUID `db:"image_id" json:"image_id" format:"uuid" example:"550e8400-e29b-41d4-a716-446655440000" description:"UUID of the image file"` + ImageFileName string `db:"image_file_name" json:"image_file_name" example:"background.png" description:"Name of the image file"` + ImageType string `db:"image_type" json:"image_type" example:"image/png" description:"Type of the image file"` + ImageLink string `json:"image_link" example:"https://cdn.example.com/images/550e8400-e29b-41d4-a716-446655440000" description:"Public URL of the image"` // Поля для аудио - AudioFileId uuid.UUID `db:"audio_id" json:"audio_id"` - AudioFileName string `db:"audio_file_name" json:"audio_file_name"` - AudioType string `db:"audio_type" json:"audio_type"` - AudioLink string `json:"audio_link"` + AudioFileId uuid.UUID `db:"audio_id" json:"audio_id" format:"uuid" example:"123e4567-e89b-12d3-a456-426614174000" description:"UUID of the audio file"` + AudioFileName string `db:"audio_file_name" json:"audio_file_name" example:"alert.mp3" description:"Name of the audio file"` + AudioType string `db:"audio_type" json:"audio_type" example:"audio/mp3" description:"Type of the audio file"` + AudioLink string `json:"audio_link" example:"https://cdn.example.com/audio/123e4567-e89b-12d3-a456-426614174000" description:"Public URL of the audio"` } type WidgetWithFileLink struct { diff --git a/internal/model/sql/model.go b/internal/model/sql/model.go index 2f23105..b532162 100644 --- a/internal/model/sql/model.go +++ b/internal/model/sql/model.go @@ -6,6 +6,7 @@ CREATE TABLE IF NOT EXISTS widgets ( streamer_id INTEGER NOT NULL, template_id INTEGER, group_id INTEGER NOT NULL DEFAULT 1, + is_active BOOLEAN NOT NULL DEFAULT "true", name VARCHAR(50) NOT NULL, image UUID REFERENCES files(id) NOT NULL ON DELETE CASCADE,