Skip to content

Commit

Permalink
[#83] Refactor : 2차 대규모 리팩토링을 진행한다
Browse files Browse the repository at this point in the history
  • Loading branch information
packdev937 committed Jan 16, 2024
1 parent db420ce commit cb55497
Show file tree
Hide file tree
Showing 32 changed files with 336 additions and 439 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.stereotype.Component;
import ssu.eatssu.domain.user.entity.User;
import ssu.eatssu.domain.repository.UserRepository;
import ssu.eatssu.domain.user.repository.UserRepository;
import ssu.eatssu.global.handler.response.BaseException;
import ssu.eatssu.global.handler.response.BaseResponseStatus;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ssu.eatssu.domain.user.entity;
package ssu.eatssu.domain.auth.entity;

public enum OauthProvider {
EATSSU, KAKAO, APPLE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@ public class OauthConfig {
@Bean
public RestTemplate restTemplate() {
HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory();
//SocketConfig socketConfig = SocketConfig.custom().setSoTimeout(5000).build(); //5s
/*HttpClient client = HttpClientBuilder.create()
.setMaxConnTotal(50) //연결을 유지할 최대 숫자
.setMaxConnPerRoute(20) // 특정 경로당 최대 숫자
.setDefaultSocketConfig(socketConfig)
.build();*/
CloseableHttpClient client = HttpClientBuilder.create().build();
factory.setConnectTimeout(3000); //3s
factory.setHttpClient(client);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import ssu.eatssu.domain.repository.UserRepository;
import ssu.eatssu.domain.user.repository.UserRepository;
import ssu.eatssu.domain.auth.service.OauthService;
import ssu.eatssu.global.handler.response.BaseResponse;
import ssu.eatssu.domain.auth.dto.AppleLogin;
Expand All @@ -28,22 +28,20 @@
@RestController
@RequestMapping("/oauth")
@RequiredArgsConstructor
@Tag(name="Oauth",description = "Oauth API")
@Tag(name = "Oauth", description = "Oauth API")
public class OauthController {

private final OauthService oauthService;
private final UserRepository userRepository;
private final SecurityUtil securityUtil;

/**
* 카카오 회원가입, 로그인
*/
@Operation(summary = "카카오 회원가입, 로그인", description = """
카카오 회원가입, 로그인 API 입니다.<br><br>
가입된 회원일 경우 카카오 로그인, 미가입 회원일 경우 회원가입 후 자동 로그인됩니다.
""")
카카오 회원가입, 로그인 API 입니다.<br><br>
가입된 회원일 경우 카카오 로그인, 미가입 회원일 경우 회원가입 후 자동 로그인됩니다.
""")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "카카오 회원가입/로그인 성공", content = @Content(schema = @Schema(implementation = BaseResponse.class)))
@ApiResponse(responseCode = "200", description = "카카오 회원가입/로그인 성공", content = @Content(schema = @Schema(implementation = BaseResponse.class)))
})
@PostMapping("/kakao")
public BaseResponse<Tokens> kakaoLogin(@Valid @RequestBody KakaoLogin login) {
Expand All @@ -55,16 +53,17 @@ public BaseResponse<Tokens> kakaoLogin(@Valid @RequestBody KakaoLogin login) {
* 애플 회원가입, 로그인
*/
@Operation(summary = "애플 회원가입, 로그인", description = """
애플 로그인, 회원가입 API 입니다.<br><br>
가입된 회원일 경우 카카오 로그인, 미가입 회원일 경우 회원가입 후 자동 로그인됩니다.
""")
애플 로그인, 회원가입 API 입니다.<br><br>
가입된 회원일 경우 카카오 로그인, 미가입 회원일 경우 회원가입 후 자동 로그인됩니다.
""")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "애플 회원가입/로그인 성공", content = @Content(schema = @Schema(implementation = BaseResponse.class))),
@ApiResponse(responseCode = "404", description = "존재하지 않는 유저", content = @Content(schema = @Schema(implementation = BaseResponse.class)))
@ApiResponse(responseCode = "200", description = "애플 회원가입/로그인 성공", content = @Content(schema = @Schema(implementation = BaseResponse.class))),
@ApiResponse(responseCode = "404", description = "존재하지 않는 유저", content = @Content(schema = @Schema(implementation = BaseResponse.class)))
})
@PostMapping("/apple")
public BaseResponse<Tokens> appleLogin(@Valid @RequestBody AppleLogin login) throws NoSuchAlgorithmException,
InvalidKeySpecException {
public BaseResponse<Tokens> appleLogin(@Valid @RequestBody AppleLogin login)
throws NoSuchAlgorithmException,
InvalidKeySpecException {
Tokens tokens = oauthService.appleLogin(login.getIdentityToken());
return BaseResponse.success(tokens);
}
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/ssu/eatssu/domain/auth/service/OauthService.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package ssu.eatssu.domain.auth.service;


import static ssu.eatssu.global.handler.response.BaseResponseStatus.INVALID_IDENTITY_TOKEN;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
Expand All @@ -16,11 +18,9 @@
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponentsBuilder;
import ssu.eatssu.domain.user.entity.User;
import ssu.eatssu.domain.user.entity.OauthProvider;
import ssu.eatssu.domain.repository.UserRepository;
import ssu.eatssu.domain.auth.entity.OauthProvider;
import ssu.eatssu.domain.user.repository.UserRepository;
import ssu.eatssu.domain.user.service.UserService;
import ssu.eatssu.handler.response.BaseException;
import ssu.eatssu.handler.response.BaseResponseStatus;
import ssu.eatssu.domain.auth.dto.OauthInfo;
import ssu.eatssu.domain.auth.dto.AppleKeys;
import ssu.eatssu.domain.user.dto.Tokens;
Expand All @@ -34,8 +34,8 @@
import java.security.spec.RSAPublicKeySpec;
import java.util.Base64;
import java.util.Map;
import ssu.eatssu.global.handler.response.BaseException;

import static ssu.eatssu.handler.response.BaseResponseStatus.INVALID_IDENTITY_TOKEN;

@Slf4j
@RequiredArgsConstructor
Expand Down Expand Up @@ -182,7 +182,7 @@ private PublicKey generatePublicKeyWithApplePublicKey(AppleKeys.Key matchedKey)
KeyFactory keyFactory = KeyFactory.getInstance(matchedKey.getKty());
return keyFactory.generatePublic(publicKeySpec);
} catch (NoSuchAlgorithmException | InvalidKeySpecException ex) {
throw new BaseException(BaseResponseStatus.INVALID_IDENTITY_TOKEN);
throw new BaseException(INVALID_IDENTITY_TOKEN);
}
}

