Skip to content
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

[BE] refactor: 코드 포맷 적용, 컨벤션 적용 #632

Merged
merged 12 commits into from
Sep 14, 2023
Merged
6 changes: 3 additions & 3 deletions backend/src/main/java/com/funeat/FuneatApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
@SpringBootApplication
public class FuneatApplication {

public static void main(String[] args) {
SpringApplication.run(FuneatApplication.class, args);
}
public static void main(String[] args) {
SpringApplication.run(FuneatApplication.class, args);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ public interface AuthController {
description = "기존 회원이면 홈으로 이동, 신규 회원이면 마이페이지로 이동."
)
@GetMapping
ResponseEntity<Void> loginAuthorizeUser(@RequestParam("code") String code, HttpServletRequest request);
ResponseEntity<Void> loginAuthorizeUser(@RequestParam("code") final String code, final HttpServletRequest request);

@Operation(summary = "로그아웃", description = "로그아웃을 한다")
@ApiResponse(
responseCode = "302",
description = "로그아웃 성공."
)
@PostMapping
ResponseEntity<Void> logout(@AuthenticationPrincipal LoginInfo loginInfo, HttpServletRequest request,
HttpServletResponse response);
ResponseEntity<Void> logout(@AuthenticationPrincipal final LoginInfo loginInfo, final HttpServletRequest request,
final HttpServletResponse response);
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,20 @@ public class KakaoPlatformUserProvider implements PlatformUserProvider {

private final RestTemplate restTemplate;
private final ObjectMapper objectMapper;
private final String kakaoRestApiKey;
private final String redirectUri;
private final String kakaoAdminKey;

@Value("${kakao.rest-api-key}")
private String kakaoRestApiKey;

@Value("${kakao.redirect-uri}")
private String redirectUri;

@Value("${kakao.admin-key}")
private String kakaoAdminKey;

public KakaoPlatformUserProvider(final RestTemplateBuilder restTemplateBuilder,
final ObjectMapper objectMapper,
@Value("${kakao.rest-api-key}") final String kakaoRestApiKey,
@Value("${kakao.redirect-uri}") final String redirectUri,
@Value("${kakao.admin-key}") final String kakaoAdminKey) {
final ObjectMapper objectMapper) {
this.restTemplate = restTemplateBuilder.build();
this.objectMapper = objectMapper;
this.kakaoRestApiKey = kakaoRestApiKey;
this.redirectUri = redirectUri;
this.kakaoAdminKey = kakaoAdminKey;
}

@Override
Expand Down Expand Up @@ -118,10 +118,10 @@ private KakaoUserInfoDto convertJsonToKakaoUserDto(final String responseBody) {

@Override
public String getRedirectURI() {
final StringJoiner joiner = new StringJoiner("&");
joiner.add("response_type=code");
joiner.add("client_id=" + kakaoRestApiKey);
joiner.add("redirect_uri=" + redirectUri);
final StringJoiner joiner = new StringJoiner("&")
.add("response_type=code")
.add("client_id=" + kakaoRestApiKey)
.add("redirect_uri=" + redirectUri);

return AUTHORIZATION_BASE_URL + OAUTH_URI + "?" + joiner;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
public class CustomPageableHandlerMethodArgumentResolver extends PageableHandlerMethodArgumentResolver {

@Override
public Pageable resolveArgument(MethodParameter methodParameter, ModelAndViewContainer mavContainer,
NativeWebRequest webRequest, WebDataBinderFactory binderFactory) {
public Pageable resolveArgument(final MethodParameter methodParameter, final ModelAndViewContainer mavContainer,
final NativeWebRequest webRequest, final WebDataBinderFactory binderFactory) {
final Pageable pageable = super.resolveArgument(methodParameter, mavContainer, webRequest, binderFactory);

final Sort lastPrioritySort = Sort.by("id").descending();
Expand Down
2 changes: 1 addition & 1 deletion backend/src/main/java/com/funeat/common/WebConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void addFormatters(final FormatterRegistry registry) {
}

@Override
public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers) {
public void addArgumentResolvers(final List<HandlerMethodArgumentResolver> resolvers) {
resolvers.add(customPageableHandlerMethodArgumentResolver);
resolvers.add(authArgumentResolver);
}
Expand Down
6 changes: 3 additions & 3 deletions backend/src/main/java/com/funeat/common/s3/S3Uploader.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.funeat.common.exception.CommonException.NotAllowedFileExtensionException;
import com.funeat.common.exception.CommonException.S3UploadFailException;
import java.io.IOException;
import java.util.List;
import java.util.UUID;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Profile;
Expand All @@ -20,8 +21,7 @@
@Profile("!test")
public class S3Uploader implements ImageUploader {

public static final String JPEG = "image/jpeg";
public static final String PNG = "image/png";
private static final List<String> INCLUDE_EXTENSIONS = List.of("image/jpeg", "image/png");

@Value("${cloud.aws.s3.bucket}")
private String bucket;
Expand Down Expand Up @@ -55,7 +55,7 @@ public String upload(final MultipartFile image) {

private void validateExtension(final MultipartFile image) {
final String contentType = image.getContentType();
if (!contentType.equals(JPEG) && !contentType.equals(PNG)) {
if (!INCLUDE_EXTENSIONS.contains(contentType)){
throw new NotAllowedFileExtensionException(IMAGE_EXTENSION_ERROR_CODE, contentType);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
@RestControllerAdvice
public class GlobalControllerAdvice {

private static final String ERROR_MESSAGE_DELIMITER = ", ";
private static final String RESPONSE_DELIMITER = ". ";

private final Logger log = LoggerFactory.getLogger(this.getClass());
private final ObjectMapper objectMapper;

Expand All @@ -50,9 +53,9 @@ public ResponseEntity<?> handleParamValidationException(final MethodArgumentNotV
.getAllErrors()
.stream()
.map(DefaultMessageSourceResolvable::getDefaultMessage)
.collect(Collectors.joining(", "));
.collect(Collectors.joining(ERROR_MESSAGE_DELIMITER));

final String responseErrorMessage = errorMessage + ". " + REQUEST_VALID_ERROR_CODE.getMessage();
final String responseErrorMessage = errorMessage + RESPONSE_DELIMITER + REQUEST_VALID_ERROR_CODE.getMessage();

final ErrorCode<?> errorCode = new ErrorCode<>(REQUEST_VALID_ERROR_CODE.getCode(), responseErrorMessage);

Expand All @@ -66,7 +69,7 @@ private static String getMethodArgumentExceptionLogMessage(final MethodArgumentN
.getFieldErrors()
.stream()
.map(FieldError::getField)
.collect(Collectors.joining(", "));
.collect(Collectors.joining(ERROR_MESSAGE_DELIMITER));

return filedErrorMessages + " 요청 실패";
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package com.funeat.member.dto;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.funeat.product.domain.Product;
import com.funeat.recipe.domain.Recipe;
import com.funeat.recipe.domain.RecipeImage;
import java.time.LocalDateTime;
import java.util.List;
import java.util.stream.Collectors;

public class MemberRecipeDto {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ public class MemberReviewDto {
private final Long favoriteCount;

private MemberReviewDto(final Long reviewId, final Long productId, final String categoryType,
final String productName, final String content,
final Long rating, final Long favoriteCount) {
final String productName, final String content,
final Long rating, final Long favoriteCount) {
this.reviewId = reviewId;
this.productId = productId;
this.categoryType = categoryType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ public MemberApiController(final MemberService memberService, final ReviewServic

@GetMapping
public ResponseEntity<MemberProfileResponse> getMemberProfile(@AuthenticationPrincipal final LoginInfo loginInfo) {
final Long memberId = loginInfo.getId();

final MemberProfileResponse response = memberService.getMemberProfile(memberId);
final MemberProfileResponse response = memberService.getMemberProfile(loginInfo.getId());

return ResponseEntity.ok(response);
}
Expand All @@ -49,9 +47,7 @@ public ResponseEntity<MemberProfileResponse> getMemberProfile(@AuthenticationPri
public ResponseEntity<Void> putMemberProfile(@AuthenticationPrincipal final LoginInfo loginInfo,
@RequestPart(required = false) final MultipartFile image,
@RequestPart @Valid final MemberRequest memberRequest) {
final Long memberId = loginInfo.getId();

memberService.modify(memberId, image, memberRequest);
memberService.modify(loginInfo.getId(), image, memberRequest);

return ResponseEntity.ok().build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public interface MemberController {
description = "사용자 정보 조회 성공."
)
@GetMapping
ResponseEntity<MemberProfileResponse> getMemberProfile(@AuthenticationPrincipal LoginInfo loginInfo);
ResponseEntity<MemberProfileResponse> getMemberProfile(@AuthenticationPrincipal final LoginInfo loginInfo);

@Operation(summary = "사용자 정보 수정", description = "사용자 닉네임과 프로필 사진을 수정한다.")
@ApiResponse(
Expand All @@ -44,15 +44,15 @@ public ResponseEntity<Void> putMemberProfile(@AuthenticationPrincipal final Logi
description = "사용자 리뷰 조회 성공."
)
@GetMapping
ResponseEntity<MemberReviewsResponse> getMemberReview(@AuthenticationPrincipal LoginInfo loginInfo,
@PageableDefault Pageable pageable);
ResponseEntity<MemberReviewsResponse> getMemberReview(@AuthenticationPrincipal final LoginInfo loginInfo,
@PageableDefault final Pageable pageable);

@Operation(summary = "사용자 꿀조합 조회", description = "사용자가 작성한 꿀조합을 조회한다.")
@ApiResponse(
responseCode = "200",
description = "사용자 꿀조합 조회 성공."
)
@GetMapping
ResponseEntity<MemberRecipesResponse> getMemberRecipe(@AuthenticationPrincipal LoginInfo loginInfo,
@PageableDefault Pageable pageable);
ResponseEntity<MemberRecipesResponse> getMemberRecipe(@AuthenticationPrincipal final LoginInfo loginInfo,
@PageableDefault final Pageable pageable);
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.funeat.tag.domain.Tag;
import java.util.Comparator;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
Expand All @@ -46,6 +47,7 @@ public class ProductService {
private static final int THREE = 3;
private static final int TOP = 0;
public static final String REVIEW_COUNT = "reviewCount";
private static final int RANKING_SIZE = 3;

private final CategoryRepository categoryRepository;
private final ProductRepository productRepository;
Expand Down Expand Up @@ -82,7 +84,7 @@ public ProductsInCategoryResponse getAllProductsInCategory(final Long categoryId
}

private Page<ProductInCategoryDto> getAllProductsInCategory(final Pageable pageable, final Category category) {
if (pageable.getSort().getOrderFor(REVIEW_COUNT) != null) {
if (Objects.nonNull(pageable.getSort().getOrderFor(REVIEW_COUNT))) {
final PageRequest pageRequest = PageRequest.of(pageable.getPageNumber(), pageable.getPageSize());
return productRepository.findAllByCategoryOrderByReviewCountDesc(category, pageRequest);
}
Expand All @@ -106,7 +108,7 @@ public RankingProductsResponse getTop3Products() {

final List<RankingProductDto> rankingProductDtos = productsAndReviewCounts.stream()
.sorted(rankingScoreComparator)
.limit(3)
.limit(RANKING_SIZE)
.map(it -> RankingProductDto.toDto(it.getProduct()))
.collect(Collectors.toList());

Expand All @@ -125,7 +127,8 @@ public SearchProductsResponse searchProducts(final String query, final Pageable
}

public SearchProductResultsResponse getSearchResults(final String query, final Pageable pageable) {
final Page<ProductReviewCountDto> products = productRepository.findAllWithReviewCountByNameContaining(query, pageable);
final Page<ProductReviewCountDto> products = productRepository.findAllWithReviewCountByNameContaining(query,
pageable);

final PageDto pageDto = PageDto.toDto(products);
final List<SearchProductResultDto> resultDtos = products.stream()
Expand Down
5 changes: 0 additions & 5 deletions backend/src/main/java/com/funeat/product/domain/Product.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.funeat.member.domain.bookmark.ProductBookmark;
import com.funeat.review.domain.Review;
import java.util.List;
import java.util.Objects;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
Expand Down Expand Up @@ -80,10 +79,6 @@ public void updateImage(final String topFavoriteImage) {
this.image = topFavoriteImage;
}

public boolean isNotEqualImage(final String anotherImage) {
return !Objects.equals(this.image, anotherImage);
}

public Long getId() {
return id;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,23 @@

public interface ProductRepository extends JpaRepository<Product, Long> {

@Query(value = "SELECT new com.funeat.product.dto.ProductInCategoryDto(p.id, p.name, p.price, p.image, p.averageRating, COUNT(r)) " +
"FROM Product p " +
"LEFT JOIN p.reviews r " +
"WHERE p.category = :category " +
"GROUP BY p ",
@Query(value = "SELECT new com.funeat.product.dto.ProductInCategoryDto(p.id, p.name, p.price, p.image, p.averageRating, COUNT(r)) "
+ "FROM Product p "
+ "LEFT JOIN p.reviews r "
+ "WHERE p.category = :category "
+ "GROUP BY p ",
countQuery = "SELECT COUNT(p) FROM Product p WHERE p.category = :category")
Page<ProductInCategoryDto> findAllByCategory(@Param("category") final Category category, final Pageable pageable);

@Query(value = "SELECT new com.funeat.product.dto.ProductInCategoryDto(p.id, p.name, p.price, p.image, p.averageRating, COUNT(r)) " +
"FROM Product p " +
"LEFT JOIN p.reviews r " +
"WHERE p.category = :category " +
"GROUP BY p " +
"ORDER BY COUNT(r) DESC, p.id DESC ",
@Query(value = "SELECT new com.funeat.product.dto.ProductInCategoryDto(p.id, p.name, p.price, p.image, p.averageRating, COUNT(r)) "
+ "FROM Product p "
+ "LEFT JOIN p.reviews r "
+ "WHERE p.category = :category "
+ "GROUP BY p "
+ "ORDER BY COUNT(r) DESC, p.id DESC ",
countQuery = "SELECT COUNT(p) FROM Product p WHERE p.category = :category")
Page<ProductInCategoryDto> findAllByCategoryOrderByReviewCountDesc(@Param("category") final Category category, final Pageable pageable);
Page<ProductInCategoryDto> findAllByCategoryOrderByReviewCountDesc(@Param("category") final Category category,
final Pageable pageable);

@Query("SELECT new com.funeat.product.dto.ProductReviewCountDto(p, COUNT(r.id)) "
+ "FROM Product p "
Expand All @@ -50,5 +51,6 @@ public interface ProductRepository extends JpaRepository<Product, Long> {
+ "GROUP BY p.id "
+ "ORDER BY "
+ "(CASE WHEN p.name LIKE CONCAT(:name, '%') THEN 1 ELSE 2 END), p.id DESC")
Page<ProductReviewCountDto> findAllWithReviewCountByNameContaining(@Param("name") final String name, final Pageable pageable);
Page<ProductReviewCountDto> findAllWithReviewCountByNameContaining(@Param("name") final String name,
final Pageable pageable);
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public ProductApiController(final ProductService productService) {

@GetMapping("/categories/{categoryId}/products")
public ResponseEntity<ProductsInCategoryResponse> getAllProductsInCategory(@PathVariable final Long categoryId,
@PageableDefault Pageable pageable) {
@PageableDefault final Pageable pageable) {
final ProductsInCategoryResponse response = productService.getAllProductsInCategory(categoryId, pageable);
return ResponseEntity.ok(response);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public interface ProductController {
)
@GetMapping
ResponseEntity<ProductsInCategoryResponse> getAllProductsInCategory(
@PathVariable(name = "category_id") final Long categoryId, @PageableDefault Pageable pageable
@PathVariable(name = "category_id") final Long categoryId, @PageableDefault final Pageable pageable
);

@Operation(summary = "해당 상품 상세 조회", description = "해당 상품 상세정보를 조회한다.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ public static RankingRecipeDto toDto(final Recipe recipe, final List<RecipeImage
if (images.isEmpty()) {
return new RankingRecipeDto(recipe.getId(), null, recipe.getTitle(), author, recipe.getFavoriteCount());
}
return new RankingRecipeDto(recipe.getId(), images.get(0).getImage(), recipe.getTitle(), author, recipe.getFavoriteCount());
return new RankingRecipeDto(recipe.getId(), images.get(0).getImage(), recipe.getTitle(), author,
recipe.getFavoriteCount());
}

public Long getId() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ public interface RecipeController {
description = "꿀조합 작성 성공."
)
@PostMapping
ResponseEntity<Void> writeRecipe(@AuthenticationPrincipal LoginInfo loginInfo,
@RequestPart List<MultipartFile> images,
@RequestPart RecipeCreateRequest recipeRequest);
ResponseEntity<Void> writeRecipe(@AuthenticationPrincipal final LoginInfo loginInfo,
@RequestPart final List<MultipartFile> images,
@RequestPart final RecipeCreateRequest recipeRequest);

@Operation(summary = "꿀조합 상세 조회", description = "꿀조합의 상세 정보를 조회한다.")
@ApiResponse(
Expand All @@ -52,7 +52,7 @@ ResponseEntity<RecipeDetailResponse> getRecipeDetail(@AuthenticationPrincipal fi
description = "꿀조합 목록 조회 성공."
)
@GetMapping
ResponseEntity<SortingRecipesResponse> getSortingRecipes(@PageableDefault Pageable pageable);
ResponseEntity<SortingRecipesResponse> getSortingRecipes(@PageableDefault final Pageable pageable);

@Operation(summary = "꿀조합 좋아요", description = "꿀조합에 좋아요 또는 취소를 한다.")
@ApiResponse(
Expand All @@ -62,7 +62,7 @@ ResponseEntity<RecipeDetailResponse> getRecipeDetail(@AuthenticationPrincipal fi
@PatchMapping
ResponseEntity<Void> likeRecipe(@AuthenticationPrincipal final LoginInfo loginInfo,
@PathVariable final Long recipeId,
@RequestBody RecipeFavoriteRequest request);
@RequestBody final RecipeFavoriteRequest request);

@Operation(summary = "꿀조합 랭킹 조회", description = "전체 꿀조합들 중에서 랭킹 TOP3를 조회한다.")
@ApiResponse(
Expand Down
Loading