Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
라이앤캐처스 크루공간
허창호
연습용
Commits
969fb9e8
Commit
969fb9e8
authored
Feb 06, 2022
by
madvirus
Browse files
Initial Commit
parents
Changes
187
Hide whitespace changes
Inline
Side-by-side
src/main/resources/templates/loggedOut.html
0 → 100644
View file @
969fb9e8
<!DOCTYPE html>
<html
xmlns:th=
"http://www.thymeleaf.org"
>
<head>
<meta
charset=
"UTF-8"
>
<title>
마이샵
</title>
<th:block
th:replace=
"fragments/layout :: cssjs"
/>
</head>
<body>
<div
th:replace=
"fragments/layout :: header"
></div>
<div
class=
"container"
>
<div
class=
"alert alert-info"
role=
"alert"
>
로그아웃했습니다.
</div>
</div>
<div
th:replace=
"fragments/layout :: footer"
></div>
</body>
</html>
\ No newline at end of file
src/main/resources/templates/login.html
0 → 100644
View file @
969fb9e8
<!DOCTYPE html>
<html
xmlns:th=
"http://www.thymeleaf.org"
>
<head>
<meta
charset=
"UTF-8"
>
<title>
로그인
</title>
<th:block
th:replace=
"fragments/layout :: cssjs"
/>
</head>
<body>
<div
th:replace=
"fragments/layout :: header"
></div>
<div
class=
"container"
>
<form
method=
"post"
>
<div
class=
"mb-3"
>
<label
for=
"username"
class=
"form-label"
>
아이디
</label>
<input
type=
"text"
class=
"form-control"
id=
"username"
name=
"username"
>
</div>
<div
class=
"mb-3"
>
<label
for=
"password"
class=
"form-label"
>
암호
</label>
<input
type=
"password"
class=
"form-control"
id=
"password"
name=
"password"
>
</div>
<button
type=
"submit"
class=
"btn btn-primary"
>
로그인
</button>
</form>
</div>
<hr>
<div
th:replace=
"fragments/layout :: footer"
></div>
</body>
</html>
\ No newline at end of file
src/main/resources/templates/my/myMain.html
0 → 100644
View file @
969fb9e8
<!DOCTYPE html>
<html
xmlns:th=
"http://www.thymeleaf.org"
xmlns:sec=
"http://www.thymeleaf.org/extras/spring-security"
>
<head>
<meta
charset=
"UTF-8"
>
<title>
마이샵
</title>
<th:block
th:replace=
"fragments/layout :: cssjs"
/>
</head>
<body>
<div
th:replace=
"fragments/layout :: header"
></div>
<div
class=
"container"
>
<h2><span
sec:authentication=
"principal.username"
>
user
</span>
님
</h2>
<ul>
<li><a
href=
"/my/orders"
>
주문 목록 보기
</a></li>
</ul>
</div>
<div
th:replace=
"fragments/layout :: footer"
></div>
</body>
</html>
\ No newline at end of file
src/main/resources/templates/my/noOrder.html
0 → 100644
View file @
969fb9e8
<!DOCTYPE html>
<html
xmlns:th=
"http://www.thymeleaf.org"
>
<head>
<meta
charset=
"UTF-8"
>
<title>
내 주문
</title>
<th:block
th:replace=
"fragments/layout :: cssjs"
/>
</head>
<body>
<div
th:replace=
"fragments/layout :: header"
></div>
<div
class=
"container"
>
<div
class=
"alert alert-danger"
role=
"alert"
>
존재하지 않는 주문입니다.[NO]
</div>
</div>
<div
th:replace=
"fragments/layout :: footer"
></div>
</body>
</html>
src/main/resources/templates/my/notYourOrder.html
0 → 100644
View file @
969fb9e8
<!DOCTYPE html>
<html
xmlns:th=
"http://www.thymeleaf.org"
>
<head>
<meta
charset=
"UTF-8"
>
<title>
내 주문
</title>
<th:block
th:replace=
"fragments/layout :: cssjs"
/>
</head>
<body>
<div
th:replace=
"fragments/layout :: header"
></div>
<div
class=
"container"
>
<div
class=
"alert alert-danger"
role=
"alert"
>
존재하지 않는 주문입니다.[NYO]
</div>
</div>
<div
th:replace=
"fragments/layout :: footer"
></div>
</body>
</html>
src/main/resources/templates/my/orderCanceled.html
0 → 100644
View file @
969fb9e8
<!DOCTYPE html>
<html
xmlns:th=
"http://www.thymeleaf.org"
>
<head>
<meta
charset=
"UTF-8"
>
<title>
마이샵
</title>
<th:block
th:replace=
"fragments/layout :: cssjs"
/>
</head>
<body>
<div
th:replace=
"fragments/layout :: header"
></div>
<div
class=
"container"
>
<div
class=
"alert alert-success"
role=
"alert"
>
주문[
<span
th:text=
"${orderNo}"
>
번호
</span>
"]을 취소했습니다.
</div>
<a
class=
"btn btn-primary"
th:href=
"@{/my/orders/{orderNo}(orderNo=${orderNo})}"
role=
"button"
>
주문 내역 보기
</a>
<a
class=
"btn btn-dark"
href=
"/my/orders"
role=
"button"
>
주문 목록 보기
</a>
<a
class=
"btn btn-dark"
href=
"/home"
role=
"button"
>
첫 화면으로 이동하기
</a>
</div>
<div
th:replace=
"fragments/layout :: footer"
></div>
</body>
</html>
src/main/resources/templates/my/orderDetail.html
0 → 100644
View file @
969fb9e8
<!DOCTYPE html>
<html
xmlns:th=
"http://www.thymeleaf.org"
>
<head>
<meta
charset=
"UTF-8"
>
<title
th:text=
"|주문 상세: ${order.number}|"
>
주문 상세
</title>
<th:block
th:replace=
"fragments/layout :: cssjs"
/>
</head>
<body>
<div
th:replace=
"fragments/layout :: header"
></div>
<div
class=
"container"
>
<h2>
주문 상세
</h2>
<table
class=
"table"
>
<tbody>
<tr>
<td
rowspan=
"2"
>
주문
</td>
<td>
번호
</td>
<td
th:text=
"${order.number}"
></td>
</tr>
<tr>
<td>
상태
</td>
<td
th:text=
"#{${order.state}}"
></td>
</tr>
<tr>
<td>
주문자
</td>
<td>
이름
</td>
<td
th:text=
"${order.orderer.name}"
></td>
</tr>
<tr>
<td
rowspan=
"3"
>
받는사람
</td>
<td>
이름
</td>
<td
th:text=
"${order.shippingInfo.receiver.name}"
></td>
</tr>
<tr>
<td>
연락처
</td>
<td
th:text=
"${order.shippingInfo.receiver.phone}"
></td>
</tr>
<tr>
<td>
주소
</td>
<td>
<span
th:text=
"${order.shippingInfo.address.zipCode}"
></span>
<span
th:text=
"${order.shippingInfo.address.address1}"
></span>
<span
th:text=
"${order.shippingInfo.address.address2}"
></span>
</td>
</tr>
</tbody>
</table>
<table
class=
"table"
>
<thead>
<tr>
<th>
상품
</th>
<th>
가격
</th>
<th>
개수
</th>
<th>
합
</th>
</tr>
</thead>
<tbody>
<tr
th:each=
"ol: ${order.orderLines}"
>
<td
th:text=
"${ol.productName}"
></td>
<td
th:text=
"${ol.price}"
></td>
<td
th:text=
"${ol.quantity}"
></td>
<td
th:text=
"${ol.amounts}"
></td>
</tr>
</tbody>
<tfoot>
<tr>
<td
colspan=
"3"
>
총합
</td>
<td
th:text=
"${order.totalAmounts}"
>
총합
</td>
</tr>
</tfoot>
</table>
<block
th:if=
"${order.notYetShipped}"
>
<button
id=
"cancelBtn"
class=
"btn btn-danger"
>
주문 취소하기
</button>
</block>
<a
class=
"btn btn-dark"
href=
"/my/orders"
role=
"button"
>
주문 목록 보기
</a>
<a
class=
"btn btn-dark"
href=
"/home"
role=
"button"
>
첫 화면으로 이동하기
</a>
</div>
<div
th:replace=
"fragments/layout :: footer"
></div>
<form
id=
"goCancelForm"
th:action=
"@{/my/orders/{orderNo}/cancel(orderNo=${order.number})}"
method=
"post"
></form>
<script>
$
(
function
()
{
$
(
"
#cancelBtn
"
).
click
(
function
()
{
if
(
confirm
(
"
주문을 취소하시겠습니까?
"
))
{
$
(
"
#goCancelForm
"
).
submit
();
}
});
});
</script>
</body>
</html>
\ No newline at end of file
src/main/resources/templates/my/orders.html
0 → 100644
View file @
969fb9e8
<!DOCTYPE html>
<html
xmlns:th=
"http://www.thymeleaf.org"
xmlns:sec=
"http://www.thymeleaf.org/extras/spring-security"
>
<head>
<meta
charset=
"UTF-8"
>
<title>
마이샵
</title>
<th:block
th:replace=
"fragments/layout :: cssjs"
/>
</head>
<body>
<div
th:replace=
"fragments/layout :: header"
></div>
<div
class=
"container"
>
<h2>
주문 목록
</h2>
<div
class=
"alert alert-info"
role=
"alert"
th:if=
"${orders.isEmpty()}"
>
주문 내역이 없습니다.
</div>
<table
class=
"table"
th:if=
"${!orders.isEmpty()}"
>
<thead>
<tr>
<th>
주문번호
</th>
<th>
금액
</th>
<th>
상태
</th>
<th>
상품
</th>
</tr>
</thead>
<tbody>
<tr
th:each=
"order : ${orders}"
>
<td><a
href=
"#"
th:href=
"@{/my/orders/{orderNumber}(orderNumber=${order.number})}"
th:text=
"${order.number}"
>
주문번호
</a></td>
<td
th:text=
"${order.totalAmounts}"
>
금액
</td>
<td
th:text=
"#{${order.state}}"
>
상태
</td>
<td><span
th:text=
"${order.productName}"
>
제품명
</span>
등
</td>
</tr>
</tbody>
</table>
</div>
<div
th:replace=
"fragments/layout :: footer"
></div>
</body>
</html>
\ No newline at end of file
src/main/resources/templates/order/confirm.html
0 → 100644
View file @
969fb9e8
<!DOCTYPE html>
<html
xmlns:th=
"http://www.thymeleaf.org"
>
<head>
<meta
charset=
"UTF-8"
>
<title>
주문 확인
</title>
<th:block
th:replace=
"fragments/layout :: cssjs"
/>
</head>
<body>
<div
th:replace=
"fragments/layout :: header"
></div>
<div
class=
"container"
>
<form
method=
"post"
th:object=
"${orderReq}"
th:action=
"@{/orders/order}"
action=
"#"
>
<div
class=
"card mb-2"
>
<div
class=
"card-body"
>
<h5
class=
"card-title"
>
주문자
</h5>
<div
class=
"row mb-3"
>
<label
class=
"col-sm-2 col-form-label"
>
아이디
</label>
<div
class=
"col-sm-10"
>
<input
type=
"text"
readonly
class=
"form-control-plaintext"
th:value=
"${orderReq.ordererMemberId.id}"
value=
"email@example.com"
>
</div>
</div>
</div>
</div>
<div
class=
"card mb-2"
>
<div
class=
"card-body"
>
<h5
class=
"card-title"
>
주문 상품
</h5>
<table
class=
"table"
>
<thead>
<tr>
<th>
상품
</th>
<th>
가격
</th>
<th>
개수
</th>
<th>
합
</th>
</tr>
</thead>
<tbody>
<tr
th:each=
"op,status : ${orderReq.orderProducts}"
>
<td
th:text=
"${products[status.index].name}"
>
제품명
</td>
<td
th:text=
"${products[status.index].price}"
>
1000
</td>
<td><span
th:text=
"${op.quantity}"
>
1
</span>
<input
type=
"hidden"
th:name=
"${'orderProducts[' + status.index + '].productId'}"
th:value=
"${op.productId}"
/>
<input
type=
"hidden"
th:name=
"${'orderProducts[' + status.index + '].quantity'}"
th:value=
"${op.quantity}"
/>
</td>
<td
th:value=
"${products[status.index].price.value * op.quantity}"
>
금액
</td>
</tr>
</tbody>
<tfoot>
<tr>
<td
colspan=
"3"
>
총합
</td>
<td
th:text=
"${totalAmounts}"
>
총합
</td>
</tr>
</tfoot>
</table>
</div>
</div>
<div
class=
"card mb-2"
>
<div
class=
"card-body"
>
<h5
class=
"card-title"
>
받는 사람
</h5>
<div
class=
"row mb-3"
>
<label
class=
"col-sm-2 col-form-label"
for=
"shippingInfoReceiverName"
>
이름
</label>
<div
class=
"col-sm-10"
>
<input
type=
"text"
class=
"form-control"
th:field=
"*{shippingInfo.receiver.name}"
id=
"shippingInfoReceiverName"
/>
<div
class=
"form-text"
th:each=
"err : ${#fields.errors('shippingInfo.receiver.name')}"
th:text=
"${err}"
>
입력 오류 메시지
</div>
</div>
</div>
<div
class=
"row mb-3"
>
<label
class=
"col-sm-2 col-form-label"
for=
"shippingInfoReceiverPhone"
>
연락처
</label>
<div
class=
"col-sm-10"
>
<input
type=
"text"
class=
"form-control"
th:field=
"*{shippingInfo.receiver.phone}"
id=
"shippingInfoReceiverPhone"
/>
<div
class=
"form-text"
th:each=
"err : ${#fields.errors('shippingInfo.receiver.phone')}"
th:text=
"${err}"
>
입력 오류 메시지
</div>
</div>
</div>
<div
class=
"row mb-3"
>
<label
class=
"col-sm-2 col-form-label"
for=
"shippingInfoAddressZipCode"
>
우편번호
</label>
<div
class=
"col-sm-10"
>
<input
type=
"text"
class=
"form-control"
th:field=
"*{shippingInfo.address.zipCode}"
id=
"shippingInfoAddressZipCode"
/>
<div
class=
"form-text"
th:each=
"err : ${#fields.errors('shippingInfo.address.zipCode')}"
th:text=
"${err}"
>
입력 오류 메시지
</div>
</div>
</div>
<div
class=
"row mb-3"
>
<label
class=
"col-sm-2 col-form-label"
for=
"shippingInfoAddressAddress1"
>
주소1
</label>
<div
class=
"col-sm-10"
>
<input
type=
"text"
class=
"form-control"
th:field=
"*{shippingInfo.address.address1}"
id=
"shippingInfoAddressAddress1"
/>
<div
class=
"form-text"
th:each=
"err : ${#fields.errors('shippingInfo.address.address1')}"
th:text=
"${err}"
>
입력 오류 메시지
</div>
</div>
</div>
<div
class=
"row mb-3"
>
<label
class=
"col-sm-2 col-form-label"
for=
"shippingInfoAddressAddress2"
>
주소2
</label>
<div
class=
"col-sm-10"
>
<input
type=
"text"
class=
"form-control"
th:field=
"*{shippingInfo.address.address2}"
id=
"shippingInfoAddressAddress2"
/>
<div
class=
"form-text"
th:each=
"err : ${#fields.errors('shippingInfo.address.address2')}"
th:text=
"${err}"
>
입력 오류 메시지
</div>
</div>
</div>
</div>
</div>
<button
type=
"submit"
class=
"btn btn-primary"
>
구매하기
</button>
</form>
</div>
<div
th:replace=
"fragments/layout :: footer"
></div>
</body>
</html>
\ No newline at end of file
src/main/resources/templates/order/noProduct.html
0 → 100644
View file @
969fb9e8
<!DOCTYPE html>
<html
xmlns:th=
"http://www.thymeleaf.org"
>
<head>
<meta
charset=
"UTF-8"
>
<title>
마이샵
</title>
<th:block
th:replace=
"fragments/layout :: cssjs"
/>
</head>
<body>
<div
th:replace=
"fragments/layout :: header"
></div>
<div
class=
"container"
>
<div
class=
"alert alert-danger"
role=
"alert"
>
요청한 제품이 존재하지 않습니다.
</div>
</div>
<div
th:replace=
"fragments/layout :: footer"
></div>
</body>
</html>
\ No newline at end of file
src/main/resources/templates/order/orderComplete.html
0 → 100644
View file @
969fb9e8
<!DOCTYPE html>
<html
xmlns:th=
"http://www.thymeleaf.org"
>
<head>
<meta
charset=
"UTF-8"
>
<title>
마이샵
</title>
<th:block
th:replace=
"fragments/layout :: cssjs"
/>
</head>
<body>
<div
th:replace=
"fragments/layout :: header"
></div>
<div
class=
"container"
>
<div
class=
"alert alert-success"
role=
"alert"
>
주문[
<span
th:text=
"${orderNo}"
>
번호
</span>
]을 완료했습니다.
</div>
<a
class=
"btn btn-primary"
th:href=
"@{/my/orders/{orderNo}(orderNo=${orderNo})}"
role=
"button"
>
주문 내역 보기
</a>
<a
class=
"btn btn-btn"
href=
"/home"
role=
"button"
>
첫 화면으로 이동하기
</a>
</div>
<div
th:replace=
"fragments/layout :: footer"
></div>
</body>
</html>
\ No newline at end of file
src/sql/ddl.sql
0 → 100644
View file @
969fb9e8
create
database
shop
character
set
utf8mb4
collate
utf8mb4_general_ci
;
CREATE
USER
'shopuser'
@
'localhost'
IDENTIFIED
BY
'shoppass'
;
CREATE
USER
'shopuser'
@
'%'
IDENTIFIED
BY
'shoppass'
;
GRANT
ALL
PRIVILEGES
ON
shop
.
*
TO
'shopuser'
@
'localhost'
;
GRANT
ALL
PRIVILEGES
ON
shop
.
*
TO
'shopuser'
@
'%'
;
use
shop
;
create
table
shop
.
purchase_order
(
order_number
varchar
(
50
)
not
null
primary
key
,
version
bigint
,
orderer_id
varchar
(
50
),
orderer_name
varchar
(
50
),
total_amounts
int
,
shipping_zip_code
varchar
(
6
),
shipping_addr1
varchar
(
100
),
shipping_addr2
varchar
(
100
),
shipping_message
varchar
(
200
),
receiver_name
varchar
(
50
),
receiver_phone
varchar
(
50
),
state
varchar
(
20
),
order_date
datetime
)
character
set
utf8mb4
;
create
table
shop
.
order_line
(
order_number
varchar
(
50
)
not
null
,
line_idx
int
not
null
,
product_id
varchar
(
50
)
not
null
,
price
int
,
quantity
int
,
amounts
int
)
character
set
utf8mb4
;
create
index
order_line_idx
ON
order_line
(
order_number
,
line_idx
);
create
table
shop
.
category
(
category_id
bigint
not
null
primary
key
,
name
varchar
(
100
)
)
character
set
utf8mb4
;
create
table
shop
.
product
(
product_id
varchar
(
50
)
not
null
primary
key
,
name
varchar
(
100
),
price
int
,
detail
text
)
character
set
utf8mb4
;
create
table
shop
.
product_category
(
product_id
varchar
(
50
)
not
null
,
category_id
bigint
not
null
,
constraint
primary
key
(
product_id
,
category_id
)
)
character
set
utf8mb4
;
create
table
shop
.
image
(
image_id
int
not
null
auto_increment
primary
key
,
product_id
varchar
(
50
),
list_idx
int
,
image_type
varchar
(
10
),
image_path
varchar
(
255
),
upload_time
datetime
)
character
set
utf8mb4
;
create
table
shop
.
member
(
member_id
varchar
(
50
)
not
null
primary
key
,
name
varchar
(
50
),
password
varchar
(
255
),
blocked
boolean
,
emails
varchar
(
200
)
)
character
set
utf8mb4
;
create
table
shop
.
member_authorities
(
member_id
varchar
(
50
)
not
null
,
authority
varchar
(
50
)
not
null
,
primary
key
(
member_id
,
authority
)
)
character
set
utf8mb4
;
create
table
shop
.
article
(
id
int
not
null
auto_increment
primary
key
,
title
varchar
(
255
)
)
character
set
utf8mb4
;
create
table
shop
.
article_content
(
id
int
not
null
primary
key
,
content
varchar
(
255
),
content_type
varchar
(
255
)
)
character
set
utf8mb4
;
create
table
shop
.
evententry
(
id
int
not
null
AUTO_INCREMENT
PRIMARY
KEY
,
`type`
varchar
(
255
),
`content_type`
varchar
(
255
),
payload
MEDIUMTEXT
,
`timestamp`
datetime
)
character
set
utf8mb4
;
create
table
shop
.
locks
(
`type`
varchar
(
255
),
id
varchar
(
255
),
lockid
varchar
(
255
),
expiration_time
datetime
,
primary
key
(
`type`
,
id
)
)
character
set
utf8mb4
;
create
unique
index
locks_idx
ON
shop
.
locks
(
lockid
);
\ No newline at end of file
src/sql/init.sql
0 → 100644
View file @
969fb9e8
use
shop
;
truncate
table
purchase_order
;
truncate
table
order_line
;
truncate
table
category
;
truncate
table
product_category
;
truncate
table
product
;
truncate
table
image
;
truncate
table
member
;
truncate
table
member_authorities
;
truncate
table
article
;
truncate
table
article_content
;
truncate
table
evententry
;
insert
into
member
(
member_id
,
name
,
password
,
blocked
)
values
(
'user1'
,
'사용자1'
,
'1234'
,
false
);
insert
into
member
(
member_id
,
name
,
password
,
blocked
)
values
(
'user2'
,
'사용자2'
,
'5678'
,
false
);
insert
into
member
(
member_id
,
name
,
password
,
blocked
)
values
(
'admin'
,
'운영자'
,
'admin1234'
,
false
);
insert
into
member_authorities
values
(
'user1'
,
'ROLE_USER'
);
insert
into
member_authorities
values
(
'user2'
,
'ROLE_USER'
);
insert
into
member_authorities
values
(
'admin'
,
'ROLE_ADMIN'
);
insert
into
category
values
(
1001
,
'전자제품'
);
insert
into
category
values
(
2001
,
'필기구'
);
insert
into
product
values
(
'prod-001'
,
'라즈베리파이3 모델B'
,
56000
,
'모델B'
);
insert
into
image
(
product_id
,
list_idx
,
image_type
,
image_path
,
upload_time
)
values
(
'prod-001'
,
0
,
'II'
,
'rpi3.jpg'
,
now
());
insert
into
image
(
product_id
,
list_idx
,
image_type
,
image_path
,
upload_time
)
values
(
'prod-001'
,
1
,
'EI'
,
'http://external/image/path'
,
now
());
insert
into
product_category
values
(
'prod-001'
,
1001
);
insert
into
product
values
(
'prod-002'
,
'어프로치 휴대용 화이트보드 세트'
,
11920
,
'화이트보드'
);
insert
into
image
(
product_id
,
list_idx
,
image_type
,
image_path
,
upload_time
)
values
(
'prod-002'
,
0
,
'II'
,
'wbp.png'
,
now
());
insert
into
product_category
values
(
'prod-002'
,
2001
);
insert
into
product
values
(
'prod-003'
,
'볼펜 겸용 터치펜'
,
9000
,
'볼펜과 터치펜을 하나로!'
);
insert
into
image
(
product_id
,
list_idx
,
image_type
,
image_path
,
upload_time
)
values
(
'prod-003'
,
0
,
'II'
,
'pen.jpg'
,
now
());
insert
into
image
(
product_id
,
list_idx
,
image_type
,
image_path
,
upload_time
)
values
(
'prod-003'
,
1
,
'II'
,
'pen2.jpg'
,
now
());
insert
into
product_category
values
(
'prod-003'
,
1001
);
insert
into
product_category
values
(
'prod-003'
,
2001
);
\ No newline at end of file
src/test/java/com/myshop/ShopApplicationTests.java
0 → 100644
View file @
969fb9e8
package
com.myshop
;
import
org.junit.jupiter.api.Test
;
import
org.springframework.boot.test.context.SpringBootTest
;
@SpringBootTest
class
ShopApplicationTests
{
@Test
void
contextLoads
()
{
}
}
src/test/java/com/myshop/board/domain/ArticleRepositoryIT.java
0 → 100644
View file @
969fb9e8
package
com.myshop.board.domain
;
import
com.myshop.helper.DbHelper
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase
;
import
org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest
;
import
org.springframework.jdbc.core.JdbcTemplate
;
import
org.springframework.jdbc.support.rowset.SqlRowSet
;
import
java.util.Optional
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
@DataJpaTest
@AutoConfigureTestDatabase
(
replace
=
AutoConfigureTestDatabase
.
Replace
.
NONE
)
public
class
ArticleRepositoryIT
{
@Autowired
private
ArticleRepository
articleRepository
;
@Autowired
private
JdbcTemplate
jdbcTemplate
;
private
DbHelper
dbHelper
;
@BeforeEach
void
setUp
()
{
dbHelper
=
new
DbHelper
(
jdbcTemplate
);
dbHelper
.
clear
();
}
@Test
void
save
()
{
Article
aritcle
=
new
Article
(
"title"
,
new
ArticleContent
(
"content"
,
"type"
)
);
articleRepository
.
save
(
aritcle
);
SqlRowSet
rsArticle
=
jdbcTemplate
.
queryForRowSet
(
"select * from article where id = ?"
,
aritcle
.
getId
());
assertThat
(
rsArticle
.
next
()).
isTrue
();
assertThat
(
rsArticle
.
getString
(
"title"
)).
isEqualTo
(
"title"
);
SqlRowSet
rsContent
=
jdbcTemplate
.
queryForRowSet
(
"select * from article_content where id = ?"
,
aritcle
.
getId
());
assertThat
(
rsContent
.
next
()).
isTrue
();
assertThat
(
rsContent
.
getString
(
"content"
)).
isEqualTo
(
"content"
);
assertThat
(
rsContent
.
getString
(
"content_type"
)).
isEqualTo
(
"type"
);
}
@Test
void
findByIdNoData
()
{
assertThat
(
articleRepository
.
findById
(
0L
)).
isEmpty
();
}
@Test
void
findById
()
{
jdbcTemplate
.
update
(
"insert into article values (100, 'title')"
);
jdbcTemplate
.
update
(
"insert into article_content values (100, 'content', 'type')"
);
Optional
<
Article
>
articleOpt
=
articleRepository
.
findById
(
100L
);
assertThat
(
articleOpt
).
isPresent
();
Article
article
=
articleOpt
.
get
();
assertThat
(
article
.
getTitle
()).
isEqualTo
(
"title"
);
assertThat
(
article
.
getContent
().
getContent
()).
isEqualTo
(
"content"
);
assertThat
(
article
.
getContent
().
getContentType
()).
isEqualTo
(
"type"
);
}
}
src/test/java/com/myshop/catalog/command/domain/product/ProductRepositoryIT.java
0 → 100644
View file @
969fb9e8
package
com.myshop.catalog.command.domain.product
;
import
com.myshop.common.model.Money
;
import
com.myshop.helper.DbHelper
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.jdbc.core.JdbcTemplate
;
import
org.springframework.jdbc.support.rowset.SqlRowSet
;
import
org.springframework.transaction.annotation.Transactional
;
import
java.time.LocalDateTime
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.Optional
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
@SpringBootTest
class
ProductRepositoryIT
{
@Autowired
private
ProductRepository
productRepository
;
@Autowired
private
JdbcTemplate
jdbcTemplate
;
@Autowired
private
DbHelper
dbHelper
;
@BeforeEach
void
setUp
()
{
dbHelper
.
clear
();
}
@Test
void
save
()
{
List
<
Image
>
images
=
new
ArrayList
<>();
images
.
add
(
new
ExternalImage
(
"https://extern.image.com/some-img.png"
));
images
.
add
(
new
InternalImage
(
"internal-img.png"
));
Product
product
=
new
Product
(
ProductId
.
of
(
"PRD-01"
),
"제품-01"
,
new
Money
(
9000
),
"상세 내용"
,
images
);
productRepository
.
save
(
product
);
SqlRowSet
rsProd
=
jdbcTemplate
.
queryForRowSet
(
"select * from product where product_id = ?"
,
"PRD-01"
);
assertThat
(
rsProd
.
next
()).
isTrue
();
assertThat
(
rsProd
.
getInt
(
"price"
)).
isEqualTo
(
9000
);
SqlRowSet
rsImg
=
jdbcTemplate
.
queryForRowSet
(
"select * from image where product_id = ? order by list_idx"
,
"PRD-01"
);
assertThat
(
rsImg
.
next
()).
isTrue
();
assertThat
(
rsImg
.
getString
(
"image_type"
)).
isEqualTo
(
"EI"
);
}
@Transactional
@Test
void
updateImages
()
{
jdbcTemplate
.
update
(
"insert into product values (?,?,?,?)"
,
"PROD-02"
,
"PRD 2"
,
10000
,
"상세"
);
jdbcTemplate
.
update
(
"insert into image values (?,?,?,?,?,?)"
,
1
,
"PROD-02"
,
0
,
"EI"
,
"http://images.img/img.01.png"
,
LocalDateTime
.
now
());
jdbcTemplate
.
update
(
"insert into image values (?,?,?,?,?,?)"
,
2
,
"PROD-02"
,
1
,
"EI"
,
"http://images.img/img.02.png"
,
LocalDateTime
.
now
());
Product
product
=
productRepository
.
findById
(
ProductId
.
of
(
"PROD-02"
)).
get
();
product
.
changeImages
(
List
.
of
(
new
InternalImage
(
"/path01.png"
),
new
InternalImage
(
"/path02.png"
)
));
productRepository
.
flush
();
}
}
\ No newline at end of file
src/test/java/com/myshop/catalog/domain/category/CategoryRepositoryIT.java
0 → 100644
View file @
969fb9e8
package
com.myshop.catalog.domain.category
;
import
com.myshop.catalog.command.domain.category.Category
;
import
com.myshop.catalog.command.domain.category.CategoryId
;
import
com.myshop.catalog.command.domain.category.CategoryRepository
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase
;
import
org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest
;
import
org.springframework.jdbc.core.JdbcTemplate
;
import
java.util.List
;
import
java.util.Optional
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
@DataJpaTest
@AutoConfigureTestDatabase
(
replace
=
AutoConfigureTestDatabase
.
Replace
.
NONE
)
class
CategoryRepositoryIT
{
@Autowired
private
CategoryRepository
categoryRepository
;
@Autowired
private
JdbcTemplate
jdbcTemplate
;
@BeforeEach
void
setUp
()
{
jdbcTemplate
.
update
(
"truncate table category"
);
jdbcTemplate
.
update
(
"insert into category values (1, 'cat1')"
);
jdbcTemplate
.
update
(
"insert into category values (2, 'cat2')"
);
}
@Test
void
findAll
()
{
List
<
Category
>
categories
=
categoryRepository
.
findAll
();
assertThat
(
categories
).
hasSize
(
2
);
}
@Test
void
findById
()
{
Optional
<
Category
>
catOpt
=
categoryRepository
.
findById
(
CategoryId
.
of
(
2L
));
assertThat
(
catOpt
).
isPresent
();
assertThat
(
catOpt
.
get
().
getName
()).
isEqualTo
(
"cat2"
);
}
}
\ No newline at end of file
src/test/java/com/myshop/catalog/domain/product/ProductRepositoryIT.java
0 → 100644
View file @
969fb9e8
package
com.myshop.catalog.domain.product
;
import
com.myshop.catalog.command.domain.product.ProductRepository
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.context.SpringBootTest
;
@SpringBootTest
class
ProductRepositoryIT
{
@Autowired
private
ProductRepository
productRepository
;
}
\ No newline at end of file
src/test/java/com/myshop/catalog/query/product/ProductDataDaoIT.java
0 → 100644
View file @
969fb9e8
package
com.myshop.catalog.query.product
;
import
com.myshop.catalog.command.domain.category.CategoryId
;
import
com.myshop.catalog.command.domain.product.ProductId
;
import
com.myshop.helper.DbHelper
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.boot.test.context.SpringBootTest
;
import
org.springframework.data.domain.Page
;
import
org.springframework.data.domain.PageRequest
;
import
org.springframework.data.domain.Sort
;
import
org.springframework.jdbc.core.JdbcTemplate
;
import
java.time.LocalDateTime
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
@SpringBootTest
class
ProductDataDaoIT
{
@Autowired
private
ProductDataDao
productDataDao
;
@Autowired
private
JdbcTemplate
jdbcTemplate
;
@Autowired
private
DbHelper
dbHelper
;
@BeforeEach
void
setUp
()
{
dbHelper
.
clear
();
}
@Test
void
findByCategoryIds
()
{
jdbcTemplate
.
update
(
"insert into product values (?,?,?,?)"
,
"PROD-01"
,
"PRD 1"
,
10000
,
"상세"
);
jdbcTemplate
.
update
(
"insert into image values (?,?,?,?,?,?)"
,
1
,
"PROD-02"
,
0
,
"EI"
,
"http://images.img/img.01.png"
,
LocalDateTime
.
now
());
jdbcTemplate
.
update
(
"insert into product_category values (?, ?)"
,
"PROD-01"
,
1
);
jdbcTemplate
.
update
(
"insert into product_category values (?, ?)"
,
"PROD-01"
,
2
);
jdbcTemplate
.
update
(
"insert into product values (?,?,?,?)"
,
"PROD-02"
,
"PRD 2"
,
10000
,
"상세"
);
jdbcTemplate
.
update
(
"insert into product_category values (?, ?)"
,
"PROD-02"
,
2
);
jdbcTemplate
.
update
(
"insert into product_category values (?, ?)"
,
"PROD-02"
,
3
);
jdbcTemplate
.
update
(
"insert into product values (?,?,?,?)"
,
"PROD-03"
,
"PRD 3"
,
10000
,
"상세"
);
jdbcTemplate
.
update
(
"insert into product_category values (?, ?)"
,
"PROD-03"
,
2
);
jdbcTemplate
.
update
(
"insert into product_category values (?, ?)"
,
"PROD-03"
,
3
);
jdbcTemplate
.
update
(
"insert into product values (?,?,?,?)"
,
"PROD-04"
,
"PRD 4"
,
10000
,
"상세"
);
jdbcTemplate
.
update
(
"insert into product_category values (?, ?)"
,
"PROD-04"
,
1
);
jdbcTemplate
.
update
(
"insert into product_category values (?, ?)"
,
"PROD-04"
,
3
);
PageRequest
pageRequest
=
PageRequest
.
of
(
0
,
2
,
Sort
.
by
(
Sort
.
Direction
.
DESC
,
"id"
));
Page
<
ProductData
>
products
=
productDataDao
.
findByCategoryIdsContains
(
CategoryId
.
of
(
2L
),
pageRequest
);
assertThat
(
products
.
getNumberOfElements
()).
isEqualTo
(
2
);
assertThat
(
products
.
getContent
()).
hasSize
(
2
);
assertThat
(
products
.
getContent
().
get
(
0
).
getId
()).
isEqualTo
(
ProductId
.
of
(
"PROD-03"
));
assertThat
(
products
.
getContent
().
get
(
1
).
getId
()).
isEqualTo
(
ProductId
.
of
(
"PROD-02"
));
}
}
\ No newline at end of file
src/test/java/com/myshop/helper/DbHelper.java
0 → 100644
View file @
969fb9e8
package
com.myshop.helper
;
import
org.springframework.jdbc.core.JdbcTemplate
;
import
org.springframework.stereotype.Component
;
@Component
public
class
DbHelper
{
private
JdbcTemplate
jdbcTemplate
;
public
DbHelper
(
JdbcTemplate
jdbcTemplate
)
{
this
.
jdbcTemplate
=
jdbcTemplate
;
}
public
void
clear
()
{
jdbcTemplate
.
update
(
"truncate table member"
);
jdbcTemplate
.
update
(
"truncate table article"
);
jdbcTemplate
.
update
(
"truncate table article_content"
);
jdbcTemplate
.
update
(
"truncate table purchase_order"
);
jdbcTemplate
.
update
(
"truncate table order_line"
);
jdbcTemplate
.
update
(
"truncate table product"
);
jdbcTemplate
.
update
(
"truncate table image"
);
jdbcTemplate
.
update
(
"truncate table category"
);
jdbcTemplate
.
update
(
"truncate table product_category"
);
}
}
Prev
1
…
5
6
7
8
9
10
Next
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment