add router for get moderation settings
This commit is contained in:
parent
62b457d42b
commit
0586252a25
@ -389,14 +389,28 @@ func UpdateFiltersSettings(donatService model.DonatService) echo.HandlerFunc {
|
|||||||
// @Tags Donate
|
// @Tags Donate
|
||||||
// @Accept json
|
// @Accept json
|
||||||
// @Produce json
|
// @Produce json
|
||||||
|
// @Security BearerAuth
|
||||||
// @Success 200 {object} model.ModerationResponse "Current moderation settings"
|
// @Success 200 {object} model.ModerationResponse "Current moderation settings"
|
||||||
// @Failure 400 {object} echo.HTTPError "Bad request"
|
// @Failure 400 {object} echo.HTTPError "Bad request"
|
||||||
// @Failure 401 {object} echo.HTTPError "Unauthorized or expired token"
|
// @Failure 401 {object} echo.HTTPError "Unauthorized or expired token"
|
||||||
// @Failure 422 {object} echo.HTTPError "Validation error"
|
// @Failure 422 {object} echo.HTTPError "Validation error"
|
||||||
// @Router /moderation-settings [get]
|
// @Router /moderation-settings [get]
|
||||||
func GetModerationSettings(donatService model.DonatService) echo.HandlerFunc {
|
func GetModerationSettings(donatService model.DonatService) echo.HandlerFunc {
|
||||||
return func(c echo.Context) error {
|
return func(request echo.Context) error {
|
||||||
return nil
|
ctx := context.Background()
|
||||||
|
|
||||||
|
authData, err := donatService.CheckToken(request)
|
||||||
|
if err != nil {
|
||||||
|
slog.Error("Unauthorized")
|
||||||
|
return echo.NewHTTPError(http.StatusUnauthorized, err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
moderationSettings, err := donatService.GetModerationSettings(ctx, authData.AccountID)
|
||||||
|
if err != nil {
|
||||||
|
slog.Error("Failed to get moderation settings", "error", err)
|
||||||
|
return echo.NewHTTPError(http.StatusInternalServerError, "Internal server error")
|
||||||
|
}
|
||||||
|
return request.JSON(http.StatusOK, moderationSettings)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -406,6 +420,7 @@ func GetModerationSettings(donatService model.DonatService) echo.HandlerFunc {
|
|||||||
// @Tags Donate
|
// @Tags Donate
|
||||||
// @Accept json
|
// @Accept json
|
||||||
// @Produce json
|
// @Produce json
|
||||||
|
// @Security BearerAuth
|
||||||
// @Success 200 {object} model.UpdateModeration "Update moderation settings"
|
// @Success 200 {object} model.UpdateModeration "Update moderation settings"
|
||||||
// @Failure 400 {object} echo.HTTPError "Bad request"
|
// @Failure 400 {object} echo.HTTPError "Bad request"
|
||||||
// @Failure 401 {object} echo.HTTPError "Unauthorized or expired token"
|
// @Failure 401 {object} echo.HTTPError "Unauthorized or expired token"
|
||||||
|
@ -81,6 +81,9 @@ func IncludeDonatHandlers(
|
|||||||
server.GET(PREFIX+"/filters-settings", GetFiltersSettings(donatService))
|
server.GET(PREFIX+"/filters-settings", GetFiltersSettings(donatService))
|
||||||
server.PATCH(PREFIX+"/filters-settings", UpdateFiltersSettings(donatService))
|
server.PATCH(PREFIX+"/filters-settings", UpdateFiltersSettings(donatService))
|
||||||
|
|
||||||
|
server.GET(PREFIX+"/moderation-settings", GetModerationSettings(donatService))
|
||||||
|
server.PATCH(PREFIX+"/moderation-settings", UpdateModerationSettings(donatService))
|
||||||
|
|
||||||
server.GET(PREFIX+"/donat/get/:streamerID", GetDonat(donatService))
|
server.GET(PREFIX+"/donat/get/:streamerID", GetDonat(donatService))
|
||||||
|
|
||||||
server.POST(PREFIX+"/donat/view/:donatID", MarkDonatView(donatService))
|
server.POST(PREFIX+"/donat/view/:donatID", MarkDonatView(donatService))
|
||||||
|
@ -323,12 +323,6 @@ const docTemplate = `{
|
|||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/donat-widget_internal_model.UpdateFilterSettings"
|
"$ref": "#/definitions/donat-widget_internal_model.UpdateFilterSettings"
|
||||||
}
|
}
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "file",
|
|
||||||
"description": "Background image",
|
|
||||||
"name": "background",
|
|
||||||
"in": "formData"
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
@ -407,6 +401,11 @@ const docTemplate = `{
|
|||||||
},
|
},
|
||||||
"/moderation-settings": {
|
"/moderation-settings": {
|
||||||
"get": {
|
"get": {
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"BearerAuth": []
|
||||||
|
}
|
||||||
|
],
|
||||||
"description": "Get donat moderation settings",
|
"description": "Get donat moderation settings",
|
||||||
"consumes": [
|
"consumes": [
|
||||||
"application/json"
|
"application/json"
|
||||||
@ -446,6 +445,11 @@ const docTemplate = `{
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"patch": {
|
"patch": {
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"BearerAuth": []
|
||||||
|
}
|
||||||
|
],
|
||||||
"description": "Update donat moderation settings",
|
"description": "Update donat moderation settings",
|
||||||
"consumes": [
|
"consumes": [
|
||||||
"application/json"
|
"application/json"
|
||||||
|
@ -316,12 +316,6 @@
|
|||||||
"schema": {
|
"schema": {
|
||||||
"$ref": "#/definitions/donat-widget_internal_model.UpdateFilterSettings"
|
"$ref": "#/definitions/donat-widget_internal_model.UpdateFilterSettings"
|
||||||
}
|
}
|
||||||
},
|
|
||||||
{
|
|
||||||
"type": "file",
|
|
||||||
"description": "Background image",
|
|
||||||
"name": "background",
|
|
||||||
"in": "formData"
|
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
@ -400,6 +394,11 @@
|
|||||||
},
|
},
|
||||||
"/moderation-settings": {
|
"/moderation-settings": {
|
||||||
"get": {
|
"get": {
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"BearerAuth": []
|
||||||
|
}
|
||||||
|
],
|
||||||
"description": "Get donat moderation settings",
|
"description": "Get donat moderation settings",
|
||||||
"consumes": [
|
"consumes": [
|
||||||
"application/json"
|
"application/json"
|
||||||
@ -439,6 +438,11 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"patch": {
|
"patch": {
|
||||||
|
"security": [
|
||||||
|
{
|
||||||
|
"BearerAuth": []
|
||||||
|
}
|
||||||
|
],
|
||||||
"description": "Update donat moderation settings",
|
"description": "Update donat moderation settings",
|
||||||
"consumes": [
|
"consumes": [
|
||||||
"application/json"
|
"application/json"
|
||||||
|
@ -484,10 +484,6 @@ paths:
|
|||||||
required: true
|
required: true
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/donat-widget_internal_model.UpdateFilterSettings'
|
$ref: '#/definitions/donat-widget_internal_model.UpdateFilterSettings'
|
||||||
- description: Background image
|
|
||||||
in: formData
|
|
||||||
name: background
|
|
||||||
type: file
|
|
||||||
produces:
|
produces:
|
||||||
- application/json
|
- application/json
|
||||||
responses:
|
responses:
|
||||||
@ -565,6 +561,8 @@ paths:
|
|||||||
description: Validation error
|
description: Validation error
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/echo.HTTPError'
|
$ref: '#/definitions/echo.HTTPError'
|
||||||
|
security:
|
||||||
|
- BearerAuth: []
|
||||||
summary: Get donat moderation settings
|
summary: Get donat moderation settings
|
||||||
tags:
|
tags:
|
||||||
- Donate
|
- Donate
|
||||||
@ -591,6 +589,8 @@ paths:
|
|||||||
description: Validation error
|
description: Validation error
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/echo.HTTPError'
|
$ref: '#/definitions/echo.HTTPError'
|
||||||
|
security:
|
||||||
|
- BearerAuth: []
|
||||||
summary: Update donat moderation settings
|
summary: Update donat moderation settings
|
||||||
tags:
|
tags:
|
||||||
- Donate
|
- Donate
|
||||||
|
@ -96,7 +96,7 @@ type DonatService interface {
|
|||||||
GetFiltersSettings(ctx context.Context, streamerID int) (FilterSettingResponse, error)
|
GetFiltersSettings(ctx context.Context, streamerID int) (FilterSettingResponse, error)
|
||||||
UpdateFiltersSettings(ctx context.Context, streamerID int, updateModel UpdateFilterSettings) error
|
UpdateFiltersSettings(ctx context.Context, streamerID int, updateModel UpdateFilterSettings) error
|
||||||
|
|
||||||
GetModerationSettings(ctx context.Context, streamerID StreamerID) (ModerationResponse, error)
|
GetModerationSettings(ctx context.Context, streamerID int) (ModerationResponse, error)
|
||||||
UpdateModerationSettings(ctx context.Context, streamerID StreamerID, updateModel UpdateModeration) error
|
UpdateModerationSettings(ctx context.Context, streamerID StreamerID, updateModel UpdateModeration) error
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -135,6 +135,8 @@ type DonatRepo interface {
|
|||||||
AddFilteredWords(ctx context.Context, filterID int, words []string) error
|
AddFilteredWords(ctx context.Context, filterID int, words []string) error
|
||||||
RemoveFilteredWords(ctx context.Context, filterID int, words []string) error
|
RemoveFilteredWords(ctx context.Context, filterID int, words []string) error
|
||||||
GetFilterIDByStreamer(ctx context.Context, streamerID int) (int, error)
|
GetFilterIDByStreamer(ctx context.Context, streamerID int) (int, error)
|
||||||
|
|
||||||
|
GetModeration(ctx context.Context, streamerID int) (ModerationResponse, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type TargetService interface {
|
type TargetService interface {
|
||||||
|
@ -301,3 +301,9 @@ var DeleteFilteredWordsBatch = `
|
|||||||
DELETE FROM filters_words
|
DELETE FROM filters_words
|
||||||
WHERE donat_filter_id = @donat_filter_id AND word = ANY(@words);
|
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;`
|
||||||
|
|
||||||
|
var GetModeration = `
|
||||||
|
SELECT enable, duration FROM moderation WHERE streamer_id = @streamer_id;`
|
||||||
|
@ -559,3 +559,46 @@ func (repoDonat *RepoDonat) RemoveFilteredWords(
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (repoDonat *RepoDonat) GetModeration(ctx context.Context, streamerID int) (model.ModerationResponse, error) {
|
||||||
|
args := pgx.NamedArgs{
|
||||||
|
"streamer_id": streamerID,
|
||||||
|
}
|
||||||
|
row, err := repoDonat.db.SelectOne(ctx, sql.GetModeration, args)
|
||||||
|
if err != nil {
|
||||||
|
slog.Error("Failed to get moderation state", "error", err)
|
||||||
|
return model.ModerationResponse{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
var response model.ModerationResponse
|
||||||
|
err = row.Scan(&response.Enable, &response.Duration)
|
||||||
|
if err != nil {
|
||||||
|
slog.Error("Failed to get moderation state", "error", err)
|
||||||
|
return model.ModerationResponse{}, err
|
||||||
|
}
|
||||||
|
return response, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (repoDonat *RepoDonat) UpdateModeration(
|
||||||
|
ctx context.Context,
|
||||||
|
streamerID int,
|
||||||
|
enable *bool,
|
||||||
|
duration *int,
|
||||||
|
) error {
|
||||||
|
args := pgx.NamedArgs{
|
||||||
|
"streamer_id": streamerID,
|
||||||
|
}
|
||||||
|
|
||||||
|
if enable != nil {
|
||||||
|
args["enable"] = enable
|
||||||
|
}
|
||||||
|
if duration != nil {
|
||||||
|
args["duration"] = duration
|
||||||
|
}
|
||||||
|
err := repoDonat.db.Exec(ctx, sql.UpdateModeration, args)
|
||||||
|
if err != nil {
|
||||||
|
slog.Error("Failed to update moderation state", "error", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
@ -416,9 +416,18 @@ func (donatService *ServiceDonat) UpdateFiltersSettings(
|
|||||||
|
|
||||||
func (donatService *ServiceDonat) GetModerationSettings(
|
func (donatService *ServiceDonat) GetModerationSettings(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
streamerID model.StreamerID,
|
streamerID int,
|
||||||
) (model.ModerationResponse, error) {
|
) (model.ModerationResponse, error) {
|
||||||
return model.ModerationResponse{}, nil
|
moderationModel, err := donatService.donatRepo.GetModeration(
|
||||||
|
ctx,
|
||||||
|
streamerID,
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
slog.Error("Failed to get moderation settings", "error", err)
|
||||||
|
return model.ModerationResponse{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return moderationModel, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (donatService *ServiceDonat) UpdateModerationSettings(
|
func (donatService *ServiceDonat) UpdateModerationSettings(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user