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
a0a8aea2
Commit
a0a8aea2
authored
Oct 19, 2020
by
keita.onoguchi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
カート機能途中
parent
c949e8a3
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
66 additions
and
50 deletions
+66
-50
SecurityConfig.java
src/main/java/com/example/SecurityConfig.java
+1
-1
EcsiteRestController.java
src/main/java/com/example/api/EcsiteRestController.java
+21
-13
ItemData.java
src/main/java/com/example/domain/ItemData.java
+2
-1
Items.java
src/main/java/com/example/domain/Items.java
+1
-34
ItemsService.java
src/main/java/com/example/service/ItemsService.java
+31
-0
EcsiteController.java
src/main/java/com/example/web/EcsiteController.java
+10
-1
No files found.
src/main/java/com/example/SecurityConfig.java
View file @
a0a8aea2
...
...
@@ -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/**"
);
web
.
debug
(
false
).
ignoring
().
antMatchers
(
"/images/**"
,
"/js/**"
,
"/css/**"
,
"/fonts/**"
,
"/limited/inputCart"
);
}
@Override
...
...
src/main/java/com/example/api/EcsiteRestController.java
View file @
a0a8aea2
...
...
@@ -3,33 +3,35 @@ package com.example.api;
import
java.sql.Date
;
import
java.time.LocalDate
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
javax.servlet.http.HttpSession
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.security.crypto.password.Pbkdf2PasswordEncoder
;
import
org.springframework.ui.Model
;
import
org.springframework.web.bind.annotation.ModelAttribute
;
import
org.springframework.web.bind.annotation.PostMapping
;
import
org.springframework.web.bind.annotation.RequestBody
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
org.springframework.web.bind.annotation.RestController
;
import
org.springframework.web.bind.annotation.SessionAttributes
;
import
com.example.domain.
Cart
;
import
com.example.domain.
CartData
;
import
com.example.domain.
ItemData
;
import
com.example.domain.
Items
;
import
com.example.domain.User
;
import
com.example.service.ItemsService
;
import
com.example.service.LoginUserDetailsService
;
@RestController
@RequestMapping
(
"limited"
)
//@SessionAttributes(names ="cart
")
@SessionAttributes
(
names
=
"itemData
"
)
public
class
EcsiteRestController
{
@Autowired
LoginUserDetailsService
loginUserDetailsService
;
@ModelAttribute
(
"cart"
)
// (1)
public
ArrayList
<
Cart
>
setSessionData
(
ArrayList
<
Cart
>
arrayList
)
{
return
arrayList
;
}
@Autowired
ItemsService
itemsService
;
@Autowired
HttpSession
session
;
@PostMapping
(
"signUp"
)
public
User
createUser
(
@RequestBody
User
user
)
{
...
...
@@ -44,10 +46,15 @@ public class EcsiteRestController {
}
@PostMapping
(
"inputCart"
)
public
void
inputCart
(
@RequestBody
CartData
data
,
Model
model
)
{
Cart
cart
=
new
Cart
();
cart
.
setCart
(
data
.
getShoesId
(),
data
.
getQuantity
());
//return cart.getCart();
public
void
inputCart
(
@RequestBody
ItemData
data
,
HashMap
<
String
,
Items
>
cart
)
{
if
(
session
.
getAttribute
(
"cart"
)
==
null
){
cart
.
put
((
data
.
getShoesId
()).
toString
(),
itemsService
.
findOne
(
data
.
getShoesId
(),
data
.
getQuantity
()));
session
.
setAttribute
(
"cart"
,
cart
);
}
else
{
cart
=
(
HashMap
<
String
,
Items
>)
session
.
getAttribute
(
"cart"
);
cart
.
put
((
data
.
getShoesId
()).
toString
(),
itemsService
.
findOne
(
data
.
getShoesId
(),
data
.
getQuantity
()));
session
.
setAttribute
(
"cart"
,
cart
);
}
}
}
\ No newline at end of file
src/main/java/com/example/domain/
Cart
Data.java
→
src/main/java/com/example/domain/
Item
Data.java
View file @
a0a8aea2
...
...
@@ -8,7 +8,7 @@ import lombok.Setter;
@Component
@Setter
@Getter
public
class
Cart
Data
{
public
class
Item
Data
{
private
Integer
shoesId
;
private
Integer
quantity
;
}
\ No newline at end of file
src/main/java/com/example/domain/
Cart
.java
→
src/main/java/com/example/domain/
Items
.java
View file @
a0a8aea2
package
com
.
example
.
domain
;
import
java.io.Serializable
;
import
java.util.ArrayList
;
import
org.springframework.context.annotation.Scope
;
import
org.springframework.context.annotation.ScopedProxyMode
;
import
org.springframework.stereotype.Component
;
import
com.example.service.ShoesService
;
import
lombok.Getter
;
import
lombok.Setter
;
...
...
@@ -16,7 +13,7 @@ import lombok.Setter;
@Scope
(
value
=
"session"
,
proxyMode
=
ScopedProxyMode
.
TARGET_CLASS
)
@Getter
@Setter
public
class
Cart
implements
Serializable
{
public
class
Items
implements
Serializable
{
/**
*
*/
...
...
@@ -29,33 +26,4 @@ public class Cart implements Serializable{
private
Integer
quantity
;
private
Integer
price
;
private
Integer
productStatus
;
public
void
setCart
(
Integer
shoesId
,
Integer
quantity
)
{
System
.
out
.
println
(
shoesId
);
Shoes
shoes
=
new
Shoes
();
ShoesService
shoesService
=
new
ShoesService
();
shoes
=
shoesService
.
findOne
(
shoesId
);
//System.out.println(shoes);
// this.shoesId = shoesId;
// this.photo = shoes.getPhoto();
// this.shoesName = shoes.getName();
// this.shoesSize = shoes.getSize();
// this.quantity = quantity;
// this.price = shoes.getPrice() * quantity;
// System.out.print(this.price);
}
public
ArrayList
<
Cart
>
getCart
(){
ArrayList
<
Cart
>
cartList
=
new
ArrayList
<
Cart
>();
Cart
data
=
new
Cart
();
data
.
getShoesId
();
data
.
getPhoto
();
data
.
getShoesName
();
data
.
getShoesSize
();
data
.
getQuantity
();
data
.
getPrice
();
cartList
.
add
(
data
);
return
cartList
;
}
}
\ No newline at end of file
src/main/java/com/example/service/ItemsService.java
0 → 100644
View file @
a0a8aea2
package
com
.
example
.
service
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.stereotype.Service
;
import
com.example.domain.Items
;
import
com.example.domain.Shoes
;
import
com.example.repository.ShoesRepository
;
import
lombok.Data
;
@Service
@Data
public
class
ItemsService
{
@Autowired
ShoesRepository
shoesRepository
;
public
Items
findOne
(
Integer
shoesId
,
Integer
quantity
){
Items
items
=
new
Items
();
Shoes
shoes
=
new
Shoes
();
shoes
=
shoesRepository
.
findOne
(
shoesId
);
items
.
setShoesId
(
shoesId
);
items
.
setPhoto
(
shoes
.
getPhoto
());
items
.
setShoesName
(
shoes
.
getName
());
items
.
setShoesSize
(
shoes
.
getSize
());
items
.
setQuantity
(
quantity
);
items
.
setPrice
(
shoes
.
getPrice
()
*
quantity
);
items
.
setProductStatus
(
shoes
.
getProductStatus
());
return
items
;
}
}
src/main/java/com/example/web/EcsiteController.java
View file @
a0a8aea2
...
...
@@ -4,8 +4,11 @@ import java.io.ByteArrayOutputStream;
import
java.io.FileInputStream
;
import
java.sql.Date
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
javax.servlet.http.HttpSession
;
import
org.springframework.beans.factory.annotation.Autowired
;
import
org.springframework.security.core.annotation.AuthenticationPrincipal
;
import
org.springframework.stereotype.Controller
;
...
...
@@ -14,6 +17,7 @@ import org.springframework.web.bind.annotation.GetMapping;
import
org.springframework.web.bind.annotation.PathVariable
;
import
org.springframework.web.bind.annotation.RequestMapping
;
import
com.example.domain.Items
;
import
com.example.domain.SalesLog
;
import
com.example.domain.Shoes
;
import
com.example.domain.User
;
...
...
@@ -29,6 +33,8 @@ public class EcsiteController {
@Autowired
SalesLogService
salesLogService
;
@Autowired
HttpSession
session
;
//写真の表示用メソッド
public
String
photoView
(
String
Photo
)
{
...
...
@@ -112,9 +118,12 @@ public class EcsiteController {
}
@GetMapping
(
"cart"
)
public
String
Cart
(
Model
model
,
@AuthenticationPrincipal
LoginUser
userDetails
){
public
String
Cart
(
Model
model
,
@AuthenticationPrincipal
LoginUser
userDetails
,
HashMap
<
String
,
Items
>
cart
){
User
user
=
userDetails
.
getUser
();
model
.
addAttribute
(
"user"
,
user
);
cart
=
(
HashMap
<
String
,
Items
>)
session
.
getAttribute
(
"cart"
);
// cart.forEach((key, value) ->{
// });
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