-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
docs: migrate custom model methods #4476
Conversation
8ff376f
to
06aa2eb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for kicking off this work!
I like that you are mentioning disableRemoteMethodByName
API and the whole idea of hiding some of the standard REST API endpoints, it used to be a frequently asked feature in the past.
I see the following scenarios that should be covered by our docs:
- At Repository level:
- Customize behavior of a method
- Add a new method (e.g.
findByName
in addition to built-infindById
andfind
)
- At Controller level:
- Remove an endpoint
- Customize the behavior of an existing (scaffolded) endpoint
- Change the signature (API spec) of an existing (scaffolded) endpoint
- Add a new (custom) endpoint
I think that some of those scenarios are not specific to migration from LB3 to LB4 and thus can be covered elsewhere. (E.g. adding a new method to a Repository or a Controller.) In the context of the migration guide, I consider as important to connect the dots and explain things from the point of view of a LB3 user.
- If my LB3 model has a custom method that's exposed via REST API, then I am supposed to implement two new methods in LB4 - one in the repository and another in the controller.
- If my LB3 model customizes behavior of a built-in method while preserving the (public) API (both REST and JavaScript), then in LB4 I need to change the Repository method only.
If my LB3 model changes only the public (REST) API of a built-in method, then in LB4 it's probably enough to customize the Controller method while keeping the default Repository implementation.
``` | ||
|
||
It extends [DefaultCrudRepository](https://github.com/strongloop/loopback-next/blob/master/packages/repository/src/repositories/legacy-juggler-bridge.ts). To customize the `find` method, you would override this method in the `NoteRepository` class. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please add a code snippet showing how a custom version of find
would look like? Ideally, the snippet should show the outcome of migrating the custom method described earlier in LB3 code snippet.
|
||
To hide all REST API endpoints of a particular model, simply do not create a controller class for it. | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please explain how to customize a particular REST API endpoint? How to add a new (custom) endpoint?
}) | ||
async deleteById(@param.path.number('id') id: number): Promise<void> { | ||
await this.noteRepository.deleteById(id); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find this code snippet as way too long, hiding more important content on this page.
I am also concerned about maintenance costs, I am pretty much certain we will often forget to update this code after modifying controller templates in our CLI.
Can you please shorten this snippet and show only one or two methods? You can point users to one of our example controllers (e.g. https://github.com/strongloop/loopback-next/blob/master/examples/todo-list/src/controllers/todo-list.controller.ts) for a full version.
3879a02
to
fcd43cb
Compare
After speaking with @bajtos , we decided: to remove this :
to leave this discussion
for a non-migration guide. This document will focus on : a) how to control which endpoints become public b) If my LB3 model has a custom method that's exposed via REST API, then I am supposed to implement two new methods in LB4 - one in the repository and another in the controller. c) If my LB3 model customizes behavior of a built-in method while preserving the (public) API (both REST and JavaScript), then in LB4 I need to change the Repository method only. |
fcd43cb
to
6bcfece
Compare
6bcfece
to
5053d44
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lovely writeup! Left some minor comments.
5053d44
to
917d108
Compare
@slnode test please |
917d108
to
e958761
Compare
`findByTitle` to `NoteRepository`, a **new** method `findByTitle` to | ||
`NoteController`, and specify an endpoint url of `/notes/byTitle/{title}`. | ||
|
||
**src/repositories/note.repository.ts** |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you update to use {% include code-caption.html content="..." %}
here and similar areas?
e958761
to
3074ef3
Compare
Content for
docs/site/migration/models/methods.md
Explains how to migrate model methods defined by the user.
connect to: #3949
Checklist
👉 Read and sign the CLA (Contributor License Agreement) 👈
npm test
passes on your machinepackages/cli
were updatedexamples/*
were updated👉 Check out how to submit a PR 👈