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
c363330c
Commit
c363330c
authored
Oct 21, 2020
by
keita.onoguchi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ウォレット機能途中
parent
0617b3f2
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
64 additions
and
7 deletions
+64
-7
EcsiteRestController.java
src/main/java/com/example/api/EcsiteRestController.java
+15
-3
WalletsService.java
src/main/java/com/example/service/WalletsService.java
+12
-0
EcsiteController.java
src/main/java/com/example/web/EcsiteController.java
+24
-4
WalletsForm.java
src/main/java/com/example/web/WalletsForm.java
+9
-0
cart.js
src/main/resources/static/js/cart.js
+4
-0
No files found.
src/main/java/com/example/api/EcsiteRestController.java
View file @
c363330c
...
...
@@ -23,11 +23,13 @@ import com.example.domain.ItemData;
import
com.example.domain.Items
;
import
com.example.domain.Shoes
;
import
com.example.domain.User
;
import
com.example.domain.Wallets
;
import
com.example.service.ItemsService
;
import
com.example.service.LoginUser
;
import
com.example.service.LoginUserDetailsService
;
import
com.example.service.SalesLogService
;
import
com.example.service.ShoesService
;
import
com.example.service.WalletsService
;
@RestController
@RequestMapping
(
"limited"
)
...
...
@@ -43,6 +45,9 @@ public class EcsiteRestController {
SalesLogService
salesLogService
;
@Autowired
ShoesService
shoesService
;
@Autowired
WalletsService
walletsService
;
int
totalPrice
;
String
sameId
;
...
...
@@ -56,6 +61,10 @@ public class EcsiteRestController {
user
.
setUpdatedAt
(
nowDate
);
user
.
setPassword
(
new
Pbkdf2PasswordEncoder
().
encode
(
user
.
getPassword
()));
loginUserDetailsService
.
create
(
user
);
Wallets
wallet
=
new
Wallets
();
wallet
.
setUserId
(
user
.
getId
());
wallet
.
setAmount
(
0
);
walletsService
.
create
(
wallet
);
return
user
;
}
...
...
@@ -107,13 +116,16 @@ public class EcsiteRestController {
}
@GetMapping
(
"buy"
)
public
void
buy
(
@AuthenticationPrincipal
LoginUser
userDetails
,
LinkedHashMap
<
String
,
Items
>
items
,
ArrayList
<
Items
>
cart
){
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();
User
user
=
userDetails
.
getUser
();
Integer
userId
=
user
.
getId
();
salesLogService
.
update
(
1
,
cart
);
session
.
removeAttribute
(
"cart"
);
session
.
removeAttribute
(
"cartValue"
);
...
...
src/main/java/com/example/service/WalletsService.java
View file @
c363330c
...
...
@@ -5,14 +5,18 @@ import java.util.List;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
com.example.domain.BadRequestException
;
import
com.example.domain.Wallets
;
import
com.example.repository.WalletsRepository
;
import
com.example.web.EcsiteController
;
//ユーザウォレットのサービス
@Service
public
class
WalletsService
{
@Autowired
WalletsRepository
walletsRepository
;
@Autowired
Wallets
wallet
;
public
List
<
Wallets
>
findAll
(){
return
walletsRepository
.
findAll
();
...
...
@@ -29,4 +33,12 @@ public class WalletsService {
public
Wallets
update
(
Wallets
wallet
){
return
walletsRepository
.
save
(
wallet
);
}
//支払い処理
public
Wallets
pay
(
Integer
id
,
Integer
amount
){
//対象の財布情報を取得
wallet
=
this
.
findOne
(
id
);
wallet
.
setAmount
(
wallet
.
getAmount
()
-
amount
);
return
walletsRepository
.
save
(
wallet
);
}
}
src/main/java/com/example/web/EcsiteController.java
View file @
c363330c
...
...
@@ -13,28 +13,34 @@ import org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.security.core.annotation.AuthenticationPrincipal
;
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.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
;
import
com.example.domain.User
;
import
com.example.domain.Wallets
;
import
com.example.service.LoginUser
;
import
com.example.service.SalesLogService
;
import
com.example.service.ShoesService
;
import
com.example.service.WalletsService
;
@Controller
@RequestMapping
(
"limited"
)
public
class
EcsiteController
{
@Autowired
ShoesService
shoesService
;
@Autowired
WalletsService
walletsService
;
@Autowired
SalesLogService
salesLogService
;
@Autowired
HttpSession
session
;
@Autowired
HttpSession
session
;
int
totalPrice
=
0
;
//写真の表示用メソッド
...
...
@@ -132,11 +138,15 @@ HttpSession session;
public
String
historyDetails
(
@PathVariable
Date
created
,
Model
model
,
@AuthenticationPrincipal
LoginUser
userDetails
)
{
User
user
=
userDetails
.
getUser
();
model
.
addAttribute
(
"user"
,
user
);
if
(
salesLogService
.
historyDetails
(
created
,
user
.
getId
())
==
null
){
return
"logDetails"
;
}
List
<
SalesLog
>
list
=
salesLogService
.
historyDetails
(
created
,
user
.
getId
());
model
.
addAttribute
(
"logDetails"
,
list
);
return
"logDetails"
;
}
//カート画面
@GetMapping
(
"cart"
)
public
String
Cart
(
Model
model
,
@AuthenticationPrincipal
LoginUser
userDetails
,
LinkedHashMap
<
String
,
Items
>
items
,
ArrayList
<
Items
>
cart
){
User
user
=
userDetails
.
getUser
();
...
...
@@ -156,6 +166,7 @@ HttpSession session;
totalPrice
+=
item
.
getPrice
();
});
model
.
addAttribute
(
"totalPrice"
,
totalPrice
);
session
.
setAttribute
(
"totalprice"
,
totalPrice
);
totalPrice
=
0
;
if
(
session
.
getAttribute
(
"cartValue"
)
==
null
)
{
model
.
addAttribute
(
"cartValue"
,
0
);
...
...
@@ -167,9 +178,18 @@ HttpSession session;
//財布画面
@GetMapping
(
"wallets/{id}"
)
public
String
wallets
(
Model
model
,
@AuthenticationPrincipal
LoginUser
userDetails
)
{
public
String
wallets
(
@PathVariable
Integer
id
,
Model
model
,
@AuthenticationPrincipal
LoginUser
userDetails
,
Wallets
wallet
)
{
User
user
=
userDetails
.
getUser
();
model
.
addAttribute
(
"user"
,
user
);
wallet
=
walletsService
.
findOne
(
id
);
model
.
addAttribute
(
"wallet"
,
wallet
);
return
"wallets"
;
}
//財布チャージ処理
@PostMapping
(
"wallets/charge/{id}"
)
public
String
walletsCharge
(
@PathVariable
Integer
id
,
@Validated
WalletsForm
form
){
walletsService
.
pay
(
id
,
form
.
getAmount
());
return
"redirect:/top"
;
}
}
src/main/java/com/example/web/WalletsForm.java
0 → 100644
View file @
c363330c
package
com
.
example
.
web
;
import
lombok.Getter
;
import
lombok.Setter
;
@Getter
@Setter
public
class
WalletsForm
{
private
Integer
amount
;
}
src/main/resources/static/js/cart.js
View file @
c363330c
...
...
@@ -21,4 +21,7 @@ $('#ok-btn').on('click',function(){
alert
(
"購入が完了しました。"
);
window
.
location
.
href
=
"/limited/top"
;
})
.
faild
(
function
(){
alert
(
"ウォレットの残高が足りません。チャージしてください"
);
})
});
\ No newline at end of file
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