본문 바로가기

전체 글74

[Toy - Smart] PathConverter 구현 PathConverter 살펴보기 PathConverter는 파일 저장이나 조회 시 매개변수로 전달하는 path에 대해 리소스 접근에 기본 경로를 추가해준다. - 모든 메서드는 static으로 선언되어 있다. - PropertyUtils에 초기화된 환경설정 값을 가져와 사용한다. - toImgAccessUrl, toImgAccessLocal 메서드가 구현되어 있다. /** * 매개변수로 받은 경로에 대해 리소스 접근을 위한 추가적인 기본 경로를 추가한다. */ public class PathConverter { /** * 경로를 이미지 리소스에 접근하기 위한 url 형태로 변경한다. * @param imgPath : 이미지 파일의 위치 * @return : 이미지 리소스 접근 url */ public s.. 2023. 2. 28.
[Toy - Smart] CustomFileUtils 리팩토링 CustomFileUtils 살펴보기 CustomFileUtil은 파일 저장에 대한 처리 기능을 구현한 클래스이다. 의존성을 줄이고 재상용성을 높이기 위해 매개변수는 String, MultipartFile 등의 타입만을 받도록 설계하였다. - 사용자 정의 Util 클래스로 모든 메서드가 static으로 선언돼있다. - application.properties에 정의된 환경값을 PropertyUtil의 get 메서드를 이용해 접근한다. - 이미지 확인이 불가능한 경우 'images/empty/noimg.jpeg' 파일로 대체한다. - getAccessUrl, getAccessUrls, findFiles, findFile, saveFiles, saveFile, deleteDirectory, deleteAll.. 2023. 2. 28.
[Toy - Smart] ProductServiceImpl 리팩토링 ProductServiceImpl 살펴보기 제품에 관한 비즈니스 로직을 처리하는 클래스이다. - Service 클래스이며 ProductService 인터페이스를 상속한다. - ProductRepository와 OrderItemRepository를 생성자의 매개변수로 주입 받는다. - findOne, findAll, findAllWithFilter, save, update, delete 메서드가 구현되었다. @Service @Transactional(readOnly = true) @RequiredArgsConstructor public class ProductServiceImpl implements ProductService { private final ProductRepository productRepo.. 2023. 2. 26.
[Toy - Smart] ProductDao 구현 ProductDao 살펴보기 ProductDao는 기존 Spring Data JPA의 JpaRepository를 이용해 구현한 메서드로는 해결하기 애매한 필터 기능을 다른 방식으로 처리하기 위해 구현한 클래스이다. - Repository 관련 로직을 처리한다. - 쿼리를 직접 생성하여 처리한다. - existsByName, findById, findByName, findAllByFilter, save, deleteById, count, createWhere, createSort 메서드를 구현하고 있다. @Repository @RequiredArgsConstructor public class ProductDaoImpl implements ProductDao { private final EntityManag.. 2023. 2. 25.
[Toy - Smart] ProductInfoDto 리팩토링 ProductInfoDto 살펴보기 ProductInfoDto는 제품에 대한 정보를 응답에 맞게 변환하여 저장하는 클래스이다. - DTO 클래스이다. - 반환되는 데이터 형식으로 사용된다. @Getter @Setter @ToString @NoArgsConstructor public class ProductInfoDto { private Long productId; private List imgFiles; private String name; private Integer price; private String code; private String size; private String detailInfo; public ProductInfoDto(Product product, List productAccess.. 2023. 2. 25.
[Toy - Smart] ProductUpdateDto 리팩토링 ProductUpdateDto 살펴보기 ProductUpdateDto는 클라이언트 요청에 담긴 제품 정보를 저장하고 Product Entity를 업데이트하기 위한 클래스이다. - DTO 클래스이다. - ProductDto 인터페이스를 상속받고 있다. - getDirectoryPath, getViewPath 메서드가 구현되어 있다. @Getter @Builder @AllArgsConstructor @ToString(callSuper = true) public class ProductUpdateDto implements ProductDto { private Long productId; private List imgFiles; @NotBlank(message = "제품 이름이 필요합니다.") private S.. 2023. 2. 25.