Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
E
Ecsite
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
shoei.kanno
Ecsite
Commits
2a00476e
Commit
2a00476e
authored
Oct 21, 2020
by
shoei.kanno
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
財布機能追加
parent
b67d62f3
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
35 additions
and
13 deletions
+35
-13
EcsiteRestController.java
src/main/java/com/example/api/EcsiteRestController.java
+13
-7
WalletsService.java
src/main/java/com/example/service/WalletsService.java
+9
-0
EcsiteController.java
src/main/java/com/example/web/EcsiteController.java
+9
-3
cart.js
src/main/resources/static/js/cart.js
+2
-1
list.js
src/main/resources/static/js/list.js
+1
-1
wallets.html
src/main/resources/templates/wallets.html
+1
-1
No files found.
src/main/java/com/example/api/EcsiteRestController.java
View file @
2a00476e
...
...
@@ -48,8 +48,8 @@ public class EcsiteRestController {
@Autowired
WalletsService
walletsService
;
int
totalPrice
;
String
sameId
;
int
totalPrice
;
//アカウント新規登録
@PostMapping
(
"signUp"
)
...
...
@@ -117,17 +117,22 @@ public class EcsiteRestController {
@GetMapping
(
"buy"
)
public
void
buy
(
@AuthenticationPrincipal
LoginUser
userDetails
,
LinkedHashMap
<
String
,
Items
>
items
,
ArrayList
<
Items
>
cart
,
Wallets
wallet
){
if
(
walletsService
.
findOne
(
userDetails
.
getId
()).
getAmount
()
<
totalPrice
){
throw
new
BadRequestException
();
}
items
=
(
LinkedHashMap
<
String
,
Items
>)
session
.
getAttribute
(
"cart"
);
items
.
forEach
((
key
,
value
)
->
{
cart
.
add
(
value
);
});
User
user
=
userDetails
.
getUser
();
Integer
userId
=
user
.
getId
();
salesLogService
.
update
(
1
,
cart
);
cart
.
forEach
(
item
->{
totalPrice
+=
item
.
getPrice
();
});
Integer
userId
=
(
Integer
)
session
.
getAttribute
(
"userId"
);
if
(
walletsService
.
findOne
(
userId
).
getAmount
()
<
totalPrice
){
throw
new
BadRequestException
();
}
//支払い
walletsService
.
pay
(
userId
,
totalPrice
);
salesLogService
.
update
(
userId
,
cart
);
session
.
removeAttribute
(
"cart"
);
session
.
removeAttribute
(
"cartValue"
);
totalPrice
=
0
;
}
}
\ No newline at end of file
src/main/java/com/example/service/WalletsService.java
View file @
2a00476e
...
...
@@ -30,6 +30,15 @@ public class WalletsService {
return
walletsRepository
.
save
(
wallet
);
}
//チャージ処理
public
Wallets
charge
(
Integer
id
,
Integer
amount
){
//対象の財布情報を取得
Wallets
wallet
=
new
Wallets
();
wallet
=
this
.
findOne
(
id
);
wallet
.
setAmount
(
wallet
.
getAmount
()
+
amount
);
return
walletsRepository
.
save
(
wallet
);
}
//支払い処理
public
Wallets
pay
(
Integer
id
,
Integer
amount
){
//対象の財布情報を取得
...
...
src/main/java/com/example/web/EcsiteController.java
View file @
2a00476e
...
...
@@ -15,11 +15,11 @@ import org.springframework.stereotype.Controller;
import
org.springframework.ui.Model
;
import
org.springframework.validation.annotation.Validated
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.ModelAttribute
;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
com.example.domain.BadRequestException
;
import
com.example.domain.Items
;
import
com.example.domain.SalesLog
;
import
com.example.domain.Shoes
;
...
...
@@ -42,6 +42,11 @@ public class EcsiteController {
@Autowired
HttpSession
session
;
@ModelAttribute
WalletsForm
setUpForm
()
{
return
new
WalletsForm
();
}
int
totalPrice
=
0
;
//写真の表示用メソッド
public
String
photoView
(
String
Photo
)
{
...
...
@@ -151,6 +156,7 @@ public class EcsiteController {
public
String
Cart
(
Model
model
,
@AuthenticationPrincipal
LoginUser
userDetails
,
LinkedHashMap
<
String
,
Items
>
items
,
ArrayList
<
Items
>
cart
){
User
user
=
userDetails
.
getUser
();
model
.
addAttribute
(
"user"
,
user
);
session
.
setAttribute
(
"userId"
,
user
.
getId
());
items
=
(
LinkedHashMap
<
String
,
Items
>)
session
.
getAttribute
(
"cart"
);
if
(
items
==
null
)
{
if
(
session
.
getAttribute
(
"cartValue"
)
==
null
)
{
...
...
@@ -189,7 +195,7 @@ public class EcsiteController {
//財布チャージ処理
@PostMapping
(
"wallets/charge/{id}"
)
public
String
walletsCharge
(
@PathVariable
Integer
id
,
@Validated
WalletsForm
form
){
walletsService
.
pay
(
id
,
form
.
getAmount
());
return
"redirect:/top"
;
walletsService
.
charge
(
id
,
form
.
getAmount
());
return
"redirect:/
limited/
top"
;
}
}
src/main/resources/static/js/cart.js
View file @
2a00476e
...
...
@@ -21,7 +21,7 @@ $('#ok-btn').on('click',function(){
alert
(
"購入が完了しました。"
);
window
.
location
.
href
=
"/limited/top"
;
})
.
fail
d
(
function
(){
.
fail
(
function
(){
alert
(
"ウォレットの残高が足りません。チャージしてください"
);
})
});
\ No newline at end of file
src/main/resources/static/js/list.js
View file @
2a00476e
...
...
@@ -98,7 +98,7 @@ $('.cartBtn').on('click', function(event){
contentType
:
'application/json'
,
dataType
:
"json"
,
data
:
JSON
.
stringify
(
data
)
})
;
})
//[#modal-content]と[#modal-overlay]をフェードアウトした後に…
$
(
"#modal-content,#modal-overlay"
).
fadeOut
(
"slow"
,
function
(){
//[#modal-overlay]を削除する
...
...
src/main/resources/templates/wallets.html
View file @
2a00476e
...
...
@@ -69,7 +69,7 @@
<div
class=
"container"
>
<p
id=
"online-shoe-store"
class=
"wallets-p"
><span
id=
"online-shoe-store-span"
>
Wallets
</span></p>
<p
id=
"balance"
>
Balance
<span
id=
"balanceSpan"
th:text=
"'¥' + ${wallet.amount}"
>
10000
</span></p>
<form
id=
"wallets-form"
method=
"post"
th:action=
"@{/limited/wallets/charge/{id}(id=${user.id})}"
th:object=
"${walletForm}"
>
<form
id=
"wallets-form"
method=
"post"
th:action=
"@{/limited/wallets/charge/{id}(id=${user.id})}"
th:object=
"${wallet
s
Form}"
>
<div
id=
"amount-form"
>
<label
for=
"amount"
>
Charge Money
</label>
<span
id=
"en"
>
¥
</span><input
type=
"number"
id=
"amount"
name=
"amount"
required=
"required"
th:field=
"*{amount}"
/>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a 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