프로젝트

[Kotlin 토이프로젝트] 프로젝트 구조설계

sian han 2022. 11. 18. 13:10

https://github.com/HAN-SEOHYUN/movie-api

 

1. Entity data class / DTO data class

 

Q. Why we creating two different classes ?

왜 두개의 클래스를 각각 생성해야 하는가 ?

 

A. Spring boot has an architecture. It has different layers and each layer has their own responsibilities.

스프링부트는 아키텍쳐를 가지고 있는데, 각 레이어들은 모두 다른 책임을 갖고있어서.

 

 

1st. controller layer (Calls the service)

  - exposed to the outside / endpoint / has responsible for calling the service

바깥에 노출되는 레이어 / 엔드포인트 / Service 를 호출할 책임을 갖고 있음

 

2nd. service layer(Business logic) 

 - be invoked from controller and perform certain operation

컨트롤러에 의해 호출되며, 특정 작업을 수행함

 - has all business logic

모든 비즈니스로직을 갖고 있음

 

3rd. persistence layer (Responsible for handling database operations)

 - responsible for saving the data into the database

데이터를 DB 에 넣을 책임

 

The Movie entity class is belongs to the persistence layer. So the dto(data transfer object) class will be passing the data transfer object from in between the layers (not the entity class).

Movie 엔티티 클래스는 Persistence layer 에 속해있다. 그래서 DTO 클래스는 data 를 레이어들 사이에서 전달해준다.

 

How spring knows it's an entity class ? => add @Entity annotaion

스프링은 어떤게 엔티티 클래스인지 어떻게 아나요 ? => @Entity 어노테이션을 통해서

 

 

 

 

2. Mapper interface / implement

Mapper interface : to convert from entity to a DTO

 

MovieMapper class : for implement methods

For add new Object to database, need to creating a Repository.

새로운 객체를 DB에 넣으려면 Repository 생성이 필요하다. 

 

 

 

3. Repository

If you extend CrudRepository, you can skip to create common function.

CrudRepository 를 extend 하면, 기본 function 메서드 생략가능

 

CrudRepository<entity, type of id> 

 

 

 

4. Service interface / ServiceImpl

Service layer will hold the entire business logic.

 

 

5. Resource (end point)