diff --git a/internal/api/http/handlers/donat/donat.go b/internal/api/http/handlers/donat/donat.go index 0cec4a9..0f5839f 100644 --- a/internal/api/http/handlers/donat/donat.go +++ b/internal/api/http/handlers/donat/donat.go @@ -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"] } } diff --git a/internal/model/models.go b/internal/model/models.go index 0d07aef..09dabea 100644 --- a/internal/model/models.go +++ b/internal/model/models.go @@ -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 diff --git a/internal/model/sql/model.go b/internal/model/sql/model.go index 47e9b0a..5352182 100644 --- a/internal/model/sql/model.go +++ b/internal/model/sql/model.go @@ -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, diff --git a/pkg/validator/validator.go b/pkg/validator/validator.go index 02b0719..9974bec 100644 --- a/pkg/validator/validator.go +++ b/pkg/validator/validator.go @@ -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 +}