Skip to content

Commit a1f83f8

Browse files
committed
fix(example-todo): use latest cli code
1 parent 67c6449 commit a1f83f8

File tree

9 files changed

+60
-25
lines changed

9 files changed

+60
-25
lines changed

examples/todo/.dockerignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
node_modules
2+
npm-debug.log
3+
/dist
4+
# Cache used by TypeScript's incremental build
5+
*.tsbuildinfo

examples/todo/Dockerfile

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Check out https://hub.docker.com/_/node to select a new base image
2+
FROM node:10-slim
3+
4+
# Set to a non-root built-in user `node`
5+
USER node
6+
7+
# Create app directory (with user `node`)
8+
RUN mkdir -p /home/node/app
9+
10+
WORKDIR /home/node/app
11+
12+
# Install app dependencies
13+
# A wildcard is used to ensure both package.json AND package-lock.json are copied
14+
# where available (npm@5+)
15+
COPY --chown=node package*.json ./
16+
17+
RUN npm install
18+
19+
# Bundle app source code
20+
COPY --chown=node . .
21+
22+
RUN npm run build
23+
24+
# Bind to all network interfaces so that it can be mapped to the host OS
25+
ENV HOST=0.0.0.0 PORT=3000
26+
27+
EXPOSE ${PORT}
28+
CMD [ "node", "." ]