Expand All @@ -201,12 +201,12 @@ private AppleKeys.Key selectMatchedKey(String identityToken, AppleKeys candidate
headerMap = new ObjectMapper().readValue(decodedHeader, new TypeReference<Map<String, String>>() {
});
} catch (JsonProcessingException e) {
throw new BaseException(BaseResponseStatus.INVALID_IDENTITY_TOKEN);
throw new BaseException(INVALID_IDENTITY_TOKEN);
}

//후보키 중에서 정답키를 찾아서 반환한다.
return candidateKeys.findKeyBy(headerMap.get("kid"), headerMap.get("alg"))
.orElseThrow(() -> new BaseException(BaseResponseStatus.INVALID_IDENTITY_TOKEN));
.orElseThrow(() -> new BaseException(INVALID_IDENTITY_TOKEN));
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/ssu/eatssu/domain/menu/entity/MenuType.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
@Getter
public enum MenuType {
FIXED("고정 메뉴", Arrays.asList(FOOD_COURT, SNACK_CORNER)),
CHANGED("변동 메뉴", Arrays.asList(DODAM, DORMITORY, HAKSIK));
VARIABLE("변동 메뉴", Arrays.asList(DODAM, DORMITORY, HAKSIK));

private final String description;
private final List<RestaurantName> restaurants;
Expand All @@ -28,7 +28,7 @@ public static boolean isFixed(RestaurantName restaurant) {
}

public static boolean isChanged(RestaurantName restaurant) {
return CHANGED.getRestaurants().contains(restaurant);
return VARIABLE.getRestaurants().contains(restaurant);
}

@JsonCreator
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ssu.eatssu.domain.rating;
package ssu.eatssu.domain.rating.entity;

import org.springframework.stereotype.Component;
import ssu.eatssu.domain.menu.entity.Meal;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package ssu.eatssu.domain.rating;
package ssu.eatssu.domain.rating.entity;

import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
import ssu.eatssu.domain.menu.entity.Meal;
import ssu.eatssu.domain.menu.entity.Menu;
import ssu.eatssu.domain.review.repository.ReviewRepository;
import ssu.eatssu.domain.repository.dto.RatingsDto;
import ssu.eatssu.domain.review.dto.RatingsDto;
import ssu.eatssu.domain.review.dto.RatingAverages;
import ssu.eatssu.domain.review.dto.ReviewRatingCount;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ssu.eatssu.domain.rating;
package ssu.eatssu.domain.rating.entity;

import ssu.eatssu.domain.menu.entity.Meal;
import ssu.eatssu.domain.menu.entity.Menu;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ssu.eatssu.domain.rating;
package ssu.eatssu.domain.rating.entity;

import io.jsonwebtoken.lang.Assert;
import jakarta.persistence.Embeddable;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package ssu.eatssu.domain.rating;
package ssu.eatssu.domain.rating.entity;

import ssu.eatssu.domain.review.dto.ReviewRatingCount;

public enum ReviewRating {
RATING_1(1),
RATING_2(2),
RATING_3(3),
RATING_4(4),
RATING_5(5);
RATING_ONE(1),
RATING_TWO(2),
RATING_THREE(3),
RATING_FOUR(4),
RATING_FIVE(5);

private final int value;
private int count;
Expand All @@ -26,19 +26,19 @@ public static void resetAll() {
public static ReviewRating fromValue(int value) {
for (ReviewRating RATING : ReviewRating.values()) {
if (RATING.value == value) {
return RATING;
return RATING;
}
}
throw new IllegalArgumentException("Invalid ratings value: " + value);
}

public static ReviewRatingCount toResponse() {
return new ReviewRatingCount(
RATING_1.getCount(),
RATING_2.getCount(),
RATING_3.getCount(),
RATING_4.getCount(),
RATING_5.getCount()
RATING_ONE.getCount(),
RATING_TWO.getCount(),
RATING_THREE.getCount(),
RATING_FOUR.getCount(),
RATING_FIVE.getCount()
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import ssu.eatssu.domain.report.dto.CreateReportRequest;
import ssu.eatssu.domain.report.dto.ReportTypeResponse;

import ssu.eatssu.domain.slack.entity.SlackService;
import ssu.eatssu.domain.slack.service.SlackService;
import ssu.eatssu.global.handler.response.BaseResponse;

@RestController
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package ssu.eatssu.domain.report.repository;

import org.springframework.data.jpa.repository.JpaRepository;
import ssu.eatssu.domain.review.entity.Report;

public interface ReportRepository extends JpaRepository<Report, Long>{
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import ssu.eatssu.domain.review.entity.Report;
import ssu.eatssu.domain.user.entity.User;
import ssu.eatssu.domain.report.entity.ReportStatus;
import ssu.eatssu.domain.review.repository.ReviewReportRepository;
import ssu.eatssu.domain.report.repository.ReportRepository;
import ssu.eatssu.domain.review.repository.ReviewRepository;
import ssu.eatssu.domain.user.repository.UserRepository;
import ssu.eatssu.domain.report.dto.CreateReportRequest;
Expand All @@ -26,7 +26,7 @@ public class ReportService {

private final ReviewRepository reviewRepository;
private final UserRepository userRepository;
private final ReviewReportRepository reviewReportRepository;
private final ReportRepository reviewReportRepository;

public Report report(CustomUserDetails userDetails, CreateReportRequest reviewReportCreate) {
User user = userRepository.findById(userDetails.getId())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import lombok.NoArgsConstructor;
import org.springframework.util.Assert;
import ssu.eatssu.domain.menu.entity.Menu;
import ssu.eatssu.domain.rating.Ratings;
import ssu.eatssu.domain.rating.entity.Ratings;
import ssu.eatssu.domain.review.entity.Review;
import ssu.eatssu.domain.user.entity.User;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
@Getter
@AllArgsConstructor
@Builder
public class MenuReviewInformationResponse implements ReviewInformationResponse {
public class MainReviewsResponse implements ReviewInformationResponse {

@Schema(description = "메뉴 리스트", example = "[\"고구마치즈돈까스\", \"막국수\", \"미니밥\", \"단무지\", \"요구르트\"]")
private String menuName;
Expand All @@ -29,10 +29,10 @@ public class MenuReviewInformationResponse implements ReviewInformationResponse
private Double tasteRating;
private ReviewRatingCount reviewRatingCount;

public static MenuReviewInformationResponse of(Menu menu,
public static MainReviewsResponse of(Menu menu,
RatingAverages ratingAverages,
ReviewRatingCount reviewRatingCount) {
return MenuReviewInformationResponse.builder()
return MainReviewsResponse.builder()
.menuName(menu.getName())
.totalReviewCount(menu.getTotalReviewCount())
.mainRating(ratingAverages.mainRating())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
@Getter
@AllArgsConstructor
@Builder
public class MealReviewInformationResponse implements ReviewInformationResponse {
public class MealReviewsResponse implements ReviewInformationResponse {

@Schema(description = "메뉴명 리스트", example = "[\"고구마치즈돈까스\", \"막국수\", \"미니밥\", \"단무지\", \"요구르트\"]")
private List<String> menuNames;
Expand All @@ -30,10 +30,10 @@ public class MealReviewInformationResponse implements ReviewInformationResponse

private ReviewRatingCount reviewRatingCount;

public static MealReviewInformationResponse of(Integer totalReviewCount, List<String> menuNames,
public static MealReviewsResponse of(Integer totalReviewCount, List<String> menuNames,
RatingAverages ratingAverages, ReviewRatingCount reviewRatingCount) {

return MealReviewInformationResponse.builder()
return MealReviewsResponse.builder()
.menuNames(menuNames)
.mainRating(ratingAverages.mainRating())
.amountRating(ratingAverages.amountRating())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package ssu.eatssu.domain.repository.dto;
package ssu.eatssu.domain.review.dto;


import ssu.eatssu.domain.rating.Ratings;
import ssu.eatssu.domain.rating.entity.Ratings;
public record RatingsDto (Ratings ratings){

public Integer getMainRating() {
Expand Down
Loading

0 comments on commit cb55497

Please sign in to comment.