add rotuer for out donate page response
This commit is contained in:
parent
6f2ca61d91
commit
86e8341f59
@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"donat-widget/internal/model"
|
||||
"donat-widget/pkg/validator"
|
||||
"donat-widget/pkg/custom_response"
|
||||
"fmt"
|
||||
"github.com/google/uuid"
|
||||
"github.com/labstack/echo/v4"
|
||||
@ -153,15 +154,24 @@ func GetInnerDonatePage(donatService model.DonatService) echo.HandlerFunc {
|
||||
// @Tags Donate
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param streamer-login path string true "Login стримера"
|
||||
// @Success 200 {object} model.OuterDonatePageResponse "Current donate page state"
|
||||
// @Failure 400 {object} echo.HTTPError "Bad request"
|
||||
// @Failure 401 {object} echo.HTTPError "Unauthorized or expired token"
|
||||
// @Failure 422 {object} echo.HTTPError "Validation error"
|
||||
// @Router /outer-donate-page [get]
|
||||
// @Router /outer-donate-page/:streamer-login [get]
|
||||
func GetOuterDonatePage(donatService model.DonatService) echo.HandlerFunc {
|
||||
return func(request echo.Context) error {
|
||||
ctx := context.Background()
|
||||
streamerLogin := request.Param("streamer-login")
|
||||
|
||||
return nil
|
||||
outerPageResponse, err := donatService.GetOuterDonatPage(
|
||||
ctx, streamerLogin,
|
||||
)
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusInternalServerError, custom_response.InternalError)
|
||||
}
|
||||
return request.JSON(http.StatusOK, outerPageResponse)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -45,7 +45,7 @@ type DonatService interface {
|
||||
MarkDonatView(ctx context.Context, DonatID DonatID) error
|
||||
|
||||
GetInnerDonatPage(ctx context.Context, streamerID StreamerID) (InnerDonatePageResponse, error)
|
||||
GetOuterDonatPage(ctx context.Context, streamerID StreamerID) (OuterDonatePageResponse, error)
|
||||
GetOuterDonatPage(ctx context.Context, streamerLogin string) (OuterDonatePageResponse, error)
|
||||
UpdateDonatePage(ctx context.Context, streamerID StreamerID, updateModel UpdateDonatPage) error
|
||||
|
||||
GetVoiceSettings(ctx context.Context, streamerID StreamerID) (VoiceSettingsResponse, error)
|
||||
@ -68,6 +68,7 @@ type DonatRepo interface {
|
||||
MarkDonatView(ctx context.Context, DonatID DonatID) error
|
||||
|
||||
GetDonatPage(ctx context.Context, streamerID StreamerID) (DonatePage, error)
|
||||
GetDonatPageByLogin(ctx context.Context, streamerLogin string) (DonatePage, error)
|
||||
}
|
||||
|
||||
type TargetService interface {
|
||||
|
@ -57,9 +57,10 @@ type DonatePage struct {
|
||||
StreamerID int `db:"streamer_id"`
|
||||
Description string `db:"description"`
|
||||
TextAfterDonat string `db:"text_after_donat"`
|
||||
PageBackground string `db:"page_background"`
|
||||
HeadImg string `db:"head_img"`
|
||||
Avatar string `db:"avatar"`
|
||||
BackgroundImg string `db:"background_img"`
|
||||
StreamerLogin string `db:"streamer_login"`
|
||||
}
|
||||
|
||||
type Moderation struct {
|
||||
@ -72,15 +73,18 @@ type Moderation struct {
|
||||
type InnerDonatePageResponse struct {
|
||||
Description string `json:"description"`
|
||||
TextAfterDonat string `json:"textAfterDonat"`
|
||||
PageBackground string `json:"pageBackground"`
|
||||
HeadImg string `json:"headImg"`
|
||||
Avatar string `json:"avatar"`
|
||||
BackgroundImg string `json:"backgroundImg"`
|
||||
}
|
||||
|
||||
type OuterDonatePageResponse struct {
|
||||
Login string `json:"login"`
|
||||
OnLine string `json:"online"`
|
||||
Description string `json:"description"`
|
||||
Login string `json:"login"`
|
||||
OnLine string `json:"online"`
|
||||
Description string `json:"description"`
|
||||
BackgroundImg string `json:"background_url"`
|
||||
AvatarImg string `json:"avatar_url"`
|
||||
HeadImg string `json:"headImg"`
|
||||
}
|
||||
|
||||
type Filter struct {
|
||||
|
@ -49,12 +49,13 @@ CREATE TABLE IF NOT EXISTS targets (
|
||||
|
||||
CREATE TABLE IF NOT EXISTS donate_pages (
|
||||
id SERIAL PRIMARY KEY,
|
||||
streamer_login STRING NOT NULL,
|
||||
streamer_id INTEGER NOT NULL,
|
||||
description TEXT DEFAULT '',
|
||||
text_after_donat TEXT DEFAULT '',
|
||||
page_background TEXT DEFAULT '',
|
||||
avatar TEXT DEFAULT '',
|
||||
background_img TEXT DEFAULT '',
|
||||
head_img TEXT DEFAULT '',
|
||||
)
|
||||
|
||||
|
||||
|
@ -85,3 +85,7 @@ WHERE id = (@target_id);
|
||||
var GetDonationPage = `
|
||||
SELECT * FROM donate_pages WHERE streamer_id = (@streamer_id);
|
||||
`
|
||||
|
||||
var GetDonationPageByLogin = `
|
||||
SELECT * FROM donate_pages WHERE streamer_login = (@streamer_login);
|
||||
`
|
||||
|
@ -157,5 +157,30 @@ func (repoDonat *RepoDonat) GetDonatPage(
|
||||
}
|
||||
|
||||
return *donatePage[0], nil
|
||||
|
||||
}
|
||||
|
||||
func (repoDonat *RepoDonat) GetDonatPageByLogin(
|
||||
ctx context.Context,
|
||||
streamerLogin string,
|
||||
) (model.DonatePage, error) {
|
||||
args := pgx.NamedArgs{
|
||||
"streamer_login": streamerLogin,
|
||||
}
|
||||
rows, err := repoDonat.db.Select(ctx, sql.GetDonationPageByLogin, args)
|
||||
if err != nil {
|
||||
slog.Error(err.Error())
|
||||
return model.DonatePage{}, err
|
||||
}
|
||||
|
||||
var donatePage []*model.DonatePage
|
||||
err = pgxscan.ScanAll(&donatePage, rows)
|
||||
if err != nil {
|
||||
slog.Error(err.Error())
|
||||
return model.DonatePage{}, err
|
||||
}
|
||||
if len(donatePage) == 0 {
|
||||
return model.DonatePage{}, errors.New("donat not found")
|
||||
}
|
||||
|
||||
return *donatePage[0], nil
|
||||
}
|
||||
|
@ -160,7 +160,7 @@ func (donatService *ServiceDonat) GetInnerDonatPage(
|
||||
var innerDonatePageResponse = model.InnerDonatePageResponse{
|
||||
Description: donatePage.Description,
|
||||
TextAfterDonat: donatePage.TextAfterDonat,
|
||||
PageBackground: donatePage.PageBackground,
|
||||
HeadImg: donatePage.HeadImg,
|
||||
Avatar: donatePage.Avatar,
|
||||
BackgroundImg: donatePage.BackgroundImg,
|
||||
}
|
||||
@ -170,9 +170,23 @@ func (donatService *ServiceDonat) GetInnerDonatPage(
|
||||
|
||||
func (donatService *ServiceDonat) GetOuterDonatPage(
|
||||
ctx context.Context,
|
||||
streamerID model.StreamerID,
|
||||
streamerLogin string,
|
||||
) (model.OuterDonatePageResponse, error) {
|
||||
return model.OuterDonatePageResponse{}, nil
|
||||
donatePage, err := donatService.donatRepo.GetDonatPageByLogin(ctx, streamerLogin)
|
||||
if err != nil {
|
||||
slog.Error(err.Error())
|
||||
return model.OuterDonatePageResponse{}, err
|
||||
}
|
||||
|
||||
var outerDonatePageResponse = model.OuterDonatePageResponse{
|
||||
Description: donatePage.Description,
|
||||
Login: donatePage.StreamerLogin,
|
||||
OnLine: "online",
|
||||
BackgroundImg: donatePage.BackgroundImg,
|
||||
HeadImg: donatePage.HeadImg,
|
||||
AvatarImg: donatePage.Avatar,
|
||||
}
|
||||
return outerDonatePageResponse, nil
|
||||
}
|
||||
|
||||
func (donatService *ServiceDonat) UpdateDonatePage(
|
||||
|
Loading…
x
Reference in New Issue
Block a user