Skip to content
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

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

iampujan
Copy link
Contributor

@iampujan iampujan commented Jun 5, 2022

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/

@iampujan iampujan self-assigned this Jun 5, 2022
@bmnepali bmnepali changed the title SKT-2: added get and post request in cats controller SKT-2: Added get and post request in cats controller Jun 6, 2022
@bmnepali
Copy link
Contributor

bmnepali commented Jun 6, 2022

@iampujan Could you add more info about each endpoint you have created in this PR?
Also what do you mean by (used async)? Please explain.

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: [],
Copy link
Collaborator

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],
Copy link
Collaborator

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],
Copy link
Collaborator

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 {
Copy link
Collaborator

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!.';
Copy link
Collaborator

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`;
Copy link
Collaborator

@bhuwantm bhuwantm Jun 13, 2022

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants