Skip to content

Commit 75eba76

Browse files
committed
docs: update todolist doc and minor doc fixes
1 parent fa69b6c commit 75eba76

17 files changed

+67
-32
lines changed

docs/site/BelongsTo-relation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ repository, the following are required:
101101
The following code snippet shows how it would look like:
102102

103103
{% include code-caption.html
104-
content="/src/repositories/order.repository.ts.ts" %}
104+
content="/src/repositories/order.repository.ts" %}
105105

106106
```ts
107107
import {Getter, inject} from '@loopback/context';

docs/site/DataSources.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,16 @@ Example DataSource Class:
3434

3535
```ts
3636
import {inject} from '@loopback/core';
37-
import {juggler, DataSource} from '@loopback/repository';
37+
import {juggler} from '@loopback/repository';
38+
import * as config from './db.datasource.json';
3839

3940
export class DbDataSource extends juggler.DataSource {
40-
constructor(@inject('datasources.config.db') dsConfig: DataSource) {
41+
static dataSourceName = 'db';
42+
43+
constructor(
44+
@inject('datasources.config.db', {optional: true})
45+
dsConfig: object = config,
46+
) {
4147
super(dsConfig);
4248
}
4349
}

docs/site/Defining-the-API-using-code-first-approach.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ of your routes and `@param` or `@requestBody` to its parameters:
134134

135135
```ts
136136
import {Todo} from '../models/todo.model';
137-
import {post, get, param, requestBody} from '@loopback/openapi-v3';
137+
import {post, get, param, requestBody} from '@loopback/rest';
138138

139139
export class TodoController {
140140
constructor() {}

docs/site/Getting-started.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ follows:
7373
lb4 controller
7474
```
7575

76+
- _Note: If your application is still running, press **CTRL+C** to stop it
77+
before calling the command_
78+
7679
- Answer the prompts as follows:
7780

7881
```sh
@@ -81,7 +84,7 @@ lb4 controller
8184
create src/controllers/hello.controller.ts
8285
update src/controllers/index.ts
8386

84-
Controller Hello was now created in src/controllers/
87+
Controller hello was now created in src/controllers/
8588
```
8689

8790
- Paste the following contents into the file
@@ -100,9 +103,6 @@ lb4 controller
100103

101104
- Start the application using `npm start`.
102105

103-
- _Note: If your application is still running, press **CTRL+C** to stop it
104-
before restarting it_
105-
106106
- Visit <http://127.0.0.1:3000/hello> to see `Hello world!`
107107

108108
## Code sample

docs/site/HasMany-relation.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,11 @@ repository, the following are required:
114114
The following code snippet shows how it would look like:
115115

116116
{% include code-caption.html
117-
content="/src/repositories/customer.repository.ts.ts" %}
117+
content="/src/repositories/customer.repository.ts" %}
118118

119119
```ts
120120
import {Order, Customer} from '../models';
121-
import {OrderRepository} from './order.repository.ts';
121+
import {OrderRepository} from './order.repository';
122122
import {
123123
DefaultCrudRepository,
124124
juggler,
@@ -127,7 +127,7 @@ import {
127127
} from '@loopback/repository';
128128
import {inject, Getter} from '@loopback/core';
129129

130-
class CustomerRepository extends DefaultCrudRepository<
130+
export class CustomerRepository extends DefaultCrudRepository<
131131
Customer,
132132
typeof Customer.prototype.id
133133
> {

docs/site/Model.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ To define a model for use with the juggler bridge, extend your classes from
9999
`Entity` and decorate them with the `@model` and `@property` decorators.
100100

101101
```ts
102-
import {model, property} from '@loopback/repository';
102+
import {model, property, Entity} from '@loopback/repository';
103103

