Skip to content

Commit

Permalink
Merge pull request #98 from HyunJunSon/feature/mainPageTestCode
Browse files Browse the repository at this point in the history
Feature/main page test code
  • Loading branch information
gunsight1 authored Jan 29, 2024
2 parents f35b3f7 + c878dfa commit 6d3d5ab
Show file tree
Hide file tree
Showing 28 changed files with 653 additions and 82 deletions.
5 changes: 3 additions & 2 deletions module-api/src/docs/asciidoc/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
:sectlinks:

include::overview.adoc[]
include::sample-api.adoc[]
// FIXME :: 위 라인 1줄은 추후 삭제 예정입니다
// include::sample-api.adoc[]
include::main-api.adoc[]

41 changes: 41 additions & 0 deletions module-api/src/docs/asciidoc/main-api.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
== Main API

// [[]] 안에는 a 태그 이름 들어갑니다 (http://localhost:8080/docs/index#공통코드-조회)
[[Banner-조회]]
=== Banner 조회

===== HTTP Request
include::{snippets}/banner/get-banner/http-request.adoc[]

==== Response
include::{snippets}/banner/get-banner/response-fields-value.adoc[]

===== HTTP Response 예시
include::{snippets}/banner/get-banner/http-response.adoc[]


[[Recommend-Product-조회]]
=== Recommend-Product-조회

===== HTTP Request
include::{snippets}/recommend-products/get-recommend-products/http-request.adoc[]

==== Response
include::{snippets}/recommend-products/get-recommend-products/response-fields.adoc[]

===== HTTP Response 예시
include::{snippets}/recommend-products/get-recommend-products/http-response.adoc[]


[[Products-rank-최신순]]
== Products-rank-최신순

===== HTTP Request
include::{snippets}/products/get-products-view-count-order/http-request.adoc[]

===== Response
include::{snippets}/products/get-products-view-count-order/response-fields.adoc[]

===== HTTP Response 예시
include::{snippets}/products/get-products-view-count-order/http-response.adoc[]

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.kernel360.commoncode.dto.CommonCodeDto;
import com.kernel360.response.ApiResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class InterceptorConfig implements WebMvcConfigurer {
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(acceptInterceptor)
.addPathPatterns("/member/testJwt");
// .addPathPatterns("/mypage/**");
//.excludePathPatterns("/public/**"); // 제외할 URL 패턴
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.kernel360.main.code;

import com.kernel360.code.ErrorCode;
import org.springframework.http.HttpStatus;

public enum ConverterErrorCode implements ErrorCode {

NOT_FOUND_CONVERTER(HttpStatus.BAD_REQUEST.value(), "CMB001", "적절한 조회타입이 존재하지 않습니다.");

private final int status;
private final String code;
private final String message;

ConverterErrorCode(int status, String code, String message) {
this.status = status;
this.code = code;
this.message = message;
}

@Override
public int getStatus() {
return status;
}

@Override
public String getCode() {
return code;
}

@Override
public String getMessage() {
return message;
}
}
15 changes: 15 additions & 0 deletions module-api/src/main/java/com/kernel360/main/config/WebConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.kernel360.main.config;

import com.kernel360.main.conveter.StringToSortConverter;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {

@Override
public void addFormatters(FormatterRegistry registry) {
registry.addConverter(new StringToSortConverter());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,23 @@
@RequiredArgsConstructor
public class MainContoller {
private final ProductService productService;
private final MainService mainService;

@GetMapping("/banner")
ResponseEntity<ApiResponse<BannerDto>> getBanner() {

return ApiResponse.toResponseEntity(BannerBusinessCode.GET_BANNER_DATA_SUCCESS, MainService.getSampleBanner());
return ApiResponse.toResponseEntity(BannerBusinessCode.GET_BANNER_DATA_SUCCESS, mainService.getSampleBanner());
}

@GetMapping("/recommend_products")
@GetMapping("/recommend-products")
ResponseEntity<ApiResponse<List<RecommendProductsDto>>> getRecommendProducts() {
List<RecommendProductsDto> recommendProductList = productService.getRecommendProductList();

return ApiResponse.toResponseEntity(ProductsBusinessCode.GET_RECOMMEND_PRODUCT_DATA_SUCCESS, recommendProductList);

}
@GetMapping("/products/")
ResponseEntity<ApiResponse<List<ProductDto>>> getProducts(@RequestParam(name ="sortType", defaultValue = "viewCnt_order") Sort sortType){
@GetMapping("/products/rank")
ResponseEntity<ApiResponse<List<ProductDto>>> getProducts(@RequestParam(name ="sortType", defaultValue = "viewCnt-order") Sort sortType){
List<ProductDto> productDtos = sortType.sort(productService);

return ApiResponse.toResponseEntity(ProductsBusinessCode.GET_PRODUCT_DATA_SUCCESS, productDtos);
Expand Down
12 changes: 8 additions & 4 deletions module-api/src/main/java/com/kernel360/main/controller/Sort.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,29 @@

public enum Sort {

VIEW_COUNT_PRODUCT_ORDER("viewCnt_order") {
VIEW_COUNT_PRODUCT_ORDER("viewCnt-order") {
@Override
List<ProductDto> sort(ProductService productService) {

return productService.getProductListOrderByViewCount();
}
},
SAFE_PRODUCT_LIST("violation_product") {
VIOLATION_PRODUCT_LIST("violation-products") {
@Override
List<ProductDto> sort(ProductService productService) {

return productService.getViolationProducts();
}
},
RECOMMENDATION_PRODUCT_ORDER("recommend_order") {
RECOMMENDATION_PRODUCT_ORDER("recommend-order") {
@Override
List<ProductDto> sort(ProductService productService) {
//Fixme :: 향후 Like Table 구현후, 정렬메소드 변경이 필요합니다.(임시로 violationProduct 리턴으로 구현)

return productService.getViolationProducts();
}
},
RECENT_PRODUCT_ORDER("recent_order") {
RECENT_PRODUCT_ORDER("recent-order") {
@Override
List<ProductDto> sort(ProductService productService) {

Expand All @@ -43,5 +43,9 @@ List<ProductDto> sort(ProductService productService) {
this.orderType = orderType;
}

public String getOrderType() {
return orderType;
}

abstract List<ProductDto> sort(ProductService productService);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.kernel360.main.conveter;

import com.kernel360.exception.BusinessException;
import com.kernel360.main.code.ConverterErrorCode;
import com.kernel360.main.controller.Sort;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

@Component
public class StringToSortConverter implements Converter<String, Sort> {

@Override
public Sort convert(String source) {
for (Sort sort : Sort.values()) {
if (sort.getOrderType().equalsIgnoreCase(source)) {
return sort;
}
}
throw new BusinessException(ConverterErrorCode.NOT_FOUND_CONVERTER);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

public record BannerDto (
Long id,
String src,
String image,
String alt
) {
public static BannerDto of(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@

public class MainService {

public static BannerDto getSampleBanner() {

return BannerDto.of(1L,
"classpath:static/bannerSample.png",
"Banner Image");
public BannerDto getSampleBanner() {
return BannerDto.of(1L, "classpath:static/bannerSample.png", "Banner Image");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@
public enum MemberBusinessCode implements BusinessCode {

SUCCESS_REQUEST_JOIN_MEMBER_CREATED(HttpStatus.CREATED.value(), "BMC001", "회원가입 성공"),
SUCCESS_REQUEST_LOGIN_MEMBER(HttpStatus.OK.value(), "BMC002", "로그인 성공");
SUCCESS_REQUEST_LOGIN_MEMBER(HttpStatus.OK.value(), "BMC002", "로그인 성공"),
SUCCESS_FIND_REQUEST_MEMBER(HttpStatus.OK.value(), "BMC003", "회원 조회 성공"),
SUCCESS_FIND_CAR_INFO_IN_MEMBER(HttpStatus.OK.value(), "BMC004", "차량정보 조회 성공"),
SUCCESS_REQUEST_DELETE_MEMBER(HttpStatus.OK.value(), "BMC005", "회원이 탈퇴 되었습니다."),
SUCCESS_REQUEST_UPDATE_MEMBER(HttpStatus.OK.value(), "BMC006", "회원정보가 변경 되었습니다."),
SUCCESS_REQUEST_CHANGE_PASSWORD_MEMBER(HttpStatus.OK.value(), "BMC007", "비밀번호가 변경 되었습니다.");


private final int status;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;

import java.util.EnumSet;

@RequiredArgsConstructor
public enum MemberErrorCode implements ErrorCode {

Expand All @@ -12,8 +14,8 @@ public enum MemberErrorCode implements ErrorCode {
FAILED_NOT_MAPPING_ENUM_VALUEOF(HttpStatus.INTERNAL_SERVER_ERROR.value(), "EMC003", "PARAMETER 값과 ENUM의 NAME이 불일치함."),
FAILED_GENERATE_JOIN_MEMBER_INFO(HttpStatus.INTERNAL_SERVER_ERROR.value(), "EMC004", "회원가입에 필요한 정보 생성 실패"),
FAILED_GENERATE_LOGIN_REQUEST_INFO(HttpStatus.INTERNAL_SERVER_ERROR.value(), "EMC005", "정보 불일치로 인한 로그인 정보 생성 실패"),
FAILED_REQUEST_LOGIN(HttpStatus.BAD_REQUEST.value(), "EMC006", "정보 불일치로 인한 로그인 실패");

FAILED_REQUEST_LOGIN(HttpStatus.BAD_REQUEST.value(), "EMC006", "정보 불일치로 인한 로그인 실패"),
FAILED_FIND_MEMBER_INFO(HttpStatus.BAD_REQUEST.value(), "EMC007", "요청 회원정보가 존재하지 않습니다.");


private final int status;
Expand Down
12 changes: 12 additions & 0 deletions module-api/src/main/java/com/kernel360/member/dto/MemberInfo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.kernel360.member.dto;

public record MemberInfo( String id,
String password
) {
static MemberInfo of(
String id,
String password
) {
return new MemberInfo(id, password);
}
}
Loading

0 comments on commit 6d3d5ab

Please sign in to comment.