-
Notifications
You must be signed in to change notification settings - Fork 0
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] Controller 및 테스트 코드 작성 #6
Merged
Changes from 10 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
a96e668
feat: 샵 등록 컨트롤러 추가
sssukho f3d0722
test: 샵 등록 컨트롤러 테스트 코드 추가
sssukho bccdae6
fix: 누락사항 반영 및 불필요 파일 삭제
sssukho e6789eb
feat: Shop 리스트 조회 컨트롤러 추가
sssukho 999f389
test: Shop 리스트 조회 테스트 코드 추가
sssukho b42f273
test: ShopList 조회 실패 테스트에서 데이터 타입이 맞지 않는 케이스 추가
sssukho c59e8fb
feat: bp-dto 모듈에 java-test-fixtures 플러그인 적용
sssukho cf0f57f
refactor: 하위 모듈에서 gradle 관련 설정 중복되지 않도록 수정
sssukho d7a13d3
refactor: 목적이 명확하도록 테스트 코드 변경 및 Controller 에서의 return type 변경
sssukho 31a5a06
refactor: 불필요 모듈(bp-dto, bp-core-web) 제거 및 통합
sssukho 9cc2054
feat: shop 등록 API, shop 리스트 조회 API 통합 테스트 추가
sssukho c6f027a
commit#9cc2054 누락사항 반영
sssukho 7c2329e
test: review controller 통합테스트 추가
sssukho 39173fa
chore: 빌드시 통합테스트는 제외 및 테스트 결과들이 콘솔에 출력되게끔 로깅 처리
sssukho 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
.idea | ||
.gradle | ||
build | ||
out | ||
|
||
### Java ### | ||
# Compiled class file | ||
|
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,8 +1,26 @@ | ||
plugins { | ||
id 'org.springframework.boot' version '3.3.5' | ||
id 'io.spring.dependency-management' version '1.1.6' | ||
id 'io.freefair.lombok' version '8.11' | ||
} | ||
|
||
dependencies { | ||
implementation 'org.springframework.boot:spring-boot-starter-web' | ||
|
||
implementation project(':bp-domain-rdb') | ||
implementation project(':bp-kafka-event-publisher') | ||
implementation project(':bp-dto') | ||
implementation project(':bp-utils') | ||
implementation project(':bp-core-web') | ||
} | ||
|
||
implementation 'org.apache.commons:commons-lang3:3.14.0' | ||
implementation 'org.springframework.boot:spring-boot-starter-validation' | ||
|
||
testImplementation 'org.springframework.boot:spring-boot-starter-test' | ||
testImplementation 'org.junit.jupiter:junit-jupiter-api' | ||
|
||
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine' | ||
testRuntimeOnly 'org.junit.platform:junit-platform-launcher' | ||
|
||
test { | ||
useJUnitPlatform() | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
bp-app-api/src/main/java/com/beautify_project/bp_app_api/controller/ShopController.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,55 @@ | ||
package com.beautify_project.bp_app_api.controller; | ||
|
||
import com.beautify_project.bp_app_api.dto.common.ResponseMessage; | ||
import com.beautify_project.bp_app_api.dto.shop.ImageFiles; | ||
import com.beautify_project.bp_app_api.dto.shop.ShopFindListRequestParameters; | ||
import com.beautify_project.bp_app_api.dto.shop.ShopRegistrationRequest; | ||
import com.beautify_project.bp_app_api.enumeration.OrderType; | ||
import com.beautify_project.bp_app_api.enumeration.ShopSearchType; | ||
import com.beautify_project.bp_app_api.service.ShopService; | ||
import jakarta.validation.Valid; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RequestPart; | ||
import org.springframework.web.bind.annotation.ResponseStatus; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
public class ShopController { | ||
|
||
private final ShopService shopService; | ||
|
||
@PostMapping("/v1/shops") | ||
@ResponseStatus(code = HttpStatus.OK) | ||
ResponseMessage registerShop( | ||
@RequestPart(value = "images", required = false) final List<MultipartFile> imageFiles, | ||
@Valid @RequestPart(value = "shopRegistrationInfo") final ShopRegistrationRequest shopRegistrationRequest) { | ||
|
||
return shopService.registerShop(new ImageFiles(imageFiles), shopRegistrationRequest); | ||
} | ||
|
||
@GetMapping("/v1/shops") | ||
@ResponseStatus(code = HttpStatus.OK) | ||
ResponseMessage findShopList(@RequestParam(name = "type") final String searchType, | ||
@RequestParam(name = "page", required = false, defaultValue = "0") final Integer page, | ||
@RequestParam(name = "count", required = false, defaultValue = "10") final Integer count, | ||
@RequestParam(name = "order", required = false, defaultValue = "asc") final String order) | ||
throws RuntimeException { | ||
|
||
return shopService.findShopList( | ||
new ShopFindListRequestParameters(ShopSearchType.from(searchType), page, count, | ||
OrderType.from(order))); | ||
} | ||
|
||
// TODO: 샵 상세 조회 구현 | ||
// TODO: 샵 수정 구현 | ||
// TODO: 샵 삭제 구현 | ||
// TODO: 샵 좋아요 구현 | ||
// TODO: 샵 좋아요 취소 구현 | ||
} |
33 changes: 33 additions & 0 deletions
33
bp-app-api/src/main/java/com/beautify_project/bp_app_api/dto/common/ErrorCode.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,33 @@ | ||
package com.beautify_project.bp_app_api.dto.common; | ||
|
||
import lombok.Getter; | ||
import org.springframework.http.HttpStatus; | ||
|
||
@Getter | ||
public enum ErrorCode { | ||
|
||
BR001(HttpStatus.BAD_REQUEST, "BR001", "요청 파라미터가 잘못되었습니다."), | ||
BR002(HttpStatus.BAD_REQUEST, "BR002", "본문 형식이 맞지 않습니다."), | ||
|
||
UA001(HttpStatus.UNAUTHORIZED, "UA001", "접근 토큰이 존재하지 않습니다."), | ||
UA002(HttpStatus.UNAUTHORIZED, "UA002", "접근 토큰이 만료되었습니다. "), | ||
|
||
FB001(HttpStatus.FORBIDDEN, "FB001", "해당 API 사용 권한이 없습니다."), | ||
|
||
NF001(HttpStatus.NOT_FOUND, "NF001", "요청 URL이 잘못되었습니다."), | ||
|
||
SH001(HttpStatus.NOT_FOUND, "SH001", "등록되지 않은 미용 시술소입니다."), | ||
|
||
IS001(HttpStatus.INTERNAL_SERVER_ERROR, "IS001", "시스템 에러가 발생하였습니다. 관리자에게 문읜해주세요.") | ||
; | ||
|
||
private final HttpStatus httpStatus; | ||
private final String errorCode; | ||
private final String errorMessage; | ||
|
||
ErrorCode(final HttpStatus httpStatus, final String errorCode, final String errorMessage) { | ||
this.httpStatus = httpStatus; | ||
this.errorCode = errorCode; | ||
this.errorMessage = errorMessage; | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
...pp-api/src/main/java/com/beautify_project/bp_app_api/dto/common/ErrorResponseMessage.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,39 @@ | ||
package com.beautify_project.bp_app_api.dto.common; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnore; | ||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import com.fasterxml.jackson.annotation.JsonInclude.Include; | ||
import lombok.AccessLevel; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.ToString; | ||
import org.springframework.http.HttpStatus; | ||
|
||
@NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
@Getter | ||
@ToString | ||
public class ErrorResponseMessage { | ||
|
||
@JsonIgnore | ||
private HttpStatus httpStatus; | ||
@JsonInclude(Include.NON_NULL) | ||
private String errorCode; | ||
@JsonInclude(Include.NON_NULL) | ||
private String errorMessage; | ||
|
||
private ErrorResponseMessage(final HttpStatus httpStatus, final String errorCode, | ||
final String errorMessage) { | ||
this.httpStatus = httpStatus; | ||
this.errorCode = errorCode; | ||
this.errorMessage = errorMessage; | ||
} | ||
|
||
public static ErrorResponseMessage createCustomErrorMessage(final ErrorCode errorCode, final String message) { | ||
return new ErrorResponseMessage(errorCode.getHttpStatus(), errorCode.getErrorCode(), message); | ||
} | ||
|
||
public static ErrorResponseMessage createErrorMessage(final ErrorCode errorCode) { | ||
return new ErrorResponseMessage(errorCode.getHttpStatus(), errorCode.getErrorCode(), | ||
errorCode.getErrorMessage()); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
bp-app-api/src/main/java/com/beautify_project/bp_app_api/dto/common/ResponseMessage.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,32 @@ | ||
package com.beautify_project.bp_app_api.dto.common; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.ToString; | ||
|
||
@NoArgsConstructor(access = AccessLevel.PRIVATE) | ||
@Getter | ||
@ToString | ||
public class ResponseMessage { | ||
|
||
private Object returnValue; | ||
|
||
private ResponseMessage(final Object returnValue) { | ||
this.returnValue = returnValue; | ||
} | ||
|
||
// private ResponseMessage(final HttpStatus httpStatus, final Object returnValue) { | ||
// this.httpStatus = httpStatus; | ||
// this.returnValue = returnValue; | ||
// } | ||
|
||
public static ResponseMessage createResponseMessage(final Object responseBody) { | ||
return new ResponseMessage(responseBody); | ||
} | ||
|
||
// public static ResponseMessage createResponseMessage(final HttpStatus httpStatus, | ||
// final Object returnValue) { | ||
// return new ResponseMessage(httpStatus, returnValue); | ||
// } | ||
} |
30 changes: 30 additions & 0 deletions
30
bp-app-api/src/main/java/com/beautify_project/bp_app_api/dto/shop/ImageFiles.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,30 @@ | ||
package com.beautify_project.bp_app_api.dto.shop; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
public record ImageFiles(List<MultipartFile> files) { | ||
|
||
public ImageFiles { | ||
createEmptyListIfNull(files); | ||
} | ||
|
||
private void createEmptyListIfNull(List<MultipartFile> files) { | ||
if (files == null || files.isEmpty()) { | ||
files = new ArrayList<>(); | ||
} | ||
} | ||
|
||
public boolean isEmpty() { | ||
return files == null || files.isEmpty(); | ||
} | ||
|
||
public int size() { | ||
return files.size(); | ||
} | ||
|
||
public MultipartFile get(final int index) { | ||
return files().get(index); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...src/main/java/com/beautify_project/bp_app_api/dto/shop/ShopFindListRequestParameters.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,10 @@ | ||
package com.beautify_project.bp_app_api.dto.shop; | ||
|
||
|
||
import com.beautify_project.bp_app_api.enumeration.OrderType; | ||
import com.beautify_project.bp_app_api.enumeration.ShopSearchType; | ||
|
||
public record ShopFindListRequestParameters(ShopSearchType searchType, Integer page, Integer count, | ||
OrderType orderType) { | ||
|
||
} |
18 changes: 18 additions & 0 deletions
18
bp-app-api/src/main/java/com/beautify_project/bp_app_api/dto/shop/ShopFindListResponse.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,18 @@ | ||
package com.beautify_project.bp_app_api.dto.shop; | ||
|
||
import java.util.List; | ||
import lombok.Builder; | ||
|
||
@Builder | ||
public record ShopFindListResponse( | ||
String id, | ||
String name, | ||
List<String> operations, | ||
List<String> supportFacilities, | ||
String rate, | ||
Integer likes, | ||
Boolean likePushed, | ||
String thumbnail | ||
) { | ||
|
||
} |
49 changes: 49 additions & 0 deletions
49
...p-api/src/main/java/com/beautify_project/bp_app_api/dto/shop/ShopRegistrationRequest.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,49 @@ | ||
package com.beautify_project.bp_app_api.dto.shop; | ||
|
||
import jakarta.validation.constraints.NotNull; | ||
import jakarta.validation.constraints.Size; | ||
import java.time.LocalTime; | ||
import java.util.List; | ||
|
||
|
||
public record ShopRegistrationRequest( | ||
@NotNull @Size(max = 128) String name, | ||
@NotNull @Size(max = 13) String contact, | ||
@Size(max = 2048) String introduction, | ||
List<IdName> operations, | ||
List<IdName> categories, | ||
List<IdName> supportFacilities, | ||
BusinessTime businessTime, | ||
Address address) { | ||
|
||
|
||
public record IdName ( | ||
@Size(max = 64) String id, | ||
@Size(max = 128) String name) { } | ||
|
||
public record BusinessTime ( | ||
LocalTime openTime, | ||
LocalTime closeTime, | ||
LocalTime breakBeginTime, | ||
LocalTime breakEndTime, | ||
List<String> offDayOfWeek){ | ||
|
||
} | ||
|
||
public record Address ( | ||
String dongCode, | ||
String siDoName, | ||
String siGoonGooName, | ||
String eubMyunDongName, | ||
String roadNameCode, | ||
String roadName, | ||
String underGround, | ||
String roadMainNum, | ||
String roadSubNum, | ||
String siGoonGooBuildingName, | ||
String zipCode, | ||
String apartComplex, | ||
String eubMyunDongSerialNumber, | ||
String latitude, | ||
String longitude) { } | ||
} |
19 changes: 19 additions & 0 deletions
19
bp-app-api/src/main/java/com/beautify_project/bp_app_api/enumeration/OrderType.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,19 @@ | ||
package com.beautify_project.bp_app_api.enumeration; | ||
|
||
|
||
import com.beautify_project.bp_app_api.exception.EnumMismatchException; | ||
|
||
public enum OrderType { | ||
ASC, | ||
DESC | ||
; | ||
|
||
public static OrderType from(final String input) { | ||
final String inputUpperCase = input.toUpperCase(); | ||
try { | ||
return valueOf(inputUpperCase); | ||
} catch (IllegalArgumentException e) { | ||
throw new EnumMismatchException("OrderType", input); | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
bp-app-api/src/main/java/com/beautify_project/bp_app_api/enumeration/ShopSearchType.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,26 @@ | ||
package com.beautify_project.bp_app_api.enumeration; | ||
|
||
import com.beautify_project.bp_app_api.exception.EnumMismatchException; | ||
import org.apache.commons.lang3.StringUtils; | ||
|
||
public enum ShopSearchType { | ||
SHOP_NAME, | ||
LOCATION, | ||
LIKE, | ||
RATE | ||
; | ||
|
||
public static ShopSearchType from(final String input) { | ||
String inputUpperCase = input.toUpperCase(); | ||
|
||
if (StringUtils.equals("SHOPNAME", inputUpperCase)) { | ||
inputUpperCase = "SHOP_NAME"; | ||
} | ||
|
||
try { | ||
return valueOf(inputUpperCase); | ||
} catch (IllegalArgumentException e) { | ||
throw new EnumMismatchException("ShopSearchType", input); | ||
} | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...pp-api/src/main/java/com/beautify_project/bp_app_api/exception/EnumMismatchException.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,21 @@ | ||
package com.beautify_project.bp_app_api.exception; | ||
|
||
import lombok.Getter; | ||
|
||
@Getter | ||
public class EnumMismatchException extends RuntimeException { | ||
|
||
private String enumName; | ||
private String value; | ||
|
||
public EnumMismatchException(String message) { | ||
super(message); | ||
} | ||
|
||
public EnumMismatchException(final String enumName, final String value) { | ||
super(enumName + "에 해당하는 값 " + "'" + value + "' 은 올바르지 않습니다."); | ||
this.enumName = enumName; | ||
this.value = value; | ||
} | ||
|
||
} |
Oops, something went wrong.
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.
요건 뭐 .. 특별히 안된다고 보기는 어렵지만, 스프링에도 비슷한 기능을 하는 클래스들이 있지 않을까요? ㅎㅎ
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.
spring-core 에도 비슷한 역할을 클래스가 있기는 한데, apache의 라이브러리를 계속 사용해왔던지라 사용하게 되었습니다.
혹시 관련해서 비추천 하는 이유가 있으실까요?