Skip to content

Commit db787f6

Browse files
authored
Merge pull request #69 from xdorro/dev
Merge dev v1.0.2
2 parents 1eba3a0 + b17db11 commit db787f6

File tree

86 files changed

+1607
-284
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+1607
-284
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ out/
3636
### VS Code ###
3737
.vscode/
3838

39-
/uploads
4039
/logs
4140
application-dev.yml
4241
application-local.yml
-614 Bytes
Binary file not shown.

Documents/phan_ra_qtv.png

-1.23 KB
Loading

src/main/java/com/example/multikart/common/Utils.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,28 @@
11
package com.example.multikart.common;
22

33
import com.example.multikart.domain.dto.CartDTO;
4+
import com.example.multikart.domain.model.Customer;
5+
import com.example.multikart.domain.model.User;
46

57
import javax.servlet.http.HttpSession;
8+
import java.text.Normalizer;
69
import java.util.ArrayList;
710
import java.util.List;
11+
import java.util.Locale;
12+
import java.util.regex.Pattern;
813

914
public class Utils {
15+
16+
private static final Pattern NONLATIN = Pattern.compile("[^\\w-]");
17+
private static final Pattern WHITESPACE = Pattern.compile("[\\s]");
18+
19+
public static String toSlug(String input) {
20+
String nowhitespace = WHITESPACE.matcher(input).replaceAll("-");
21+
String normalized = Normalizer.normalize(nowhitespace, Normalizer.Form.NFD);
22+
String slug = NONLATIN.matcher(normalized).replaceAll("");
23+
return slug.toLowerCase(Locale.ENGLISH);
24+
}
25+
1026
public static boolean checkExistCart(List<CartDTO> carts, long id) {
1127
return carts.stream().anyMatch(c -> c.getProductId().equals(id));
1228
}
@@ -24,4 +40,22 @@ public static float getTotalPriceCart(List<CartDTO> carts) {
2440
var total = 0.0f;
2541
return carts.stream().map(cart -> cart.getPrice() * cart.getQuantity()).reduce(total, Float::sum);
2642
}
43+
44+
public static Customer getCustomerSession(HttpSession session) {
45+
var customer = (Customer) session.getAttribute("customer");
46+
if (DataUtils.isNullOrEmpty(customer)) {
47+
return new Customer();
48+
}
49+
50+
return customer;
51+
}
52+
53+
public static User getUserSession(HttpSession session) {
54+
var user = (User) session.getAttribute("user");
55+
if (DataUtils.isNullOrEmpty(user)) {
56+
return new User();
57+
}
58+
59+
return user;
60+
}
2761
}

src/main/java/com/example/multikart/common/interceptor/AdminInterceptor.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,14 @@ public boolean preHandle(HttpServletRequest request, HttpServletResponse respons
2424
log.info("User : {}", user);
2525

2626
if (DataUtils.isNullOrEmpty(user)) {
27-
response.sendRedirect(request.getContextPath() + "/dashboard/login");
27+
var url = request.getContextPath() + "/dashboard/login";
28+
29+
String referer = request.getHeader("Referer");
30+
if (!DataUtils.isNullOrEmpty(referer)) {
31+
url += "?redirect=" + referer;
32+
}
33+
34+
response.sendRedirect(url);
2835
return false;
2936
}
3037

src/main/java/com/example/multikart/controller/AuthController.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ public String login(Model model) {
2626
}
2727

2828
@PostMapping("/dashboard/login")
29-
public String postLogin(@Valid @ModelAttribute("user") UserLoginRequestDTO input, HttpSession session, BindingResult result, Model model) {
30-
return authService.backendPostLogin(input, session, result, model);
29+
public String postLogin(@RequestParam(value = "redirect", required = false) String referer, @Valid @ModelAttribute("user") UserLoginRequestDTO input, HttpSession session, BindingResult result, Model model) {
30+
return authService.backendPostLogin(referer, input, session, result, model);
3131
}
3232

3333
@PostMapping("/dashboard/logout")
@@ -75,8 +75,13 @@ public String frontendPostLogin(@Valid @ModelAttribute("customer") UserRegisterR
7575
}
7676

7777
@GetMapping("/profile")
78-
public String frontendProfile(HttpSession session, Model model) {
79-
return authService.frontendProfile(session, model);
78+
public String frontendProfile(HttpSession session, Model model, RedirectAttributes redirect) {
79+
return authService.frontendProfile(session, model, redirect);
80+
}
81+
82+
@PostMapping("/profile")
83+
public String frontendPostProfile(@Valid @ModelAttribute("customer") UserProfileRequestDTO input, HttpSession session, BindingResult result, Model model, RedirectAttributes redirect) {
84+
return authService.frontendPostProfile(input, session, result, model, redirect);
8085
}
8186

8287
}

src/main/java/com/example/multikart/controller/CheckoutController.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
package com.example.multikart.controller;
22

3+
import com.example.multikart.domain.dto.CheckoutRequestDTO;
34
import com.example.multikart.service.CheckoutService;
45
import org.springframework.beans.factory.annotation.Autowired;
56
import org.springframework.stereotype.Controller;
67
import org.springframework.ui.Model;
8+
import org.springframework.validation.BindingResult;
79
import org.springframework.web.bind.annotation.GetMapping;
10+
import org.springframework.web.bind.annotation.ModelAttribute;
11+
import org.springframework.web.bind.annotation.PostMapping;
812
import org.springframework.web.bind.annotation.RequestMapping;
13+
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
914

1015
import javax.servlet.http.HttpSession;
1116

@@ -20,4 +25,9 @@ public String view(HttpSession session, Model model) {
2025
return checkoutService.view(session, model);
2126
}
2227

28+
@PostMapping
29+
public String checkout(@ModelAttribute("checkout") CheckoutRequestDTO input, BindingResult result, HttpSession session, Model model, RedirectAttributes redirect) {
30+
return checkoutService.checkout(input, result, session, model, redirect);
31+
}
32+
2333
}

src/main/java/com/example/multikart/controller/OrderController.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,31 @@
99
import org.springframework.web.bind.annotation.RequestMapping;
1010
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
1111

12+
import javax.servlet.http.HttpSession;
13+
1214
@Controller
13-
@RequestMapping("/dashboard/orders")
15+
@RequestMapping("/")
1416
public class OrderController {
1517
@Autowired
1618
private OrderService orderService;
1719

18-
@GetMapping
20+
@GetMapping("/dashboard/orders")
1921
public String index(Model model) {
2022
return orderService.findAllOrders(model);
2123
}
2224

23-
@GetMapping("/{id}")
25+
@GetMapping("/dashboard/orders/{id}")
2426
public String view(@PathVariable("id") Long id, Model model, RedirectAttributes redirect) {
2527
return orderService.viewOrder(id, model, redirect);
2628
}
29+
30+
@GetMapping("/orders")
31+
public String frontendListOrder(HttpSession session, Model model, RedirectAttributes redirect) {
32+
return orderService.frontendListOrder(session, model, redirect);
33+
}
34+
35+
@GetMapping("/orders/{id}")
36+
public String frontendViewOrder(@PathVariable("id") Long id, HttpSession session, Model model, RedirectAttributes redirect) {
37+
return orderService.frontendViewOrder(id, session, model, redirect);
38+
}
2739
}

src/main/java/com/example/multikart/domain/dto/CartDTO.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,13 @@ public CartDTO(Product product, Integer number) {
2828
quantity = number;
2929
price = product.getExportPrice();
3030
}
31+
32+
public CartDTO(ItemProductDTO product, Integer number) {
33+
productId = product.getProductId();
34+
name = product.getName();
35+
slug = product.getSlug();
36+
image = product.getImage();
37+
quantity = number;
38+
price = product.getExportPrice();
39+
}
3140
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.example.multikart.domain.dto;
2+
3+
import lombok.*;
4+
5+
import javax.validation.constraints.Email;
6+
import javax.validation.constraints.NotBlank;
7+
8+
@Getter
9+
@Setter
10+
@Builder
11+
@NoArgsConstructor
12+
@AllArgsConstructor
13+
public class CheckoutRequestDTO {
14+
@NotBlank
15+
private String name;
16+
17+
private Long customerId;
18+
19+
private String phone;
20+
21+
@Email
22+
private String email;
23+
24+
private String provinceId;
25+
26+
private String districtId;
27+
28+
private String wardId;
29+
30+
private String address;
31+
32+
private String description;
33+
34+
private Long paymentId;
35+
36+
private Long transportId;
37+
}

0 commit comments

Comments
 (0)