Commit a0a8aea2 authored by keita.onoguchi's avatar keita.onoguchi

カート機能途中

parent c949e8a3
...@@ -14,7 +14,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter{ ...@@ -14,7 +14,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter{
@Override @Override
public void configure(WebSecurity web) throws Exception{ 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 @Override
......
...@@ -3,33 +3,35 @@ package com.example.api; ...@@ -3,33 +3,35 @@ package com.example.api;
import java.sql.Date; import java.sql.Date;
import java.time.LocalDate; import java.time.LocalDate;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.password.Pbkdf2PasswordEncoder; import org.springframework.security.crypto.password.Pbkdf2PasswordEncoder;
import org.springframework.ui.Model; 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.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.SessionAttributes; import org.springframework.web.bind.annotation.SessionAttributes;
import com.example.domain.Cart; import com.example.domain.ItemData;
import com.example.domain.CartData; import com.example.domain.Items;
import com.example.domain.User; import com.example.domain.User;
import com.example.service.ItemsService;
import com.example.service.LoginUserDetailsService; import com.example.service.LoginUserDetailsService;
@RestController @RestController
@RequestMapping("limited") @RequestMapping("limited")
//@SessionAttributes(names ="cart") @SessionAttributes(names ="itemData")
public class EcsiteRestController { public class EcsiteRestController {
@Autowired @Autowired
LoginUserDetailsService loginUserDetailsService; LoginUserDetailsService loginUserDetailsService;
@Autowired
@ModelAttribute("cart") // (1) ItemsService itemsService;
public ArrayList<Cart> setSessionData(ArrayList<Cart> arrayList) { @Autowired
return arrayList; HttpSession session;
}
@PostMapping("signUp") @PostMapping("signUp")
public User createUser(@RequestBody User user) { public User createUser(@RequestBody User user) {
...@@ -44,10 +46,15 @@ public class EcsiteRestController { ...@@ -44,10 +46,15 @@ public class EcsiteRestController {
} }
@PostMapping("inputCart") @PostMapping("inputCart")
public void inputCart(@RequestBody CartData data, Model model) { public void inputCart(@RequestBody ItemData data, HashMap<String, Items> cart) {
Cart cart = new Cart(); if(session.getAttribute("cart") == null){
cart.setCart(data.getShoesId(), data.getQuantity()); cart.put((data.getShoesId()).toString(), itemsService.findOne(data.getShoesId(),data.getQuantity()));
//return cart.getCart(); 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
...@@ -8,7 +8,7 @@ import lombok.Setter; ...@@ -8,7 +8,7 @@ import lombok.Setter;
@Component @Component
@Setter @Setter
@Getter @Getter
public class CartData{ public class ItemData{
private Integer shoesId; private Integer shoesId;
private Integer quantity; private Integer quantity;
} }
\ No newline at end of file
package com.example.domain; package com.example.domain;
import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList;
import org.springframework.context.annotation.Scope; import org.springframework.context.annotation.Scope;
import org.springframework.context.annotation.ScopedProxyMode; import org.springframework.context.annotation.ScopedProxyMode;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import com.example.service.ShoesService;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
...@@ -16,7 +13,7 @@ import lombok.Setter; ...@@ -16,7 +13,7 @@ import lombok.Setter;
@Scope(value= "session", proxyMode = ScopedProxyMode.TARGET_CLASS) @Scope(value= "session", proxyMode = ScopedProxyMode.TARGET_CLASS)
@Getter @Getter
@Setter @Setter
public class Cart implements Serializable{ public class Items implements Serializable{
/** /**
* *
*/ */
...@@ -29,33 +26,4 @@ public class Cart implements Serializable{ ...@@ -29,33 +26,4 @@ public class Cart implements Serializable{
private Integer quantity; private Integer quantity;
private Integer price; private Integer price;
private Integer productStatus; 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
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;
}
}
...@@ -4,8 +4,11 @@ import java.io.ByteArrayOutputStream; ...@@ -4,8 +4,11 @@ import java.io.ByteArrayOutputStream;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.sql.Date; import java.sql.Date;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.List; import java.util.List;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
...@@ -14,6 +17,7 @@ import org.springframework.web.bind.annotation.GetMapping; ...@@ -14,6 +17,7 @@ import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import com.example.domain.Items;
import com.example.domain.SalesLog; import com.example.domain.SalesLog;
import com.example.domain.Shoes; import com.example.domain.Shoes;
import com.example.domain.User; import com.example.domain.User;
...@@ -29,6 +33,8 @@ public class EcsiteController { ...@@ -29,6 +33,8 @@ public class EcsiteController {
@Autowired @Autowired
SalesLogService salesLogService; SalesLogService salesLogService;
@Autowired
HttpSession session;
//写真の表示用メソッド //写真の表示用メソッド
public String photoView(String Photo) { public String photoView(String Photo) {
...@@ -112,9 +118,12 @@ public class EcsiteController { ...@@ -112,9 +118,12 @@ public class EcsiteController {
} }
@GetMapping("cart") @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(); User user = userDetails.getUser();
model.addAttribute("user", user); model.addAttribute("user", user);
cart = (HashMap<String, Items>) session.getAttribute("cart");
// cart.forEach((key, value) ->{
// });
return "Cart"; return "Cart";
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment