예제 #1
0
        public ProductRoutes(IProductService productSvc, IDestinationService destinationSvc)
            : base("v1")
        {
            this.RequiresAuthentication();

            Get("/products", _ =>
            {
                this.RequiresClaims(c => c.Type == HttpMethod.Get.Verb());
                var tagParameter = (DynamicDictionaryValue)Request.Query["tags"];
                var tags         = ConvertParameterToTags(tagParameter);

                var products = (tagParameter.HasValue)
                    ? productSvc.GetByTags(tags).ToViewModel <List <Product>, List <RQModel.Product> >()
                    : productSvc.GetAll().ToViewModel <List <Product>, List <RQModel.Product> >();

                return(products);
            });

            Get("/product/{productId}/destinations", _ =>
            {
                this.RequiresClaims(c => c.Type == HttpMethod.Get.Verb());
                var destinations = destinationSvc
                                   .GetByProductId((Guid)_.productId)
                                   .ToViewModel <List <Destination>, List <ADModel.Destination> >();

                return(destinations);
            });


            Get("/product/mapping/{mappingId}/destinations", _ =>
            {
                this.RequiresClaims(c => c.Type == HttpMethod.Get.Verb());
                var destinations = destinationSvc
                                   .GetByMappingId((int)_.mappingId)
                                   .ToViewModel <List <Destination>, List <ADModel.Destination> >();

                return(destinations);
            });
        }