-
Notifications
You must be signed in to change notification settings - Fork 0
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
SKT-2: Added get and post request in cats controller #6
base: develop
Are you sure you want to change the base?
Conversation
@iampujan Could you add more info about each endpoint you have created in this PR? Also instead of loading the controller, services for cats, create a cats module and import it in the app module. We will use this cats module as example module and add more functionalities. |
@@ -1,10 +1,12 @@ | |||
import { Module } from '@nestjs/common'; | |||
import { AppController } from './app.controller'; | |||
import { AppService } from './app.service'; | |||
import { CatsController } from './cats/cats.controller'; | |||
import { CatService } from './cats/cats.service'; | |||
|
|||
@Module({ | |||
imports: [], |
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.
- separate out cats module, it allows us to group related items in a single module
- import the cats.module.ts here
- by doing this things related to cats are placed under cats folder and access to items in cats occurs through it
|
||
@Module({ | ||
imports: [], | ||
controllers: [AppController], | ||
providers: [AppService], | ||
controllers: [AppController, CatsController], |
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.
- after the cats.module.ts is imported we can remove CatsController from here
controllers: [AppController], | ||
providers: [AppService], | ||
controllers: [AppController, CatsController], | ||
providers: [AppService, CatService], |
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.
- after the cats.module.ts is imported we can remove CatsService from here
@@ -0,0 +1,5 @@ | |||
export class CreateCatDto { |
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.
create a dto folder and place all dto created files in there
@Injectable() | ||
export class CatService { | ||
findAll(): string { | ||
return 'This is cat world!.'; |
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.
- create an interface folder and create interface for cat
- don't just return plain string
- create a list of demo data of cats having type as defined in interface
- return list of above demo data
@Get(':id') | ||
findOne(@Param() params): string { | ||
console.log(params.id); | ||
return `This action returns a #${params.id} cat`; |
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.
- use service function to get specific cat (see comments in service file)
Summary:
Implementation of GET and POST requests in cats controller/
Description:
GET Requests:
i. GET
/cats/profile
ii. GET
/cats/
(used async)iii. GET
/cats/:Id
(any number or id)POST requests:
i. POST
/cats/