Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Proxy Pattern & Decorator Pattern] 예제 프로젝트 만들기 v3
- Loading branch information
1 parent
f6df360
commit b139e5d
Showing
3 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
proxy/src/main/java/hello/proxy/app/v3/OrderControllerV3.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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
23
proxy/src/main/java/hello/proxy/app/v3/OrderRepositoryV3.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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
17
proxy/src/main/java/hello/proxy/app/v3/OrderServiceV3.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |