Skip to content

Commit

Permalink
Added button and Controler "/addAccount"
Browse files Browse the repository at this point in the history
  • Loading branch information
iwokonl committed Feb 29, 2024
1 parent ca79660 commit 96f6b06
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
package pl.zeto.backend.VMC.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import pl.zeto.backend.VMC.model.AppAccount;
import pl.zeto.backend.VMC.model.AppUser;
import pl.zeto.backend.VMC.service.AccountService;
import org.springframework.ui.Model;

@RestController
@RequestMapping("/accounts")
@Controller
public class AccountController {

@Autowired
private AccountService accountService;

@PostMapping("/addAccount")
public AppAccount addAccount(@RequestBody AppAccount account) {
return accountService.addAccount(account);
@GetMapping("/addAccount")
public String addAccount(Model model) {
model.addAttribute("account", new AppAccount());
return "adding new account";
}

@GetMapping("/getAccount/{id}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class AccountService {

public AppAccount addAccount(AppAccount account) {
account.setBalance(new BigDecimal(0));

return accountRepository.save(account);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void saveUser(AppUser user) {

public AppUser addUser(AppUser user) {


user.setRole(Role.USER);
user.setPassword(passwordEncoder.encode(user.getPassword()));
return userRepository.save(user);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Dodaj konto walutowe</title>
<link rel="stylesheet" href="/webjars/bootstrap/5.1.3/css/bootstrap.min.css" />
</head>
<body class="d-flex flex-column min-vh-100" >

<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" href="#">Kantor Walut</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarContent" aria-controls="navbarContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>

<div class="collapse navbar-collapse" id="navbarContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Konto Walutowe
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown" th:if="${not #lists.isEmpty(accounts)}">
<a class="dropdown-item" th:each="account : ${accounts}" th:text="${account.name}" th:href="@{/selectAccount(accountId=${account.id})}"></a>
</div>
</li>
<li class="nav-item"><a class="nav-link" href="/addAccount">Dodaj konto walutowe</a></li>
<li class="nav-item"><a class="nav-link" href="#">Profil</a></li>
<li class="nav-item"><a class="nav-link" href="#">Ustawienia</a></li>
<li class="nav-item"><a class="nav-link" href="#">Wiadomości</a></li>
</ul>
<form class="form-inline" action="/logout" method="post">
<input type="hidden" name="_csrf" th:value="${_csrf.token}"/>
<button class="btn btn-outline-danger my-2 my-sm-0" type="submit">Wyloguj się</button>
</form>
</div>
</nav>
<div class="container mt-5">

<h2>Dodaj konto walutowe</h2>
<form th:action="@{/addAccount}" th:object="${account}" method="post">
<div class="mb-3">
<label for="name" class="form-label">Nazwa konta</label>
</div>
<div class="mb-3">
<label for="currency" class="form-label">Waluta</label>
<select class="form-select" id="currency" th:field="*{currency}" required>
<option value="" selected>Wybierz...</option>
<option th:each="currency : ${currencies}" th:value="${currency}" th:text="${currency}"></option>
</select>
</div>
<button type="submit" class="btn btn-primary">Dodaj</button>
</form>
</div>
<footer class="mt-auto">
<div class="text-center p-3" style="background-color: rgba(0, 0, 0, 0.2); flex-grow: 1;">
© 2024 Kantor Walut, Wszelkie prawa zastrzeżone.
</div>
</footer>
<script src="/webjars/bootstrap/5.1.3/js/bootstrap.bundle.min.js"></script>
</body>
</html>
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<a class="dropdown-item" th:each="account : ${accounts}" th:text="${account.name}" th:href="@{/selectAccount(accountId=${account.id})}"></a>
</div>
</li>
<li class="nav-item"><a class="nav-link" href="/addAccount">Dodaj konto walutowe</a></li>
<li class="nav-item"><a class="nav-link" href="#">Profil</a></li>
<li class="nav-item"><a class="nav-link" href="#">Ustawienia</a></li>
<li class="nav-item"><a class="nav-link" href="#">Wiadomości</a></li>
Expand Down

0 comments on commit 96f6b06

Please sign in to comment.