examples/todo/src/__tests__/acceptance/todo.acceptance.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
import {TodoListApplication} from '../../application';
1515
import {Todo} from '../../models/';
1616
import {TodoRepository} from '../../repositories/';
17-
import {GeocoderService} from '../../services';
17+
import {Geocoder} from '../../services';
1818
import {
1919
aLocation,
2020
getProxiedGeoCoderConfig,
@@ -40,7 +40,7 @@ describe('TodoApplication', () => {
4040
before(async function() {
4141
// eslint-disable-next-line no-invalid-this
4242
this.timeout(30 * 1000);
43-
const service = await app.get<GeocoderService>('services.GeocoderService');
43+
const service = await app.get<Geocoder>('services.Geocoder');
4444
available = await isGeoCoderServiceAvailable(service);
4545
});
4646

examples/todo/src/__tests__/helpers.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {merge} from 'lodash';
88
import path from 'path';
99
import GEO_CODER_CONFIG from '../datasources/geocoder.datasource.config.json';
1010
import {Todo} from '../models/index';
11-
import {GeocoderService, GeoPoint} from '../services/geocoder.service';
11+
import {Geocoder, GeoPoint} from '../services/geocoder.service';
1212

1313
/*
1414
==============================================================================
@@ -74,7 +74,7 @@ export async function givenCachingProxy() {
7474
return proxy;
7575
}
7676

77-
export async function isGeoCoderServiceAvailable(service: GeocoderService) {
77+
export async function isGeoCoderServiceAvailable(service: Geocoder) {
7878
try {
7979
await service.geocode(aLocation.address);
8080
return true;

examples/todo/src/__tests__/integration/services/geocoder.service.integration.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import {expect} from '@loopback/testlab';
77
import {GeocoderDataSource} from '../../../datasources/geocoder.datasource';
8-
import {GeocoderService, GeocoderServiceProvider} from '../../../services';
8+
import {Geocoder, GeocoderProvider} from '../../../services';
99
import {
1010
aLocation,
1111
getProxiedGeoCoderConfig,
@@ -22,7 +22,7 @@ describe('GeoLookupService', function() {
2222
before(async () => (cachingProxy = await givenCachingProxy()));
2323
after(() => cachingProxy.stop());
2424

25-
let service: GeocoderService;
25+
let service: Geocoder;
2626
before(givenGeoService);
2727

2828
let available = true;
@@ -42,6 +42,6 @@ describe('GeoLookupService', function() {
4242
async function givenGeoService() {
4343
const config = getProxiedGeoCoderConfig(cachingProxy);
4444
const dataSource = new GeocoderDataSource(config);
45-
service = await new GeocoderServiceProvider(dataSource).value();
45+
service = await new GeocoderProvider(dataSource).value();
4646
}
4747
});

examples/todo/src/__tests__/unit/controllers/todo.controller.unit.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ import {
1313
import {TodoController} from '../../../controllers';
1414
import {Todo} from '../../../models/index';
1515
import {TodoRepository} from '../../../repositories';
16-
import {GeocoderService} from '../../../services';
16+
import {Geocoder} from '../../../services';
1717
import {aLocation, givenTodo} from '../../helpers';
1818

1919
describe('TodoController', () => {
2020
let todoRepo: StubbedInstanceWithSinonAccessor<TodoRepository>;
21-
let geoService: GeocoderService;
21+
let geoService: Geocoder;
2222

2323
let geocode: sinon.SinonStub;
2424

examples/todo/src/controllers/todo.controller.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ import {
1818
} from '@loopback/rest';
1919
import {Todo} from '../models';
2020
import {TodoRepository} from '../repositories';
21-
import {GeocoderService} from '../services';
21+
import {Geocoder} from '../services';
2222

2323
export class TodoController {
2424
constructor(
25-
@repository(TodoRepository) protected todoRepo: TodoRepository,
26-
@inject('services.GeocoderService') protected geoService: GeocoderService,
25+
@repository(TodoRepository) protected todoRepository: TodoRepository,
26+
@inject('services.Geocoder') protected geoService: Geocoder,
2727
) {}
2828

2929
@post('/todos', {
@@ -52,7 +52,7 @@ export class TodoController {
5252
// https://gis.stackexchange.com/q/7379
5353
todo.remindAtGeo = `${geo[0].y},${geo[0].x}`;
5454
}
55-
return this.todoRepo.create(todo);
55+
return this.todoRepository.create(todo);
5656
}
5757

5858
@get('/todos/{id}', {
@@ -67,7 +67,7 @@ export class TodoController {
6767
@param.path.number('id') id: number,
6868
@param.query.boolean('items') items?: boolean,
6969
): Promise<Todo> {
70-
return this.todoRepo.findById(id);
70+
return this.todoRepository.findById(id);
7171
}
7272

7373
@get('/todos', {
@@ -86,7 +86,7 @@ export class TodoController {
8686
@param.query.object('filter', getFilterSchemaFor(Todo))
8787
filter?: Filter<Todo>,
8888
): Promise<Todo[]> {
89-
return this.todoRepo.find(filter);
89+
return this.todoRepository.find(filter);
9090
}
9191

9292
@put('/todos/{id}', {
@@ -100,7 +100,7 @@ export class TodoController {
100100
@param.path.number('id') id: number,
101101
@requestBody() todo: Todo,
102102
): Promise<void> {
103-
await this.todoRepo.replaceById(id, todo);
103+
await this.todoRepository.replaceById(id, todo);
104104
}
105105

106106
@patch('/todos/{id}', {
@@ -121,7 +121,7 @@ export class TodoController {
121121
})
122122
todo: Partial<Todo>,
123123
): Promise<void> {
124-
await this.todoRepo.updateById(id, todo);
124+
await this.todoRepository.updateById(id, todo);
125125
}
126126

127127
@del('/todos/{id}', {
@@ -132,6 +132,6 @@ export class TodoController {
132132
},
133133
})
134134
async deleteTodo(@param.path.number('id') id: number): Promise<void> {
135-
await this.todoRepo.deleteById(id);
135+
await this.todoRepository.deleteById(id);
136136
}
137137
}

examples/todo/src/models/todo.model.ts

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export class Todo extends Entity {
1010
@property({
1111
type: 'number',
1212
id: true,
13+
generated: false,
1314
})
1415
id?: number;
1516

Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
// Copyright IBM Corp. 2018. All Rights Reserved.
1+
// Copyright IBM Corp. 2018,2020. All Rights Reserved.
22
// Node module: @loopback/example-todo
33
// This file is licensed under the MIT License.
44
// License text available at https://opensource.org/licenses/MIT
55

6-
import {getService, juggler} from '@loopback/service-proxy';
76
import {inject, Provider} from '@loopback/core';
8-
import {GeocoderDataSource} from '../datasources/geocoder.datasource';
7+
import {getService} from '@loopback/service-proxy';
8+
import {GeocoderDataSource} from '../datasources';
99

1010
export interface GeoPoint {
1111
/**
@@ -19,17 +19,18 @@ export interface GeoPoint {
1919
x: number;
2020
}
2121

22-
export interface GeocoderService {
22+
export interface Geocoder {
2323
geocode(address: string): Promise<GeoPoint[]>;
2424
}
2525

26-
export class GeocoderServiceProvider implements Provider<GeocoderService> {
26+
export class GeocoderProvider implements Provider<Geocoder> {
2727
constructor(
28+
// geocoder must match the name property in the datasource json file
2829
@inject('datasources.geocoder')
29-
protected dataSource: juggler.DataSource = new GeocoderDataSource(),
30+
protected dataSource: GeocoderDataSource = new GeocoderDataSource(),
3031
) {}
3132

32-
value(): Promise<GeocoderService> {
33+
value(): Promise<Geocoder> {
3334
return getService(this.dataSource);
3435
}
3536
}

0 commit comments

Comments
 (0)