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

hotfix - LocalDate가 배열로 오는 문제 해결 main hot fix #181

Merged
merged 22 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
b66c89d
refactor - #174 불필요한 JsonProperty 삭제
kseysh Jul 15, 2024
08989a6
refactor - #174 user validate를 addUser 메서드가 하도록 변경
kseysh Jul 15, 2024
fe333c8
refactor - #174 챌린지 생성과 User에 currentChallengeId를 업데이트하는 로직이 같이 작동하도록 수정
kseysh Jul 15, 2024
ef34a85
refactor - #174 addChallenge메서드 네이밍을 하는 일과 적합하도록 변경
kseysh Jul 15, 2024
4577419
refactor - #174 챌린지 네이밍 수정
kseysh Jul 15, 2024
57d37bf
refactor - #174 로그인 메서드 파라미터 수정 및 가독성 개선을 위한 줄바꿈
kseysh Jul 15, 2024
02f72d9
modify - #174 이전 챌린지 앱을 가져오는 로직 단순화
kseysh Jul 15, 2024
fee93d8
modify - #174 챌린지를 처음 시작하는 메서드와 이전 챌린지를 이용하여 챌린지를 생성하는 로직으로 분리
kseysh Jul 15, 2024
31c0fc6
refactor - #174 challenge에서 startDate를 가져오는 로직 dailyChallengeService로 이동
kseysh Jul 15, 2024
0d24b30
feat - #174 유저를 이용해 currentChallengeId를 가져오는 메서드 추가
kseysh Jul 16, 2024
972a762
feat - #174 ChallengeRequest를 생성하는 로직 위치 변경
kseysh Jul 16, 2024
7b6ecc9
feat - #174 앱 저장 로직 변경
kseysh Jul 16, 2024
ee7d5de
modify - #174 삭제 예정 유저 recover 로직 다른 메서드로 책임 이동
kseysh Jul 16, 2024
a12962f
refactor - #174 AuthFacade 로직 개선
kseysh Jul 16, 2024
6513a46
refactor - #174 사용되지 않는 메서드 제거
kseysh Jul 16, 2024
761e34b
refactor - #174 사용되지 않는 implementation 제거
kseysh Jul 16, 2024
f62efcb
refactor - #174 challengeAppRepository 추상화
kseysh Jul 16, 2024
3251a18
refactor - #174 비즈니스 로직인 에러처리를 service에서 책임을 갖도록 수정
kseysh Jul 16, 2024
cbbffcb
feat - #174 Querydsl에 필요한 build.gradle 설정 추가
kseysh Jul 16, 2024
479eacc
fix - #174 @EnableWebMvc 제거로 예상하지 않은 기능이 구현되지 않도록 수정
kseysh Jul 16, 2024
e4c8a63
Merge pull request #180 from Team-HMH/fix/#179-local-date-response-re…
kseysh Jul 17, 2024
1fd02be
Merge pull request #178 from Team-HMH/fix/#174-signup-npe
kseysh Jul 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -173,4 +173,7 @@ application-prod.yml
### Test ###
data.sql

### Querydsl ###
**/generated/

