add default widget

This commit is contained in:
harold 2025-04-20 15:28:41 +05:00
parent b62bfb89f9
commit e0dc89fe8d
4 changed files with 44 additions and 1 deletions

View File

@ -24,6 +24,7 @@ type ServiceDonat struct {
defaultAvatar string
defaultBackground string
defaultHead string
defaultWidgetID int
}
func New(
@ -39,6 +40,9 @@ func New(
var defaultAvatar = "25b2b94c-e5e6-49e4-9f40-d8814f632847"
var defaultBackground = "56527f54-87c0-4f4d-92b5-df6cb61b27d4"
var defaultHead = "fef345e0-ec9a-4c68-8f2a-dcccf660e640"
var defaultWidgetID = 0
return &ServiceDonat{
donatRepo: donatRepo,
widgetRepo: widgetRepo,
@ -51,6 +55,7 @@ func New(
defaultAvatar: defaultAvatar,
defaultBackground: defaultBackground,
defaultHead: defaultHead,
defaultWidgetID: defaultWidgetID,
}
}
@ -86,6 +91,8 @@ func (donatService *ServiceDonat) CreateDonat(
targetID *int,
amount int,
) (api.CreatePaymentResponse, error) {
amount = amount / 100 // Translate to rub.
donatePage, err := donatService.donatRepo.GetDonatPageByLogin(ctx, streamerLogin)
if err != nil {
slog.Error("Failed to get donate page", "error", err.Error())
@ -100,13 +107,14 @@ func (donatService *ServiceDonat) CreateDonat(
orderID := uuid.New()
var widgetID int
widgetID := donatService.defaultWidgetID
for _, widget := range widgets {
if amount >= widget.MinAmount && amount <= widget.MaxAmount {
widgetID = widget.ID
break
}
}
err = donatService.donatRepo.CreateDonat(
ctx, donatePage.StreamerID, targetID, widgetID, orderID, amount, text, donatUser,
)

View File

@ -179,6 +179,41 @@ VALUES (
);
INSERT INTO public.files (id, file_type, file_name, extension, streamer_id, size, entity)
VALUES (
'f84afcbf-2193-48de-af18-403660b8d10c',
'image/gif',
'default_widget_img.gif',
'.gif',
0,
512,
'widget'
);
INSERT INTO public.files (id, file_type, file_name, extension, streamer_id, size, entity)
VALUES (
'7d45d22f-91e5-44da-8e3b-88caa87b0054',
'audio/mpeg',
'default_sound_widget.mp3',
'.mp3',
0,
512,
'widget'
);
INSERT INTO public.widgets (id, streamer_id, name, image, audio, duration, min_amount, max_amount)
VALUES (
0,
0,
'Default widget',
'f84afcbf-2193-48de-af18-403660b8d10c',
'fef345e0-ec9a-4c68-8f2a-dcccf660e640',
10,
0,
9999999
);
INSERT INTO languages (id, iso_code, ru_name, en_name)
VALUES
(1, 'en', 'Английский', 'English'),

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 235 KiB