Skip to content

Commit f48dbcf

Browse files
committed
docs: 시퀀스다이어그램 추가
1 parent 50a501d commit f48dbcf

1 file changed

Lines changed: 384 additions & 0 deletions

File tree

docs/week2/02-sequence-diagrams.md

Lines changed: 384 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,384 @@
1+
## 시퀀스 다이어그램
2+
3+
---
4+
### 상품 조회
5+
6+
```mermaid
7+
sequenceDiagram
8+
participant User
9+
participant ProductController
10+
participant ProductService
11+
participant ProductRepository
12+
participant LikeRepository
13+
14+
User->>ProductController: GET /api/v1/products?sort={option}&page={n}&size=20
15+
ProductController->>ProductService: getProducts(userId, sortOption, page)
16+
ProductService->>ProductRepository: findAllOrderBy(sortOption, page)
17+
18+
19+
loop 상품 목록 내 각 상품
20+
alt 유저 아이디가 있는 경우
21+
ProductService->>LikeRepository: existsByUserIdAndProductId(userId, productId)
22+
LikeRepository-->>ProductService: isLiked (true/false)
23+
else 유저 아이디가 없는 경우
24+
LikeRepository-->>ProductService: isLiked (false), false값만 반환
25+
end
26+
ProductService->>LikeRepository: countByProductId(productId)
27+
LikeRepository -->> ProductService: likeCount
28+
end
29+
30+
alt 상품이 있는 경우
31+
ProductService-->>ProductController: 상품 목록 + 좋아요 수 + 유저 좋아요 여부 + 다음 페이지 URL
32+
ProductController-->>User: 상품 목록 응답 (JSON)
33+
else 상품이 없는 경우
34+
ProductService-->>ProductController: 빈 리스트 제공
35+
ProductController-->>User: 상품 없음 응답 (JSON)
36+
end
37+
```
38+
39+
---
40+
### 상품 상세 조회
41+
42+
```mermaid
43+
sequenceDiagram
44+
participant User
45+
participant ProductController
46+
participant ProductService
47+
participant ProductRepository
48+
participant LikeRepository
49+
50+
User->>ProductController: GET /api/v1/products/{productId}
51+
ProductController->>ProductService: getProductDetail(userId, productId)
52+
53+
ProductService->>ProductRepository: findById(productId)
54+
ProductRepository-->>ProductService: Product (name, price, brand, description, stock)
55+
56+
ProductService->>LikeRepository: countByProductId(productId)
57+
LikeRepository-->>ProductService: likeCount
58+
59+
alt 유저 아이디가 있는 경우
60+
ProductService->>LikeRepository: existsByUserIdAndProductId(userId, productId)
61+
LikeRepository-->>ProductService: isLiked (true/false)
62+
else 유저 아이디가 없는 경우
63+
LikeRepository-->>ProductService: isLiked (false)
64+
end
65+
66+
alt 상품이 존재하는 경우
67+
alt 재고가 0인 경우(stock == 0)
68+
ProductService-->>ProductController: 상품 상세 정보 + likeCount + isLiked + 품절 상태
69+
ProductController-->>User: 상품 상세 응답 (status="SOLD_OUT")
70+
else 재고가 있는 경우(stock > 0)
71+
ProductService-->>ProductController: 상품 상세 정보 + likeCount + isLiked
72+
ProductController-->>User: 상품 상세 응답 (JSON)
73+
end
74+
else 상품이 존재하지 않는 경우
75+
ProductService-->>ProductController: 예외 발생
76+
ProductController-->>User: 404 Not Found (상품을 찾을 수 없습니다)
77+
end
78+
```
79+
80+
---
81+
### 브랜드 조회
82+
83+
```mermaid
84+
sequenceDiagram
85+
participant User
86+
participant BrandController
87+
participant BrandService
88+
participant BrandRepository
89+
participant ProductRepository
90+
91+
User->>BrandController: GET /api/v1/brands/{brandId}
92+
BrandController->>BrandService: getBrandDetail(brandId)
93+
BrandService->>BrandRepository: findById(brandId)
94+
95+
alt 브랜드 존재
96+
BrandRepository-->>BrandService: 브랜드 정보(이름, 설명)
97+
BrandService->>ProductRepository: findByBrandId(brandId)
98+
ProductRepository-->>BrandService: 상품 목록
99+
100+
alt 상품 존재
101+
BrandService-->>BrandController: 브랜드 정보 + 상품 목록
102+
BrandController-->>User: 브랜드 정보 및 상품 목록 응답 (JSON)
103+
else 상품 없음
104+
BrandService-->>BrandController: 브랜드 정보 + 빈 상품 목록
105+
BrandController-->>User: 브랜드 정보 + “상품이 없습니다.” 응답 (JSON)
106+
end
107+
else 브랜드 미존재
108+
BrandRepository-->>BrandService: null
109+
BrandService-->>BrandController: 예외 발생
110+
BrandController-->>User: 404 Not Found (브랜드를 찾을 수 없습니다.)
111+
end
112+
113+
```
114+
115+
---
116+
### 상품 좋아요
117+
118+
```mermaid
119+
sequenceDiagram
120+
participant User
121+
participant LikeController
122+
participant LikeFacade
123+
participant LikeService
124+
participant ProductService
125+
participant LikeRepository
126+
127+
User->>LikeController: POST /api/v1/like/products/{productId}
128+
129+
alt X-USER-ID 없음 (미로그인)
130+
LikeController-->>User: 401 Unauthorized (로그인이 필요합니다)
131+
else 로그인한 사용자
132+
LikeController->>LikeFacade: addLike(userId, productId)
133+
134+
LikeFacade->>ProductService: getLike(productId)
135+
136+
alt productId에 대한 상품이 존재하지 않는 경우
137+
ProductService-->>LikeFacade: NotFoundException
138+
LikeFacade-->>LikeController: 404 Not Found (상품을 찾을 수 없습니다)
139+
LikeController-->>User: 404 Not Found
140+
else 상품 존재
141+
ProductService-->>LikeFacade: ProductEntity
142+
143+
LikeFacade->>LikeService: toggleLike(userId, productId)
144+
LikeService->>LikeRepository: existsByUserIdAndProductId(userId, productId)
145+
146+
alt 좋아요 이력이 없음
147+
LikeService->>LikeRepository: save(userId, productId)
148+
LikeRepository-->>LikeService: saved
149+
else 이미 좋아요한 상태
150+
LikeService-->>LikeController: 상태 유지
151+
end
152+
153+
LikeService->>LikeRepository: countByProductId(productId)
154+
LikeRepository-->>LikeService: likeCount
155+
156+
LikeFacade-->>LikeController: { liked: true, likeCount }
157+
LikeController-->>User: JSON 응답 (좋아요 상태 및 총 좋아요 수)
158+
end
159+
end
160+
161+
```
162+
163+
---
164+
### 상품 좋아요 취소
165+
166+
```mermaid
167+
168+
sequenceDiagram
169+
participant User
170+
participant LikeController
171+
participant LikeFacade
172+
participant LikeService
173+
participant ProductService
174+
participant LikeRepository
175+
176+
User->>LikeController: DELETE /api/v1/like/products/{productId}
177+
178+
alt X-USER-ID 없음 (미로그인)
179+
LikeController-->>User: 401 Unauthorized (로그인이 필요합니다)
180+
else 로그인한 사용자
181+
LikeController->>LikeFacade: removeLike(userId, productId)
182+
183+
LikeFacade->>ProductService: get(productId)
184+
185+
alt productId에 대한 상품이 존재하지 않는 경우
186+
ProductService-->>LikeFacade: NotFoundException
187+
LikeFacade-->>LikeController: 404 Not Found (상품을 찾을 수 없습니다)
188+
LikeController-->>User: 404 Not Found
189+
else 상품 존재
190+
ProductService-->>LikeFacade: ProductEntity
191+
192+
LikeFacade->>LikeService: removeLike(userId, productId)
193+
LikeService->>LikeRepository: existsByUserIdAndProductId(userId, productId)
194+
195+
alt 좋아요 이력이 존재함
196+
LikeService->>LikeRepository: delete(userId, productId)
197+
LikeRepository-->>LikeService: deleted
198+
else 좋아요하지 않은 상태
199+
LikeService-->>LikeController: 상태 유지
200+
end
201+
202+
LikeService->>LikeRepository: countByProductId(productId)
203+
LikeRepository-->>LikeService: likeCount
204+
205+
LikeFacade-->>LikeController: { liked: false, likeCount }
206+
LikeController-->>User: JSON 응답 (좋아요 취소 완료)
207+
end
208+
end
209+
210+
```
211+
212+
---
213+
### 내가 좋아요한 상품 목록 조회
214+
215+
```mermaid
216+
sequenceDiagram
217+
participant User
218+
participant LikeController
219+
participant LikeService
220+
participant LikeRepository
221+
participant ProductRepository
222+
223+
User->>LikeController: GET /api/v1/like/products
224+
alt X-USER-ID 없음 (미로그인)
225+
LikeController-->>User: 401 Unauthorized (로그인이 필요합니다)
226+
else 로그인한 사용자
227+
LikeController->>LikeService: getLikedProducts(userId)
228+
229+
LikeService->>LikeRepository: findAllByUserId(userId)
230+
LikeRepository-->>LikeService: likedProductIds
231+
232+
LikeService->>ProductRepository: findAllByIds(likedProductIds)
233+
ProductRepository-->>LikeService: ProductList
234+
alt 리스트가 있는 경우
235+
LikeService-->>LikeController: ProductList (상품 정보 + 좋아요 수)
236+
LikeController-->>User: JSON 응답 (좋아요한 상품 목록)
237+
else 빈 리스트인 경우
238+
LikeService-->>LikeController:빈 리스트 반환
239+
end
240+
end
241+
```
242+
243+
---
244+
### 주문 생성 및 결제 요청
245+
246+
```mermaid
247+
sequenceDiagram
248+
participant User
249+
participant OrderController
250+
participant OrderFacade
251+
participant OrderService
252+
participant ProductService
253+
participant PointService
254+
participant ExternalPaymentSystem
255+
participant OrderRepository
256+
257+
User ->> OrderController: POST /api/v1/orders (items, quantities)
258+
259+
alt X-USER-ID 없음 (미로그인)
260+
OrderController -->> User: 401 Unauthorized (로그인이 필요합니다)
261+
else 로그인한 사용자
262+
OrderController ->> OrderFacade: createOrder(userId, items)
263+
264+
loop for each item
265+
OrderFacade ->> ProductService: checkStock(productId, quantity)
266+
267+
alt 재고 부족(stock < quantity)
268+
ProductService -->> OrderFacade: stockAvailable == false
269+
OrderFacade -->> OrderController: 400 Bad Request ("품절된 상품입니다.")
270+
OrderController -->> User: 품절된 상품입니다.
271+
else 재고 있음(stock >= quantity)
272+
ProductService -->> OrderFacade: stockAvailable == true
273+
end
274+
end
275+
276+
OrderFacade ->> PointService: verifyUserPoint(userId, totalPrice)
277+
278+
alt 포인트 부족(point < totalPrice)
279+
PointService -->> OrderFacade: pointAvailable == false
280+
OrderFacade -->> OrderController: 400 Bad Request ("잔액이 부족합니다.")
281+
OrderController -->> User: 잔액이 부족합니다.
282+
else 포인트 충분
283+
PointService -->> OrderFacade: pointAvailable == true
284+
285+
OrderFacade ->> OrderService: createOrder(userId, items)
286+
OrderService -->> OrderFacade: OrderEntity
287+
288+
OrderFacade ->> ProductService: decreaseStock(productId, quantity)
289+
ProductService -->> OrderFacade: success
290+
291+
OrderFacade ->> PointService: deductPoints(userId, totalPrice)
292+
PointService -->> OrderFacade: success
293+
294+
OrderFacade ->> OrderRepository: save(order)
295+
OrderRepository -->> OrderFacade: saved
296+
297+
OrderFacade ->> ExternalPaymentSystem: sendOrderInfo(order)
298+
299+
alt 외부 결제 시스템 오류
300+
ExternalPaymentSystem -->> OrderFacade: failure
301+
OrderFacade ->> OrderRepository: rollback(order)
302+
OrderFacade -->> OrderController: 500 Internal Server Error ("결제 실패")
303+
OrderController -->> User: 결제 실패
304+
else 결제 성공
305+
ExternalPaymentSystem -->> OrderFacade: success
306+
OrderFacade -->> OrderController: success(orderId)
307+
OrderController -->> User: 주문 완료 (200 OK)
308+
end
309+
end
310+
end
311+
312+
```
313+
314+
---
315+
### 주문 목록 조회
316+
317+
```mermaid
318+
sequenceDiagram
319+
participant User
320+
participant OrderController
321+
participant OrderService
322+
participant OrderRepository
323+
324+
User ->> OrderController: GET /api/v1/orders
325+
326+
alt X-USER-ID 없음 (미로그인)
327+
OrderController -->> User: 401 Unauthorized (로그인이 필요합니다)
328+
else 로그인한 사용자
329+
OrderController ->> OrderService: getUserOrders(userId)
330+
OrderService ->> OrderRepository: findByUserId(userId)
331+
OrderRepository -->> OrderService: 주문 리스트
332+
alt 주문 목록이 있는 경우
333+
OrderService -->> OrderController: 주문 리스트
334+
OrderController -->> User: 주문 목록 반환 (200 OK)
335+
else 주문 목록이 없는 경우
336+
OrderService -->> OrderController: 빈 리스트
337+
end
338+
end
339+
```
340+
341+
---
342+
### 단일 주문 상세 조회
343+
344+
```mermaid
345+
sequenceDiagram
346+
participant User
347+
participant OrderController
348+
participant OrderFacade
349+
participant OrderService
350+
participant ProductService
351+
participant OrderRepository
352+
353+
alt X-USER-ID 없음 (미로그인)
354+
OrderController -->> User: 401 Unauthorized (로그인이 필요합니다)
355+
else 로그인한 사용자
356+
User ->> OrderController: GET /api/v1/orders/{orderId}
357+
OrderController ->> OrderFacade: getOrderDetail(orderId, userId)
358+
359+
OrderFacade ->> OrderService: findOrder(orderId)
360+
361+
alt 존재하지 않는 주문
362+
OrderService -->> OrderFacade: NotFoundException
363+
OrderFacade -->> OrderController: 404 Not Found (주문을 찾을 수 없습니다)
364+
OrderController -->> User: 주문을 찾을 수 없습니다 (404)
365+
else 주문 존재
366+
OrderService -->> OrderFacade: OrderEntity
367+
368+
alt 요청자 ≠ 주문자
369+
OrderFacade -->> OrderController: 403 Forbidden (접근 권한이 없습니다)
370+
OrderController -->> User: 접근 권한이 없습니다 (403)
371+
else 주문자 일치
372+
OrderFacade ->> ProductService: getProductDetails(order.items)
373+
ProductService -->> OrderFacade: ProductDetails
374+
375+
OrderFacade ->> OrderService: toOrderDetailResponse(order, ProductDetails)
376+
OrderService -->> OrderFacade: OrderDetailResponse
377+
378+
OrderFacade -->> OrderController: OrderDetailResponse
379+
OrderController -->> User: 주문 상세 반환 (200 OK)
380+
end
381+
end
382+
end
383+
384+
```

0 commit comments

Comments
 (0)