Skip to content

Commit

Permalink
Checkout-v1
Browse files Browse the repository at this point in the history
  • Loading branch information
JavierGasparinoMunoz committed Feb 16, 2023
1 parent 312f2c0 commit 67cf44d
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 68 deletions.
81 changes: 81 additions & 0 deletions backend/src/main/java/app/controller/CheckoutController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package app.controller;

import java.io.IOException;
import java.security.Principal;
import java.sql.Blob;
import java.sql.SQLException;
import java.util.Optional;

import javax.servlet.http.HttpServletRequest;

import org.hibernate.engine.jdbc.BlobProxy;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.io.InputStreamResource;
import org.springframework.core.io.Resource;
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.multipart.MultipartFile;

import app.model.Game;
import app.model.User;
import app.service.GameService;
import app.service.PurchaseService;
import app.service.UserService;

@Controller
public class CheckoutController {

@Autowired
private UserService userService;

@Autowired
private GameService gameService;


User currentUser;

@ModelAttribute
public void addAttributes(Model model, HttpServletRequest request) {

Principal principal = request.getUserPrincipal();

if(principal != null) {
userService.findByMail(principal.getName()).ifPresent(u -> currentUser = u);
model.addAttribute("logged", true);
model.addAttribute("userName", currentUser.getName());
model.addAttribute("admin", request.isUserInRole("ADMIN"));
} else {
model.addAttribute("logged", false);
}
}
@GetMapping("/{userId}/checkout")
public String checkout(Model model,@PathVariable long userId) {
try{
User user = userService.findById(userId).orElseThrow();
if (!user.getId().equals(currentUser.getId())){
throw new Exception();
}
currentUser.getCart();
userService.save(currentUser);
return "redirect:/";
} catch(Exception e){
return "redirect:/error";
}
}

@RequestMapping("/{userId}/checkout")

private void getDataCheckout(User user){
if(user.getBillingInformation().equals(null)){

}
}
}
39 changes: 5 additions & 34 deletions backend/src/main/resources/templates/checkout.html
Original file line number Diff line number Diff line change
Expand Up @@ -353,54 +353,25 @@ <h2 class="mt-0">Billing Details</h2>

<!-- Cart -->
<h2>Your Games in Cart</h2>

<!-- Single Product Block -->
<div class="item angled-bg">
<div class="row">
<div class="col-xs-6 col-md-9">
<h4 class="ml-20">Skyrim</h4>
</div>
<div class="col-xs-6 col-md-3 align-right">
<div class="price">
$11.99
</div>
</div>
</div>
</div>
<!-- /Single Product Block -->

<!-- Single Product Block -->
<div class="item angled-bg">
<div class="row">
<div class="col-xs-6 col-md-9">
<h4 class="ml-20">Dragons Dogma</h4>
</div>
<div class="col-xs-6 col-md-3 align-right">
<div class="price">
$34.99
</div>
</div>
</div>
</div>
<!-- /Single Product Block -->

{{#currentUser.cart}}
<!-- Single Product Block -->
<div class="item angled-bg">
<div class="row">
<div class="col-xs-6 col-md-9">
<h4 class="ml-20">The Witcher</h4>
<h4 class="ml-20">{{name}}</h4>
</div>
<div class="col-xs-6 col-md-3 align-right">
<div class="price">
$14.99
${{price}}
</div>
</div>
</div>
</div>
<!-- /Single Product Block -->
{{/currentUser.cart}}

<div class="align-right h3 mr-20 mb-20">
Total: <strong>$46.88</strong>
Total: <strong>${{currentUser.totalPrice}}</strong>
</div>
<!-- Cart -->

Expand Down
39 changes: 5 additions & 34 deletions backend/target/classes/templates/checkout.html
Original file line number Diff line number Diff line change
Expand Up @@ -353,54 +353,25 @@ <h2 class="mt-0">Billing Details</h2>

<!-- Cart -->
<h2>Your Games in Cart</h2>

<!-- Single Product Block -->
<div class="item angled-bg">
<div class="row">
<div class="col-xs-6 col-md-9">
<h4 class="ml-20">Skyrim</h4>
</div>
<div class="col-xs-6 col-md-3 align-right">
<div class="price">
$11.99
</div>
</div>
</div>
</div>
<!-- /Single Product Block -->

<!-- Single Product Block -->
<div class="item angled-bg">
<div class="row">
<div class="col-xs-6 col-md-9">
<h4 class="ml-20">Dragons Dogma</h4>
</div>
<div class="col-xs-6 col-md-3 align-right">
<div class="price">
$34.99
</div>
</div>
</div>
</div>
<!-- /Single Product Block -->

{{#currentUser.cart}}
<!-- Single Product Block -->
<div class="item angled-bg">
<div class="row">
<div class="col-xs-6 col-md-9">
<h4 class="ml-20">The Witcher</h4>
<h4 class="ml-20">{{name}}</h4>
</div>
<div class="col-xs-6 col-md-3 align-right">
<div class="price">
$14.99
${{price}}
</div>
</div>
</div>
</div>
<!-- /Single Product Block -->
{{/currentUser.cart}}

<div class="align-right h3 mr-20 mb-20">
Total: <strong>$46.88</strong>
Total: <strong>${{currentUser.totalPrice}}</strong>
</div>
<!-- Cart -->

Expand Down

0 comments on commit 67cf44d

Please sign in to comment.