Commit ab047db3 authored by DESKTOP-FI5PFC1\tevir's avatar DESKTOP-FI5PFC1\tevir

カート機能途中

parent 67e5977c
......@@ -5,19 +5,32 @@ import java.time.LocalDate;
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.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.SessionAttributes;
import com.example.domain.SessionData;
import com.example.domain.User;
import com.example.service.LoginUserDetailsService;
@RestController
@RequestMapping("limited")
@SessionAttributes(types = { SessionData.class})
public class EcsiteRestController {
@Autowired
LoginUserDetailsService loginUserDetailsService;
@Autowired
SessionData sessionData;
@ModelAttribute(value = "sessionData") // (1)
public SessionData setUpSessionData() {
return new SessionData();
}
@PostMapping("signUp")
public User createUser(@RequestBody User user) {
......@@ -30,4 +43,11 @@ public class EcsiteRestController {
loginUserDetailsService.create(user);
return user;
}
@PostMapping("inputCart")
public void inputCart(@RequestParam SessionData data, Model model) {
sessionData.setSesionData(data.getShoesId(), data.getQuantity());
model.addAttribute("cart", sessionData.getCart());
}
}
\ No newline at end of file
package com.example.domain;
import java.util.ArrayList;
import org.springframework.beans.factory.annotation.Autowired;
import com.example.service.ShoesService;
import lombok.Getter;
import lombok.Setter;
@Setter
@Getter
public class SessionData {
@Autowired
ShoesService shoesService;
private Integer shoesId;
private String photo;
private String shoesName;
private Integer shoesSize;
private Integer quantity;
private Integer price;
public void setSesionData(Integer shoesId, Integer quantity) {
Shoes shoes = new Shoes();
shoes = shoesService.findOne(shoesId);
this.shoesId = shoesId;
this.photo = shoes.getPhoto();
this.shoesName = shoes.getName();
this.shoesSize = shoes.getSize();
this.quantity = quantity;
this.price = shoes.getPrice() * quantity;
}
public ArrayList<SessionData> getCart(){
ArrayList<SessionData> cartList = new ArrayList<SessionData>();
SessionData data = new SessionData();
data.getShoesId();
data.getPhoto();
data.getShoesName();
data.getShoesSize();
data.getQuantity();
data.getPrice();
cartList.add(data);
return cartList;
}
}
\ No newline at end of file
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