모든 게시물을 가져오는 서비스 만들기(R)
모든 게시물 데이터를 데이터베이스에서 가져오는 로직 구현
Service에서 구현한다.
boards.controller.ts
boards.service.ts
정리
클라이언트에서 요청을 보내면 Controller로 가고, Controller에서 알맞은 요청 경로에 라우팅하여 해당 Handler로 가게 해준다.
그 후 , 요청을 처리해주기 위해서 Service로 들어가며 그 요청에 맞는 로직을 Service에서 처리해준 후 Controller에 리턴값을 보내주고, Controller에서 클라이언트로 결과값을 보내준다.
Controller는 결국
요청을 처리해주고 결과값을 리턴해주는 역할
을 한다.
Board Model 정의하기
게시물에 필요한 데이터가 어떤 것이 필요한지를 정의해주기 위해
게시물의 모델을 만들어야 한다.
ex) id, 이름, 설명
모델을 정의하려면 Class나 Interface를 이용한다.
Class는 변수의 타입도 체크하고 인스턴스 또한 생성할 수 있다.
Interface는 변수의 타입만을 체크한다.
BoardStatus란?
게시물이 공개 게시물인지 비밀 게시물인지 나눠주는것.
두 가지 상태 이외엔 나오면 안되기 때문에 Typescript의 기능인 **enumeration(문자열)**을 사용한다.
타입 정의해주기