- 
                Notifications
    You must be signed in to change notification settings 
- Fork 170
[4기 - 안재영] SpringBoot Part3 Weekly Mission PR 제출합니다. #862
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: JaeyoungAhn
Are you sure you want to change the base?
Changes from all commits
6fd1b4a
              ef8a1c2
              c7c9f98
              f431383
              ec7bdcd
              3bd683a
              717d7f5
              cea3204
              84a32db
              1a813a4
              9f70c61
              File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| GET http://localhost:8080/api/json/v1/vouchers | ||
|  | ||
| ### | ||
|  | ||
| GET http://localhost:8080/api/json/v1/vouchers/search?startDate=2023-07-16T00:00:00&endDate=2023-07-19T23:59:59& | ||
| discountType=fixed | ||
|  | ||
| ### | ||
|  | ||
| POST http://localhost:8080/api/json/v1/vouchers | ||
| Content-Type: application/json | ||
|  | ||
| { | ||
| "discountType": "fixed", | ||
| "discountStringValue": "123" | ||
| } | ||
|  | ||
| ### | ||
|  | ||
| DELETE http://localhost:8080/api/json/v1/vouchers/f3ac7182-4f80-470a-99e7-478c29c41b0f | ||
|  | ||
| ### | ||
|  | ||
| GET http://localhost:8080/api/json/v1/vouchers/cc295caf-cdb1-4fe6-8360-a2149a74f1b9 | ||
|  | ||
| ### | ||
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| GET http://localhost:8080/api/xml/v1/vouchers | ||
|  | ||
| ### | ||
|  | ||
| GET http://localhost:8080/api/xml/v1/vouchers/search?startDate=2023-07-16T00:00:00&endDate=2023-07-19T23:59:59& | ||
| discountType=fixed | ||
|  | ||
| ### | ||
|  | ||
| POST http://localhost:8080/api/xml/v1/vouchers | ||
| Content-Type: application/xml | ||
|  | ||
| <VoucherRequest> | ||
| <discountType>fixed</discountType> | ||
| <discountStringValue>123</discountStringValue> | ||
| </VoucherRequest> | ||
|  | ||
| ### | ||
|  | ||
| DELETE http://localhost:8080/api/xml/v1/vouchers/ea50d33d-d668-4dcd-b2b2-980b184ff003 | ||
|  | ||
| ### | ||
|  | ||
| GET http://localhost:8080/api/xml/v1/vouchers/fef87c80-ee1c-4aca-bf14-375930aff54c | ||
|  | ||
| ### | 
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| package com.prgmrs.voucher.controller.json; | ||
|  | ||
| import com.prgmrs.voucher.dto.request.VoucherIdRequest; | ||
| import com.prgmrs.voucher.dto.request.VoucherRequest; | ||
| import com.prgmrs.voucher.dto.request.VoucherSearchRequest; | ||
| import com.prgmrs.voucher.dto.response.RemoveResponse; | ||
| import com.prgmrs.voucher.dto.response.VoucherListResponse; | ||
| import com.prgmrs.voucher.dto.response.VoucherResponse; | ||
| import com.prgmrs.voucher.service.VoucherService; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.*; | ||
|  | ||
| @RestController | ||
| @RequestMapping("/api/json/v1") | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. rest api 아닌가요? 헤더와 mapping 어노테이션을 이용할수 있습니다 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 해당 내용에 대해서 공부를 해보았는데 URL에는 어떠한 데이터 형식으로 주고받는지에 대한 내용이 있으면 안되는 것을 배웠습니다. 대신 mapping의 옵션에서 어떤 데이터를 받아들일지 명확히 나타내도록 하겠습니다. | ||
| public class VoucherJsonController { | ||
|  | ||
| private final VoucherService voucherService; | ||
|  | ||
| public VoucherJsonController(VoucherService voucherService) { | ||
| this.voucherService = voucherService; | ||
| } | ||
|  | ||
| @GetMapping("/vouchers") | ||
| public ResponseEntity<VoucherListResponse> findAll() { | ||
| return ResponseEntity.ok(voucherService.findAll()); | ||
| } | ||
|  | ||
| @GetMapping("/vouchers/search") | ||
| public ResponseEntity<VoucherListResponse> findByCreationTimeAndDiscountType(VoucherSearchRequest voucherSearchRequest) { | ||
| return ResponseEntity.ok(voucherService.findByCreationTimeAndDiscountType(voucherSearchRequest)); | ||
| } | ||
|  | ||
| @PostMapping("/vouchers") | ||
| public ResponseEntity<VoucherResponse> createVoucher(@RequestBody VoucherRequest voucherRequest) { | ||
| return ResponseEntity.ok(voucherService.createVoucher(voucherRequest)); | ||
| } | ||
|  | ||
| @DeleteMapping("/vouchers/{voucherId}") | ||
| public ResponseEntity<RemoveResponse> removeVoucher(@PathVariable("voucherId") VoucherIdRequest voucherIdRequest) { | ||
| return ResponseEntity.ok(voucherService.removeVoucher(voucherIdRequest)); | ||
| } | ||
|  | ||
| @GetMapping("/vouchers/{voucherId}") | ||
| public ResponseEntity<VoucherResponse> findById(@PathVariable("voucherId") VoucherIdRequest voucherIdRequest) { | ||
| return ResponseEntity.ok(voucherService.findById(voucherIdRequest)); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,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"; | ||
| } | ||
| } | 
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| package com.prgmrs.voucher.controller.mvc.dto; | ||
|  | ||
| public class VoucherMvcCreateRequest { | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. setter를 안써도 됩니다. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. | ||
| private String discountType; | ||
| private String discountStringValue; | ||
|  | ||
| public VoucherMvcCreateRequest() { | ||
| // Do nothing for thymeleaf support purpose | ||
| } | ||
|  | ||
| public String getDiscountType() { | ||
| return discountType; | ||
| } | ||
|  | ||
| public void setDiscountType(String discountType) { | ||
| this.discountType = discountType; | ||
| } | ||
|  | ||
| public String getDiscountStringValue() { | ||
| return discountStringValue; | ||
| } | ||
|  | ||
| public void setDiscountStringValue(String discountStringValue) { | ||
| this.discountStringValue = discountStringValue; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| package com.prgmrs.voucher.controller.mvc.dto; | ||
|  | ||
| public class VoucherMvcRemoveRequest { | ||
| private String voucherId; | ||
|  | ||
| public VoucherMvcRemoveRequest() { | ||
| // Do nothing for thymeleaf support purpose | ||
| } | ||
|  | ||
| public String getVoucherId() { | ||
| return voucherId; | ||
| } | ||
|  | ||
| public void setVoucherId(String voucherId) { | ||
| this.voucherId = voucherId; | ||
| } | ||
| } | 
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| package com.prgmrs.voucher.controller.xml; | ||
|  | ||
| import com.prgmrs.voucher.dto.request.VoucherIdRequest; | ||
| import com.prgmrs.voucher.dto.request.VoucherRequest; | ||
| import com.prgmrs.voucher.dto.request.VoucherSearchRequest; | ||
| import com.prgmrs.voucher.dto.response.RemoveResponse; | ||
| import com.prgmrs.voucher.dto.response.VoucherListResponse; | ||
| import com.prgmrs.voucher.dto.response.VoucherResponse; | ||
| import com.prgmrs.voucher.service.VoucherService; | ||
| import org.springframework.http.ResponseEntity; | ||
| import org.springframework.web.bind.annotation.*; | ||
|  | ||
| @RestController | ||
| @RequestMapping("/api/xml/v1") | ||
| There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. VoucherJsonController와 | ||
| public class VoucherXmlController { | ||
| private final VoucherService voucherService; | ||
|  | ||
| public VoucherXmlController(VoucherService voucherService) { | ||
| this.voucherService = voucherService; | ||
| } | ||
|  | ||
| @GetMapping(value = "/vouchers", produces = "application/xml") | ||
| public ResponseEntity<VoucherListResponse> findAll() { | ||
| return ResponseEntity.ok(voucherService.findAll()); | ||
| } | ||
| 
      Comment on lines
    
      +22
     to 
      +25
    
   There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 제가 한가지 언급안했던 부분이 있긴한데 ㅠ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 
 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 형식별로 두개의 컨트롤러를 만들어야 하나 생각했는데, 이렇게 배열로 처리 할 수 있군요..! | ||
|  | ||
| @GetMapping(value = "/vouchers/search", produces = "application/xml") | ||
| public ResponseEntity<VoucherListResponse> findByCreationTimeAndDiscountType(VoucherSearchRequest voucherSearchRequest) { | ||
| return ResponseEntity.ok(voucherService.findByCreationTimeAndDiscountType(voucherSearchRequest)); | ||
| } | ||
|  | ||
| @PostMapping(value = "/vouchers", consumes = "application/xml", produces = "application/xml") | ||
| public ResponseEntity<VoucherResponse> createVoucher(@RequestBody VoucherRequest voucherRequest) { | ||
| System.out.println(voucherRequest); // or use a logger | ||
| return ResponseEntity.ok(voucherService.createVoucher(voucherRequest)); | ||
| } | ||
|  | ||
| @DeleteMapping(value = "/vouchers/{voucherId}", produces = "application/xml") | ||
| public ResponseEntity<RemoveResponse> removeVoucher(@PathVariable("voucherId") VoucherIdRequest voucherIdRequest) { | ||
| return ResponseEntity.ok(voucherService.removeVoucher(voucherIdRequest)); | ||
| } | ||
|  | ||
| @GetMapping(value = "/vouchers/{voucherId}", produces = "application/xml") | ||
| public ResponseEntity<VoucherResponse> findById(@PathVariable("voucherId") VoucherIdRequest voucherIdRequest) { | ||
| return ResponseEntity.ok(voucherService.findById(voucherIdRequest)); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -1,5 +1,4 @@ | ||
| package com.prgmrs.voucher.dto.request; | ||
|  | ||
| public record VoucherRequest(String discountType, String discountStringValue) { | ||
|  | ||
| } | 
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| package com.prgmrs.voucher.dto.request; | ||
|  | ||
| import com.prgmrs.voucher.exception.WrongRangeFormatException; | ||
|  | ||
| import java.time.LocalDateTime; | ||
|  | ||
| public record VoucherSearchRequest(LocalDateTime startDate, LocalDateTime endDate, String discountType) { | ||
| public VoucherSearchRequest { | ||
| if (startDate == null) { | ||
| throw new WrongRangeFormatException("startDate cannot be null"); | ||
| } | ||
| if (endDate == null) { | ||
| throw new WrongRangeFormatException("endDate cannot be null"); | ||
| } | ||
| if (discountType == null || discountType.isBlank()) { | ||
| throw new WrongRangeFormatException("discountType cannot be null or blank"); | ||
| } | ||
| } | ||
| } | 
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| package com.prgmrs.voucher.dto.response; | ||
|  | ||
| public record RemoveResponse(int rowsDeleted) { | ||
| } | 
| Original file line number | Diff line number | Diff line change | 
|---|---|---|
|  | @@ -5,4 +5,4 @@ | |
| import java.util.UUID; | ||
|  | ||
| public record VoucherResponse(UUID voucherUuid, DiscountStrategy discountStrategy) { | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good
이렇게 다양한 방식으로 테스트해보는것도 좋다고 생각합니다