-
Notifications
You must be signed in to change notification settings - Fork 1
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
반경 내 주차장 조회 기능 구현 #13
Changes from 1 commit
f44658b
43ca5c9
85f7423
7674fc9
c1fa2c3
ba3c449
97ce588
c4fad88
0372e0d
d399ab5
3469889
7f49f6d
6288499
35a5747
2d059a8
592b1c7
f8b4dbd
d33ee40
44ae717
28ce548
6b7459f
d5ca66d
4c780fc
5f608cc
d008f2e
0035310
227cf26
a4dc6a1
84b1100
2973615
9d03477
1f31077
6c04212
b35c425
f1fa25b
3b9d046
9d5693e
dfac844
4528710
5362f5d
03dcdd3
fc15e7e
7b48ca1
4fe6e61
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,37 @@ | ||
package com.example.parking.application.parking.dto; | ||
|
||
import com.example.parking.domain.parking.OperationType; | ||
import com.example.parking.domain.parking.ParkingType; | ||
import com.example.parking.domain.parking.PayType; | ||
import com.example.parking.domain.searchcondition.FeeType; | ||
import java.util.List; | ||
|
||
public class ParkingSearchConditionRequest { | ||
|
||
private static final ParkingSearchConditionRequest BASE = new ParkingSearchConditionRequest( | ||
OperationType.getAllValues(), | ||
ParkingType.getAllValues(), | ||
FeeType.getAllValues(), | ||
PayType.getAllValues(), | ||
1 | ||
); | ||
|
||
private final List<String> operationTypes; | ||
private final List<String> parkingTypes; | ||
private final List<String> feeTypes; | ||
private final List<String> payTypes; | ||
private final int hours; | ||
|
||
public ParkingSearchConditionRequest(List<String> operationTypes, List<String> parkingTypes, List<String> feeTypes, | ||
List<String> payTypes, int hours) { | ||
this.operationTypes = operationTypes; | ||
this.parkingTypes = parkingTypes; | ||
this.feeTypes = feeTypes; | ||
this.payTypes = payTypes; | ||
this.hours = hours; | ||
} | ||
|
||
public static ParkingSearchConditionRequest base() { | ||
return BASE; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.example.parking.config.argumentresolver.parking; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
@Target(ElementType.PARAMETER) | ||
@Retention(RetentionPolicy.RUNTIME) | ||
public @interface ParkingSearchCondition { | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package com.example.parking.config.argumentresolver.parking; | ||
|
||
import com.example.parking.application.parking.dto.ParkingSearchConditionRequest; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import org.springframework.core.MethodParameter; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.web.bind.support.WebDataBinderFactory; | ||
import org.springframework.web.context.request.NativeWebRequest; | ||
import org.springframework.web.method.support.HandlerMethodArgumentResolver; | ||
import org.springframework.web.method.support.ModelAndViewContainer; | ||
|
||
@Component | ||
public class ParkingSearchConditionArgumentResolver implements HandlerMethodArgumentResolver { | ||
|
||
@Override | ||
public boolean supportsParameter(MethodParameter parameter) { | ||
return parameter.hasParameterAnnotation(ParkingSearchCondition.class); | ||
} | ||
|
||
@Override | ||
public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, | ||
NativeWebRequest webRequest, WebDataBinderFactory binderFactory) { | ||
|
||
String[] operationTypes = webRequest.getParameterValues("operationTypes"); | ||
String[] parkingTypes = webRequest.getParameterValues("parkingTypes"); | ||
String[] feeTypes = webRequest.getParameterValues("feeTypes"); | ||
String[] payTypes = webRequest.getParameterValues("payTypes"); | ||
Integer hours = Integer.parseInt(webRequest.getParameter("hours")); | ||
|
||
if (containsNull(operationTypes, parkingTypes, feeTypes, payTypes, hours)) { | ||
return ParkingSearchConditionRequest.base(); | ||
} | ||
|
||
return new ParkingSearchConditionRequest( | ||
toCollection(operationTypes), | ||
toCollection(parkingTypes), | ||
toCollection(feeTypes), | ||
toCollection(payTypes), | ||
hours | ||
); | ||
} | ||
|
||
private boolean containsNull(String[] operationTypes, String[] parkingTypes, String[] feeTypes, | ||
String[] payTypes, Integer hours) { | ||
if (operationTypes == null || parkingTypes == null || feeTypes == null || payTypes == null || hours == null) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
private List<String> toCollection(String[] parameters) { | ||
return Arrays.stream(parameters) | ||
.toList(); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
package com.example.parking.domain.parking; | ||
|
||
import com.example.parking.domain.searchcondition.SearchConditionAvailable; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
|
@@ -16,6 +18,13 @@ public enum OperationType implements SearchConditionAvailable { | |
this.description = description; | ||
} | ||
|
||
public static List<String> getAllValues() { | ||
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. 중복 메서드 static <E extends SearchConditionAvailable> List<String> getAllValues(E... values) {
return Arrays.stream(values)
.filter(e -> e != e.getDefault())
.map(E::getDescription)
.toList();
} 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. 적용했습니다~ |
||
return Arrays.stream(OperationType.values()) | ||
.filter(operationType -> operationType != OperationType.NO_INFO) | ||
.map(operationType -> operationType.description) | ||
.toList(); | ||
} | ||
|
||
@Override | ||
public OperationType getDefault() { | ||
return NO_INFO; | ||
|
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.
toList()는 어때요 ?
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.
고민했었는데 toList로 바꿀게여 ㅋㅋㅋㅋ