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

購入機能途中

parent 2bc89f53
...@@ -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/**", "/limited/inputCart"); web.debug(false).ignoring().antMatchers("/images/**", "/js/**", "/css/**", "/fonts/**", "/limited/inputCart", "/limited/buy");
} }
@Override @Override
......
...@@ -2,12 +2,15 @@ package com.example.api; ...@@ -2,12 +2,15 @@ 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.LinkedHashMap; import java.util.LinkedHashMap;
import javax.servlet.http.HttpSession; 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.crypto.password.Pbkdf2PasswordEncoder; import org.springframework.security.crypto.password.Pbkdf2PasswordEncoder;
import org.springframework.web.bind.annotation.GetMapping;
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;
...@@ -18,7 +21,9 @@ import com.example.domain.ItemData; ...@@ -18,7 +21,9 @@ import com.example.domain.ItemData;
import com.example.domain.Items; import com.example.domain.Items;
import com.example.domain.User; import com.example.domain.User;
import com.example.service.ItemsService; import com.example.service.ItemsService;
import com.example.service.LoginUser;
import com.example.service.LoginUserDetailsService; import com.example.service.LoginUserDetailsService;
import com.example.service.SalesLogService;
@RestController @RestController
@RequestMapping("limited") @RequestMapping("limited")
...@@ -30,6 +35,9 @@ public class EcsiteRestController { ...@@ -30,6 +35,9 @@ public class EcsiteRestController {
ItemsService itemsService; ItemsService itemsService;
@Autowired @Autowired
HttpSession session; HttpSession session;
@Autowired
SalesLogService salesLogService;
int totalPrice;
@PostMapping("signUp") @PostMapping("signUp")
public User createUser(@RequestBody User user) { public User createUser(@RequestBody User user) {
...@@ -58,4 +66,15 @@ public class EcsiteRestController { ...@@ -58,4 +66,15 @@ public class EcsiteRestController {
session.setAttribute("cart", cart); session.setAttribute("cart", cart);
} }
} }
@GetMapping("buy")
public void buy(@AuthenticationPrincipal LoginUser userDetails, LinkedHashMap<String, Items> items, ArrayList <Items> cart){
items = (LinkedHashMap<String, Items>) session.getAttribute("cart");
items.forEach((key, value) -> {
cart.add(value);
});
//User user = userDetails.getUser();
//Integer userId = user.getId();
salesLogService.update(1, cart);
}
} }
\ No newline at end of file
package com.example.service; package com.example.service;
import java.sql.Date; import java.sql.Date;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.example.domain.Items;
import com.example.domain.SalesLog; import com.example.domain.SalesLog;
import com.example.repository.SalesLogRepository; import com.example.repository.SalesLogRepository;
...@@ -26,8 +29,22 @@ public class SalesLogService { ...@@ -26,8 +29,22 @@ public class SalesLogService {
return salesLogRepository.save(salesLog); return salesLogRepository.save(salesLog);
} }
public SalesLog update(SalesLog salesLog){ public void update(Integer userId, ArrayList <Items> cart){
return salesLogRepository.save(salesLog); int count = 0;
java.util.Date d1 = new java.util.Date();
//d1をSQL.DATE型に変換してtodayに代入
java.sql.Date today = new java.sql.Date(d1.getTime());
System.out.println(cart.size());
for(int i = 0; i < cart.size(); i++){
SalesLog salesLog = new SalesLog();
salesLog.setUserId(userId);
salesLog.setShoesId((cart.get(i)).getShoesId());
salesLog.setPrice((cart.get(i)).getPrice());
salesLog.setCreated(today);
salesLogRepository.save(salesLog);
count++;
}
System.out.println(count);
} }
public List<SalesLog> history(Integer id) { public List<SalesLog> history(Integer id) {
......
...@@ -36,6 +36,7 @@ public class EcsiteController { ...@@ -36,6 +36,7 @@ public class EcsiteController {
@Autowired @Autowired
HttpSession session; HttpSession session;
int totalPrice = 0;
//写真の表示用メソッド //写真の表示用メソッド
public String photoView(String Photo) { public String photoView(String Photo) {
// 画像を検索してbyteとしてViewへ受け渡す // 画像を検索してbyteとしてViewへ受け渡す
...@@ -131,6 +132,11 @@ HttpSession session; ...@@ -131,6 +132,11 @@ HttpSession session;
cart.add(value); cart.add(value);
}); });
model.addAttribute("cart", cart); model.addAttribute("cart", cart);
cart.forEach(item -> {
totalPrice += item.getPrice();
});
model.addAttribute("totalPrice", totalPrice);
totalPrice = 0;
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