-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #84 from TeamSevenWeb/add-cards-page
Add cards page
- Loading branch information
Showing
11 changed files
with
146 additions
and
33 deletions.
There are no files selected for viewing
57 changes: 34 additions & 23 deletions
57
src/main/java/com/telerikacademy/web/virtualwallet/controllers/mvc/CardMvcController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,62 @@ | ||
package com.telerikacademy.web.virtualwallet.controllers.mvc; | ||
|
||
import com.telerikacademy.web.virtualwallet.exceptions.AuthenticationException; | ||
import com.telerikacademy.web.virtualwallet.exceptions.AuthorizationException; | ||
import com.telerikacademy.web.virtualwallet.exceptions.EntityDuplicateException; | ||
import com.telerikacademy.web.virtualwallet.models.Card; | ||
import com.telerikacademy.web.virtualwallet.models.User; | ||
import com.telerikacademy.web.virtualwallet.models.dtos.CardDto; | ||
import com.telerikacademy.web.virtualwallet.services.contracts.CardService; | ||
import com.telerikacademy.web.virtualwallet.services.contracts.UserService; | ||
import com.telerikacademy.web.virtualwallet.utils.AuthenticationHelper; | ||
import com.telerikacademy.web.virtualwallet.utils.CardMapper; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
import jakarta.servlet.http.HttpSession; | ||
import jakarta.validation.Valid; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestHeader; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.ui.Model; | ||
import org.springframework.web.bind.annotation.*; | ||
import org.springframework.web.server.ResponseStatusException; | ||
|
||
import java.util.List; | ||
import java.util.Set; | ||
|
||
@Controller | ||
@RequestMapping("users/cards") | ||
@RequestMapping("/users/cards") | ||
public class CardMvcController { | ||
|
||
private final UserService userService; | ||
private final CardService cardService; | ||
|
||
private final CardMapper cardMapper; | ||
private final AuthenticationHelper authenticationHelper; | ||
|
||
private final CardService cardService; | ||
@Autowired | ||
public CardMvcController(UserService userService, CardMapper cardMapper, CardService cardService) { | ||
this.userService = userService; | ||
this.cardMapper = cardMapper; | ||
public CardMvcController(CardService cardService, AuthenticationHelper authenticationHelper) { | ||
this.authenticationHelper = authenticationHelper; | ||
this.cardService = cardService; | ||
} | ||
|
||
@ModelAttribute("isAuthenticated") | ||
public boolean populateIsAuthenticated(HttpSession session) { | ||
return session.getAttribute("currentUser") != null; | ||
} | ||
|
||
// @PostMapping() | ||
// public void create(@RequestHeader HttpHeaders headers, @Valid @RequestBody CardDto cardDto) { | ||
// try { | ||
// User holder = userService.getById(1); | ||
// Card card = cardMapper.fromDto(holder,cardDto); | ||
// cardService.create(holder,card); | ||
// } catch (EntityDuplicateException e) { | ||
// throw new ResponseStatusException(HttpStatus.CONFLICT, e.getMessage()); | ||
// } catch (AuthorizationException e) { | ||
// throw new ResponseStatusException(HttpStatus.UNAUTHORIZED, e.getMessage()); | ||
// } | ||
// } | ||
@ModelAttribute("requestURI") | ||
public String requestURI(final HttpServletRequest request) { | ||
return request.getRequestURI(); | ||
} | ||
@GetMapping | ||
public String showCardsPage(HttpSession session, Model model) { | ||
try { | ||
User holder = authenticationHelper.tryGetCurrentUser(session); | ||
List<Card> cards = cardService.getUsersCards(holder); | ||
model.addAttribute("currentUser",holder); | ||
model.addAttribute("userCards",cards); | ||
return "CardsView"; | ||
}catch (AuthenticationException | AuthorizationException e) { | ||
return "redirect:/auth/login"; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<!DOCTYPE html> | ||
<html lang="en" xmlns:th="http://www.thymeleaf.org"> | ||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css" integrity="sha512-XXXXX" crossorigin="anonymous" /> | ||
<div th:insert="~{fragments/PageFrame :: head('Cards')}"></div> | ||
<script th:inline="javascript"> | ||
var userCardsEmpty = [[${currentUser.userCards.isEmpty()}]]; | ||
var username = [[${currentUser.username}]]; | ||
var password = [[${currentUser.password}]]; | ||
</script> | ||
<body> | ||
<div th:replace="~{fragments/PageFrame :: navbar}"></div> | ||
<section class="page-section"> | ||
<header class="navigate"> | ||
<!-- Masthead Heading--> | ||
<h1 th:unless="${userCards.isEmpty()}" class="text-uppercase mb-0 font-aquire" th:text="#{cards.page.title}">All | ||
Cards</h1> | ||
<h1 th:if="${userCards.isEmpty()}" class="text-uppercase mb-0 font-aquire" th:text="#{cards.page.empty.title}">No | ||
Cards </h1> | ||
</header> | ||
</section> | ||
<section class="page-section text-center font-aquire"> | ||
<div th:unless="${userCards.isEmpty()}"> | ||
|
||
<div class="multi-container navigate mar-l-r-40"> | ||
<div th:each="card : ${userCards}"> | ||
<div class="wallet-block"> | ||
<br/> | ||
<span class="font-aquire" th:text="${'**** **** **** '+card.number.subSequence(12,16)}"></span> | ||
<br/> | ||
<label style="font-weight: bold" th:text="${card.holder.firstName}">Holdings</label> | ||
<br/><br/> | ||
<span class="font-aquire" th:text="${card.expirationDate}"></span> | ||
<br/><br/> | ||
<i th:if="${card.number.startsWith('6')}" class="enlarged-fab fab fa-cc-discover"></i> <!-- Discover --> | ||
<i th:if="${card.number.startsWith('5')}" class="enlarged-fab fab fa-cc-mastercard"></i> <!-- Mastercard --> | ||
<i th:if="${card.number.startsWith('4')}" class="enlarged-fab fab fa-cc-visa"></i> <!-- VISA --> | ||
<i th:if="${card.number.startsWith('3')}" class="enlarged-fab fab fa-cc-amex"></i> <!-- AMEX --> | ||
<i th:unless="${card.number.startsWith('6') or card.number.startsWith('5') or card.number.startsWith('4') or card.number.startsWith('3')}" class="enlarged-fab fab fa-credit-card"></i> <!-- Default icon (Credit Card) --> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
<br/><br/> | ||
<div class="modal-overlay" id="modalOverlay"></div> | ||
<div class="modal" id="cardFlyout" style="display: none;"> | ||
<div class="modal-header"> | ||
<span type="button" class="close" data-dismiss="modal">×</span> | ||
<span style="font-size: 18px;" class="modal-title font-aquire">Enter Card Details</span> | ||
</div> | ||
<div class="modal-content"> | ||
<br/> | ||
<br/> | ||
<form id="cardForm"> | ||
<input class="simple-input-style w-10" oninput="removeSpaces()" type="text" id="number" placeholder="Card Number" required><br> | ||
<input class="simple-input-style w-10" type="text" id="holder" placeholder="Cardholder Name" required><br> | ||
<input class="simple-input-style w-10" oninput="formatCVV()" type="text" id="cvv" placeholder="Cvv Number" required><br> | ||
<input class="simple-input-style w-10" oninput="formatExpiryDate()" onblur="validateExpiryDate()" | ||
type="text" id="expiryDate" placeholder="Expiry Date (MM/YY)" required><br> | ||
<span id="expiryDateError" class="error f-size-08 display-none">Invalid date</span><br> | ||
<br> | ||
<button class="py-3-create w-8 rounded font-aquire" type="submit">Save card</button> | ||
</form> | ||
</div> | ||
</br> | ||
</div> | ||
|
||
<button class="py-3-create w-8 rounded font-aquire" id="openFlyout">Add Card</button> | ||
</section> | ||
<div th:replace="~{fragments/PageFrame :: scripts}"></div> | ||
</body> | ||
<script src="../../static/js/card.js" th:src="@{/js/card.js}"></script> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters