-
Notifications
You must be signed in to change notification settings - Fork 165
Expand file tree
/
Copy pathVoucherMvcController.java
More file actions
67 lines (57 loc) · 2.59 KB
/
VoucherMvcController.java
File metadata and controls
67 lines (57 loc) · 2.59 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
package com.prgmrs.voucher.controller.mvc;
import com.prgmrs.voucher.controller.mvc.dto.VoucherMvcCreateRequest;
import com.prgmrs.voucher.controller.mvc.dto.VoucherMvcRemoveRequest;
import com.prgmrs.voucher.dto.request.VoucherIdRequest;
import com.prgmrs.voucher.dto.request.VoucherRequest;
import com.prgmrs.voucher.dto.response.VoucherListResponse;
import com.prgmrs.voucher.model.Voucher;
import com.prgmrs.voucher.service.VoucherService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import java.util.List;
@Controller
@RequestMapping("/vouchers")
public class VoucherMvcController {
private final VoucherService voucherService;
public VoucherMvcController(VoucherService voucherService) {
this.voucherService = voucherService;
}
@GetMapping("/")
public String showMainPage() {
return "voucher-main";
}
@GetMapping("/list")
public String showListPage(Model model) {
VoucherListResponse voucherListResponse = voucherService.findAll();
List<Voucher> voucherList = voucherListResponse.voucherList();
model.addAttribute("voucherList", voucherList);
return "voucher-list";
}
@GetMapping("/create")
public String showCreatePage(Model model) {
model.addAttribute("voucherCreateRequest", new VoucherMvcCreateRequest());
return "voucher-create";
}
@PostMapping("/create")
public String createVoucher(@ModelAttribute VoucherMvcCreateRequest voucherMvcCreateRequest) {
voucherService.createVoucher(new VoucherRequest(voucherMvcCreateRequest.getDiscountType(), voucherMvcCreateRequest.getDiscountStringValue()));
return "voucher-request-success";
}
@GetMapping("/remove")
public String showRemovePage(Model model) {
VoucherListResponse voucherListResponse = voucherService.findAll();
List<Voucher> voucherList = voucherListResponse.voucherList();
model.addAttribute("voucherList", voucherList);
model.addAttribute("voucherRemoveRequest", new VoucherMvcRemoveRequest());
return "voucher-remove";
}
@PostMapping("/remove")
public String removeVoucher(@ModelAttribute VoucherMvcRemoveRequest voucherMvcRemoveRequest) {
voucherService.removeVoucher(new VoucherIdRequest(voucherMvcRemoveRequest.getVoucherId()));
return "voucher-request-success";
}
}