# End of https://www.gitignore.io/api/java,macos,gradle,intellij
11 changes: 9 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,11 @@ dependencies {
runtimeOnly group: 'io.jsonwebtoken', name: 'jjwt-impl', version: '0.11.5'
runtimeOnly group: 'io.jsonwebtoken', name: 'jjwt-jackson', version: '0.11.5'

// Redis
implementation 'org.springframework.boot:spring-boot-starter-data-redis'
// Querydsl
implementation 'com.querydsl:querydsl-jpa:5.0.0:jakarta'
annotationProcessor "com.querydsl:querydsl-apt:${dependencyManagement.importedProperties['querydsl.version']}:jakarta"
annotationProcessor "jakarta.annotation:jakarta.annotation-api"
annotationProcessor "jakarta.persistence:jakarta.persistence-api"

// Open Feign
implementation 'org.springframework.cloud:spring-cloud-starter-openfeign:4.1.0'
Expand All @@ -59,4 +62,8 @@ tasks.named('test') {
useJUnitPlatform()
}

clean {
delete file('src/main/generated')
}

jar.enabled = false

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,7 @@

import org.springframework.data.jpa.repository.JpaRepository;
import sopt.org.hmh.domain.app.domain.HistoryApp;
import sopt.org.hmh.domain.app.domain.exception.AppError;
import sopt.org.hmh.domain.app.domain.exception.AppException;

import java.util.Optional;

public interface HistoryAppRepository extends JpaRepository<HistoryApp, Long> {

Optional<HistoryApp> findFirstByDailyChallengeIdAndAppCodeAndOs(Long dailyChallengeId, String appCode, String os);

default HistoryApp findFirstByDailyChallengeIdAndAppCodeAndOsOrElseThrow(Long dailyChallengeId, String appCode, String os) {
return findFirstByDailyChallengeIdAndAppCodeAndOs(dailyChallengeId, appCode, os).orElseThrow(() -> new AppException(
AppError.APP_NOT_FOUND));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package sopt.org.hmh.domain.app.repository.challenge_app;

import java.util.List;
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;
import sopt.org.hmh.domain.app.domain.ChallengeApp;

public interface ChallengeAppJpaRepository extends JpaRepository<ChallengeApp, Long> {

Optional<ChallengeApp> findFirstByChallengeIdAndAppCodeAndOs(Long challengeId, String appCode, String os);

boolean existsByChallengeIdAndAppCodeAndOs(Long challengeId, String appCode, String os);

List<ChallengeApp> findAllByChallengeId(Long previousChallengeId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package sopt.org.hmh.domain.app.repository.challenge_app;

import java.util.List;
import sopt.org.hmh.domain.app.domain.ChallengeApp;
import java.util.Optional;

public interface ChallengeAppRepository {

void saveAll(List<ChallengeApp> challengeApps);

void delete(ChallengeApp appToRemove);

Optional<ChallengeApp> findFirstByChallengeIdAndAppCodeAndOs(Long challengeId, String appCode, String os);

boolean existsByChallengeIdAndAppCodeAndOs(Long challengeId, String appCode, String os);

List<ChallengeApp> findAllByChallengeId(Long previousChallengeId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package sopt.org.hmh.domain.app.repository.challenge_app;

import java.util.List;
import java.util.Optional;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;
import sopt.org.hmh.domain.app.domain.ChallengeApp;

@Repository
@RequiredArgsConstructor
public class ChallengeAppRepositoryImpl implements ChallengeAppRepository{

private final ChallengeAppJpaRepository challengeAppJpaRepository;

@Override
public void saveAll(List<ChallengeApp> challengeApps) {
challengeAppJpaRepository.saveAll(challengeApps);
}

@Override
public void delete(ChallengeApp appToRemove) {
challengeAppJpaRepository.delete(appToRemove);
}

@Override
public Optional<ChallengeApp> findFirstByChallengeIdAndAppCodeAndOs(Long challengeId, String appCode, String os) {
return challengeAppJpaRepository.findFirstByChallengeIdAndAppCodeAndOs(challengeId, appCode, os);
}

@Override
public boolean existsByChallengeIdAndAppCodeAndOs(Long challengeId, String appCode, String os) {
return challengeAppJpaRepository.existsByChallengeIdAndAppCodeAndOs(challengeId, appCode, os);
}

@Override
public List<ChallengeApp> findAllByChallengeId(Long previousChallengeId) {
return challengeAppJpaRepository.findAllByChallengeId(previousChallengeId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import sopt.org.hmh.domain.app.domain.exception.AppError;
import sopt.org.hmh.domain.app.domain.exception.AppException;
import sopt.org.hmh.domain.app.dto.request.ChallengeAppRequest;
import sopt.org.hmh.domain.app.repository.ChallengeAppRepository;
import sopt.org.hmh.domain.app.repository.challenge_app.ChallengeAppRepository;
import sopt.org.hmh.domain.challenge.domain.Challenge;

@Service
Expand All @@ -18,23 +18,37 @@ public class ChallengeAppService {

public void removeApp(Challenge challenge, String appcode, String os) {
ChallengeApp appToRemove =
challengeAppRepository.findFirstByChallengeIdAndAppCodeAndOsOrElseThrow(challenge.getId(), appcode, os);
this.findFirstByChallengeIdAndAppCodeAndOsOrElseThrow(challenge.getId(), appcode, os);
challengeAppRepository.delete(appToRemove);
}

public void addApps(Challenge challenge, List<ChallengeAppRequest> requests, String os) {
challengeAppRepository.saveAll(
requests.stream().map(
request -> {
validateAppExist(challenge.getId(), request.appCode(), os);
return request.toEntity(challenge, os);
}).toList());
public void addAppsByPreviousChallengeApp(String os, Long previousChallengeId, Challenge challenge) {
this.addApps(challengeAppRepository.findAllByChallengeId(previousChallengeId)
.stream().map(previousApp ->
new ChallengeAppRequest(previousApp.getAppCode(), previousApp.getGoalTime())
.toEntity(challenge, os))
.toList()
);
}

private void validateAppExist(Long challengeId, String appCode, String os) {
if (challengeAppRepository.existsByChallengeIdAndAppCodeAndOs(challengeId, appCode, os)) {
public void addApps(List<ChallengeApp> challengeApps) {
this.validateAppsExist(challengeApps);
challengeAppRepository.saveAll(challengeApps);
}

private void validateAppsExist(List<ChallengeApp> challengeApps) {
challengeApps.forEach(this::validateAppExist);
}

private void validateAppExist(ChallengeApp challengeApp) {
if (challengeAppRepository.existsByChallengeIdAndAppCodeAndOs(
challengeApp.getChallenge().getId(), challengeApp.getAppCode(), challengeApp.getOs())) {
throw new AppException(AppError.APP_EXIST_ALREADY);
}
}

private ChallengeApp findFirstByChallengeIdAndAppCodeAndOsOrElseThrow(Long challengeId, String appCode, String os) {
return challengeAppRepository.findFirstByChallengeIdAndAppCodeAndOs(challengeId, appCode, os)
.orElseThrow(() -> new AppException(AppError.APP_NOT_FOUND));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ public ResponseEntity<BaseResponse<?>> orderLogin(
) {
return ResponseEntity
.status(AuthSuccess.LOGIN_SUCCESS.getHttpStatus())
.body(BaseResponse.success(AuthSuccess.LOGIN_SUCCESS, authFacade.login(socialAccessToken, request)));
.body(BaseResponse.success(
AuthSuccess.LOGIN_SUCCESS,
authFacade.login(socialAccessToken, request.socialPlatform())
));
}

@PostMapping("/signup")
Expand All @@ -44,7 +47,10 @@ public ResponseEntity<BaseResponse<?>> orderSignup(
) {
return ResponseEntity
.status(AuthSuccess.SIGNUP_SUCCESS.getHttpStatus())
.body(BaseResponse.success(AuthSuccess.SIGNUP_SUCCESS, authFacade.signup(socialAccessToken, request, os)));
.body(BaseResponse.success(
AuthSuccess.SIGNUP_SUCCESS,
authFacade.signup(request, socialAccessToken, os)
));
}

@PostMapping("/reissue")
Expand All @@ -54,7 +60,10 @@ public ResponseEntity<BaseResponse<?>> orderReissue(
) {
return ResponseEntity
.status(AuthSuccess.REISSUE_SUCCESS.getHttpStatus())
.body(BaseResponse.success(AuthSuccess.REISSUE_SUCCESS, authFacade.reissueToken(refreshToken)));
.body(BaseResponse.success(
AuthSuccess.REISSUE_SUCCESS,
authFacade.reissueToken(refreshToken)
));
}

@GetMapping("/social/token/kakao")
Expand All @@ -63,6 +72,9 @@ public ResponseEntity<BaseResponse<SocialAccessTokenResponse>> orderGetKakaoAcce
) {
return ResponseEntity
.status(AuthSuccess.GET_SOCIAL_ACCESS_TOKEN_SUCCESS.getHttpStatus())
.body(BaseResponse.success(AuthSuccess.GET_SOCIAL_ACCESS_TOKEN_SUCCESS, authFacade.getSocialAccessTokenByAuthorizationCode(code)));
.body(BaseResponse.success(
AuthSuccess.GET_SOCIAL_ACCESS_TOKEN_SUCCESS,
authFacade.getSocialAccessTokenByAuthorizationCode(code)
));
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package sopt.org.hmh.domain.auth.dto.request;

import com.fasterxml.jackson.annotation.JsonProperty;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import java.util.List;
Expand All @@ -14,26 +13,20 @@ public record SocialSignUpRequest(
@NotNull(message = "소셜 플랫폼은 null일 수 없습니다.")
SocialPlatform socialPlatform,
String name,
@JsonProperty(value = "onboarding")
OnboardingRequest onboardingRequest,
OnboardingRequest onboarding,
@Valid
@JsonProperty(value = "challenge")
ChallengeSignUpRequest challengeSignUpRequest
ChallengeSignUpRequest challenge
) {

public ChallengeRequest toChallengeRequest() {
return new ChallengeRequest(challengeSignUpRequest.period(), challengeSignUpRequest.goalTime());
}

public OnboardingInfo toOnboardingInfo(Long userId) {
return OnboardingInfo.builder()
.averageUseTime(onboardingRequest.averageUseTime())
.averageUseTime(onboarding.averageUseTime())
.userId(userId)
.build();
}

public List<OnboardingProblem> toProblemList(Long onboardingInfoId) {
return onboardingRequest.problemList().stream()
return onboarding.problemList().stream()
.map(problem -> OnboardingProblem.builder()
.onboardingInfoId(onboardingInfoId)
.problem(problem)
Expand Down
54 changes: 29 additions & 25 deletions src/main/java/sopt/org/hmh/domain/auth/service/AuthFacade.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,9 @@
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import sopt.org.hmh.domain.app.service.ChallengeAppService;
import sopt.org.hmh.domain.auth.dto.response.ReissueResponse;
import sopt.org.hmh.domain.challenge.domain.Challenge;
import sopt.org.hmh.domain.challenge.service.ChallengeFacade;
import sopt.org.hmh.domain.user.domain.User;
import sopt.org.hmh.domain.auth.dto.request.SocialPlatformRequest;
import sopt.org.hmh.domain.auth.dto.request.SocialSignUpRequest;
import sopt.org.hmh.domain.auth.dto.response.LoginResponse;
import sopt.org.hmh.domain.user.service.UserService;
Expand All @@ -27,53 +24,60 @@ public class AuthFacade {
private final KakaoLoginService kakaoLoginService;
private final AppleOAuthProvider appleOAuthProvider;
private final ChallengeFacade challengeFacade;
private final ChallengeAppService challengeAppService;
private final TokenService tokenService;
private final UserService userService;

@Transactional(readOnly = true)
public LoginResponse login(String socialAccessToken, SocialPlatformRequest request) {
SocialPlatform socialPlatform = request.socialPlatform();
public LoginResponse login(String socialAccessToken, SocialPlatform socialPlatform) {
String socialId = this.getSocialIdBySocialAccessToken(socialPlatform, socialAccessToken);
User loginUser = userService.getUserBySocialPlatformAndSocialId(socialPlatform, socialId);

return performLogin(socialAccessToken, socialPlatform, loginUser);
return performLogin(loginUser, socialAccessToken, socialPlatform);
}

@Transactional
public LoginResponse signup(String socialAccessToken, SocialSignUpRequest request, String os) {
public LoginResponse signup(SocialSignUpRequest request, String socialAccessToken, String os) {
SocialPlatform socialPlatform = request.socialPlatform();
String socialId = this.getSocialIdBySocialAccessToken(socialPlatform, socialAccessToken);

userService.validateDuplicateUser(socialId, socialPlatform);
User user = userService.addUser(socialPlatform, socialId, request.name());
Long userId = user.getId();
userService.registerOnboardingInfo(request, userId);
User newUser = userService.addUser(socialPlatform, socialId, request.name());
Long newUserId = newUser.getId();

userService.registerOnboardingInfo(request, newUserId);

Challenge challenge = challengeFacade.addChallenge(userId, request.toChallengeRequest() , os);
challengeAppService.addApps(challenge, request.challengeSignUpRequest().apps(), os);
challengeFacade.startFirstChallengeWithChallengeSignUpRequest(request.challenge(), newUser , os);

return performLogin(socialAccessToken, socialPlatform, user);
return performLogin(newUser, socialAccessToken, socialPlatform);
}

private String getSocialIdBySocialAccessToken(SocialPlatform socialPlatform, String socialAccessToken) {
return switch (socialPlatform.toString()) {
case "KAKAO" -> kakaoLoginService.getSocialIdByKakao(socialAccessToken);
case "APPLE" -> appleOAuthProvider.getApplePlatformId(socialAccessToken);
default -> throw new JwtException(JwtError.INVALID_SOCIAL_ACCESS_TOKEN);
};
if (socialPlatform == SocialPlatform.APPLE) {
return appleOAuthProvider.getApplePlatformId(socialAccessToken);
}
if (socialPlatform == SocialPlatform.KAKAO) {
return kakaoLoginService.getSocialIdByKakao(socialAccessToken);
}
throw new JwtException(JwtError.INVALID_SOCIAL_ACCESS_TOKEN);
}

public ReissueResponse reissueToken(String refreshToken) {
return tokenService.reissueToken(refreshToken);
private LoginResponse performLogin(User loginUser, String socialAccessToken, SocialPlatform socialPlatform) {
this.updateAdditionalUserLoginInfo(loginUser, socialAccessToken, socialPlatform);

Long userId = loginUser.getId();
return new LoginResponse(userId, tokenService.issueToken(userId.toString()));
}

private LoginResponse performLogin(String socialAccessToken, SocialPlatform socialPlatform, User loginUser) {
private void updateAdditionalUserLoginInfo(User loginUser, String socialAccessToken, SocialPlatform socialPlatform) {
userService.recoverIfIsDeletedUser(loginUser);

if (socialPlatform == SocialPlatform.KAKAO) {
kakaoLoginService.updateUserInfoByKakao(loginUser, socialAccessToken);
}
Long userId = loginUser.getId();
return new LoginResponse(userId, tokenService.issueToken(userId.toString()));
}


public ReissueResponse reissueToken(String refreshToken) {
return tokenService.reissueToken(refreshToken);
}

public SocialAccessTokenResponse getSocialAccessTokenByAuthorizationCode(String code) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public ResponseEntity<BaseResponse<?>> orderAddChallenge(
@UserId final Long userId,
@RequestHeader("OS") final String os,
@RequestBody @Valid final ChallengeRequest request) {
challengeFacade.addChallenge(userId, request, os);
challengeFacade.startNewChallengeByPreviousChallenge(userId, request, os);

return ResponseEntity
.status(ChallengeSuccess.ADD_CHALLENGE_SUCCESS.getHttpStatus())
Expand Down
Loading
Loading