-
Notifications
You must be signed in to change notification settings - Fork 165
Expand file tree
/
Copy pathThymeleafWalletController.java
More file actions
69 lines (57 loc) · 2.61 KB
/
ThymeleafWalletController.java
File metadata and controls
69 lines (57 loc) · 2.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package org.prgms.kdtspringweek1.controller.thymeleafController;
import org.prgms.kdtspringweek1.customer.service.dto.FindCustomerResponseDto;
import org.prgms.kdtspringweek1.voucher.service.dto.FindVoucherResponseDto;
import org.prgms.kdtspringweek1.wallet.service.WalletService;
import org.prgms.kdtspringweek1.wallet.service.dto.CreateWalletRequestDto;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import java.time.LocalDateTime;
import java.util.List;
import java.util.UUID;
@Controller
@RequestMapping("thymeleaf")
@Profile({"thymeleaf"})
public class ThymeleafWalletController {
private final WalletService walletService;
public ThymeleafWalletController(WalletService walletService) {
this.walletService = walletService;
}
@PostMapping("/wallet")
public String createWallet(@ModelAttribute CreateWalletRequestDto createWalletRequestDto) {
walletService.registerWallet(createWalletRequestDto.toWallet());
return "wallet/wallet-create";
}
@GetMapping("/customer/wallets") // customerId로 PATHVARIABLE 가능
public String searchAllVouchersByCustomerId(@RequestParam String customerId, Model model) {
List<FindVoucherResponseDto> vouchers = walletService.searchAllVouchersByCustomerId(UUID.fromString(customerId));
model.addAttribute("serverTime", LocalDateTime.now());
model.addAttribute("vouchers", vouchers);
return "wallet/wallet-search";
}
@PostMapping("/wallet-delete")
public String deleteWalletByVoucherIdAndCustomerId(@RequestParam String voucherId, @RequestParam String customerId) {
walletService.deleteWalletByVoucherIdAndCustomerId(UUID.fromString(voucherId), UUID.fromString(customerId));
return "wallet/wallet-delete";
}
@GetMapping("/voucher/wallets")
public String searchAllCustomersByVoucherId(@RequestParam String voucherId, Model model) {
List<FindCustomerResponseDto> customers = walletService.searchAllCustomersByVoucherId(UUID.fromString(voucherId));
model.addAttribute("serverTime", LocalDateTime.now());
model.addAttribute("customers", customers);
return "wallet/wallet-search";
}
@GetMapping("/wallet")
public String searchWallet() {
return "wallet/wallet-search";
}
@GetMapping("/wallet-delete")
public String deleteWallet() {
return "wallet/wallet-delete";
}
@GetMapping("/wallet-create")
public String createWallet() {
return "wallet/wallet-create";
}
}