add router for get all streamers widgets
This commit is contained in:
parent
70269a3bb4
commit
d6d6ce73dc
@ -93,6 +93,10 @@ func GetStreamersWidgets(widgetService model.WidgetService) echo.HandlerFunc {
|
|||||||
return request.JSON(http.StatusInternalServerError, err.Error())
|
return request.JSON(http.StatusInternalServerError, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if widgets == nil {
|
||||||
|
return request.JSON(http.StatusOK, []string{})
|
||||||
|
}
|
||||||
|
|
||||||
return request.JSON(http.StatusOK, widgets)
|
return request.JSON(http.StatusOK, widgets)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@ type WidgetService interface {
|
|||||||
audio string,
|
audio string,
|
||||||
name string,
|
name string,
|
||||||
) (WidgetID, error)
|
) (WidgetID, error)
|
||||||
GetWidgetsByStreamer(ctx context.Context, streamerID int) ([]*GetWidgetDb, error)
|
GetWidgetsByStreamer(ctx context.Context, streamerID int) ([]*WidgetWithFileLink, error)
|
||||||
|
|
||||||
//GetWidgetByID(ctx context.Context, widgetID WidgetID) ([]*GetWidgetDb, error)
|
//GetWidgetByID(ctx context.Context, widgetID WidgetID) ([]*GetWidgetDb, error)
|
||||||
//GetWidgetHTML(ctx context.Context, streamerID StreamerID) (WidgetHTML, error)
|
//GetWidgetHTML(ctx context.Context, streamerID StreamerID) (WidgetHTML, error)
|
||||||
|
@ -1,26 +1,37 @@
|
|||||||
package model
|
package model
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/google/uuid"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
type GetWidgetDb struct {
|
type GetWidgetDb struct {
|
||||||
ID int `db:"id"`
|
ID int `db:"id" json:"id"`
|
||||||
StreamerID int `db:"streamer_id"`
|
StreamerID int `db:"streamer_id" json:"streamer_id"`
|
||||||
TemplateID int `db:"template_id"`
|
TemplateID int `db:"template_id" json:"template_id"`
|
||||||
Duration int `db:"duration"`
|
Duration int `db:"duration" json:"duration"`
|
||||||
MinAmount int `db:"min_amount"`
|
MinAmount int `db:"min_amount" json:"min_amount"`
|
||||||
MaxAmount int `db:"max_amount"`
|
MaxAmount int `db:"max_amount" json:"max_amount"`
|
||||||
CreatedAt time.Time `db:"created_at"`
|
CreatedAt time.Time `db:"created_at" json:"created_at"`
|
||||||
UpdatedAt time.Time `db:"updated_at"`
|
UpdatedAt time.Time `db:"updated_at" json:"updated_at"`
|
||||||
|
GroupID int `db:"group_id" json:"group_id"`
|
||||||
|
|
||||||
// Поля для изображения
|
// Поля для изображения
|
||||||
ImageFileName string `db:"image_file_name"`
|
ImageFileId uuid.UUID `db:"image_id" json:"image_id"`
|
||||||
ImageType string `db:"image_type"`
|
ImageFileName string `db:"image_file_name" json:"image_file_name"`
|
||||||
|
ImageType string `db:"image_type" json:"image_type"`
|
||||||
|
ImageLink string `json:"image_link"`
|
||||||
|
|
||||||
// Поля для аудио
|
// Поля для аудио
|
||||||
AudioFileName string `db:"audio_file_name"`
|
AudioFileId uuid.UUID `db:"audio_id" json:"audio_id"`
|
||||||
AudioType string `db:"audio_type"`
|
AudioFileName string `db:"audio_file_name" json:"audio_file_name"`
|
||||||
|
AudioType string `db:"audio_type" json:"audio_type"`
|
||||||
|
AudioLink string `json:"audio_link"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type WidgetWithFileLink struct {
|
||||||
|
GroupID int `json:"group_id"`
|
||||||
|
Widgets []*GetWidgetDb `json:"widgets"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Donat struct {
|
type Donat struct {
|
||||||
|
@ -5,6 +5,7 @@ CREATE TABLE IF NOT EXISTS widgets (
|
|||||||
id SERIAL PRIMARY KEY,
|
id SERIAL PRIMARY KEY,
|
||||||
streamer_id INTEGER NOT NULL,
|
streamer_id INTEGER NOT NULL,
|
||||||
template_id INTEGER,
|
template_id INTEGER,
|
||||||
|
group_id INTEGER NOT NULL DEFAULT 1,
|
||||||
|
|
||||||
name VARCHAR(50) NOT NULL,
|
name VARCHAR(50) NOT NULL,
|
||||||
image UUID REFERENCES files(id) NOT NULL ON DELETE CASCADE,
|
image UUID REFERENCES files(id) NOT NULL ON DELETE CASCADE,
|
||||||
|
@ -96,8 +96,10 @@ SELECT
|
|||||||
w.id,
|
w.id,
|
||||||
w.streamer_id,
|
w.streamer_id,
|
||||||
w.template_id,
|
w.template_id,
|
||||||
|
img.id AS image_id,
|
||||||
img.file_name AS image_file_name,
|
img.file_name AS image_file_name,
|
||||||
img.file_type AS image_type,
|
img.file_type AS image_type,
|
||||||
|
audio.id AS audio_id,
|
||||||
audio.file_name AS audio_file_name,
|
audio.file_name AS audio_file_name,
|
||||||
audio.file_type AS audio_type,
|
audio.file_type AS audio_type,
|
||||||
w.duration,
|
w.duration,
|
||||||
|
@ -70,15 +70,31 @@ func (widgetService *ServiceWidget) CreateWidget(
|
|||||||
func (widgetService *ServiceWidget) GetWidgetsByStreamer(
|
func (widgetService *ServiceWidget) GetWidgetsByStreamer(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
streamerID int,
|
streamerID int,
|
||||||
) ([]*model.GetWidgetDb, error) {
|
) ([]*model.WidgetWithFileLink, error) {
|
||||||
|
widgets, err := widgetService.widgetRepo.GetWidgetsByStreamerID(ctx, streamerID)
|
||||||
widget, err := widgetService.widgetRepo.GetWidgetsByStreamerID(ctx, streamerID)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
slog.Error(err.Error())
|
slog.Error(err.Error())
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return widget, nil
|
groupedWidgets := make(map[int][]*model.GetWidgetDb)
|
||||||
|
|
||||||
|
for _, widget := range widgets {
|
||||||
|
widget.AudioLink = fmt.Sprintf("http://localhost/%d", widget.AudioFileId)
|
||||||
|
widget.ImageLink = fmt.Sprintf("http://localhost/%d", widget.ImageLink)
|
||||||
|
|
||||||
|
groupedWidgets[widget.GroupID] = append(groupedWidgets[widget.GroupID], widget)
|
||||||
|
}
|
||||||
|
|
||||||
|
var result []*model.WidgetWithFileLink
|
||||||
|
for groupID, widgets := range groupedWidgets {
|
||||||
|
result = append(result, &model.WidgetWithFileLink{
|
||||||
|
GroupID: groupID,
|
||||||
|
Widgets: widgets,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
Loading…
x
Reference in New Issue
Block a user