Ejemplo n.º 1
0
        public ActionResult GetReactionsByProductID([FromHeader(Name = "CommunicationKey")] string key, [FromQuery] int productID, [FromQuery] int userID)
        {
            if (productMockRepository.GetProductByID(productID) == null)
            {
                return(StatusCode(StatusCodes.Status400BadRequest, "There is no product with given ID"));
            }

            var sellerID = productMockRepository.GetProductByID(productID).SellerID;

            // korisnik ne moze videti reakcije proizvoda cije vlasnike je on blokirao ili su njega blokirali
            if (reactionRepository.CheckDidIBlockedSeller(userID, sellerID))
            {
                return(StatusCode(StatusCodes.Status400BadRequest, String.Format("You can not see products with sellerID {0} ", sellerID)));
            }

            //korisnik ne moze videti reakcije koje su dodali korisnici koje je on blokirao ili su njega blokirali
            var reactions = reactionRepository.GetRectionByProductID(productID, userID);

            if (reactions.Count == 0)
            {
                return(StatusCode(StatusCodes.Status404NotFound, "This product has no reactions added"));
            }

            return(Ok(mapper.Map <List <ReactionsDto> >(reactions)));
        }