Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@ private KakaoIdTokenPayload parseIdToken(String idToken) {
claims.getSubject(), // 카카오 회원번호
claims.getIssueTime() != null ? claims.getIssueTime().getTime() / 1000 : null,
claims.getExpirationTime() != null ? claims.getExpirationTime().getTime() / 1000 : null,
claims.getDateClaim("auth_time") != null ?
claims.getDateClaim("auth_time") != null
?
claims.getDateClaim("auth_time").getTime() / 1000 : null,
claims.getStringClaim("nonce"),
claims.getStringClaim("nickname"),
Expand Down
82 changes: 44 additions & 38 deletions src/main/java/com/back/b2st/domain/auth/service/AuthService.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,20 @@ public KakaoAuthorizeUrlRes generateKakaoAuthorizeUrl() {

// 카카오 로그인 URL 새성
String authrizeUrl = String.format(
"https://kauth.kakao.com/oauth/authorize" +
"?client_id=%s" +
"&redirect_uri=%s" +
"&response_type=code" +
"&scope=openid%%20profile_nickname%%20account_email" + // URL 인코딩
"&nonce=%s" +
"&state=%s",
kakaoClientId, kakaoRedirectUri, nonce, state);
"https://kauth.kakao.com/oauth/authorize"
+
"?client_id=%s"
+
"&redirect_uri=%s"
+
"&response_type=code"
+
"&scope=openid%%20profile_nickname%%20account_email"
+ // URL 인코딩
"&nonce=%s"
+
"&state=%s",
kakaoClientId, kakaoRedirectUri, nonce, state);

return new KakaoAuthorizeUrlRes(authrizeUrl, state, nonce);
}
Expand All @@ -155,7 +161,7 @@ public TokenInfo reissue(String accessToken, String refreshToken) {

// Redis 업데이트
saveRefreshToken(email, newToken.refreshToken(),
storedToken.getFamily(), storedToken.getGeneration() + 1);
storedToken.getFamily(), storedToken.getGeneration() + 1);

