File tree Expand file tree Collapse file tree
src/main/java/org/prgrms/kdtspringdemo/voucher/controller Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ package org .prgrms .kdtspringdemo .voucher .controller ;
2+
3+ import org .prgrms .kdtspringdemo .voucher .domain .Voucher ;
4+ import org .prgrms .kdtspringdemo .voucher .domain .dto .VoucherViewDto ;
5+ import org .prgrms .kdtspringdemo .voucher .service .VoucherService ;
6+ import org .springframework .http .HttpStatus ;
7+ import org .springframework .http .ResponseEntity ;
8+ import org .springframework .web .bind .annotation .GetMapping ;
9+ import org .springframework .web .bind .annotation .RequestMapping ;
10+ import org .springframework .web .bind .annotation .RestController ;
11+
12+ import java .util .List ;
13+
14+ @ RestController
15+ @ RequestMapping ("/api/v1/voucher" )
16+ public class VoucherRestController {
17+ private final VoucherService voucherService ;
18+
19+ public VoucherRestController (VoucherService voucherService ) {
20+ this .voucherService = voucherService ;
21+ }
22+
23+ @ GetMapping ("/vouchers" )
24+ ResponseEntity <List <VoucherViewDto >> showAllVouchers () {
25+ final List <VoucherViewDto > vouchers = voucherService .findAll ().stream ()
26+ .map (VoucherViewDto ::new ).toList ();
27+ return new ResponseEntity <>(vouchers , HttpStatus .OK );
28+
29+ }
30+
31+ }
You can’t perform that action at this time.
0 commit comments