Skip to content

Commit

Permalink
refactor(rest-crud): use defineCrudRepositoryClass from `@loopback/…
Browse files Browse the repository at this point in the history
…repository`

Drop our own implementation in favor of the new generic version.

Co-authored-by: Miroslav Bajtoš <[email protected]>
  • Loading branch information
raymondfeng and bajtos committed May 3, 2020
1 parent faa0240 commit aaf77df
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 61 deletions.
10 changes: 7 additions & 3 deletions packages/rest-crud/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ class defined without the need for a repository or controller class file.

If you would like more flexibility, e.g. if you would only like to define a
default `CrudRest` controller or repository, you can use the two helper methods
(`defineCrudRestController` and `defineCrudRepositoryClass`) exposed from
`@loopback/rest-crud`. These functions will help you create controllers and
respositories using code.
(`defineCrudRestController` from `@loopback/rest-crud` and
`defineCrudRepositoryClass` from `@loopback/repository`). These functions will
help you create controllers and repositories using code.

For the examples in the following sections, we are also assuming a model named
`Product`, and a datasource named `db` have already been created.
Expand Down Expand Up @@ -106,6 +106,8 @@ on the Model) for your app.
Usage example:

```ts
import {defineCrudRepositoryClass} from '@loopback/repository';

const ProductRepository = defineCrudRepositoryClass(Product);
this.repository(ProductRepository);
inject('datasources.db')(ProductRepository, undefined, 0);
Expand All @@ -118,6 +120,8 @@ Here is an example of an app which uses `defineCrudRepositoryClass` and
requirements.

```ts
import {defineCrudRepositoryClass} from '@loopback/repository';

export class TryApplication extends BootMixin(
ServiceMixin(RepositoryMixin(RestApplication)),
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// License text available at https://opensource.org/licenses/MIT

import {
defineCrudRepositoryClass,
Entity,
EntityCrudRepository,
juggler,
Expand All @@ -18,7 +19,7 @@ import {
givenHttpServerConfig,
toJSON,
} from '@loopback/testlab';
import {defineCrudRepositoryClass, defineCrudRestController} from '../..';
import {defineCrudRestController} from '../..';

// In this test scenario, we create a product with a required & an optional
// property and use the default model settings (strict mode, forceId).
Expand Down
3 changes: 2 additions & 1 deletion packages/rest-crud/src/crud-rest.api-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ import {
import {
ApplicationWithRepositories,
Class,
defineCrudRepositoryClass,
Entity,
EntityCrudRepository,
} from '@loopback/repository';
import {Model} from '@loopback/rest';
import debugFactory from 'debug';
import {defineCrudRepositoryClass, defineCrudRestController} from '.';
import {defineCrudRestController} from '.';

const debug = debugFactory('loopback:boot:crud-rest');

Expand Down
3 changes: 2 additions & 1 deletion packages/rest-crud/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
* @packageDocumentation
*/

// Re-export `defineCrudRepositoryClass` for backward-compatibility
export {defineCrudRepositoryClass} from '@loopback/repository';
export * from './crud-rest.api-builder';
export * from './crud-rest.component';
export * from './crud-rest.controller';
export * from './repository-builder';
55 changes: 0 additions & 55 deletions packages/rest-crud/src/repository-builder.ts

This file was deleted.

0 comments on commit aaf77df

Please sign in to comment.