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())
|
||||
}
|
||||
|
||||
if widgets == nil {
|
||||
return request.JSON(http.StatusOK, []string{})
|
||||
}
|
||||
|
||||
return request.JSON(http.StatusOK, widgets)
|
||||
}
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ type WidgetService interface {
|
||||
audio string,
|
||||
name string,
|
||||
) (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)
|
||||
//GetWidgetHTML(ctx context.Context, streamerID StreamerID) (WidgetHTML, error)
|
||||
|
@ -1,26 +1,37 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"github.com/google/uuid"
|
||||
"time"
|
||||
)
|
||||
|
||||
type GetWidgetDb struct {
|
||||
ID int `db:"id"`
|
||||
StreamerID int `db:"streamer_id"`
|
||||
TemplateID int `db:"template_id"`
|
||||
Duration int `db:"duration"`
|
||||
MinAmount int `db:"min_amount"`
|
||||
MaxAmount int `db:"max_amount"`
|
||||
CreatedAt time.Time `db:"created_at"`
|
||||
UpdatedAt time.Time `db:"updated_at"`
|
||||
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"`
|
||||
|
||||
// Поля для изображения
|
||||
ImageFileName string `db:"image_file_name"`
|
||||
ImageType string `db:"image_type"`
|
||||
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"`
|
||||
|
||||
// Поля для аудио
|
||||
AudioFileName string `db:"audio_file_name"`
|
||||
AudioType string `db:"audio_type"`
|
||||
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"`
|
||||
}
|
||||
|
||||
type WidgetWithFileLink struct {
|
||||
GroupID int `json:"group_id"`
|
||||
Widgets []*GetWidgetDb `json:"widgets"`
|
||||
}
|
||||
|
||||
type Donat struct {
|
||||
|
@ -5,6 +5,7 @@ CREATE TABLE IF NOT EXISTS widgets (
|
||||
id SERIAL PRIMARY KEY,
|
||||
streamer_id INTEGER NOT NULL,
|
||||
template_id INTEGER,
|
||||
group_id INTEGER NOT NULL DEFAULT 1,
|
||||
|
||||
name VARCHAR(50) NOT NULL,
|
||||
image UUID REFERENCES files(id) NOT NULL ON DELETE CASCADE,
|
||||
|
@ -96,8 +96,10 @@ SELECT
|
||||
w.id,
|
||||
w.streamer_id,
|
||||
w.template_id,
|
||||
img.id AS image_id,
|
||||
img.file_name AS image_file_name,
|
||||
img.file_type AS image_type,
|
||||
audio.id AS audio_id,
|
||||
audio.file_name AS audio_file_name,
|
||||
audio.file_type AS audio_type,
|
||||
w.duration,
|
||||
|
@ -70,15 +70,31 @@ func (widgetService *ServiceWidget) CreateWidget(
|
||||
func (widgetService *ServiceWidget) GetWidgetsByStreamer(
|
||||
ctx context.Context,
|
||||
streamerID int,
|
||||
) ([]*model.GetWidgetDb, error) {
|
||||
|
||||
widget, err := widgetService.widgetRepo.GetWidgetsByStreamerID(ctx, streamerID)
|
||||
) ([]*model.WidgetWithFileLink, error) {
|
||||
widgets, err := widgetService.widgetRepo.GetWidgetsByStreamerID(ctx, streamerID)
|
||||
if err != nil {
|
||||
slog.Error(err.Error())
|
||||
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