Util 모듈 제거

This commit is contained in:
roy-zz
2022-05-05 13:04:53 +09:00
parent 0a0c4129ee
commit 1a30d73b36
35 changed files with 255 additions and 409 deletions

View File

@@ -1,6 +1,26 @@
dependencies {
implementation(project(":util"))
plugins {
id 'org.springframework.boot' version '2.6.6'
id 'io.spring.dependency-management' version '1.0.11.RELEASE'
id 'java-library'
}
group = 'com.roy'
version = '1.0'
repositories {
mavenLocal()
mavenCentral()
}
jar {
enabled(true)
}
ext {
set('springCloudVersion', "2021.0.1")
}
dependencies {
implementation 'org.springframework.kafka:spring-kafka'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-validation'

View File

@@ -3,7 +3,6 @@ package com.roy.springcloud.catalogservice.controller;
import com.roy.springcloud.catalogservice.dto.CatalogDto;
import com.roy.springcloud.catalogservice.service.CatalogService;
import com.roy.springcloud.catalogservice.vo.response.CatalogResponse;
import com.roy.springcloud.util.mapper.MapperUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.core.env.Environment;
import org.springframework.http.HttpStatus;
@@ -16,6 +15,8 @@ import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.stream.Collectors;
import static com.roy.springcloud.catalogservice.mapper.MapperUtil.toObject;
@RestController
@RequiredArgsConstructor
@RequestMapping("/catalog-service")
@@ -32,7 +33,7 @@ public class CatalogController {
public ResponseEntity<List<CatalogResponse>> getCatalogs() {
List<CatalogDto> savedCatalogs = catalogService.getAllCatalogs();
List<CatalogResponse> response = savedCatalogs.stream()
.map(catalog -> MapperUtil.toObject(catalog, CatalogResponse.class))
.map(catalog -> toObject(catalog, CatalogResponse.class))
.collect(Collectors.toList());
return ResponseEntity.status(HttpStatus.OK).body(response);
}

View File

@@ -0,0 +1,24 @@
package com.roy.springcloud.catalogservice.mapper;
import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.springframework.beans.BeanUtils;
import java.util.List;
import java.util.stream.Collectors;
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class MapperUtil {
public static <T, S> T toObject(S source, Class<T> targetClass, String... ignoreProperties) {
T target = BeanUtils.instantiateClass(targetClass);
BeanUtils.copyProperties(source, target, ignoreProperties);
return target;
}
public static <T, S> List<T> toList(List<S> sources, Class<T> targetClass, String... ignoreProperties) {
return sources.stream()
.map(source -> toObject(source, targetClass, ignoreProperties))
.collect(Collectors.toList());
}
}

View File

@@ -4,7 +4,6 @@ import com.roy.springcloud.catalogservice.domain.Catalog;
import com.roy.springcloud.catalogservice.dto.CatalogDto;
import com.roy.springcloud.catalogservice.repository.CatalogRepository;
import com.roy.springcloud.catalogservice.service.CatalogService;
import com.roy.springcloud.util.mapper.MapperUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.env.Environment;
@@ -13,6 +12,8 @@ import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;
import static com.roy.springcloud.catalogservice.mapper.MapperUtil.toObject;
@Slf4j
@Service
@RequiredArgsConstructor
@@ -25,7 +26,7 @@ public class CatalogServiceImpl implements CatalogService {
Iterable<Catalog> savedCatalogs = catalogRepository.findAll();
List<CatalogDto> response = new ArrayList<>();
savedCatalogs.forEach(catalog -> {
response.add(MapperUtil.toObject(catalog, CatalogDto.class));
response.add(toObject(catalog, CatalogDto.class));
});
return response;
}

View File

@@ -1,13 +0,0 @@
package com.roy.springcloud.catalogservice;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
@SpringBootTest
class CatalogServiceApplicationTests {
@Test
void contextLoads() {
}
}