Commit 8330d198 authored by keita.onoguchi's avatar keita.onoguchi

Merge branch 'カート機能' into 'master'

カート機能途中

See merge request !34
parents ea4aa9c1 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
......
......@@ -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
......@@ -8,7 +8,7 @@ import lombok.Setter;
@Component
@Setter
@Getter
public class CartData{
public class ItemData{
private Integer shoesId;
private Integer quantity;
}
\ No newline at end of file
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
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;
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) {
......@@ -116,9 +122,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";
}
}
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