전체 글
-
테스트 코드로 알아보는 DITIL 2024. 6. 10. 22:04
서비스를 개발하던 도중 테스트 코드를 작성해야할 필요가 있었고, bcrypt와 같은 외부라이브러리를 사용할때, 함수 모킹이 되지않고, 테스트속도가 오래걸린다는 문제가 있었습니다 (bcrypt와 같은 암호화하는 작업들은 cpu 작업량을 많이요구하고 시간도 오래걸립니다) 문제가 생긴 메서드import * as bcrypt from 'bcryptjs';async signIn(loginDto: LoginDto): Promise { const channel = await this.prisma.channel.findFirst({ where: { id: loginDto.id }, }); if (!channel) { throw new UnauthorizedException(..
-
모듈 분리 / 서비스 코드 분리 기준TIL 2024. 6. 10. 17:26
모듈 분리, 서비스 코드 분리 기준에 대해 생각해보자 각각 언제해야할까? 예를들어 댓글 CRUD기능과 댓글 좋아요기능이 있다고 가정해보자 그럼 1. 댓글 CRUD기능과 댓글 좋아요 기능의 서비스 코드를 분리해야할까? -> 특정 서비스내의 메서드들 중에서 어떤 것은 export를 해야하고 어떤 것은 export를 할 필요가 없다(해서는 안된다). 이때 각 메서드들은 별도의 클래스로 분리해야한다( 객체지향설계 SOLID 중 인터페이스 분리 원칙) (인터페이스 분리 원칙 : 클라이언트가 자신이 이용하지 않는 메서드에 의존하지 않아야 한다는 원칙이다. -> 사용하지않는 불필요한 메서드 들은 가져오면 안된다. 꼭 필요한 메서드들만 주입 받아야한다 ) 2. 댓글 CRUD기능과 댓글 좋아요 기능의..
-
의존성 주입(Dependency Injection)TIL 2024. 6. 10. 17:02
의존성 주입을 쓰는이유 1. 클래스간 결합도를 낮출 수 있다 -> 결합도를 낮춘다는 것(의존성을 줄인다는 것)은 변화에 강하다는것 객체의 생성과 사용을 분리한다 다른 객체를 직접 생성하지않고 외부에서 필요한 객체를 주입받기 때문에 각 역할을 분리할 수 있다 2. 테스트가 가능하다* -> 테스트코드를 작성하는 것은 별도의 모의 객체를 생성하고 그 객체의 함수가 어떤 값을 반환한다고 가정한다(모킹) -> 이것도 의존성을 낮춰줘서 가능한일. 의존성 주입을 하지않으면 모의 객체의 함수를 모킹하는것이 아니라 실제 클래스의 함수를 가져와야하는데, 그럼 문제가 발생한다. 실제로 동작하면 안되는 것들이 동작하게 될 수 있다. 실제객체가 아닌 모의객체를 이용한 테스트가 가능해진다 (예시1 : db연결이 실제..
-
API entry point 만들기 예제)카테고리 없음 2024. 6. 1. 18:18
꼭 Review 모듈에 속해있다고 '/review'로 시작할 필요는 없다 유저가 북마크한 게시물들GET /user/:userIdx/review/bookmarkGET /review/bookmark?userIdx=1유저가 댓글을 단 게시물들GET /user/:userIdx/review/commentedGET /review/commented?userIdx=1유저가 작성한 게시물들GET /user/:userIdx/reviewGET /review?userIdx=1
-
부트캠프 후기 (스테이지어스)카테고리 없음 2024. 5. 31. 22:32
1. 한줄평약 7개월동안 쉽지는 않았지만 정말 많은 것들을 배울 수 있었다.스테이지어스를 다니기 이전 맨처음 아무지식도 없이 갔던 그때의 나와 비교해본다면, 정말 많이 바뀌었다고 느껴진다.혼자서 공부했다면 절대 여기까지 오지 못했을 것 같다.! 2.간단소개 내 소개)비전공, 웹개발(백엔드희망), 아무지식도 없었음 스테이지어스 소개)웹개발(백엔드/프론트엔드)에 관한 지식을 배우는 곳소요시간 : 약 6~7개월위치 : 인하대학교 후문 인근 (도보 5분거리)소규모 오프라인 수업으로 진행된다 3. 내가 스테이지어스에 가게된 배경)"개발분야는 인터넷에 모든 정보가 있어서 누구나 쉽게 입문할 수 있고, 노력만한다면 누구나 금방 성장할 수 있다."는 말은 반은맞고 반은 틀린말이다. 이것도 일정 수준 이상에..
-
[nest.js] swagger 적용하기TIL 2024. 5. 29. 16:04
왜 swagger를 쓰는가?) swagger 를 사용하면 api명세서를 코드내에서 자동으로 쓸 수 있게해준다 api가 많아질경우 api명세서를 쓰는 시간을 훨씬 더 단축시킬 수 있고, 백엔드 작업을 하다보면 놓친부분이나, api명세서 변경이 꽤 많이 일어난다. 그럴때마다 코드와 api명세서를 둘다 수정하는 것은 시간도 오래걸리고, 만약 코드만 수정하고, api명세서 수정하는 것을 깜빡하면 프론트엔드쪽에서는 잘못된 명세서를 많은 시간을 낭비하게된다. swagger 설치하기 npm install --save @nestjs/swagger main.ts에 swagger 적용하기) main.tsimport { NestFactory } from '@nestjs/core';import { Swag..
-
[ERROR] ReferenceError: exports is not defined in ES module scopeTIL 2024. 5. 28. 12:26
nest project를 실행할때 에러가 발생했다. ReferenceError: exports is not defined in ES module scopeThis file is being treated as an ES module because it has a '.js' file extension and '/Users/kiju/dev/study/crime-city/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension. package.json에 "type" : "module" 을 지웠더니 해결되었다 참고)https://stackoverflo..
-
Express staticTIL 2024. 5. 25. 15:05
Express static 미들웨어 express 에서 기본적으로 제공하는 미들웨어이고, express 객체안에서 바로 꺼내 쓸 수 있다정적파일인 이미지, css, javascript등 파일을 쓸때 사용한다 지정된 디렉토리에서 파일을 찾아서 클라이언트에게 제공한다 이 미들웨어를 통해 정적파일에 restful한 방식으로 접근할 수 있다. 사용법 예시1)app.use('요청경로', express.static('실제경로'));app.use('/', express.static(path.join(__dirname, 'public'))); app.use('/', express.static(path.join(__dirname, 'public')));ㄴ 현재 위치한 파일에 대한 절대경로 + '/public' => 이..