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
cdca7b31
Commit
cdca7b31
authored
Oct 20, 2020
by
keita.onoguchi
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '購入機能' into 'master'
購入機能途中 See merge request
!41
parents
2bc89f53
baf3dc57
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
46 additions
and
3 deletions
+46
-3
SecurityConfig.java
src/main/java/com/example/SecurityConfig.java
+1
-1
EcsiteRestController.java
src/main/java/com/example/api/EcsiteRestController.java
+20
-0
SalesLogService.java
src/main/java/com/example/service/SalesLogService.java
+19
-2
EcsiteController.java
src/main/java/com/example/web/EcsiteController.java
+6
-0
No files found.
src/main/java/com/example/SecurityConfig.java
View file @
cdca7b31
...
...
@@ -14,7 +14,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter{
@Override
public
void
configure
(
WebSecurity
web
)
throws
Exception
{
web
.
debug
(
false
).
ignoring
().
antMatchers
(
"/images/**"
,
"/js/**"
,
"/css/**"
,
"/fonts/**"
,
"/limited/inputCart"
);
web
.
debug
(
false
).
ignoring
().
antMatchers
(
"/images/**"
,
"/js/**"
,
"/css/**"
,
"/fonts/**"
,
"/limited/inputCart"
,
"/limited/buy"
);
}
@Override
...
...
src/main/java/com/example/api/EcsiteRestController.java
View file @
cdca7b31
...
...
@@ -2,12 +2,15 @@ package com.example.api;
import
java.sql.Date
;
import
java.time.LocalDate
;
import
java.util.ArrayList
;
import
java.util.LinkedHashMap
;
import
javax.servlet.http.HttpSession
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.security.core.annotation.AuthenticationPrincipal
;
import
org.springframework.security.crypto.password.Pbkdf2PasswordEncoder
;
import
org.springframework.web.bind.annotation.GetMapping
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
...
...
@@ -18,7 +21,9 @@ import com.example.domain.ItemData;
import
com.example.domain.Items
;
import
com.example.domain.User
;
import
com.example.service.ItemsService
;
import
com.example.service.LoginUser
;
import
com.example.service.LoginUserDetailsService
;
import
com.example.service.SalesLogService
;
@RestController
@RequestMapping
(
"limited"
)
...
...
@@ -30,6 +35,9 @@ public class EcsiteRestController {
ItemsService
itemsService
;
@Autowired
HttpSession
session
;
@Autowired
SalesLogService
salesLogService
;
int
totalPrice
;
@PostMapping
(
"signUp"
)
public
User
createUser
(
@RequestBody
User
user
)
{
...
...
@@ -58,4 +66,15 @@ public class EcsiteRestController {
session
.
setAttribute
(
"cart"
,
cart
);
}
}
@GetMapping
(
"buy"
)
public
void
buy
(
@AuthenticationPrincipal
LoginUser
userDetails
,
LinkedHashMap
<
String
,
Items
>
items
,
ArrayList
<
Items
>
cart
){
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
);
}
}
\ No newline at end of file
src/main/java/com/example/service/SalesLogService.java
View file @
cdca7b31
package
com
.
example
.
service
;
import
java.sql.Date
;
import
java.util.ArrayList
;
import
java.util.List
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.security.core.annotation.AuthenticationPrincipal
;
import
org.springframework.stereotype.Service
;
import
com.example.domain.Items
;
import
com.example.domain.SalesLog
;
import
com.example.repository.SalesLogRepository
;
...
...
@@ -26,8 +29,22 @@ public class SalesLogService {
return
salesLogRepository
.
save
(
salesLog
);
}
public
SalesLog
update
(
SalesLog
salesLog
){
return
salesLogRepository
.
save
(
salesLog
);
public
void
update
(
Integer
userId
,
ArrayList
<
Items
>
cart
){
int
count
=
0
;
java
.
util
.
Date
d1
=
new
java
.
util
.
Date
();
//d1をSQL.DATE型に変換してtodayに代入
java
.
sql
.
Date
today
=
new
java
.
sql
.
Date
(
d1
.
getTime
());
System
.
out
.
println
(
cart
.
size
());
for
(
int
i
=
0
;
i
<
cart
.
size
();
i
++){
SalesLog
salesLog
=
new
SalesLog
();
salesLog
.
setUserId
(
userId
);
salesLog
.
setShoesId
((
cart
.
get
(
i
)).
getShoesId
());
salesLog
.
setPrice
((
cart
.
get
(
i
)).
getPrice
());
salesLog
.
setCreated
(
today
);
salesLogRepository
.
save
(
salesLog
);
count
++;
}
System
.
out
.
println
(
count
);
}
public
List
<
SalesLog
>
history
(
Integer
id
)
{
...
...
src/main/java/com/example/web/EcsiteController.java
View file @
cdca7b31
...
...
@@ -36,6 +36,7 @@ public class EcsiteController {
@Autowired
HttpSession
session
;
int
totalPrice
=
0
;
//写真の表示用メソッド
public
String
photoView
(
String
Photo
)
{
// 画像を検索してbyteとしてViewへ受け渡す
...
...
@@ -131,6 +132,11 @@ HttpSession session;
cart
.
add
(
value
);
});
model
.
addAttribute
(
"cart"
,
cart
);
cart
.
forEach
(
item
->
{
totalPrice
+=
item
.
getPrice
();
});
model
.
addAttribute
(
"totalPrice"
,
totalPrice
);
totalPrice
=
0
;
return
"Cart"
;
}
}
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