Skip to content

Commit a4ac945

Browse files
committed
feat : voucher 정보 view dto 생성
1 parent cc0cb03 commit a4ac945

6 files changed

Lines changed: 28 additions & 17 deletions

File tree

src/main/java/org/prgrms/kdtspringdemo/voucher/controller/VoucherWebController.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
import org.prgrms.kdtspringdemo.voucher.domain.Voucher;
44
import org.prgrms.kdtspringdemo.voucher.domain.VoucherTypeFunction;
55
import org.prgrms.kdtspringdemo.voucher.domain.dto.VoucherRequestDto;
6+
import org.prgrms.kdtspringdemo.voucher.domain.dto.VoucherViewDto;
67
import org.prgrms.kdtspringdemo.voucher.service.VoucherService;
78
import org.springframework.stereotype.Controller;
89
import org.springframework.ui.Model;
910
import org.springframework.web.bind.annotation.*;
1011

12+
import java.util.ArrayList;
1113
import java.util.List;
1214
import java.util.UUID;
1315

@@ -29,14 +31,17 @@ public String getAllVouchers(@RequestParam(name = "policy", required = false) St
2931
vouchers = voucherService.findAll();
3032
}
3133

32-
model.addAttribute("vouchers", vouchers);
34+
List<VoucherViewDto> voucherViewDtos = new ArrayList<>();
35+
vouchers.stream().forEach(voucher -> voucherViewDtos.add(new VoucherViewDto(voucher)));
36+
37+
model.addAttribute("vouchers", voucherViewDtos);
3338
return "voucher";
3439
}
3540

3641
@GetMapping("/{voucherId}")
3742
public String viewVoucher(@PathVariable UUID voucherId, Model model) {
38-
Voucher voucher = voucherService.findById(voucherId);
39-
model.addAttribute("voucher", voucher);
43+
VoucherViewDto voucherViewDto = new VoucherViewDto(voucherService.findById(voucherId));
44+
model.addAttribute("voucher", voucherViewDto);
4045
return "voucher_details";
4146
}
4247

src/main/java/org/prgrms/kdtspringdemo/wallet/controller/WalletWebController.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.prgrms.kdtspringdemo.wallet.controller;
22

33
import org.prgrms.kdtspringdemo.voucher.domain.Voucher;
4+
import org.prgrms.kdtspringdemo.voucher.domain.dto.VoucherViewDto;
45
import org.prgrms.kdtspringdemo.voucher.service.VoucherService;
56
import org.prgrms.kdtspringdemo.wallet.domain.Wallet;
67
import org.prgrms.kdtspringdemo.wallet.domain.dto.AddVoucherToWalletDto;
@@ -10,6 +11,7 @@
1011
import org.springframework.ui.Model;
1112
import org.springframework.web.bind.annotation.*;
1213

14+
import java.util.ArrayList;
1315
import java.util.List;
1416
import java.util.UUID;
1517

