add models for json

This commit is contained in:
harold 2025-02-24 22:04:48 +05:00
parent 544dfcc2b4
commit 2d05ab2b55
4 changed files with 66 additions and 2 deletions

View File

@ -3,6 +3,7 @@ package donat
import (
"context"
"donat-widget/internal/model"
"donat-widget/pkg/validator"
"fmt"
"github.com/google/uuid"
"github.com/labstack/echo/v4"
@ -143,8 +144,21 @@ func GetOuterDonatePage(donatService model.DonatService) echo.HandlerFunc {
// @Failure 422 {object} echo.HTTPError "Validation error"
// @Router /donat-page [patch]
func UpdateDonatePage(donatService model.DonatService) echo.HandlerFunc {
return func(c echo.Context) error {
return nil
return func(request echo.Context) error {
var body model.UpdateDonatPage
err := validator.ParseAndValidate(&body, request)
if err != nil {
slog.Error(err.Error())
return echo.NewHTTPError(http.StatusUnprocessableEntity, "Unprocessable Entity")
}
form, err := request.MultipartForm()
if err != nil {
slog.Error(err.Error())
return echo.NewHTTPError(http.StatusUnprocessableEntity, "Unprocessable Entity")
}
backgroundFile, backgroundOk := form.File["background"]
avatarFile, avatarOk := form.File["avatar"]
}
}

View File

@ -110,6 +110,44 @@ type UpdateDonatPage struct {
PageBackground string `json:"pageBackground"`
}
type VoiceSettingsResponse struct {
Id int `json:"id"`
StreamerID int `json:"streamerID"`
VoiceSpeed int `json:"voiceSpeed"`
Scenery string `json:"scenery"`
VoiceSoundPercent int `json:"voiceSoundPercent"`
MinPrice int `json:"minPrice"`
}
type UpdateVoiceSettings struct {
Enable bool `json:"enable"`
VoiceSpeed int `json:"voiceSpeed"`
Scenery string `json:"scenery"`
VoiceSoundPercent int `json:"voiceSoundPercent"`
MinPrice int `json:"minPrice"`
}
type FilterSettingResponse struct {
EnableLinks bool `json:"enableLinks"`
FilteredWords []string `json:"filteredWords"`
}
type UpdateFilterSettings struct {
EnableLinks bool `json:"enableLinks"`
AddWords []string `json:"addWords"`
RemoveWords []string `json:"removeWords"`
}
type ModerationResponse struct {
Enable bool `json:"enable"`
Duration int `json:"duration"`
}
type UpdateModeration struct {
Enable bool `json:"enable"`
Duration int `json:"duration"`
}
type DonatAndWidget struct {
Widget *Widget
Donat *Donat

View File

@ -80,6 +80,7 @@ CREATE TABLE IF NOT EXISTS filters_words (
CREATE TABLE IF NOT EXISTS voice_settings (
id SERIAL PRIMARY KEY,
streamer_id INTEGER NOT NULL,
enable BOOLEAN DEFAULT FALSE,
voice_speed INTEGER NOT NULL,
scenery TEXT DEFAULT 'after_donat',
voice_sound_percent INTEGER NOT NULL,

View File

@ -2,6 +2,7 @@ package validator
import (
"errors"
"github.com/labstack/echo/v4"
"strings"
validator "github.com/go-playground/validator/v10"
@ -23,3 +24,13 @@ func (val *Validator) Validate(i interface{}) error {
err = errors.New(strings.Replace(err.Error(), "\n", ", ", -1))
return err
}
func ParseAndValidate(i interface{}, request echo.Context) error {
if err := request.Bind(i); err != nil {
return err
}
if err := request.Validate(i); err != nil {
return err
}
return nil
}