Skip to content

Commit

Permalink
fix advert with no auth
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxorella committed May 26, 2024
1 parent 1b823e6 commit e56166a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion internal/pkg/adverts/delivery/grpc/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (h *AdvertsServerHandler) GetAdvertById(ctx context.Context, reqAdv *genAdv

if err != nil {

h.logger.Error(ctx.Value("requestId").(string) + " " + err.Error())
// h.logger.Error(ctx.Value("requestId").(string) + " " + err.Error())
// utils.LogErrorResponse(h.logger, ctx.Value("requestId").(string), utils.DeliveryLayer, SignUpMethod, err, http.StatusBadRequest)
return &genAdverts.GetAdvertByIdResponse{RespCode: StatusBadRequest}, err
}
Expand Down
9 changes: 7 additions & 2 deletions internal/pkg/adverts/delivery/http/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,13 @@ func (h *AdvertsClientHandler) GetAdvertById(w http.ResponseWriter, r *http.Requ
utils.WriteError(w, http.StatusBadRequest, "invalid id parameter")
return
}

md := metadata.New(map[string]string{"userid": strconv.FormatInt(r.Context().Value(middleware.CookieName).(int64), 10)})
userId := r.Context().Value(middleware.CookieName)
var md metadata.MD
if userId == nil {
md = metadata.New(map[string]string{"userid": "0"})
} else {
md = metadata.New(map[string]string{"userid": strconv.FormatInt(r.Context().Value(middleware.CookieName).(int64), 10)})
}
ctx := metadata.NewOutgoingContext(context.Background(), md)

advertDataResponse, err := h.client.GetAdvertById(ctx, &genAdverts.GetAdvertByIdRequest{Id: advertId})
Expand Down
3 changes: 1 addition & 2 deletions internal/pkg/adverts/repo/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -1923,7 +1923,7 @@ func (r *AdvertRepo) LikeAdvert(ctx context.Context, advertId int64, userId int6
return err
}

if _, err = r.UpdatePriority(ctx, tx, adId, 100); err != nil {
if _, err = r.UpdatePriority(ctx, tx, advertId, 100); err != nil {
return err
}

Expand Down Expand Up @@ -2022,7 +2022,6 @@ func (r *AdvertRepo) GetRectangleAdvertsLikedByUserId(ctx context.Context, pageS
)
AND i.is_deleted = FALSE
AND a.is_deleted = FALSE
AND a.user_id = $1
ORDER BY a.created_at DESC
LIMIT $2
OFFSET $3`
Expand Down

0 comments on commit e56166a

Please sign in to comment.