Skip to content

Commit

Permalink
[Proxy Pattern & Decorator Pattern] 예제 프로젝트 만들기 v3
Browse files Browse the repository at this point in the history
  • Loading branch information
jihunparkme committed Dec 7, 2022
1 parent f6df360 commit b139e5d
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
27 changes: 27 additions & 0 deletions proxy/src/main/java/hello/proxy/app/v3/OrderControllerV3.java
@@ -0,0 +1,27 @@
package hello.proxy.app.v3;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
public class OrderControllerV3 {

private final OrderServiceV3 orderService;

public OrderControllerV3(OrderServiceV3 orderService) {
this.orderService = orderService;
}

@GetMapping("/v3/request")
public String request(String itemId) {
orderService.orderItem(itemId);
return "ok";
}

@GetMapping("/v3/no-log")
public String noLog() {
return "ok";
}
}
23 changes: 23 additions & 0 deletions proxy/src/main/java/hello/proxy/app/v3/OrderRepositoryV3.java
@@ -0,0 +1,23 @@
package hello.proxy.app.v3;

import org.springframework.stereotype.Repository;

@Repository
public class OrderRepositoryV3 {

public void save(String itemId) {
//저장 로직
if (itemId.equals("ex")) {
throw new IllegalStateException("예외 발생!");
}
sleep(1000);
}

private void sleep(int millis) {
try {
Thread.sleep(millis);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
17 changes: 17 additions & 0 deletions proxy/src/main/java/hello/proxy/app/v3/OrderServiceV3.java
@@ -0,0 +1,17 @@
package hello.proxy.app.v3;

import org.springframework.stereotype.Service;

@Service
public class OrderServiceV3 {

private final OrderRepositoryV3 orderRepository;

public OrderServiceV3(OrderRepositoryV3 orderRepository) {
this.orderRepository = orderRepository;
}

public void orderItem(String itemId) {
orderRepository.save(itemId);
}
}

0 comments on commit b139e5d

Please sign in to comment.