From a103a13c64e0994f46c71e810f927a2e252371c8 Mon Sep 17 00:00:00 2001 From: Qaleka <91965947+Qaleka@users.noreply.github.com> Date: Sat, 21 Dec 2024 02:12:20 +0300 Subject: [PATCH] add sanitize to chat --- internal/chat/usecase/chat_usecase.go | 5 +++++ internal/regions/controller/regions_controller.go | 4 +--- internal/regions/repository/regions_repository.go | 4 ---- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/internal/chat/usecase/chat_usecase.go b/internal/chat/usecase/chat_usecase.go index ee7be61..01cd878 100644 --- a/internal/chat/usecase/chat_usecase.go +++ b/internal/chat/usecase/chat_usecase.go @@ -3,6 +3,7 @@ package usecase import ( "2024_2_FIGHT-CLUB/domain" "context" + "github.com/microcosm-cc/bluemonday" "time" ) @@ -42,6 +43,10 @@ func (cs *chatUseCase) GetChat(ctx context.Context, userID1 string, userID2 stri } func (cs *chatUseCase) SendNewMessage(ctx context.Context, receiver string, sender string, message string) error { + sanitizer := bluemonday.UGCPolicy() + message = sanitizer.Sanitize(message) + receiver = sanitizer.Sanitize(receiver) + sender = sanitizer.Sanitize(sender) err := cs.repo.SendNewMessage(ctx, receiver, sender, message) if err != nil { return err diff --git a/internal/regions/controller/regions_controller.go b/internal/regions/controller/regions_controller.go index 2049c51..4dd40bf 100644 --- a/internal/regions/controller/regions_controller.go +++ b/internal/regions/controller/regions_controller.go @@ -129,9 +129,7 @@ func (rh *RegionHandler) handleError(w http.ResponseWriter, err error, requestID "error generating random bytes for session ID", "failed to fetch reviews for host", "failed to update host score", - "error creating review", - "error updating review", - "error finding review", + "error fetching regions", "error finding host", "error updating host score", "error fetching reviews", diff --git a/internal/regions/repository/regions_repository.go b/internal/regions/repository/regions_repository.go index c0cbeb3..86112a6 100644 --- a/internal/regions/repository/regions_repository.go +++ b/internal/regions/repository/regions_repository.go @@ -51,10 +51,6 @@ func (r *RegionRepository) GetVisitedRegions(ctx context.Context, userId string) Where("\"userId\"", userId). Order("\"startVisitDate\" ASC"). Find(®ions).Error; err != nil { - if errors.Is(err, gorm.ErrRecordNotFound) { - logger.DBLogger.Warn("No regions found", zap.String("request_id", requestID), zap.String("userID", userId)) - return nil, errors.New("no regions found") - } logger.DBLogger.Error("Error fetching regions", zap.String("request_id", requestID), zap.String("userID", userId), zap.Error(err)) return nil, errors.New("error fetching regions") }