Fakultas Ilmu Komputer UI

Commit e876153e authored by MUHAMMAD AAQIL ABDULLAH's avatar MUHAMMAD AAQIL ABDULLAH
Browse files

Added timed methods

parent be88012d
......@@ -4,6 +4,7 @@ import id.ac.ui.cs.advprog.landiandfriends.forms.RegisterForm;
import id.ac.ui.cs.advprog.landiandfriends.model.User;
import id.ac.ui.cs.advprog.landiandfriends.service.PaymentServiceImpl;
import id.ac.ui.cs.advprog.landiandfriends.service.UserServiceImpl;
import io.micrometer.core.annotation.Timed;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
......@@ -24,6 +25,7 @@ public class AdminController {
String usernameAttr = "username";
@GetMapping(path={"/list-user"})
@Timed("allusers")
public String allUser(Principal principal, Model model){
model.addAttribute(usernameAttr,principal != null ? principal.getName() : "");
......@@ -63,6 +65,7 @@ public class AdminController {
}
@GetMapping(path="/list-payment")
@Timed("allpayments")
public String paymentList(Model model){
model.addAttribute("payments", paymentService.getAllPayments());
return "admin-payment-list";
......
......@@ -10,14 +10,13 @@ import id.ac.ui.cs.advprog.landiandfriends.service.ArticleServiceImpl;
import id.ac.ui.cs.advprog.landiandfriends.service.BookServiceImpl;
import id.ac.ui.cs.advprog.landiandfriends.service.CartServiceImpl;
import id.ac.ui.cs.advprog.landiandfriends.service.UserServiceImpl;
import io.micrometer.core.annotation.Timed;
import lombok.RequiredArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
import java.util.List;
......@@ -37,6 +36,7 @@ public class BaseController {
private final Logger logger = LoggerFactory.getLogger(BaseController.class);
@GetMapping(path = "/")
@Timed("home")
public String getHomePage(Principal principal, Model model) {
model.addAttribute("products",
......@@ -50,6 +50,7 @@ public class BaseController {
}
@GetMapping(path = "/articles")
@Timed("allarticles")
public String getArticles(Model model,Principal principal) {
model.addAttribute(USERNAME_ATTR, (principal != null) ? principal.getName() : "");
......@@ -75,6 +76,7 @@ public class BaseController {
@GetMapping(path = "/search/{title}")
@Timed("search")
public String getSearch(Principal principal, Model model, @PathVariable(name = "title")String title) {
model.addAttribute(USERNAME_ATTR, (principal != null) ? principal.getName() : "");
model.addAttribute("searched",
......
......@@ -6,6 +6,7 @@ import id.ac.ui.cs.advprog.landiandfriends.model.User;
import id.ac.ui.cs.advprog.landiandfriends.service.BookOrderServiceImpl;
import id.ac.ui.cs.advprog.landiandfriends.service.CartServiceImpl;
import id.ac.ui.cs.advprog.landiandfriends.service.UserServiceImpl;
import io.micrometer.core.annotation.Timed;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
......@@ -63,6 +64,7 @@ public class CartController {
}
@GetMapping(path = "/purchase")
@Timed("purchase")
public String purchaseCart(Principal principal, Model model) {
if (principal != null) {
model.addAttribute("username", principal.getName());
......
......@@ -7,6 +7,7 @@ import id.ac.ui.cs.advprog.landiandfriends.model.Genre;
import id.ac.ui.cs.advprog.landiandfriends.service.ArticleServiceImpl;
import id.ac.ui.cs.advprog.landiandfriends.service.BookServiceImpl;
import id.ac.ui.cs.advprog.landiandfriends.service.GenreServiceImpl;
import io.micrometer.core.annotation.Timed;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
......@@ -36,6 +37,7 @@ public class CuratorController {
}
@GetMapping(path={"/book-list/{page}", "/book-list"})
@Timed("booklist")
public String bookList(Model model, @PathVariable(required = false) Integer page){
if(page == null) page = 0;
model.addAttribute("books", bookService.getBookPage(page));
......@@ -125,6 +127,7 @@ public class CuratorController {
@GetMapping(path={"/genre-list/{page}", "/genre-list"})
@Timed("genrelist")
public String genreList(Model model, @PathVariable(required = false) Integer page){
if(page == null) page = 0;
model.addAttribute("genres", genreService.getGenrePage(page));
......
......@@ -3,6 +3,7 @@ package id.ac.ui.cs.advprog.landiandfriends.controller;
import id.ac.ui.cs.advprog.landiandfriends.service.UserServiceImpl;
import id.ac.ui.cs.advprog.landiandfriends.util.Utility;
import io.micrometer.core.annotation.Timed;
import net.bytebuddy.utility.RandomString;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -36,6 +37,7 @@ public class ForgotPasswordController {
}
@PostMapping("/forgot_password")
@Timed("forgotpassword")
public String processForgotPassword(HttpServletRequest request, Model model) {
String email = request.getParameter("email");
var token = RandomString.make(30);
......
......@@ -8,6 +8,7 @@ import id.ac.ui.cs.advprog.landiandfriends.model.Wishlist;
import id.ac.ui.cs.advprog.landiandfriends.service.CartServiceImpl;
import id.ac.ui.cs.advprog.landiandfriends.service.UserServiceImpl;
import id.ac.ui.cs.advprog.landiandfriends.service.WishlistServiceImpl;
import io.micrometer.core.annotation.Timed;
import lombok.RequiredArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -42,11 +43,12 @@ public class RegisterController {
}
@PostMapping({ "","/"})
@Timed("registerpost")
public ResponseEntity<String> registerUser(HttpServletRequest request, @RequestBody RegisterForm form) {
try{
var user = userService.createUser(form.getEmail(), form.getUsername(), form.getPassword());
cartService.createCart(user);
Wishlist wishlist = wishlistService.createWishlist(user);
wishlistService.createWishlist(user);
loginUser(request, form.getUsername(), form.getPassword());
return ResponseEntity.ok(user.getUserId().toString());
} catch (Exception e){
......
......@@ -25,8 +25,6 @@ public class WishlistController {
private final BookServiceImpl bookService;
private final WishlistServiceImpl wishlistService;
@GetMapping(path = {"/wishlist"})
public String getWishlist(Model model) {
model.addAttribute("wishlist", wishlistService.getUserWishlist().getWishlistItems());
......
......@@ -48,8 +48,8 @@
<body>
<div class="header">
<div style="width: 1%"></div>
<img src="https://i.imgur.com/cyBT3sP.png" alt="RBS" width="100" height="100" style="padding-left: 5px">
<img src="https://i.imgur.com/aREsEE8.png" alt="Ryan's Book Store" height="100">
<a href="/"><img src="https://i.imgur.com/cyBT3sP.png" alt="RBS" width="100" height="100" style="padding-left: 5px"></a>
<a href="/"><img src="https://i.imgur.com/aREsEE8.png" alt="Ryan's Book Store" height="100"></a>
<div style="width: 1%"></div>
<input class="search" type="text" placeholder="Search by title..">
<img src="https://i.imgur.com/WWk7FEt.png" class = "search-button" alt="search" height="40">
......
......@@ -64,8 +64,8 @@
<a href="/"><img src="https://i.imgur.com/aREsEE8.png" alt="Ryan's Book Store" height="100"></a>
<div style="width: 1%"></div>
<div class="forminput">
<form th:action="@{/book/search/{bookTitle} (bookTitle = bookTitle )}") method="get">
<input name="bookTitle" id = "bookTitle" class="search" type="text" placeholder="Search by title..">
<form id="search-form" th:action="@{/book/search/}" method="get">
<input id = "bookTitle" class="search" type="text" placeholder="Search by title..">
<button type="submit">
<img src="https://i.imgur.com/WWk7FEt.png" class = "search-button" alt="search" height="40">
</button>
......
......@@ -31,11 +31,11 @@
/* Style the search box inside the navigation bar */
.search[type=text] {
float: right;
width: 50%;
float: left;
width: 80%;
padding: 6px;
border: none;
margin-right: 2px;
margin-right: 10px;
padding-left: 10px;
font-size: 17px;
}
......@@ -43,24 +43,33 @@
padding-top: 5px;
min-width: 150px;
}
.forminput{
width:100%;
}
</style>
</head>
<body>
<div class="header">
<div class="header mb-4">
<div style="width: 1%"></div>
<img src="https://i.imgur.com/cyBT3sP.png" alt="RBS" width="100" height="100" style="padding-left: 5px">
<img src="https://i.imgur.com/aREsEE8.png" alt="Ryan's Book Store" height="100">
<a href="/"><img src="https://i.imgur.com/cyBT3sP.png" alt="RBS" width="100" height="100" style="padding-left: 5px"></a>
<a href="/"><img src="https://i.imgur.com/aREsEE8.png" alt="Ryan's Book Store" height="100"></a>
<div style="width: 1%"></div>
<input class="search" type="text" placeholder="Search by title..">
<img src="https://i.imgur.com/WWk7FEt.png" class = "search-button" alt="search" height="40">
<div class="forminput">
<form id="search-form" th:action="@{/book/search/}" method="get">
<input id = "bookTitle" class="search" type="text" placeholder="Search by title..">
<button type="submit">
<img src="https://i.imgur.com/WWk7FEt.png" class = "search-button" alt="search" height="40">
</button>
</form>
</div>
<div style="width: 3%"></div>
<a href="/wishlist"><img src="https://i.imgur.com/HwTZHG8.png" class = "wishlist-button" alt="wishlist" height="40"></a>
<div style="width: 3%"></div>
<a href="/cart"><img src="https://i.imgur.com/EPveDOI.png" class = "cart-button" alt="cart" height="40"></a>
<div style="width: 3%"></div>
<a th:href ="${'/profile'}"><img src="https://i.imgur.com/KxpWso4.png" class = "signin-button" alt="sign in" height="40" style="padding-right: 10px"></a>
<a th:href =" ${'/profile'}" class="sign-in-text" style="text-decoration: none; color: inherit" >Sign In</a>
<a href ="/profile"><img src="https://i.imgur.com/KxpWso4.png" class = "signin-button" height="40" style="padding-right: 10px"></a>
<a href ="/profile" class="sign-in-text" style="text-decoration: none; color: inherit" th:text="${user.username}"></a>
</div>
<div class = "container">
......
......@@ -92,7 +92,7 @@
<div class="container">
<img th:src="${'/image/'+article.imageId}" class="product-image", style="width: 150px">
<img th:src="|data:image;base64,*{article.getImg()}|" class="product-image" style="width: 150px">
<div class="baru" ><p th:text="${article.content}"></p></div>
</div>
</body>
......
Supports Markdown
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