Skip to content

Commit

Permalink
fixup! apply feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
nabdelgadir committed Jan 14, 2020
1 parent 7b4ef6e commit 6f6fe6f
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 18 deletions.
18 changes: 15 additions & 3 deletions docs/site/tutorials/todo-list/todo-list-tutorial-controller.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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() // ...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" %}
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions docs/site/tutorials/todo-list/todo-list-tutorial-model.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<
Expand All @@ -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)
Expand Down
11 changes: 7 additions & 4 deletions docs/site/tutorials/todo/todo-tutorial-controller.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)!

Expand Down
5 changes: 4 additions & 1 deletion docs/site/tutorials/todo/todo-tutorial-datasource.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.

Expand Down
11 changes: 6 additions & 5 deletions docs/site/tutorials/todo/todo-tutorial-geocoding-service.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion docs/site/tutorials/todo/todo-tutorial-model.md
Original file line number Diff line number Diff line change
Expand Up @@ -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!
" %}
Expand Down Expand Up @@ -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!
Expand Down
5 changes: 4 additions & 1 deletion docs/site/tutorials/todo/todo-tutorial-repository.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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).
Expand Down

0 comments on commit 6f6fe6f

Please sign in to comment.