@@ -35,7 +37,10 @@ public String listWallets(Model model) {
3537
public String viewWallet(@PathVariable UUID walletId, Model model) {
3638
Wallet wallet = walletService.findById(walletId).orElse(null);
3739
List<Voucher> vouchers = walletService.findVouchersById(wallet.getCustomerId());
38-
WalletDetailsDto walletDetailsDto = new WalletDetailsDto(walletId, wallet.getCustomerId(), vouchers);
40+
List<VoucherViewDto> voucherViewDtos = new ArrayList<>();
41+
vouchers.stream().forEach(voucher -> voucherViewDtos.add(new VoucherViewDto(voucher)));
42+
43+
WalletDetailsDto walletDetailsDto = new WalletDetailsDto(walletId, wallet.getCustomerId(), voucherViewDtos);
3944

4045
List<Voucher> unallocatedVouchers = voucherService.findUnallocatedVoucher();
4146

src/main/java/org/prgrms/kdtspringdemo/wallet/domain/dto/WalletDetailsDto.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
package org.prgrms.kdtspringdemo.wallet.domain.dto;
22

33
import org.prgrms.kdtspringdemo.voucher.domain.Voucher;
4+
import org.prgrms.kdtspringdemo.voucher.domain.dto.VoucherViewDto;
45

56
import java.util.List;
67
import java.util.UUID;
78

89
public class WalletDetailsDto {
910
private UUID walletId;
1011
private UUID customerId;
11-
private List<Voucher> voucherList;
12+
private List<VoucherViewDto> voucherList;
1213

13-
public WalletDetailsDto(UUID walletId, UUID customerId, List<Voucher> voucherList) {
14+
public WalletDetailsDto(UUID walletId, UUID customerId, List<VoucherViewDto> voucherList) {
1415
this.walletId = walletId;
1516
this.customerId = customerId;
1617
this.voucherList = voucherList;
@@ -32,11 +33,11 @@ public void setCustomerId(UUID customerId) {
3233
this.customerId = customerId;
3334
}
3435

35-
public List<Voucher> getVoucherList() {
36+
public List<VoucherViewDto> getVoucherList() {
3637
return voucherList;
3738
}
3839

39-
public void setVoucherList(List<Voucher> voucherList) {
40+
public void setVoucherList(List<VoucherViewDto> voucherList) {
4041
this.voucherList = voucherList;
4142
}
4243
}

src/main/resources/templates/voucher.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,16 @@ <h1 class="mt-5">Voucher Management</h1>
3737
<div class="form-group">
3838
<label for="policyFilter">Filter by Policy:</label>
3939
<select class="form-control" id="policyFilter" name="policy">
40-
<option value="">All Policies</option>
41-
<option value="fixedDiscount">Fixed Discount</option>
42-
<option value="percentDiscount">Percent Discount</option>
40+
<option value="">All Vouchers</option>
41+
<option value="fixedDiscount">Fixed Discount Vouchers</option>
42+
<option value="percentDiscount">Percent Discount Vouchers</option>
4343
</select>
4444
</div>
4545
<button type="submit" class="btn btn-primary">Apply Filter</button>
4646
</form>
4747

4848
<!-- Voucher List -->
49-
<h2 class="mt-3">All Vouchers</h2>
49+
<h2 class="mt-3">Voucher List</h2>
5050
<table class="table table-striped">
5151
<thead class="thead-dark">
5252
<tr>
@@ -59,8 +59,8 @@ <h2 class="mt-3">All Vouchers</h2>
5959
<tbody>
6060
<tr th:each="voucher : ${vouchers}">
6161
<td th:text="${voucher.voucherId}">Voucher ID</td>
62-
<td th:text="${voucher.voucherPolicy.voucherType}">Voucher Policy</td>
63-
<td th:text="${voucher.voucherPolicy.amount}">Discount Amount</td>
62+
<td th:text="${voucher.voucherPolicy}">Voucher Policy</td>
63+
<td th:text="${voucher.amount}">Discount Amount</td>
6464
<td>
6565
<a th:href="@{'/vouchers/' + ${voucher.voucherId}}">Details</a>
6666
<a th:href="@{'/vouchers/' + ${voucher.voucherId} + '/edit'}">Edit</a>

src/main/resources/templates/voucher_details.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ <h2 class="mt-3">Voucher Information</h2>
1818
</tr>
1919
<tr>
2020
<th>Voucher Policy:</th>
21-
<td th:text="${voucher.voucherPolicy.voucherType}">Voucher Policy</td>
21+
<td th:text="${voucher.voucherPolicy}">Voucher Policy</td>
2222
</tr>
2323
<tr>
2424
<th>Discount Amount:</th>
25-
<td th:text="${voucher.voucherPolicy.amount}">Discount Amount</td>
25+
<td th:text="${voucher.amount}">Discount Amount</td>
2626
</tr>
2727
</table>
2828

src/main/resources/templates/wallet_details.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ <h2>Add Voucher to Wallet</h2>
6666
</th:block>
6767
</select>
6868
</div>
69-
<button type="submit" class="btn btn-primary">Add Voucher</button>
69+
<button type="submit" class="btn btn-warning">Add Voucher</button>
7070
</form>
7171

7272

0 commit comments

Comments
 (0)