{"action":"created","issue":{"url":"https://api.github.com/repos/strongloop/loopback.io/issues/624","repository_url":"https://api.github.com/repos/strongloop/loopback.io","labels_url":"https://api.github.com/repos/strongloop/loopback.io/issues/624/labels{/name}","comments_url":"https://api.github.com/repos/strongloop/loopback.io/issues/624/comments","events_url":"https://api.github.com/repos/strongloop/loopback.io/issues/624/events","html_url":"https://github.com/strongloop/loopback.io/pull/624","id":297976453,"number":624,"title":"[WIP] Add best practices for bottom up approach","user":{"login":"shimks","id":18518689,"avatar_url":"https://avatars2.githubusercontent.com/u/18518689?v=4","gravatar_id":"","url":"https://api.github.com/users/shimks","html_url":"https://github.com/shimks","followers_url":"https://api.github.com/users/shimks/followers","following_url":"https://api.github.com/users/shimks/following{/other_user}","gists_url":"https://api.github.com/users/shimks/gists{/gist_id}","starred_url":"https://api.github.com/users/shimks/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/shimks/subscriptions","organizations_url":"https://api.github.com/users/shimks/orgs","repos_url":"https://api.github.com/users/shimks/repos","events_url":"https://api.github.com/users/shimks/events{/privacy}","received_events_url":"https://api.github.com/users/shimks/received_events","type":"User","site_admin":false},"labels":[{"id":552736696,"url":"https://api.github.com/repos/strongloop/loopback.io/labels/needs-priority","name":"needs-priority","color":"eeeeee","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":6,"created_at":"2018-02-17T03:54:39Z","updated_at":"2018-03-01T14:40:44Z","closed_at":null,"author_association":"CONTRIBUTOR","pull_request":{"url":"https://api.github.com/repos/strongloop/loopback.io/pulls/624","html_url":"https://github.com/strongloop/loopback.io/pull/624","diff_url":"https://github.com/strongloop/loopback.io/pull/624.diff","patch_url":"https://github.com/strongloop/loopback.io/pull/624.patch"},"body":"- connected to https://github.com/strongloop/loopback-next/issues/735\r\n- initial docs proposal for adding a 'best practices' section for bottom up approach\r\n- need link to the `getting-started-example` once that's added into the docs\r\n"},"comment":{"url":"https://api.github.com/repos/strongloop/loopback.io/issues/comments/369612424","html_url":"https://github.com/strongloop/loopback.io/pull/624#issuecomment-369612424","issue_url":"https://api.github.com/repos/strongloop/loopback.io/issues/624","id":369612424,"user":{"login":"bajtos","id":1140553,"avatar_url":"https://avatars1.githubusercontent.com/u/1140553?v=4","gravatar_id":"","url":"https://api.github.com/users/bajtos","html_url":"https://github.com/bajtos","followers_url":"https://api.github.com/users/bajtos/followers","following_url":"https://api.github.com/users/bajtos/following{/other_user}","gists_url":"https://api.github.com/users/bajtos/gists{/gist_id}","starred_url":"https://api.github.com/users/bajtos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bajtos/subscriptions","organizations_url":"https://api.github.com/users/bajtos/orgs","repos_url":"https://api.github.com/users/bajtos/repos","events_url":"https://api.github.com/users/bajtos/events{/privacy}","received_events_url":"https://api.github.com/users/bajtos/received_events","type":"User","site_admin":false},"created_at":"2018-03-01T14:40:44Z","updated_at":"2018-03-01T14:40:44Z","author_association":"OWNER","body":"> Could you be more specific as to what you're envisioning? The code in Defining-the-API-using-code-first-approach.md contains no logic, so do you mean that I should show a skeleton of the endpoints that I need to test out for the controller?\r\n\r\nRight now, your narrative is \"Define your models\", \"Define your routes\", \"Reviewing your API specification\". That's not how test-first people work! Take a look at [Incrementally implement features](https://github.com/strongloop/loopback.io/blob/7ccfb55463b36f9177a7960926f933ae47f00986/pages/en/lb4/Implementing-features.md) to see test-first approach in work for top-down approach.\r\n\r\nFor the documention of code-first approach, I would like to see a similar content/narrative:\r\n\r\n 1. Pick one (and only one!) endpoint you are going to implement.\r\n 2. Start with an acceptance test describing endpoint's behaviour (see [Write an acceptance test](https://github.com/strongloop/loopback.io/blob/7ccfb55463b36f9177a7960926f933ae47f00986/pages/en/lb4/Implementing-features.md#write-an-acceptance-test)). This acceptance test is going to server as an indicator telling you when you are done with this endpoint.\r\n 3. Write a unit-test for the new controller method you are going to implement (see [Write a unit-test for the new controller method](https://github.com/strongloop/loopback.io/blob/7ccfb55463b36f9177a7960926f933ae47f00986/pages/en/lb4/Implementing-features.md#write-a-unit-test-for-the-new-controller-method), this section contains an example of the actual controller implementation at the bottom.)\r\n 4. Write the first implementation of the controller method to make the test pass. This is time to put code-first approach in work, e.g. use REST decorators like `@get` and `@param`.\r\n 5. Write an integration test to verify that the controller is using data from the database (see [Write an integration test for the new controller method](https://github.com/strongloop/loopback.io/blob/7ccfb55463b36f9177a7960926f933ae47f00986/pages/en/lb4/Implementing-features.md#write-an-integration-test-for-the-new-controller-method)\r\n 6. Now comes the best time for defining models & repositories - see [Define Product model, repository, and data source](https://github.com/strongloop/loopback.io/blob/7ccfb55463b36f9177a7960926f933ae47f00986/pages/en/lb4/Implementing-features.md#define-product-model-repository-and-data-source). Because you are describing bottom-up approach, I think it's acceptable to assume that our data/repository/model layer is already set up and/or was configured before we started writing controllers for the REST API. This configuration should still be implemented in test-first way though!\r\n 7. [Update test helpers and the controller use real model and repository](https://github.com/strongloop/loopback.io/blob/7ccfb55463b36f9177a7960926f933ae47f00986/pages/en/lb4/Implementing-features.md#update-test-helpers-and-the-controller-use-real-model-and-repository)\r\n 8. Run the tests again and fix the issues - see [Run tests](https://github.com/strongloop/loopback.io/blob/7ccfb55463b36f9177a7960926f933ae47f00986/pages/en/lb4/Implementing-features.md#run-tests)\r\n 9. [Decouple controller from Repository](https://github.com/strongloop/loopback.io/blob/7ccfb55463b36f9177a7960926f933ae47f00986/pages/en/lb4/Implementing-features.md#decouple-controller-from-repository)\r\n 10. [Handle 'product not found' error](https://github.com/strongloop/loopback.io/blob/7ccfb55463b36f9177a7960926f933ae47f00986/pages/en/lb4/Implementing-features.md#handle-product-not-found-error)\r\n\r\nBasically I am asking you to create a guide that's similar to what we have for bottom-down approach, but with specific details changed to accommodate the bottom-up (code-first) approach.\r\n\r\nIf there are sections that can or should be reused by both guides, then it may be worth extracting them into shared content. (I don't know how easy it is, or whether it's feasible at all.)\r\n\r\nFor example, the last step in the api-first guide, [Implement a custom sequence](https://github.com/strongloop/loopback.io/blob/7ccfb55463b36f9177a7960926f933ae47f00986/pages/en/lb4/Implementing-features.md#implement-a-custom-sequence), should be pretty easy to extract into a standalone document that both code-first and api-first guide can refer to.\r\n\r\nI am not sure what's the exact scope of your task (the user story you are working on). If a guide as I described above is beyond the scope, then I can live with the shorter version you proposed here and will open a new issue to bring the code-first guide up to the level of the api-first guide. Please let me know!"}}
{"actor":{"display_login":"bajtos"}}