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

Merge branch '購入機能' into 'master'

購入機能途中

See merge request !41
parents 2bc89f53 baf3dc57
......@@ -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/**", "/limited/inputCart");
web.debug(false).ignoring().antMatchers("/images/**", "/js/**", "/css/**", "/fonts/**", "/limited/inputCart", "/limited/buy");
}
@Override
......
......@@ -2,12 +2,15 @@ package com.example.api;
import java.sql.Date;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
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.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
......@@ -18,7 +21,9 @@ import com.example.domain.ItemData;
import com.example.domain.Items;
import com.example.domain.User;
import com.example.service.ItemsService;
import com.example.service.LoginUser;
import com.example.service.LoginUserDetailsService;
import com.example.service.SalesLogService;
@RestController
@RequestMapping("limited")
......@@ -30,6 +35,9 @@ public class EcsiteRestController {
ItemsService itemsService;
@Autowired
HttpSession session;
@Autowired
SalesLogService salesLogService;
int totalPrice;
@PostMapping("signUp")
public User createUser(@RequestBody User user) {
......@@ -58,4 +66,15 @@ public class EcsiteRestController {
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;
import java.sql.Date;
import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.stereotype.Service;
import com.example.domain.Items;
import com.example.domain.SalesLog;
import com.example.repository.SalesLogRepository;
......@@ -26,8 +29,22 @@ public class SalesLogService {
return salesLogRepository.save(salesLog);
}
public SalesLog update(SalesLog salesLog){
return salesLogRepository.save(salesLog);
public void update(Integer userId, ArrayList <Items> cart){
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) {
......
......@@ -36,6 +36,7 @@ public class EcsiteController {
@Autowired
HttpSession session;
int totalPrice = 0;
//写真の表示用メソッド
public String photoView(String Photo) {
// 画像を検索してbyteとしてViewへ受け渡す
......@@ -131,6 +132,11 @@ HttpSession session;
cart.add(value);
});
model.addAttribute("cart", cart);
cart.forEach(item -> {
totalPrice += item.getPrice();
});
model.addAttribute("totalPrice", totalPrice);
totalPrice = 0;
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