본문 바로가기

전체 글155

[Python] refactoring - 01. 추상화, 생성자주입을 통한 리팩토링 목적 리팩토링할 코드를 가지고, 여러 번의 단계에 걸쳐 리팩토링을 진행한다. As-is에서 나온 개선해야할 부분을 To-be를 통해 개선한다. 리팩토링 전 문제점 파악 As-is class EricStore: def __init__(self) -> None: self.money = 0 self.name = "에릭상점" self.products = { 1: {"name": "키보드", "price": 30000}, 2: {"name": "모니터", "price": 50000}, } def set_money(self, money): self.money = money def set_products(self, products): self.products = products def get_money(self): .. 2022. 4. 20.
[NestJS] Controller 패턴 import { Controller, Get } from '@nestjs/common'; import { AppService } from './app.service'; @Controller() export class AppController { constructor(private readonly appService: AppService) {} @Get() getHello(): string { return this.appService.getHello(); } } Controller를 우선 살펴보자. Controller는 AppService를 사용하게 만든다. appService에 있는 getHello()의 리턴 값이 그대로 컨트롤러에 리턴이 되고, 그대로 컨트롤러에 있는 getHello() 가 리턴이 된다.. 2022. 1. 7.
[NestJS] NestJS의 시작 NestJS의 시작 import { NestFactory } from '@nestjs/core'; import { AppModule } from './app.module'; async function bootstrap() { const app = await NestFactory.create(AppModule); await app.listen(3000); // 포트 3000번 리스닝 } bootstrap(); NestJS는 main.ts에서 시작한다. 하나의 모듈에서 어플리케이션을 생성한다. AppModule을 호출한다. 앱 모듈은 모든 것의 루트 모듈 같은 역할을 한다. 모듈이란 어플리케이션의 일부이다. 한 가지 역할을 하는 앱이다. 예를 들어 인증을 담당하는 어플리케이션이 있다면 users 모듈이 존재.. 2021. 12. 29.
[TypeScript] 타입스크립트에서 타입힌트를 이용한 인자를 전달하는 방법 (기본, 인터페이스, 클래스) 기본적으로 사용하는 방법(인자를 파싱해서 전달해주는 방법) const person = { name: "eric", age: 25, gender: "male" } // 인자를 파싱해서 전달해주는 방법 const sayHi = (name: string, age: number , gender?: string): string => { return `Hello ${name}, you are ${age}, you are a ${gender}`; }; console.log(sayHi(name, age, gender)); 전통적인 방법이다. 파라미터들을 전달해준다. 인터페이스를 이용한 호출 interface Human { name: string; age: number; gender: string; } const per.. 2021. 12. 29.