return newToken;
}
Expand Down Expand Up @@ -246,10 +252,10 @@ private void validateWithdrawalPeriod(Member member) {
// 다른 계정에 연동된 카카오 계정이 아닌지
private void validateKakaoNotLinkedToOther(String kakaoId, Long currentMemberId) {
memberRepository.findByProviderId(kakaoId)
.filter(linked -> !linked.getId().equals(currentMemberId))
.ifPresent(linked -> {
throw new BusinessException(AuthErrorCode.OAUTH_ALREADY_LINKED);
});
.filter(linked -> !linked.getId().equals(currentMemberId))
.ifPresent(linked -> {
throw new BusinessException(AuthErrorCode.OAUTH_ALREADY_LINKED);
});
}

private void validateNonce(String nonce) {
Expand Down Expand Up @@ -286,22 +292,22 @@ private void validateTokenNotReused(RefreshToken storedToken, String providedTok

private Member findMemberById(Long memberId) {
return memberRepository.findById(memberId)
.orElseThrow(() -> new BusinessException(MemberErrorCode.MEMBER_NOT_FOUND));
.orElseThrow(() -> new BusinessException(MemberErrorCode.MEMBER_NOT_FOUND));
}

private Member findMemberByEmail(String email) {
return memberRepository.findByEmail(email)
.orElseThrow(() -> new BusinessException(MemberErrorCode.MEMBER_NOT_FOUND));
.orElseThrow(() -> new BusinessException(MemberErrorCode.MEMBER_NOT_FOUND));
}

private RefreshToken findStoredRefreshToken(String email) {
return refreshTokenRepository.findById(email)
.orElseThrow(() -> new BusinessException(AuthErrorCode.INVALID_TOKEN));
.orElseThrow(() -> new BusinessException(AuthErrorCode.INVALID_TOKEN));
}

private WithdrawalRecoveryToken findRecoveryToken(String token) {
return recoveryRepository.findById(token)
.orElseThrow(() -> new BusinessException(AuthErrorCode.RECOVERY_TOKEN_NOT_FOUND));
.orElseThrow(() -> new BusinessException(AuthErrorCode.RECOVERY_TOKEN_NOT_FOUND));
}

private Optional<Member> findMemberByProviderId(String providerId) {
Expand All @@ -320,13 +326,13 @@ private KakaoIdTokenPayload fetchKakaoUserInfo(String code) {
// 로그인 리퀘 인증
private Authentication authenticateWithEmailPassword(LoginReq request) {
UsernamePasswordAuthenticationToken authToken = new UsernamePasswordAuthenticationToken(request.email(),
request.password());
request.password());
return authenticationManagerBuilder.getObject().authenticate(authToken);
}

// 인증 객체서 유저 엔티티 추출
private Member extractMemberFromAuthentication(Authentication authentication) {
CustomUserDetails userDetails = (CustomUserDetails) authentication.getPrincipal();
CustomUserDetails userDetails = (CustomUserDetails)authentication.getPrincipal();
return userDetails.getMember();
}

Expand Down Expand Up @@ -355,8 +361,8 @@ private Member findOrCreateKakaoMember(KakaoIdTokenPayload payload) {
}
// 이메일로 가입된 회원 확인
return memberRepository.findByEmail(email)
.map(existing -> linkKakaoToExistingMember(existing, kakaoId))
.orElseGet(() -> createNewKakaoMember(email, kakaoId, nickname));
.map(existing -> linkKakaoToExistingMember(existing, kakaoId))
.orElseGet(() -> createNewKakaoMember(email, kakaoId, nickname));
}

// 이메일 연동
Expand All @@ -379,17 +385,17 @@ private Member createNewKakaoMember(String email, String kakaoId, String nicknam
String sanitizedNickname = NicknameUtils.sanitize(nickname, defaultKakaoNickname);

Member member = Member.builder()
.email(email)
.password(null)
.name(sanitizedNickname)
.phone(null)
.birth(null)
.role(Member.Role.MEMBER)
.provider(Member.Provider.KAKAO)
.providerId(kakaoId)
.isEmailVerified(true)
.isIdentityVerified(false)
.build();
.email(email)
.password(null)
.name(sanitizedNickname)
.phone(null)
.birth(null)
.role(Member.Role.MEMBER)
.provider(Member.Provider.KAKAO)
.providerId(kakaoId)
.isEmailVerified(true)
.isIdentityVerified(false)
.build();
Member saved = memberRepository.save(member);
log.info("[Kakao] 신규 회원 생성: MemberID={}, KakaoID={}", saved.getId(), kakaoId);
return saved;
Expand All @@ -399,10 +405,10 @@ private Member createNewKakaoMember(String email, String kakaoId, String nicknam
private TokenInfo generateTokenForMember(Member member) {
CustomUserDetails userDetails = new CustomUserDetails(member);
UsernamePasswordAuthenticationToken authToken = new UsernamePasswordAuthenticationToken(
userDetails, null, userDetails.getAuthorities());
userDetails, null, userDetails.getAuthorities());
TokenInfo tokenInfo = jwtTokenProvider.generateToken(authToken);
saveRefreshToken(member.getEmail(), tokenInfo.refreshToken(),
UUID.randomUUID().toString(), 1L);
UUID.randomUUID().toString(), 1L);
return tokenInfo;
}

Expand All @@ -415,10 +421,10 @@ private void saveRefreshToken(String email, String token, String family, Long ge
private String createRecoveryToken(String email, Long memberId) {
String token = UUID.randomUUID().toString();
WithdrawalRecoveryToken recoveryToken = WithdrawalRecoveryToken.builder()
.token(token)
.email(email)
.memberId(memberId)
.build();
.token(token)
.email(email)
.memberId(memberId)
.build();
recoveryRepository.save(recoveryToken);
return token;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ public EmailVerification incrementAttempt() {
.attemptCount(this.attemptCount + 1)
.build();
}

public boolean isMaxAttemptExceeded() {
return this.attemptCount >= 5;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ public static List<SectionLayoutRes> from(List<SeatInfoRes> seats) {
))
.toList();

return new SectionLayoutRes(sectionName, grades);
})
return new SectionLayoutRes(sectionName, grades);
})
.toList();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,20 @@
public interface LotteryEntryRepository extends JpaRepository<LotteryEntry, Long> {
boolean existsByMemberIdAndPerformanceIdAndScheduleId(Long memberId, Long performanceId, Long scheduleId);

@Query("""
SELECT new com.back.b2st.domain.lottery.entry.dto.response.AppliedLotteryInfo(
le.uuid, p.title, ps.startAt, ps.roundNo, le.grade, le.quantity, le.status
)
FROM LotteryEntry le
JOIN Performance p ON le.performanceId = p.performanceId
JOIN PerformanceSchedule ps ON le.scheduleId = ps.performanceScheduleId
WHERE le.memberId = :memberId
AND le.createdAt >= :month
ORDER BY le.createdAt DESC
""")
@Query(
"""
SELECT new com.back.b2st.domain.lottery.entry.dto.response.AppliedLotteryInfo(
le.uuid, p.title, ps.startAt, ps.roundNo, le.grade, le.quantity, le.status
)
FROM LotteryEntry le
JOIN Performance p ON le.performanceId = p.performanceId
JOIN PerformanceSchedule ps ON le.scheduleId = ps.performanceScheduleId
WHERE le.memberId = :memberId
AND le.createdAt >= :month
ORDER BY le.createdAt DESC
"""

)
Slice<AppliedLotteryInfo> findAppliedLotteryByMemberId(
@Param("memberId") Long memberId,
@Param("month") LocalDateTime month,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.back.b2st.domain.notification.listener;

import java.util.Map;

import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.event.TransactionalEventListener;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.event.TransactionPhase;
import org.springframework.transaction.event.TransactionalEventListener;

import com.back.b2st.domain.email.service.EmailSender;
import com.back.b2st.domain.member.entity.Member;
Expand All @@ -14,8 +16,6 @@
import com.back.b2st.domain.performance.entity.Performance;
import com.back.b2st.domain.performance.repository.PerformanceRepository;

import java.util.Map;

import lombok.RequiredArgsConstructor;

@Component
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.back.b2st.domain.payment.dto.request;

import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;

public record PaymentConfirmReq(
@NotBlank String orderId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import java.util.Optional;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import com.back.b2st.domain.payment.entity.DomainType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
import java.time.Clock;
import java.time.LocalDateTime;

import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.context.ApplicationEventPublisher;

import com.back.b2st.domain.notification.event.NotificationEmailEvent;
import com.back.b2st.domain.payment.entity.DomainType;
import com.back.b2st.domain.payment.entity.Payment;
import com.back.b2st.domain.payment.error.PaymentErrorCode;
Expand All @@ -18,7 +19,6 @@
import com.back.b2st.domain.trade.entity.TradeStatus;
import com.back.b2st.domain.trade.entity.TradeType;
import com.back.b2st.domain.trade.error.TradeErrorCode;
import com.back.b2st.domain.notification.event.NotificationEmailEvent;
import com.back.b2st.global.error.exception.BusinessException;

import jakarta.persistence.EntityManager;
Expand All @@ -30,12 +30,11 @@
@RequiredArgsConstructor
public class TradePaymentFinalizer implements PaymentFinalizer {

@PersistenceContext
private EntityManager entityManager;

private final TicketService ticketService;
private final Clock clock;
private final ApplicationEventPublisher eventPublisher;
@PersistenceContext
private EntityManager entityManager;

@Override
public boolean supports(DomainType domainType) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
package com.back.b2st.domain.performance.controller;

import com.back.b2st.domain.performance.dto.response.PerformanceDetailRes;
import com.back.b2st.domain.performance.dto.response.PerformanceListRes;
import com.back.b2st.domain.performance.service.PerformanceService;
import com.back.b2st.global.common.BaseResponse;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
Expand All @@ -14,6 +9,11 @@
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.back.b2st.domain.performance.dto.response.PerformanceDetailRes;
import com.back.b2st.domain.performance.dto.response.PerformanceListRes;
import com.back.b2st.domain.performance.service.PerformanceService;
import com.back.b2st.global.common.BaseResponse;

import lombok.RequiredArgsConstructor;

@RestController
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package com.back.b2st.domain.performance.repository;

import com.back.b2st.domain.performance.entity.Performance;
import com.back.b2st.domain.performance.entity.PerformanceStatus;

import java.util.Optional;

import org.springframework.data.domain.Page;
Expand All @@ -12,6 +9,8 @@
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import com.back.b2st.domain.performance.entity.Performance;
import com.back.b2st.domain.performance.entity.PerformanceStatus;

public interface PerformanceRepository extends JpaRepository<Performance, Long> {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package com.back.b2st.domain.performance.service;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.back.b2st.domain.performance.dto.response.PerformanceDetailRes;
import com.back.b2st.domain.performance.dto.response.PerformanceListRes;
import com.back.b2st.domain.performance.entity.PerformanceStatus;
import com.back.b2st.domain.performance.repository.PerformanceRepository;
import com.back.b2st.global.error.code.CommonErrorCode;
import com.back.b2st.global.error.exception.BusinessException;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import lombok.RequiredArgsConstructor;

@Service
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@

import jakarta.validation.Valid;

import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.back.b2st.domain.performanceschedule.dto.request.PerformanceScheduleCreateReq;
import com.back.b2st.domain.performanceschedule.dto.response.PerformanceScheduleCreateRes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,4 +187,4 @@ BaseResponse<List<ReservationDetailRes>> getMyReservationsDetail(
@Parameter(hidden = true)
UserPrincipal user
);
}
}
Loading