add update moderation router logic and some fixes
This commit is contained in:
parent
0586252a25
commit
7d421c24ab
@ -421,13 +421,34 @@ func GetModerationSettings(donatService model.DonatService) echo.HandlerFunc {
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Security BearerAuth
|
||||
// @Success 200 {object} model.UpdateModeration "Update moderation settings"
|
||||
// @Param request body model.UpdateModeration true "Update fields"
|
||||
// @Success 200 {string} string "Moderation settings updated successfully"
|
||||
// @Failure 400 {object} echo.HTTPError "Bad request"
|
||||
// @Failure 401 {object} echo.HTTPError "Unauthorized or expired token"
|
||||
// @Failure 422 {object} echo.HTTPError "Validation error"
|
||||
// @Router /moderation-settings [patch]
|
||||
func UpdateModerationSettings(donatService model.DonatService) echo.HandlerFunc {
|
||||
return func(c echo.Context) error {
|
||||
return nil
|
||||
return func(request echo.Context) error {
|
||||
ctx := context.Background()
|
||||
|
||||
var body model.UpdateModeration
|
||||
err := validator.ParseAndValidate(&body, request)
|
||||
if err != nil {
|
||||
slog.Error(err.Error())
|
||||
return echo.NewHTTPError(http.StatusUnprocessableEntity, "Unprocessable Entity")
|
||||
}
|
||||
|
||||
authData, err := donatService.CheckToken(request)
|
||||
if err != nil {
|
||||
slog.Error("Unauthorized")
|
||||
return echo.NewHTTPError(http.StatusUnauthorized, err.Error())
|
||||
}
|
||||
|
||||
donatService.UpdateModerationSettings(
|
||||
ctx,
|
||||
authData.AccountID,
|
||||
body,
|
||||
)
|
||||
return request.JSON(http.StatusOK, "Success update")
|
||||
}
|
||||
}
|
||||
|
@ -461,12 +461,23 @@ const docTemplate = `{
|
||||
"Donate"
|
||||
],
|
||||
"summary": "Update donat moderation settings",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "Update moderation settings",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "Update fields",
|
||||
"name": "request",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/donat-widget_internal_model.UpdateModeration"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "Moderation settings updated successfully",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "Bad request",
|
||||
|
@ -454,12 +454,23 @@
|
||||
"Donate"
|
||||
],
|
||||
"summary": "Update donat moderation settings",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "Update moderation settings",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "Update fields",
|
||||
"name": "request",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/donat-widget_internal_model.UpdateModeration"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "Moderation settings updated successfully",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "Bad request",
|
||||
|
@ -570,13 +570,20 @@ paths:
|
||||
consumes:
|
||||
- application/json
|
||||
description: Update donat moderation settings
|
||||
parameters:
|
||||
- description: Update fields
|
||||
in: body
|
||||
name: request
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/donat-widget_internal_model.UpdateModeration'
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: Update moderation settings
|
||||
description: Moderation settings updated successfully
|
||||
schema:
|
||||
$ref: '#/definitions/donat-widget_internal_model.UpdateModeration'
|
||||
type: string
|
||||
"400":
|
||||
description: Bad request
|
||||
schema:
|
||||
|
@ -97,7 +97,7 @@ type DonatService interface {
|
||||
UpdateFiltersSettings(ctx context.Context, streamerID int, updateModel UpdateFilterSettings) error
|
||||
|
||||
GetModerationSettings(ctx context.Context, streamerID int) (ModerationResponse, error)
|
||||
UpdateModerationSettings(ctx context.Context, streamerID StreamerID, updateModel UpdateModeration) error
|
||||
UpdateModerationSettings(ctx context.Context, streamerID int, updateModel UpdateModeration) error
|
||||
}
|
||||
|
||||
type DonatRepo interface {
|
||||
@ -137,6 +137,7 @@ type DonatRepo interface {
|
||||
GetFilterIDByStreamer(ctx context.Context, streamerID int) (int, error)
|
||||
|
||||
GetModeration(ctx context.Context, streamerID int) (ModerationResponse, error)
|
||||
UpdateModeration(ctx context.Context, streamerID int, enable *bool, duration *int) error
|
||||
}
|
||||
|
||||
type TargetService interface {
|
||||
|
@ -224,8 +224,8 @@ type ModerationResponse struct {
|
||||
}
|
||||
|
||||
type UpdateModeration struct {
|
||||
Enable bool `json:"enable"`
|
||||
Duration int `json:"duration"`
|
||||
Enable *bool `json:"enable"`
|
||||
Duration *int `json:"duration"`
|
||||
}
|
||||
|
||||
type CreateWidgetResponse struct {
|
||||
|
@ -303,7 +303,11 @@ WHERE donat_filter_id = @donat_filter_id AND word = ANY(@words);
|
||||
`
|
||||
|
||||
var UpdateModeration = `
|
||||
UPDATE moderation SET (enable, duration) VALUES (@enable, duration) WHERE streamer_id = @streamer_id;`
|
||||
|
||||
UPDATE moderation
|
||||
SET
|
||||
enable = COALESCE(@enable, enable),
|
||||
duration = COALESCE(@duration, duration)
|
||||
WHERE streamer_id = @streamer_id;
|
||||
`
|
||||
var GetModeration = `
|
||||
SELECT enable, duration FROM moderation WHERE streamer_id = @streamer_id;`
|
||||
|
@ -432,8 +432,19 @@ func (donatService *ServiceDonat) GetModerationSettings(
|
||||
|
||||
func (donatService *ServiceDonat) UpdateModerationSettings(
|
||||
ctx context.Context,
|
||||
streamerID model.StreamerID,
|
||||
streamerID int,
|
||||
updateModel model.UpdateModeration,
|
||||
) error {
|
||||
err := donatService.donatRepo.UpdateModeration(
|
||||
ctx,
|
||||
streamerID,
|
||||
updateModel.Enable,
|
||||
updateModel.Duration,
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
slog.Error("Failed to update moderation settings", "error", err)
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user