CatalogController.java
@RestController
@RequiredArgsConstructor
@RequestMapping("/catalog-service")
public class CatalogController {
private final Environment env;
private final CatalogService catalogService;
@GetMapping("/health_check")
public String status() {
return String.format("It's Working in Catalog Service on PORT %s",
env.getProperty("local.server.port"));
}
@GetMapping("/catalogs")
public ResponseEntity<List<ResponseCatalog>> getCatalogs() {
Iterable<CatalogEntity> catalogList = catalogService.getAllCatalogs();
List<ResponseCatalog> result = new ArrayList<>();
catalogList.forEach(v -> {
result.add(new ModelMapper().map(v, ResponseCatalog.class));
});
return ResponseEntity.status(HttpStatus.OK).body(result);
}
}
application.yml
server:
port: 0
spring:
application:
name: catalog-service
h2:
console:
enabled: true
settings:
web-allow-others: true
path: /h2-console
jpa:
hibernate:
ddl-auto: create-drop
show-sql: true
generate-ddl: true
datasource:
driver-class-name: org.h2.Driver
url: jdbc:h2:mem:testdb
# username: sa
# password: 1234
eureka:
instance:
instance-id: ${spring.application.name}:${spring.application.instance_id:${random.value}}
client:
register-with-eureka: true
fetch-registry: true
service-url:
defaultZone: http://127.0.0.1:8761/eureka
logging:
level:
com.kyhslam.catalogservice: DEBUG
테스트
- catalogs 목록 조회 완료