-
Notifications
You must be signed in to change notification settings - Fork 171
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
[4기 - 한승원] SpringBoot Part3 Weekly Mission 제출합니다. #831
Open
SW-H
wants to merge
9
commits into
prgrms-be-devcourse:seungwon/w1
Choose a base branch
from
SW-H:main
base: seungwon/w1
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
5d67c1d
feat : 바우처 서비스 restAPI
SW-H 00114e1
refactor
SW-H 5b7b9d3
refactor : java 버전 변경
SW-H 080a446
feat : voucher service 수정에 따른 테스트 코드 수정
SW-H 5df638b
feat : voucher service 수정에 따른 테스트 코드 수정
SW-H 3001b85
feat : 예외 처리
SW-H 8358752
refactor
SW-H 05c3629
feat : API의 URI 수정
SW-H bc87bdb
refactor
SW-H File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 1 addition & 10 deletions
11
src/main/java/co/programmers/voucher_management/ApplicationController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,12 @@ | ||
package co.programmers.voucher_management; | ||
|
||
import java.util.List; | ||
|
||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.ui.Model; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
|
||
import co.programmers.voucher_management.voucher.dto.VoucherResponseDTO; | ||
import co.programmers.voucher_management.voucher.service.VoucherService; | ||
|
||
@Controller | ||
public class ApplicationController { | ||
@GetMapping("home") | ||
public String inquiryVoucherOf(){ | ||
public String inquiryVoucherOf() { | ||
return "home"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
src/main/java/co/programmers/voucher_management/VoucherApiController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package co.programmers.voucher_management; | ||
|
||
import java.time.LocalDate; | ||
import java.util.List; | ||
|
||
import org.springframework.format.annotation.DateTimeFormat; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.DeleteMapping; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import co.programmers.voucher_management.voucher.dto.VoucherRequestDTO; | ||
import co.programmers.voucher_management.voucher.dto.VoucherResponseDTO; | ||
import co.programmers.voucher_management.voucher.service.VoucherService; | ||
|
||
@RequestMapping("/api/v1/vouchers") | ||
@RestController | ||
public class VoucherApiController { | ||
private final VoucherService voucherService; | ||
|
||
public VoucherApiController(VoucherService voucherService) { | ||
this.voucherService = voucherService; | ||
} | ||
|
||
@GetMapping | ||
public ResponseEntity<List<VoucherResponseDTO>> find( | ||
@RequestParam(required = false) String type, | ||
@RequestParam(required = false, defaultValue = "-1") Long id | ||
) { | ||
if (id > 0) { | ||
return findById(id); | ||
} | ||
if (type != null) { | ||
return findByType(type); | ||
} | ||
return findAll(); | ||
} | ||
|
||
public ResponseEntity<List<VoucherResponseDTO>> findAll() { | ||
List<VoucherResponseDTO> response = voucherService.inquiryVoucherOf(); | ||
return ResponseEntity.ok(response); | ||
} | ||
|
||
private ResponseEntity<List<VoucherResponseDTO>> findById(@PathVariable long id) { | ||
VoucherResponseDTO response = voucherService.findById(id); | ||
return ResponseEntity.ok(List.of(response)); | ||
} | ||
Comment on lines
+49
to
+52
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. ResponseEntity를 사용해서 응답을 제어하는 부분이 딱히 없다면 List 그대로 반환해도 동일한 코드가 될것 같네요 |
||
|
||
private ResponseEntity<List<VoucherResponseDTO>> findByType(@RequestParam String discountType) { | ||
List<VoucherResponseDTO> response = voucherService.findByType(discountType); | ||
return ResponseEntity.ok(response); | ||
} | ||
|
||
@GetMapping(params = {"startDate", "endDate"}) | ||
public ResponseEntity<List<VoucherResponseDTO>> findByDate( | ||
@RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate startDate, | ||
@RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") LocalDate endDate) { | ||
List<VoucherResponseDTO> response = voucherService.findByDate(startDate, endDate); | ||
return ResponseEntity.ok(response); | ||
} | ||
|
||
@PostMapping | ||
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 컨벤션을 잘지켜주시고 계시네요 |
||
public ResponseEntity<VoucherResponseDTO> create(@RequestBody VoucherRequestDTO voucherRequestDTO) { | ||
VoucherResponseDTO response = voucherService.create(voucherRequestDTO); | ||
return ResponseEntity.ok(response); | ||
} | ||
|
||
@DeleteMapping("/{id}") | ||
public ResponseEntity deleteById(@PathVariable long id) { | ||
voucherService.deleteById(id); | ||
return ResponseEntity.ok(""); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,5 @@ | |
|
||
public enum Status { | ||
NORMAL, | ||
DELETED; | ||
DELETED | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
동적 쿼리를 구현하시려고 노력한 흔적이 보이네요
이미 아실 수도 있지만 QueryDSL을 사용하면 동적쿼리를 쉽게 처리할 수 있습니다.
좀더 검색에 대한 니즈가 강해서 고도화할 필요가 있으면 엘라스틱 서치를 사용하게 될꺼구요