{"id":22540894,"url":"https://github.com/dalm1/food-delivery","last_synced_at":"2025-03-28T07:21:40.161Z","repository":{"id":243645713,"uuid":"812994797","full_name":"DALM1/Food-Delivery","owner":"DALM1","description":null,"archived":false,"fork":false,"pushed_at":"2024-06-10T10:23:14.000Z","size":18,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-02T08:14:41.710Z","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/DALM1.png","metadata":{"files":{"readme":"README.cn.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}},"created_at":"2024-06-10T09:56:39.000Z","updated_at":"2024-06-10T10:23:17.000Z","dependencies_parsed_at":"2024-06-10T12:07:17.208Z","dependency_job_id":"1d2f7b34-5ad1-41d2-a8b8-7c2761bcd02e","html_url":"https://github.com/DALM1/Food-Delivery","commit_stats":null,"previous_names":["dalm1/food-delivery"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DALM1%2FFood-Delivery","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DALM1%2FFood-Delivery/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DALM1%2FFood-Delivery/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DALM1%2FFood-Delivery/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DALM1","download_url":"https://codeload.github.com/DALM1/Food-Delivery/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245984975,"owners_count":20704895,"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-12-07T12:13:04.450Z","updated_at":"2025-03-28T07:21:40.143Z","avatar_url":"https://github.com/DALM1.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"让我们为餐厅开发一个送餐程序吧！\n\n以下是我们应用程序的第一个 **用户操作**：\n- 作为一个用户，我可以添加一个新的餐meal\n- 作为一个用户，我可以列出所有的餐meals\n- 作为一个用户，我可以添加一个新顾客customer\n- 作为一个用户，我可以列出所有的顾客customers\n\n**警告**\n\n该软件专为 **一家餐厅** 设计，因此无需满足多家餐厅的需要（例如，我们不需要 `餐厅` 模型）。\n该软件是专为 **餐厅的工作人员** 设计的，因此无需为顾客设计登录界面。\n因此，我们软件的第一个组件是：\n- **餐** **Meals**\n- **顾客** **Customers**\n\n## 1 - `餐 Meals`\n\n### 1.1 - `餐 Meal`模型\n\n我们的餐厅卖餐 meals，所以我们需要一种方法来表示餐 meal 是什么。\n\n每一个餐meal都有id、 name 和 price。\n\n编写一些代码来实现这一点，并对模型进行崩溃测试。然后通过运行 `rake meal` 来测试代码。\n\n都是绿色的？很好！是时候 `git add`, `commit` 和 `push` 了。\n\n### 1.2 - `餐 Meal` 存储库\n\n现在我们有了一个代表我们的餐 meal 的模型，我们需要一个存储库来存储它们。\n\n此存储库使用CSV文件路径初始化。它从CSV文件中读取/写入食物，并将它们作为对象保存在一个数组中。我们希望存储库可以执行以下操作：\n\n- 添加新餐meal\n- 得到所有的餐meals\n- 用id找到一个特定的餐meal\n\n编写一些代码来实现这一点，并对模型进行崩溃测试。你应该在 `data` 文件夹中创建自己的 `meals.csv` CSV文件。然后通过运行 `rake meal` 来测试代码。\n\n都是绿色的？很好！是时候 `git add`, `commit` 和 `push` 了。\n\n### 1.3 - 路由和应用程序\n\n我们还没有启动我们的应用程序。为此，我们需要一个router路由，并且需要填写 `app.rb` 文件。\n\n路由router负责显示用户可以执行的任务，并将用户的选择路由到匹配控制器的相应操作。 `app.rb` 文件负责要求所有必需的文件，实例化路由并执行其 `run` 方法来启动应用程序。\n\n填写 `router.rb` 和 `app.rb` 文件来实现这一点。如果你被困住了，你可以回到[Cookbook第二天](https://kitt.lewagon.com/camps/\u003cuser.batch_slug\u003e/challenges?path=02-OOP%2F03-Cookbook%2F02-Cookbook) 并下载答案以获得一些灵感 **无需将路由器与控制器关联**，因为我们还没有。所以当用户选择任务时，只需打印 `TODO` 。\n\n这部分没有rake。通过在终端中运行以下命令启动应用程序：\n\n```bash\nruby app.rb\n```\n\n都是绿色的？很好！是时候 `git add`, `commit` 和 `push` 了。\n\n### 1.4 - `餐 Meals` 控制器\n\n让我们转到控制器。下面是我们要实现的 **用户操作**：\n- `add` 加一个新meal\n- `list` 列出所有meals\n\n请记住，控制器的角色是将工作委派给应用程序的其他组件（模型、存储库和视图）并进行协调！\n\n首先编写 **伪代码**，将每个用户操作分解为基本步骤，并将每个步骤委托给一个组件（模型、存储库或视图）。然后编写代码来实现每个步骤。创建视图并逐步编写代码。\n\n要测试你的控制器，请通过在 `app.rb` 中实例化它并将其传递给路由器，将它链接到你的应用程序。然后，你可以通过启动应用程序对代码进行崩溃测试：\n\n```bash\nruby app.rb\n```\n\n`rake meal` 也会帮助你完成所有这些步骤。跟着你的向导走！\n\n在继续下一个功能之前，请确保你的两个用户操作正常。\n\n📝 **注意：**在这个练习中（与模型和控制器不同），没有特定的 `rake` 用于视图。这是因为有许多不同的方法来显示相关信息，并且没有一种“正确”的方式。所以请在思考您的视图应该显示什么时，可以稍微有些艺术性地思考一下 🧑‍🎨。但是，请通过运行 `ruby app.rb` 并查看应用程序是否正常工作且易于使用来确保它们正常工作。\n\n都是绿色的？很好！是时候 `git add`, `commit` 和 `push` 了。\n\n## 2 - `顾客 Customers`\n\n### 2.1 - `顾客 Customer` 模型\n\n我们的餐厅是面对顾客customers的，所以我们需要一种方式来代表顾客customer是什么。\n每个顾客customer都有一个id、一个name和一个address。\n\n编写一些代码来实现这一点，并对模型进行崩溃测试。然后通过运行 `rake customer`来测试代码。\n\n都是绿色的？很好！是时候 `git add`, `commit` 和 `push` 了。\n\n### 2.2 - `顾客 Customer` 存储库\n\n现在我们有了一个代表customers的模型，我们需要一个存储库来存储它们。\n此存储库使用CSV文件路径初始化。它从CSV文件中读取/写入customers，并将其作为数组中的对象保存。我们希望存储库可以执行以下操作：\n- 添加新customer\n- 抓住所有的customers\n- 通过id查找特定customer\n编写一些代码来实现这一点，并对存储库进行崩溃测试。你应该在 `data` 文件夹中创建自己的 `customers.csv` CSV文件。然后通过运行 `rake customer` 来测试代码。\n\n都是绿色的？很好！是时候 `git add`, `commit` 和 `push` 了。\n\n### 2.3 - 控制器\n\n让我们转到控制器。下面是我们要实现的 **用户操作**：\n- `add` 一个新customer\n- `list` 所有Customers\n\n请记住，控制器的角色是将工作委派给应用程序的其他组件（模型、存储库和视图）并进行协调！\n\n首先编写 **伪代码**，将每个用户操作分解为基本步骤，并将每个步骤委托给一个组件（模型、存储库或视图）。然后编写代码来实现每个步骤。创建视图并逐步编写代码。\n\n要测试你的控制器？请通过在 `app.rb` 中实例化它并将其传递给路由器，将它链接到你的应用程序。然后，你可以通过启动应用程序对代码进行崩溃测试：\n\n```bash\nruby app.rb\n```\n\n`rake customer` 也会帮助你完成所有这些步骤。跟着你的向导走！\n\n在继续下一个功能之前，请确保你的两个用户操作正常。\n\n都是绿色的？很好！是时候 `git add`, `commit` 和 `push` 了。\n\n## 3 - 选做部分\n\n### 3.1 - 对餐 meals 和 顾客customers 实施 `edit` 和 `destroy` 操作\n\n在我们的应用程序中，用户不能编辑或删除现有的meal或customer。\n\n实现这些附加用户操作：\n- 作为一个用户，我可以编辑现有的餐meal\n- 作为一个用户，我可以销毁现有的餐meal\n- 作为用户，我可以编辑现有的顾客customer\n- 作为一个用户，我可以删除一个现有的顾客customer\n\n完成了？很好！是时候 `git add`, `commit` 和 `push` 了。\n\n### 3.2 - Refactor repositories with inheritance\n\n`MealRepository` 和 `CustomerRepository` 有很多相似之处，不是吗？为了保持[DRY](https://en.wikipedia.org/wiki/Don%27t_repeat_yourself) (需要VPN 🛡 ), ，我们需要定义一个父类,`BaseRepository`，它有所有 `MealRepository` 和`CustomerRepository` 共同分享的行为会从中继承。\n\n写一些代码来实现这个。这是一个重构过程，所以这部分没有新的测试。如果你的 `rake` 以前都是绿色的，那以后应该都是绿色的！\n\n完成了？很好！是时候 `git add`, `commit` 和 `push` 了。\n\n你完成今天的挑战啦！\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdalm1%2Ffood-delivery","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdalm1%2Ffood-delivery","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdalm1%2Ffood-delivery/lists"}