Skip to content

Commit

Permalink
add sanitize to chat
Browse files Browse the repository at this point in the history
  • Loading branch information
Qaleka committed Dec 20, 2024
1 parent 41461d5 commit a103a13
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
5 changes: 5 additions & 0 deletions internal/chat/usecase/chat_usecase.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package usecase
import (
"2024_2_FIGHT-CLUB/domain"
"context"
"github.com/microcosm-cc/bluemonday"
"time"
)

Expand Down Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions internal/regions/controller/regions_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 0 additions & 4 deletions internal/regions/repository/regions_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,6 @@ func (r *RegionRepository) GetVisitedRegions(ctx context.Context, userId string)
Where("\"userId\"", userId).
Order("\"startVisitDate\" ASC").
Find(&regions).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")
}
Expand Down

0 comments on commit a103a13

Please sign in to comment.