From 6f6fe6fb0a4132ac8608e4c060abbcddba256f3c Mon Sep 17 00:00:00 2001 From: Nora Date: Tue, 14 Jan 2020 11:23:55 -0500 Subject: [PATCH] fixup! apply feedback --- .../todo-list/todo-list-tutorial-controller.md | 18 +++++++++++++++--- .../todo-list-tutorial-has-one-relation.md | 11 +++++++++-- .../todo-list/todo-list-tutorial-model.md | 3 +++ .../todo-list/todo-list-tutorial-repository.md | 6 +++++- .../tutorials/todo/todo-tutorial-controller.md | 11 +++++++---- .../tutorials/todo/todo-tutorial-datasource.md | 5 ++++- .../todo/todo-tutorial-geocoding-service.md | 11 ++++++----- .../site/tutorials/todo/todo-tutorial-model.md | 5 ++++- .../tutorials/todo/todo-tutorial-repository.md | 5 ++++- 9 files changed, 57 insertions(+), 18 deletions(-) diff --git a/docs/site/tutorials/todo-list/todo-list-tutorial-controller.md b/docs/site/tutorials/todo-list/todo-list-tutorial-controller.md index 56c4923aed6c..1a6fc9d5587e 100644 --- a/docs/site/tutorials/todo-list/todo-list-tutorial-controller.md +++ b/docs/site/tutorials/todo-list/todo-list-tutorial-controller.md @@ -12,8 +12,9 @@ summary: ### Controllers with related models Defining business logic to handle requests to related models isn't too different -from handling requests for standalone models. We'll create controllers to handle -requests for todo-lists and todo items under a todo-list. +from handling requests for standalone models. We'll create +[controllers](../../Controllers.md) to handle requests for todo-lists and todo +items under a todo-list. ### Create TodoList controller @@ -38,6 +39,9 @@ Controller TodoList will be created in src/controllers/todo-list.controller.ts Controller TodoList was created in src/controllers/ ``` +To view the completed file, see the +[`TodoList` example](https://github.com/strongloop/loopback-next/blob/master/examples/todo-list/src/controllers/todo-list.controller.ts). + And voilĂ ! We now have a set of basic APIs for todo-lists, just like that! #### Inclusion of Related Models @@ -128,12 +132,20 @@ async findTodoById(/*...*/) {/*...*/} Earlier when we used `lb4 relation` to create the two relations between `Todo` and `TodoList`, you may have noticed `src/controllers/todo-todo-list.controller.ts` and -`src/controllers/todo-list-todo.conrtoller.ts` were created. These files contain +`src/controllers/todo-list-todo.controller.ts` were created. These files contain a set of API for the relations. +Relation controllers act in a similar manner to normal controllers, except they +modify the relational property. For example, in the +`src/controllers/todo-list-todo.controller.ts` file, we can do requests to the +endpoint `/todo-lists/{id}/todos`, which we'll see in the +[Try it out](###Try-it-out) section. + As `src/controllers/todo-todo-list.controller.ts` only contains one method, we can move it to the `Todo` controller and delete that file: +{% include code-caption.html content="src/models/todo.controller.ts" %} + ```ts export class TodoController { constructor() // ... diff --git a/docs/site/tutorials/todo-list/todo-list-tutorial-has-one-relation.md b/docs/site/tutorials/todo-list/todo-list-tutorial-has-one-relation.md index 0aa5f34df428..664ac104ba6f 100644 --- a/docs/site/tutorials/todo-list/todo-list-tutorial-has-one-relation.md +++ b/docs/site/tutorials/todo-list/todo-list-tutorial-has-one-relation.md @@ -69,7 +69,12 @@ Repository TodoListImageRepository was created in src/repositories/ ### Add the Relation -First, let's add the relation to the model classes: +{% include note.html content=" +We are working on adding `hasOne` to the CLI command `lb4 relation`. See [issue #2980](https://github.com/strongloop/loopback-next/issues/2980). +" %} + +Adding a [`hasOne` relation](../../hasOne-relation.md) is simple. First, let's +add the relation to the model classes: {% include code-caption.html content="src/models/todo-list-image.model.ts" %} @@ -197,7 +202,9 @@ export class TodoListImageRepository extends DefaultCrudRepository< ``` {% include note.html content=" -We are working on adding `hasOne` to the CLI command `lb4 relation`. See [issue #2980](https://github.com/strongloop/loopback-next/issues/2980). +We use **default** foreign key and source property names in this case. +If you'd like to customize them, please check [`Relation Metadata`]( +../../hasOne-relation.md#relation-metadata). " %} ### Create the Controller diff --git a/docs/site/tutorials/todo-list/todo-list-tutorial-model.md b/docs/site/tutorials/todo-list/todo-list-tutorial-model.md index a2a709920d26..1803bc12610f 100644 --- a/docs/site/tutorials/todo-list/todo-list-tutorial-model.md +++ b/docs/site/tutorials/todo-list/todo-list-tutorial-model.md @@ -69,6 +69,9 @@ Enter an empty property name when done Model TodoList was created in src/models/ ``` +To view the completed file, see the +[`TodoList` example](https://github.com/strongloop/loopback-next/blob/master/examples/todo-list/src/models/todo-list.model.ts). + Once the models have been completely configured, it's time to move on to adding a [repository](todo-list-tutorial-repository.md) for `TodoList`. diff --git a/docs/site/tutorials/todo-list/todo-list-tutorial-repository.md b/docs/site/tutorials/todo-list/todo-list-tutorial-repository.md index d0bb0b633435..45a114ef7202 100644 --- a/docs/site/tutorials/todo-list/todo-list-tutorial-repository.md +++ b/docs/site/tutorials/todo-list/todo-list-tutorial-repository.md @@ -40,7 +40,8 @@ Repository TodoListRepository was created in src/repositories/ #### Custom Methods A custom method can be added to the repository class. For example, if we want to -get a `title` from the repository level, the following method can be added: +find a `TodoList` with a specific `title` from the repository level, the +following method can be added: ```ts export class TodoListRepository extends DefaultCrudRepository< @@ -57,6 +58,9 @@ export class TodoListRepository extends DefaultCrudRepository< } ``` +To view the completed file, see the +[`TodoList` example](https://github.com/strongloop/loopback-next/blob/master/examples/todo-list/src/repositories/todo-list.repository.ts). + ### Navigation Previous step: [Add TodoList model](todo-list-tutorial-model.md) diff --git a/docs/site/tutorials/todo/todo-tutorial-controller.md b/docs/site/tutorials/todo/todo-tutorial-controller.md index f3c17b6585f9..67706524430b 100644 --- a/docs/site/tutorials/todo/todo-tutorial-controller.md +++ b/docs/site/tutorials/todo/todo-tutorial-controller.md @@ -9,10 +9,10 @@ summary: LoopBack 4 Todo Application Tutorial - Add a Controller ### Controllers -In LoopBack 4, controllers handle the request-response lifecycle for your API. -Each function on a controller can be addressed individually to handle an -incoming request (like a POST request to `/todos`), to perform business logic, -and to return a response. +In LoopBack 4, [controllers](../../Controllers.md) handle the request-response +lifecycle for your API. Each function on a controller can be addressed +individually to handle an incoming request (like a POST request to `/todos`), to +perform business logic, and to return a response. `Controller` is a class that implements operations defined by application's API. It implements an application's business logic and acts as a bridge between the @@ -76,6 +76,9 @@ Some additional things to note about this example: specifying the type of certain value primitives, such as `@param.path.number('id')`. +To view the completed file, see the +[`Todo` example](https://github.com/strongloop/loopback-next/blob/master/examples/todo/src/controllers/todo.controller.ts). + Now that we've wired up the controller, our last step is to tie it all into the [Application](todo-tutorial-putting-it-together.md)! diff --git a/docs/site/tutorials/todo/todo-tutorial-datasource.md b/docs/site/tutorials/todo/todo-tutorial-datasource.md index fa5a70172225..7f0c63681750 100644 --- a/docs/site/tutorials/todo/todo-tutorial-datasource.md +++ b/docs/site/tutorials/todo/todo-tutorial-datasource.md @@ -21,7 +21,7 @@ the application. Typically, in LoopBack 4, datasources are used in conjunction with [Repositories](../../Repositories.md) to provide access to data. For more information about datasources in LoopBack, see -[DataSources](https://loopback.io/doc/en/lb4/DataSources.html). +[DataSources](../../DataSources.md). Since our Todo API will need to persist instances of Todo items, we'll need to create a datasource definition to make this possible. @@ -46,6 +46,9 @@ lb4 datasource Datasource Db was created in src/datasources/ ``` +To view the completed files, see the +[`Todo` example](https://github.com/strongloop/loopback-next/tree/master/examples/todo/src/datasources). + Create a `data` folder in the applications root and add a new file called `db.json` containing an example database. diff --git a/docs/site/tutorials/todo/todo-tutorial-geocoding-service.md b/docs/site/tutorials/todo/todo-tutorial-geocoding-service.md index 7d16952c213f..a139147ebbdf 100644 --- a/docs/site/tutorials/todo/todo-tutorial-geocoding-service.md +++ b/docs/site/tutorials/todo/todo-tutorial-geocoding-service.md @@ -11,9 +11,10 @@ summary: ### Services To call other APIs and web services from LoopBack applications, we recommend to -use Service Proxies as a design pattern for encapsulating low-level -implementation details of communication with 3rd-party services and providing -JavaScript/TypeScript API that's easy to consume e.g. from Controllers. See +use [Service Proxies](../../Services.md) as a design pattern for encapsulating +low-level implementation details of communication with 3rd-party services and +providing JavaScript/TypeScript API that's easy to consume e.g. from +Controllers. See [Calling other APIs and web services](../../Calling-other-APIs-and-Web-Services.md) for more details. @@ -93,13 +94,13 @@ docs here: [REST connector](/doc/en/lb3/REST-connector.html). ### Implement a service provider -Use the `lb4 service` command and the following inputs to create a calculator +Use the `lb4 service` command and the following inputs to create a geocoder service: ```sh lb4 service ? Service type: Remote service proxy backed by a data source -? Please select the datasource GeocoderDataSource +? Please select the datasource GeocoderDatasource ? Service name: geocoder create src/services/geocoder.service.ts update src/services/index.ts diff --git a/docs/site/tutorials/todo/todo-tutorial-model.md b/docs/site/tutorials/todo/todo-tutorial-model.md index 45a78145f1ee..76a4c4db4435 100644 --- a/docs/site/tutorials/todo/todo-tutorial-model.md +++ b/docs/site/tutorials/todo/todo-tutorial-model.md @@ -22,7 +22,7 @@ name, type, and other constraints. Models are used for data exchange on the wire or between different systems. For more information about Models and how they are used in LoopBack, see -[Models](https://loopback.io/doc/en/lb4/Model.html). +[Models](../../Model.md). {% include note.html content="LoopBack 3 treated models as the 'center' of operations; in LoopBack 4, that is no longer the case. While LoopBack 4 provides many of the helper methods and decorators that allow you to utilize models in a similar way, you are no longer _required_ to do so! " %} @@ -97,6 +97,9 @@ Enter an empty property name when done Model Todo was created in src/models/ ``` +To view the completed file, see the +[`Todo` example](https://github.com/strongloop/loopback-next/blob/master/examples/todo/src/models/todo.model.ts). + Now that we have our model, it's time to add a [datasource](todo-tutorial-datasource.md) so we can perform real CRUD operations! diff --git a/docs/site/tutorials/todo/todo-tutorial-repository.md b/docs/site/tutorials/todo/todo-tutorial-repository.md index 77bf8e376555..9e54fe02426d 100644 --- a/docs/site/tutorials/todo/todo-tutorial-repository.md +++ b/docs/site/tutorials/todo/todo-tutorial-repository.md @@ -20,7 +20,7 @@ strong-typed data access (for example, CRUD) operations of a domain model against the underlying database or service. For more information about Repositories, see -[Repositories](https://loopback.io/doc/en/lb4/Repositories.html). +[Repositories](../../Repositories.md). ### Create your repository @@ -51,6 +51,9 @@ model definition and 'db' datasource configuration and retrieves the datasource using [Dependency Injection](https://loopback.io/doc/en/lb4/Dependency-injection.html). +To view the completed file, see the +[`Todo` example](https://github.com/strongloop/loopback-next/blob/master/examples/todo/src/repositories/todo.repository.ts). + Now we can expose the `Todo` API through the [controller](todo-tutorial-controller.md).