diff --git a/src/main/java/com/softeer/backend/fo_domain/draw/dto/main/DrawMainResponseDto.java b/src/main/java/com/softeer/backend/fo_domain/draw/dto/main/DrawMainResponseDto.java index c4d4825c..71ea920c 100644 --- a/src/main/java/com/softeer/backend/fo_domain/draw/dto/main/DrawMainResponseDto.java +++ b/src/main/java/com/softeer/backend/fo_domain/draw/dto/main/DrawMainResponseDto.java @@ -12,5 +12,5 @@ public class DrawMainResponseDto { private int invitedNum; // 내가 초대한 친구 수 private int remainDrawCount; // 남은 복권 기회 - private int drawParticipationCount; // 연속 참여 일수 + private int drawAttendanceCount; // 연속 참여 일수 } diff --git a/src/main/java/com/softeer/backend/fo_domain/draw/util/DrawResponseGenerateUtil.java b/src/main/java/com/softeer/backend/fo_domain/draw/util/DrawResponseGenerateUtil.java index d9c2e222..a7a3f633 100644 --- a/src/main/java/com/softeer/backend/fo_domain/draw/util/DrawResponseGenerateUtil.java +++ b/src/main/java/com/softeer/backend/fo_domain/draw/util/DrawResponseGenerateUtil.java @@ -26,14 +26,14 @@ public class DrawResponseGenerateUtil { * * @param invitedNum 초대한 사람 수 * @param remainDrawCount 남은 추첨 기회 - * @param drawParticipationCount 연속 출석 일수 + * @param drawAttendanceCount 연속 출석 일수 * @return 7일 연속 출석 상품 모달 */ - public DrawMainFullAttendResponseDto generateMainFullAttendResponse(int invitedNum, int remainDrawCount, int drawParticipationCount) { + public DrawMainFullAttendResponseDto generateMainFullAttendResponse(int invitedNum, int remainDrawCount, int drawAttendanceCount) { return DrawMainFullAttendResponseDto.builder() .invitedNum(invitedNum) .remainDrawCount(remainDrawCount) - .drawParticipationCount(drawParticipationCount) + .drawAttendanceCount(drawAttendanceCount) .fullAttendModal(drawModalGenerateUtil.generateWinModal(7)) .build(); } @@ -43,14 +43,14 @@ public DrawMainFullAttendResponseDto generateMainFullAttendResponse(int invitedN * * @param invitedNum 초대한 사람 수 * @param remainDrawCount 남은 추첨 기회 - * @param drawParticipationCount 연속 출석 일수 + * @param drawAttendanceCount 연속 출석 일수 * @return 7일 미만 출석 상품 모달 */ - public DrawMainResponseDto generateMainNotAttendResponse(int invitedNum, int remainDrawCount, int drawParticipationCount) { + public DrawMainResponseDto generateMainNotAttendResponse(int invitedNum, int remainDrawCount, int drawAttendanceCount) { return DrawMainResponseDto.builder() .invitedNum(invitedNum) .remainDrawCount(remainDrawCount) - .drawParticipationCount(drawParticipationCount) + .drawAttendanceCount(drawAttendanceCount) .build(); } diff --git a/src/main/java/com/softeer/backend/fo_domain/share/service/ShareUrlInfoService.java b/src/main/java/com/softeer/backend/fo_domain/share/service/ShareUrlInfoService.java index 9a466cbe..4820df64 100644 --- a/src/main/java/com/softeer/backend/fo_domain/share/service/ShareUrlInfoService.java +++ b/src/main/java/com/softeer/backend/fo_domain/share/service/ShareUrlInfoService.java @@ -4,7 +4,6 @@ import com.softeer.backend.fo_domain.share.exception.ShareInfoException; import com.softeer.backend.fo_domain.share.repository.ShareUrlInfoRepository; import com.softeer.backend.global.common.code.status.ErrorStatus; -import com.softeer.backend.global.staticresources.util.StaticResourcesUtil; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; @@ -12,23 +11,22 @@ @RequiredArgsConstructor public class ShareUrlInfoService { private final ShareUrlInfoRepository shareUrlInfoRepository; - private final StaticResourcesUtil staticResourcesUtil; public ShareUrlInfoResponseDto getShortenShareUrl(Integer userId) { if (userId == null) { // 로그인하지 않은 사용자 return ShareUrlInfoResponseDto.builder() - .shareUrl(staticResourcesUtil.getData("NON_USER_SHARE_URL")) + .shareUrl("https://softeer.site") .build(); } else { // 로그인한 사용자 - String shareUrl = shareUrlInfoRepository.findShareUrlByUserId(userId).orElseThrow( + String shareCode = shareUrlInfoRepository.findShareUrlByUserId(userId).orElseThrow( () -> new ShareInfoException(ErrorStatus._NOT_FOUND) ); - // DB에 이미 생성된 단축 url 반환 + // DB에 이미 생성된 단축 url 코드 반환 return ShareUrlInfoResponseDto.builder() - .shareUrl(staticResourcesUtil.getData("BASE_URL") + shareUrl) + .shareUrl("https://softeer.site/" + shareCode) .build(); } } diff --git a/src/main/java/com/softeer/backend/fo_domain/user/controller/LoginController.java b/src/main/java/com/softeer/backend/fo_domain/user/controller/LoginController.java index ef685fe3..7438be0c 100644 --- a/src/main/java/com/softeer/backend/fo_domain/user/controller/LoginController.java +++ b/src/main/java/com/softeer/backend/fo_domain/user/controller/LoginController.java @@ -4,13 +4,9 @@ import com.softeer.backend.global.common.dto.JwtTokenResponseDto; import com.softeer.backend.fo_domain.user.service.LoginService; import com.softeer.backend.global.common.response.ResponseDto; -import io.swagger.v3.oas.annotations.Parameter; -import jakarta.servlet.http.HttpSession; import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; @RestController @RequiredArgsConstructor @@ -20,8 +16,8 @@ public class LoginController { @PostMapping("/login") ResponseDto handleLogin(@Valid @RequestBody LoginRequestDto loginRequestDto, - @Parameter(hidden = true) HttpSession session) { - JwtTokenResponseDto jwtTokenResponseDto = loginService.handleLogin(loginRequestDto, session); + @RequestHeader(value = "shareCode", required = false) String shareCode) { + JwtTokenResponseDto jwtTokenResponseDto = loginService.handleLogin(loginRequestDto, shareCode); return ResponseDto.onSuccess(jwtTokenResponseDto); } diff --git a/src/main/java/com/softeer/backend/fo_domain/user/service/LoginService.java b/src/main/java/com/softeer/backend/fo_domain/user/service/LoginService.java index db2fcdc8..899eee43 100644 --- a/src/main/java/com/softeer/backend/fo_domain/user/service/LoginService.java +++ b/src/main/java/com/softeer/backend/fo_domain/user/service/LoginService.java @@ -17,21 +17,15 @@ import com.softeer.backend.global.common.dto.JwtClaimsDto; import com.softeer.backend.global.util.JwtUtil; import com.softeer.backend.global.util.RandomCodeUtil; -import jakarta.servlet.http.HttpSession; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - @Slf4j @Service @RequiredArgsConstructor public class LoginService { - private final UserRepository userRepository; private final ShareInfoRepository shareInfoRepository; private final ShareUrlInfoRepository shareUrlInfoRepository; @@ -47,7 +41,7 @@ public class LoginService { * 4. User 객체의 id를 얻은 후에, access & refresh token을 client에게 전달한다. */ @Transactional - public JwtTokenResponseDto handleLogin(LoginRequestDto loginRequestDto, HttpSession session) { + public JwtTokenResponseDto handleLogin(LoginRequestDto loginRequestDto, String shareCode) { // 인증번호가 인증 되지 않은 경우, 예외 발생 if (!loginRequestDto.getHasCodeVerified()) { log.error("hasCodeVerified is false in loginRequest."); @@ -77,14 +71,13 @@ public JwtTokenResponseDto handleLogin(LoginRequestDto loginRequestDto, HttpSess createShareInfo(userId); // 공유 정보 생성(초대한 친구 수, 남은 추첨 횟수) createShareUrlInfo(userId); // 공유 url 생성 - String shareUrl = (String) session.getAttribute("shareUrl"); // 공유받은 url을 이용해 인증한다면 // 공유한 사람 추첨 기회 추가 // 공유한 사람의 "내가 초대한 친구 수" 추가 // 공유받은 사람은 이미 공유 url로 참여했다고 표시해주기 - if (shareUrl != null) { + if (shareCode != null) { // 공유한 사람의 아이디 - Integer shareUserId = shareUrlInfoRepository.findUserIdByShareUrl(shareUrl) + Integer shareUserId = shareUrlInfoRepository.findUserIdByShareUrl(shareCode) .orElseThrow(() -> new ShareUrlInfoException(ErrorStatus._NOT_FOUND)); // 공유한 사람 추첨 기회 추가 @@ -115,19 +108,16 @@ private void createShareInfo(Integer userId) { } private void createShareUrlInfo(Integer userId) { - List shareUrlList = shareUrlInfoRepository.findAllShareUrl(); - Set shareUrlSet = new HashSet<>(shareUrlList); - RandomCodeUtil randomCodeUtil = new RandomCodeUtil(); - String shareUrl; + String shareCode; do { - shareUrl = randomCodeUtil.generateRandomCode(4); - } while (shareUrlSet.contains(shareUrl)); + shareCode = randomCodeUtil.generateRandomCode(4); + } while (shareUrlInfoRepository.findUserIdByShareUrl(shareCode).isPresent()); ShareUrlInfo shareUrlInfo = ShareUrlInfo.builder() .userId(userId) - .shareUrl(shareUrl) + .shareUrl(shareCode) .build(); shareUrlInfoRepository.save(shareUrlInfo);