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

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

カート機能途中

See merge request !28
parents c5a4e8fc 1c0b08d9
package com.example; //package com.example;
//
import org.springframework.context.annotation.Bean; //import org.springframework.context.annotation.Bean;
import org.springframework.security.config.annotation.web.builders.HttpSecurity; //import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.builders.WebSecurity; //import org.springframework.security.config.annotation.web.builders.WebSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; //import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; //import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.crypto.password.PasswordEncoder; //import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.crypto.password.Pbkdf2PasswordEncoder; //import org.springframework.security.crypto.password.Pbkdf2PasswordEncoder;
//
//
@EnableWebSecurity //@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter{ //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/**");
} // }
//
@Override // @Override
protected void configure(HttpSecurity http) throws Exception { // protected void configure(HttpSecurity http) throws Exception {
http // http
.authorizeRequests() // .authorizeRequests()
.mvcMatchers("/limited/login","/limited/signUp").permitAll() //ログイン前でもアクセス可能なURLの指定 // .mvcMatchers("/limited/login","/limited/signUp").permitAll() //ログイン前でもアクセス可能なURLの指定
.mvcMatchers("/limited/admin/**").hasRole("ADMIN")//ADMIN権限のユーザーのみアクセスできるURLの指定 // .mvcMatchers("/limited/admin/**").hasRole("ADMIN")//ADMIN権限のユーザーのみアクセスできるURLの指定
.anyRequest().authenticated()//ログイン前は他のアドレスにログインできないよう指定s // .anyRequest().authenticated()//ログイン前は他のアドレスにログインできないよう指定s
.and() // .and()
.formLogin() // .formLogin()
.loginProcessingUrl("/login") //ログイン処理でpostするURL // .loginProcessingUrl("/login") //ログイン処理でpostするURL
.loginPage("/limited/login") //ログインページのURL // .loginPage("/limited/login") //ログインページのURL
.defaultSuccessUrl("/limited/top", true) //ログイン成功時のURL // .defaultSuccessUrl("/limited/top", true) //ログイン成功時のURL
.usernameParameter("email").passwordParameter("password") //ログインのパラメーター指定 // .usernameParameter("email").passwordParameter("password") //ログインのパラメーター指定
.and() // .and()
.logout() // .logout()
.invalidateHttpSession(true) // .invalidateHttpSession(true)
.deleteCookies("JSESSIONID") //ログアウト時キャッシュを削除する処理 // .deleteCookies("JSESSIONID") //ログアウト時キャッシュを削除する処理
.logoutSuccessUrl("/limited/login"); //ログアウト後に表示するURL // .logoutSuccessUrl("/limited/login"); //ログアウト後に表示するURL
} // }
//
@Bean //パスワードのハッシュか // @Bean //パスワードのハッシュか
PasswordEncoder passwordEncoder(){ // PasswordEncoder passwordEncoder(){
return new Pbkdf2PasswordEncoder(); // return new Pbkdf2PasswordEncoder();
} // }
} //}
...@@ -2,6 +2,7 @@ package com.example.api; ...@@ -2,6 +2,7 @@ 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 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;
...@@ -10,24 +11,24 @@ import org.springframework.web.bind.annotation.ModelAttribute; ...@@ -10,24 +11,24 @@ 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.RequestParam;
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.SessionData; import com.example.domain.Cart;
import com.example.domain.CartData;
import com.example.domain.User; import com.example.domain.User;
import com.example.service.LoginUserDetailsService; import com.example.service.LoginUserDetailsService;
@RestController @RestController
@RequestMapping("limited") @RequestMapping("limited")
@SessionAttributes(value = {"sessionData"}) @SessionAttributes(names ="cart")
public class EcsiteRestController { public class EcsiteRestController {
@Autowired @Autowired
LoginUserDetailsService loginUserDetailsService; LoginUserDetailsService loginUserDetailsService;
@ModelAttribute(value = "sessionData") // (1) @ModelAttribute("cart") // (1)
public SessionData sessionData() { public ArrayList<Cart> setSessionData(ArrayList<Cart> arrayList) {
return new SessionData(); return arrayList;
} }
@PostMapping("signUp") @PostMapping("signUp")
...@@ -43,9 +44,10 @@ public class EcsiteRestController { ...@@ -43,9 +44,10 @@ public class EcsiteRestController {
} }
@PostMapping("inputCart") @PostMapping("inputCart")
public void inputCart(@RequestParam SessionData data, Model model) { public void inputCart(@RequestBody CartData data, Model model, Cart cart) {
data.setSesionData(data.getShoesId(), data.getQuantity()); System.out.print(data.getShoesId());
model.addAttribute("cart", data.getCart()); cart.setCart(data.getShoesId(), data.getQuantity());
//return cart.getCart();
} }
} }
\ No newline at end of file
...@@ -13,26 +13,29 @@ import com.example.service.ShoesService; ...@@ -13,26 +13,29 @@ import com.example.service.ShoesService;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
@Component //@Component
@Scope(value= "session", proxyMode = ScopedProxyMode.TARGET_CLASS) //@Scope(value= "session", proxyMode = ScopedProxyMode.TARGET_CLASS)
@Setter
@Getter @Getter
public class SessionData implements Serializable{ @Setter
public class Cart /*implements Serializable*/{
/** /**
* *
*/ */
private static final long serialVersionUID = 1L; //private static final long serialVersionUID = 1L;
@Autowired @Autowired
ShoesService shoesService; ShoesService shoesService;
private Integer shoesId; private Integer shoesId;
private String photo; private String photo;
private String shoesName; private String shoesName;
private Integer shoesSize; private Integer shoesSize;
private Integer quantity; private Integer quantity;
private Integer price; private Integer price;
private Integer productStatus;
public void setSesionData(Integer shoesId, Integer quantity) { public void setCart(Integer shoesId, Integer quantity) {
System.out.println(shoesId);
Shoes shoes = new Shoes(); Shoes shoes = new Shoes();
shoes = shoesService.findOne(shoesId); shoes = shoesService.findOne(shoesId);
this.shoesId = shoesId; this.shoesId = shoesId;
...@@ -41,11 +44,12 @@ public class SessionData implements Serializable{ ...@@ -41,11 +44,12 @@ public class SessionData implements Serializable{
this.shoesSize = shoes.getSize(); this.shoesSize = shoes.getSize();
this.quantity = quantity; this.quantity = quantity;
this.price = shoes.getPrice() * quantity; this.price = shoes.getPrice() * quantity;
System.out.print(this.price);
} }
public ArrayList<SessionData> getCart(){ public ArrayList<Cart> getCart(){
ArrayList<SessionData> cartList = new ArrayList<SessionData>(); ArrayList<Cart> cartList = new ArrayList<Cart>();
SessionData data = new SessionData(); Cart data = new Cart();
data.getShoesId(); data.getShoesId();
data.getPhoto(); data.getPhoto();
data.getShoesName(); data.getShoesName();
...@@ -54,6 +58,5 @@ public class SessionData implements Serializable{ ...@@ -54,6 +58,5 @@ public class SessionData implements Serializable{
data.getPrice(); data.getPrice();
cartList.add(data); cartList.add(data);
return cartList; return cartList;
} }
} }
\ No newline at end of file
package com.example.domain;
import org.springframework.stereotype.Component;
import lombok.Getter;
import lombok.Setter;
@Component
@Setter
@Getter
public class CartData{
private Integer shoesId;
private Integer quantity;
}
\ 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