104104
@model()
105105
export class Product extends Entity {

docs/site/Repositories.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,16 +156,17 @@ configured earlier. It's recommended that you use
156156
TypeScript version:
157157

158158
```ts
159-
import {DefaultCrudRepository, DataSourceType} from '@loopback/repository';
160-
import {inject} from '@loopback/context';
159+
import {DefaultCrudRepository, juggler} from '@loopback/repository';
161160
import {Account} from '../models';
161+
import {DbDataSource} from '../datasources';
162+
import {inject} from '@loopback/context';
162163

163164
export class AccountRepository extends DefaultCrudRepository<
164165
Account,
165166
typeof Account.prototype.id
166167
> {
167-
constructor(@inject('datasources.db') protected db: DataSourceType) {
168-
super(Account, db);
168+
constructor(@inject('datasources.db') dataSource: DbDataSource) {
169+
super(Account, dataSource);
169170
}
170171
}
171172
```

docs/site/Using-components.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ allow easier extensibility of your Application.
1515
A typical LoopBack component is an [npm](https://www.npmjs.com) package
1616
exporting a Component class which can be added to your application.
1717

18+
Install the following dependencies to run the code snippet below.
19+
20+
```sh
21+
npm install --save @loopback/authentication
22+
npm install @types/passport
23+
```
24+
1825
```ts
1926
import {RestApplication} from '@loopback/rest';
2027
import {AuthenticationComponent} from '@loopback/authentication';

docs/site/todo-list-tutorial-controller.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,10 @@ export class TodoListController {
221221
}
222222
```
223223

224+
Check out our todo-list example to see the full source code generated for
225+
TodoListTodo controller:
226+
[src/controllers/todo-list-todo.controller.ts](https://github.com/strongloop/loopback-next/blob/master/examples/todo-list/src/controllers/todo-list-todo.controller.ts)
227+
224228
### Try it out
225229

226230
With the controllers complete, your application is ready to start up again!

docs/site/todo-list-tutorial-model.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,14 @@ Model TodoList was created in src/models/
6868
```
6969

7070
Now that we have our new model, we need to define its relation with the `Todo`
71-
model. Add the following property to the `TodoList` model:
71+
model. Add the following import statements and property to the `TodoList` model:
7272

7373
#### src/models/todo-list.model.ts
7474

7575
```ts
76+
import {hasMany} from '@loopback/repository';
77+
import {Todo} from './todo.model';
78+
7679
@model()
7780
export class TodoList extends Entity {
7881
// ...properties defined by the CLI...

docs/site/todo-list-tutorial-repository.md

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,22 @@ building a constrained version of `TodoRepository`.
2020

2121
### Create your repository
2222

23-
In the `src/repositories` directory:
24-
25-
- create `todo-list.repository.ts`
26-
- update `index.ts` to export the newly created repository
23+
From inside the project folder, run the `lb4 repository` command to create a
24+
repository for the `TodoList` model using the `db` datasource. The `db`
25+
datasource shows up by its class name `DbDataSource` from the list of available
26+
datasources.
27+
28+
```sh
29+
lb4 repository
30+
? Please select the datasource DbDatasource
31+
? Select the model(s) you want to generate a repository TodoList
32+
create src/repositories/todo-list.repository.ts
33+
update src/repositories/index.ts
34+
35+
Repository TodoList was created in src/repositories/
36+
```
2737
28-
Like `TodoRepository`, we'll use `DefaultCrudRepository` to extend our
29-
`TodoListRepository`. Since we're going to be using the same database used for
30-
`TodoRepository`, inject `datasources.db` in this repository as well. From there
31-
we'll need to make two more additions:
38+
From there, we'll need to make two more additions:
3239
3340
- define the `todos` property, which will be used to build a constrained
3441
`TodoRepository`
@@ -42,14 +49,14 @@ repository instance to constrain as the arguments for the function.
4249
#### src/repositories/todo-list.repository.ts
4350
4451
```ts
52+
import {Getter, inject} from '@loopback/core';
4553
import {
4654
DefaultCrudRepository,
47-
juggler,
4855
HasManyRepositoryFactory,
56+
juggler,
4957
repository,
5058
} from '@loopback/repository';
51-
import {TodoList, Todo} from '../models';
52-
import {inject, Getter} from '@loopback/core';
59+
import {Todo, TodoList} from '../models';
5360
import {TodoRepository} from './todo.repository';
5461
5562
export class TodoListRepository extends DefaultCrudRepository<

docs/site/todo-tutorial-geocoding-service.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ Controller constructor to receive `GeocodeService` as a new dependency.
174174
#### src/controllers/todo.controller.ts
175175

176176
```ts
177+
import {inject} from '@loopback/core';
177178
import {GeocoderService} from '../services';
178179

179180
export class TodoController {

docs/site/todo-tutorial-putting-it-together.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ Let's try out our application! First, you'll want to start the app.
3535

3636
```sh
3737
$ npm start
38-
Server is running on port 3000
38+
Server is running at http://[::1]:3000
3939
```
4040

4141
Next, you can use the [API Explorer](http://localhost:3000/explorer) to browse
@@ -46,7 +46,8 @@ Here are some requests you can try:
4646
- `POST /todos` with a body of `{ "title": "get the milk" }`
4747
- `GET /todos/{id}` using the ID you received from your `POST`, and see if you
4848
get your Todo object back.
49-
- `PATCH /todos/{id}` with a body of `{ "desc": "need milk for cereal" }`
49+
- `PATCH /todos/{id}` using the same ID, with a body of
50+
`{ "desc": "need milk for cereal" }`
5051

5152
That's it! You've just created your first LoopBack 4 application!
5253

docs/site/todo-tutorial-repository.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ model definition and 'db' datasource configuration and retrieves the datasource
4848
using
4949
[Dependency Injection](https://loopback.io/doc/en/lb4/Dependency-injection.html).
5050
51+
Now we can expose the `Todo` API through the
52+
[controller](todo-tutorial-controller.md).
53+
5154
### Navigation
5255
5356
Previous step: [Add a datasource](todo-tutorial-datasource.md)

docs/site/todo-tutorial-scaffolding.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ the following:
4545
```text
4646
src/
4747
controllers/
48+
home-page.controller.ts
4849
README.md
4950
ping.controller.ts
5051
datasources/
@@ -60,6 +61,7 @@ test/
6061
README.md
6162
mocha.opts
6263
acceptance/
64+
home-page.controller.acceptance.ts
6365
ping.controller.acceptance.ts
6466
node_modules/
6567
***

examples/todo-list/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ application, follow these steps:
8080
```sh
8181
$ npm start
8282
83-
Server is running on port 3000
83+
Server is running at http://127.0.0.1:3000
8484
```
8585

8686
Feel free to look around in the application's code to get a feel for how it

examples/todo/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ application, follow these steps:
7373
```sh
7474
$ npm start
7575
76-
Server is running on port 3000
76+
Server is running at http://127.0.0.1:3000
7777
```
7878

7979
Feel free to look around in the application's code to get a feel for how it

0 commit comments

Comments
 (0)