add field for crete widget file
This commit is contained in:
parent
aa993278b9
commit
f46205d2ba
@ -41,6 +41,11 @@ func (pg *Postgres) Insert(ctx context.Context, query string, args ...interface{
|
||||
return id, nil
|
||||
}
|
||||
|
||||
func (pg *Postgres) InsertReturningObj(ctx context.Context, query string, args ...interface{}) pgx.Row {
|
||||
row := pg.db.QueryRow(ctx, query, args...)
|
||||
return row
|
||||
}
|
||||
|
||||
func (pg *Postgres) Select(ctx context.Context, query string, args ...interface{}) (pgx.Rows, error) {
|
||||
result, err := pg.db.Query(ctx, query, args...)
|
||||
if err != nil {
|
||||
|
@ -17,7 +17,7 @@ import (
|
||||
// @Produce json
|
||||
// @Security BearerAuth
|
||||
// @Param new_file formData file false "New file"
|
||||
// @Success 200 {string} string "GetWidgetDb has been uploaded successfully!"
|
||||
// @Success 200 {object} model.DataFile "GetWidgetDb has been uploaded successfully!"
|
||||
// @Failure 400 {object} echo.HTTPError "Bad request"
|
||||
// @Failure 401 {object} echo.HTTPError "Unauthorized or expired token"
|
||||
// @Failure 422 {object} echo.HTTPError "Validation error"
|
||||
@ -41,7 +41,7 @@ func AddNewFile(fileService model.FileService) echo.HandlerFunc {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, "Can't upload file")
|
||||
}
|
||||
|
||||
_, err = fileService.AddNewFile(
|
||||
fileId, err := fileService.AddNewFile(
|
||||
ctx,
|
||||
*newFile,
|
||||
authData.AccountID,
|
||||
@ -51,8 +51,13 @@ func AddNewFile(fileService model.FileService) echo.HandlerFunc {
|
||||
slog.Error(err.Error())
|
||||
return request.JSON(http.StatusInternalServerError, err.Error())
|
||||
}
|
||||
fileResponse, err := fileService.GetFileInfo(ctx, fileId)
|
||||
if err != nil {
|
||||
slog.Error(err.Error())
|
||||
return request.JSON(http.StatusInternalServerError, err.Error())
|
||||
}
|
||||
|
||||
return request.JSON(http.StatusOK, "")
|
||||
return request.JSON(http.StatusOK, fileResponse)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -421,7 +421,7 @@ const docTemplate = `{
|
||||
"200": {
|
||||
"description": "GetWidgetDb has been uploaded successfully!",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
"$ref": "#/definitions/donat-widget_internal_model.DataFile"
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
|
@ -414,7 +414,7 @@
|
||||
"200": {
|
||||
"description": "GetWidgetDb has been uploaded successfully!",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
"$ref": "#/definitions/donat-widget_internal_model.DataFile"
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
|
@ -732,7 +732,7 @@ paths:
|
||||
"200":
|
||||
description: GetWidgetDb has been uploaded successfully!
|
||||
schema:
|
||||
type: string
|
||||
$ref: '#/definitions/donat-widget_internal_model.DataFile'
|
||||
"400":
|
||||
description: Bad request
|
||||
schema:
|
||||
|
@ -192,6 +192,7 @@ type PaymentClient interface {
|
||||
}
|
||||
type Db interface {
|
||||
Insert(ctx context.Context, query string, args ...interface{}) (any, error)
|
||||
InsertReturningObj(ctx context.Context, query string, args ...interface{}) pgx.Row
|
||||
Select(ctx context.Context, query string, args ...interface{}) (pgx.Rows, error)
|
||||
SelectOne(ctx context.Context, query string, args ...interface{}) (pgx.Row, error)
|
||||
Delete(ctx context.Context, query string, args ...interface{}) error
|
||||
@ -216,6 +217,7 @@ type FileRepo interface {
|
||||
) (string, error)
|
||||
GetByID(ctx context.Context, fileID string) ([]byte, string, error)
|
||||
WidgetsFiles(ctx context.Context, fileType string, streamerID int) ([]*DataFile, error)
|
||||
GetFileInfoById(ctx context.Context, fileID string) (DataFile, error)
|
||||
}
|
||||
|
||||
type FileService interface {
|
||||
@ -229,4 +231,5 @@ type FileService interface {
|
||||
) (string, error)
|
||||
GetByID(ctx context.Context, fileID string) ([]byte, string, error)
|
||||
WidgetsFiles(ctx context.Context, fileType string, streamerID int) ([]*DataFile, error)
|
||||
GetFileInfo(ctx context.Context, fileID string) (DataFile, error)
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ import (
|
||||
)
|
||||
|
||||
var CreateWidget = `
|
||||
INSERT INTO widgets (streamer_id, template_id, image, audio, duration, min_amount, max_amount name)
|
||||
INSERT INTO widgets (streamer_id, template_id, image, audio, duration, min_amount, max_amount, name)
|
||||
VALUES (@streamer_id, @template_id, @image, @audio, @duration, @min_amount, @max_amount, @name)
|
||||
RETURNING id;
|
||||
`
|
||||
@ -190,6 +190,9 @@ var GetWidgetByName = `SELECT id FROM widgets WHERE (
|
||||
|
||||
var FileById = `SELECT file_name, streamer_id, file_type FROM files WHERE id = (@id);`
|
||||
|
||||
var FileInfoById = `SELECT id, file_type, file_name, extension, streamer_id, entity, created_at, size
|
||||
FROM files WHERE id = (@id);`
|
||||
|
||||
var AudioFilesWidgets = `
|
||||
SELECT *
|
||||
FROM files
|
||||
|
@ -126,3 +126,31 @@ func (fileRepo *RepoFile) WidgetsFiles(
|
||||
|
||||
return files, nil
|
||||
}
|
||||
|
||||
func (fileRepo *RepoFile) GetFileInfoById(
|
||||
ctx context.Context,
|
||||
fileID string,
|
||||
) (model.DataFile, error) {
|
||||
args := pgx.NamedArgs{
|
||||
"id": fileID,
|
||||
}
|
||||
row, err := fileRepo.db.SelectOne(ctx, sql.FileInfoById, args)
|
||||
if err != nil {
|
||||
return model.DataFile{}, fmt.Errorf("error retrieving file info: %v", err)
|
||||
}
|
||||
var dataFile model.DataFile
|
||||
err = row.Scan(
|
||||
&dataFile.ID,
|
||||
&dataFile.FileType,
|
||||
&dataFile.FileName,
|
||||
&dataFile.Extension,
|
||||
&dataFile.StreamerID,
|
||||
&dataFile.Entity,
|
||||
&dataFile.CreatedAt,
|
||||
&dataFile.Size,
|
||||
)
|
||||
if err != nil {
|
||||
return model.DataFile{}, fmt.Errorf("error retrieving file info: %v", err)
|
||||
}
|
||||
return dataFile, nil
|
||||
}
|
||||
|
@ -59,6 +59,19 @@ func (fileService *ServiceFile) AddNewFile(
|
||||
return fileID, nil
|
||||
}
|
||||
|
||||
func (fileService *ServiceFile) GetFileInfo(
|
||||
ctx context.Context,
|
||||
fileID string,
|
||||
) (model.DataFile, error) {
|
||||
fileData, err := fileService.fileRepo.GetFileInfoById(ctx, fileID)
|
||||
if err != nil {
|
||||
return model.DataFile{}, err
|
||||
}
|
||||
fileData.FileLink = fileService.storage.DownloadLink(fileData.ID)
|
||||
|
||||
return fileData, nil
|
||||
}
|
||||
|
||||
func (fileService *ServiceFile) GetByID(
|
||||
ctx context.Context,
|
||||
fileID string,
|
||||
|
Loading…
x
Reference in New Issue
Block a user