-
Notifications
You must be signed in to change notification settings - Fork 165
Expand file tree
/
Copy pathRestVoucherController.java
More file actions
48 lines (38 loc) · 1.7 KB
/
RestVoucherController.java
File metadata and controls
48 lines (38 loc) · 1.7 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
package org.prgms.kdtspringweek1.controller.restController;
import org.prgms.kdtspringweek1.voucher.service.VoucherService;
import org.prgms.kdtspringweek1.voucher.service.dto.CreateVoucherRequestDto;
import org.prgms.kdtspringweek1.voucher.service.dto.FindVoucherResponseDto;
import org.prgms.kdtspringweek1.voucher.service.dto.SelectVoucherTypeDto;
import org.springframework.context.annotation.Profile;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import java.util.UUID;
@RestController
@RequestMapping("rest")
@Profile({"rest"})
public class RestVoucherController {
private final VoucherService voucherService;
public RestVoucherController(VoucherService voucherService) {
this.voucherService = voucherService;
}
@GetMapping("/vouchers")
public List<FindVoucherResponseDto> getAllVouchers() {
return voucherService.searchAllVouchers();
}
@GetMapping("/vouchers/type")
public List<FindVoucherResponseDto> getVoucherByVoucherType(@RequestParam String num) {
return voucherService.searchVouchersByVoucherType(SelectVoucherTypeDto.getVoucherTypeByNum(Long.parseLong(num)).getName());
}
@GetMapping("/voucher")
public FindVoucherResponseDto getVoucherByVoucherId(@RequestParam String id) {
return voucherService.searchVoucherById(UUID.fromString(id)).get();
}
@PostMapping("/voucher")
public void createVoucher(@RequestBody CreateVoucherRequestDto createVoucherRequestDto) {
voucherService.registerVoucher(createVoucherRequestDto.toVoucher());
}
@DeleteMapping("/voucher")
public void deleteVoucher(@RequestParam String id) {
voucherService.deleteVoucherById(UUID.fromString(id));
}
}