{"id":18809285,"url":"https://github.com/stupidcodefactory/react-shop-api","last_synced_at":"2025-07-20T20:33:11.599Z","repository":{"id":137704638,"uuid":"96630936","full_name":"StupidCodeFactory/react-shop-api","owner":"StupidCodeFactory","description":null,"archived":false,"fork":false,"pushed_at":"2017-07-12T00:51:09.000Z","size":54,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-22T02:40:54.548Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/StupidCodeFactory.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2017-07-08T16:34:03.000Z","updated_at":"2017-07-08T16:34:37.000Z","dependencies_parsed_at":null,"dependency_job_id":"b8906611-fcee-4eb3-a48e-029cbde905a2","html_url":"https://github.com/StupidCodeFactory/react-shop-api","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/StupidCodeFactory/react-shop-api","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StupidCodeFactory%2Freact-shop-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StupidCodeFactory%2Freact-shop-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StupidCodeFactory%2Freact-shop-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StupidCodeFactory%2Freact-shop-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/StupidCodeFactory","download_url":"https://codeload.github.com/StupidCodeFactory/react-shop-api/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/StupidCodeFactory%2Freact-shop-api/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266194244,"owners_count":23890957,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-07T23:15:52.316Z","updated_at":"2025-07-20T20:33:11.587Z","avatar_url":"https://github.com/StupidCodeFactory.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![wercker status](https://app.wercker.com/status/02c50650497b0495c55c42d3aec4f1ef/s/master \"wercker status\")](https://app.wercker.com/project/byKey/02c50650497b0495c55c42d3aec4f1ef)\n\n# Instruction\n\nRun the app\n\n```bash\n./bin/setup\n```\n\n## [ShopingBasket](https://github.com/StupidCodeFactory/react-shop-api/blob/master/app/models/shopping_basket.rb) ##\n\n    Class responsible for managing the shopping basket\n\n\n### ShopingBasket#new\n\n```ruby\nproducts         = Product.all\njeans            = products.detect {|name| name == 'jeans' }\ndelivery_charges = DeliveryCharge.all\n\n# a Hash indexed by product code, takes a SpecialOffer as value.\n# Currently on one offer is supported but easily could be extended\n# to multiple offers per product by passing an array of special offers.\nspecial_offer_catalogue = {\n  jeans.code =\u003e SpecialOffer.new(\n      -\u003e (products) { products.size == 2 }, # called to determine if the discount apply\n      -\u003e (products) { products[-1].price_in_cents / 2.0 } # called to apply the discount\n    )\n  }\n\nbasket = ShopingBasket.new(products, delivery_charges, special_offer_catalogue)\n```\n\n### ShopingBasket#add\n\nAdd a product to the basket, check and apply any discount on the fly.\n\n```ruby\nbasket.add(jeans.code)\n```\n\n### ShopingBasket#total\n\nThe the basket's total amount, with discounts applied.\n\n\n## [SpecialOffer](https://github.com/StupidCodeFactory/react-shop-api/blob/master/app/models/special_offer.rb)\n\nKeeps track of wether to apply a discount. This class is completely independant from the basket.\n\n```ruby\n\n# Both procs are passed in as an argument an array of products\n# which have not had a discount applied yet of the same price\n\n\n# For 3 items purchase\nrule = -\u003e(products) { products.length == 3 }\n\n# get 25% discount on all 3 items\nprice_processor = -\u003e(product) { products.each {|p| p.price -= (p.price / 4 ) } }\n\nprice = SpecialOffer.new(rule, price_processor)\nprice.total # \u003c= makes you customer happy\n```\n\n\nThis should serve as a backend for a [React demo app](https://github.com/StupidCodeFactory/react-shop) which is under construction...\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstupidcodefactory%2Freact-shop-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstupidcodefactory%2Freact-shop-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstupidcodefactory%2Freact-shop-api/lists"}