33import org .prgrms .kdtspringdemo .voucher .domain .Voucher ;
44import org .prgrms .kdtspringdemo .voucher .domain .VoucherTypeFunction ;
55import org .prgrms .kdtspringdemo .voucher .domain .dto .VoucherRequestDto ;
6+ import org .prgrms .kdtspringdemo .voucher .domain .dto .VoucherViewDto ;
67import org .prgrms .kdtspringdemo .voucher .service .VoucherService ;
78import org .springframework .stereotype .Controller ;
89import org .springframework .ui .Model ;
910import org .springframework .web .bind .annotation .*;
1011
12+ import java .util .ArrayList ;
1113import java .util .List ;
1214import 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
0 commit comments