Exemplo 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)));
        }
        public ActionResult <List <Comments> > GetCommentsByProductID([FromHeader(Name = "CommunicationKey")] string key, [FromQuery] int productID, [FromQuery] int userID)
        {
            if (productRepository.GetProductByID(productID) == null)
            {
                return(StatusCode(StatusCodes.Status400BadRequest, "Product with given ID does not exist"));
            }
            var sellerID = productRepository.GetProductByID(productID).SellerID;


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

            /// korisnik ne moze videti komentare koji su dodali korisnici koje je on blokirao ili koji su njega blokirali
            var comments = commentRepository.GetCommentsByProductID(productID, userID);

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

            return(Ok(comments));
        }