From d7042fbcc27751e50cd732772b4b615609a1dbd2 Mon Sep 17 00:00:00 2001 From: Peace Date: Tue, 10 Jun 2025 01:36:54 +0900 Subject: [PATCH] create module, controller, service by cli --- nest-start/.prettierrc | 6 ++-- nest-start/eslint.config.mjs | 5 +-- nest-start/src/app.controller.spec.ts | 12 +++---- nest-start/src/app.controller.ts | 13 +++----- nest-start/src/app.module.ts | 9 ++--- nest-start/src/app.service.ts | 4 +-- nest-start/src/cats/cats.controller.spec.ts | 18 ++++++++++ nest-start/src/cats/cats.controller.ts | 37 +++++++++++++++++++++ nest-start/src/cats/cats.module.ts | 9 +++++ nest-start/src/cats/cats.service.spec.ts | 18 ++++++++++ nest-start/src/cats/cats.service.ts | 4 +++ nest-start/src/main.ts | 4 +-- nest-start/src/users/users.module.ts | 4 +++ 13 files changed, 114 insertions(+), 29 deletions(-) create mode 100644 nest-start/src/cats/cats.controller.spec.ts create mode 100644 nest-start/src/cats/cats.controller.ts create mode 100644 nest-start/src/cats/cats.module.ts create mode 100644 nest-start/src/cats/cats.service.spec.ts create mode 100644 nest-start/src/cats/cats.service.ts create mode 100644 nest-start/src/users/users.module.ts diff --git a/nest-start/.prettierrc b/nest-start/.prettierrc index dcb7279..05d6e5f 100644 --- a/nest-start/.prettierrc +++ b/nest-start/.prettierrc @@ -1,4 +1,4 @@ { - "singleQuote": true, - "trailingComma": "all" -} \ No newline at end of file + "singleQuote": false, + "trailingComma": "all", +} diff --git a/nest-start/eslint.config.mjs b/nest-start/eslint.config.mjs index 2662ec6..6a8cad7 100644 --- a/nest-start/eslint.config.mjs +++ b/nest-start/eslint.config.mjs @@ -29,10 +29,7 @@ export default tseslint.config( '@typescript-eslint/no-explicit-any': 'off', '@typescript-eslint/no-floating-promises': 'warn', '@typescript-eslint/no-unsafe-argument': 'warn', - 'prettier/prettier': [ - 'error', - { endOfLine: 'auto', singleQuote: 'false' }, - ], + 'prettier/prettier': ['error', { endOfLine: 'auto', singleQuote: false }], }, }, ); diff --git a/nest-start/src/app.controller.spec.ts b/nest-start/src/app.controller.spec.ts index d22f389..f643a70 100644 --- a/nest-start/src/app.controller.spec.ts +++ b/nest-start/src/app.controller.spec.ts @@ -1,8 +1,8 @@ -import { Test, TestingModule } from '@nestjs/testing'; -import { AppController } from './app.controller'; -import { AppService } from './app.service'; +import { Test, TestingModule } from "@nestjs/testing"; +import { AppController } from "./app.controller"; +import { AppService } from "./app.service"; -describe('AppController', () => { +describe("AppController", () => { let appController: AppController; beforeEach(async () => { @@ -14,9 +14,9 @@ describe('AppController', () => { appController = app.get(AppController); }); - describe('root', () => { + describe("root", () => { it('should return "Hello World!"', () => { - expect(appController.getHello()).toBe('Hello World!'); + expect(appController.getHello()).toBe("Hello World!"); }); }); }); diff --git a/nest-start/src/app.controller.ts b/nest-start/src/app.controller.ts index 166d35c..ca9928a 100644 --- a/nest-start/src/app.controller.ts +++ b/nest-start/src/app.controller.ts @@ -1,15 +1,12 @@ -import { Body, Controller, Get, Param, Req } from '@nestjs/common'; -import { AppService } from './app.service'; +import { Body, Controller, Get } from "@nestjs/common"; +import { AppService } from "./app.service"; -@Controller('cats') +@Controller("") export class AppController { constructor(private readonly appService: AppService) {} - @Get('hello/:id') - getHello(@Req() req: Request, @Body() body: any, @Param() param): string { - // console.log(req); - console.log(body); - console.log(param); + @Get() + getHello(): string { return this.appService.getHello(); } } diff --git a/nest-start/src/app.module.ts b/nest-start/src/app.module.ts index 8662803..b2c7927 100644 --- a/nest-start/src/app.module.ts +++ b/nest-start/src/app.module.ts @@ -1,9 +1,10 @@ -import { Module } from '@nestjs/common'; -import { AppController } from './app.controller'; -import { AppService } from './app.service'; +import { Module } from "@nestjs/common"; +import { AppController } from "./app.controller"; +import { AppService } from "./app.service"; +import { CatsModule } from "./cats/cats.module"; @Module({ - imports: [], + imports: [CatsModule], controllers: [AppController], providers: [AppService], }) diff --git a/nest-start/src/app.service.ts b/nest-start/src/app.service.ts index 927d7cc..b00a667 100644 --- a/nest-start/src/app.service.ts +++ b/nest-start/src/app.service.ts @@ -1,8 +1,8 @@ -import { Injectable } from '@nestjs/common'; +import { Injectable } from "@nestjs/common"; @Injectable() export class AppService { getHello(): string { - return 'Hello World!'; + return "Hello World!"; } } diff --git a/nest-start/src/cats/cats.controller.spec.ts b/nest-start/src/cats/cats.controller.spec.ts new file mode 100644 index 0000000..fae4b94 --- /dev/null +++ b/nest-start/src/cats/cats.controller.spec.ts @@ -0,0 +1,18 @@ +import { Test, TestingModule } from "@nestjs/testing"; +import { CatsController } from "./cats.controller"; + +describe("CatsController", () => { + let controller: CatsController; + + beforeEach(async () => { + const module: TestingModule = await Test.createTestingModule({ + controllers: [CatsController], + }).compile(); + + controller = module.get(CatsController); + }); + + it("should be defined", () => { + expect(controller).toBeDefined(); + }); +}); diff --git a/nest-start/src/cats/cats.controller.ts b/nest-start/src/cats/cats.controller.ts new file mode 100644 index 0000000..59e46bf --- /dev/null +++ b/nest-start/src/cats/cats.controller.ts @@ -0,0 +1,37 @@ +import { Controller, Delete, Get, Patch, Post, Put } from "@nestjs/common"; +import { CatsService } from "./cats.service"; + +@Controller("cats") +export class CatsController { + constructor(private readonly catsService: CatsService) {} + + @Get() + getAllCat() { + return "all cat"; + } + + @Get(":id") + getOneGat() { + return "one cat"; + } + + @Post() + createCat() { + return "create cat"; + } + + @Put(":id") + updateCat() { + return "update cat"; + } + + @Patch(":id") + updatePartialCat() { + return "update partial cat"; + } + + @Delete(":id") + deleteCat() { + return "delete cat"; + } +} diff --git a/nest-start/src/cats/cats.module.ts b/nest-start/src/cats/cats.module.ts new file mode 100644 index 0000000..a65e2ef --- /dev/null +++ b/nest-start/src/cats/cats.module.ts @@ -0,0 +1,9 @@ +import { Module } from "@nestjs/common"; +import { CatsController } from "./cats.controller"; +import { CatsService } from "./cats.service"; + +@Module({ + controllers: [CatsController], + providers: [CatsService], +}) +export class CatsModule {} diff --git a/nest-start/src/cats/cats.service.spec.ts b/nest-start/src/cats/cats.service.spec.ts new file mode 100644 index 0000000..366ddca --- /dev/null +++ b/nest-start/src/cats/cats.service.spec.ts @@ -0,0 +1,18 @@ +import { Test, TestingModule } from "@nestjs/testing"; +import { CatsService } from "./cats.service"; + +describe("CatsService", () => { + let service: CatsService; + + beforeEach(async () => { + const module: TestingModule = await Test.createTestingModule({ + providers: [CatsService], + }).compile(); + + service = module.get(CatsService); + }); + + it("should be defined", () => { + expect(service).toBeDefined(); + }); +}); diff --git a/nest-start/src/cats/cats.service.ts b/nest-start/src/cats/cats.service.ts new file mode 100644 index 0000000..ae2808e --- /dev/null +++ b/nest-start/src/cats/cats.service.ts @@ -0,0 +1,4 @@ +import { Injectable } from "@nestjs/common"; + +@Injectable() +export class CatsService {} diff --git a/nest-start/src/main.ts b/nest-start/src/main.ts index f728d01..0453316 100644 --- a/nest-start/src/main.ts +++ b/nest-start/src/main.ts @@ -1,5 +1,5 @@ -import { NestFactory } from '@nestjs/core'; -import { AppModule } from './app.module'; +import { NestFactory } from "@nestjs/core"; +import { AppModule } from "./app.module"; async function bootstrap() { const app = await NestFactory.create(AppModule); diff --git a/nest-start/src/users/users.module.ts b/nest-start/src/users/users.module.ts new file mode 100644 index 0000000..e3b6a6d --- /dev/null +++ b/nest-start/src/users/users.module.ts @@ -0,0 +1,4 @@ +import { Module } from '@nestjs/common'; + +@Module({}) +export class UsersModule {}