diff --git a/src/main/java/swm_nm/morandi/config/configuration/CorsConfig.java b/src/main/java/swm_nm/morandi/config/configuration/CorsConfig.java index f8df03a7..45f8c4aa 100644 --- a/src/main/java/swm_nm/morandi/config/configuration/CorsConfig.java +++ b/src/main/java/swm_nm/morandi/config/configuration/CorsConfig.java @@ -21,6 +21,7 @@ public CorsConfigurationSource corsConfigurationSource() { "https://morandi.co.kr", "http://api.morandi.co.kr", "https://api.morandi.co.kr", + "chrome-extension://*", "chrome-extension://cmblaiddbfchipealeopkbbnboifeedc", "chrome-extension://ckepgfjakcdkjpabldbamcfcjhcdojih")); config.setAllowedMethods(List.of("GET", "POST", "PUT", "DELETE", "PATCH", "OPTIONS")); diff --git a/src/main/java/swm_nm/morandi/domain/codeSubmit/controller/CodeSubmitController.java b/src/main/java/swm_nm/morandi/domain/codeSubmit/controller/CodeSubmitController.java index 77565b45..964dd38d 100644 --- a/src/main/java/swm_nm/morandi/domain/codeSubmit/controller/CodeSubmitController.java +++ b/src/main/java/swm_nm/morandi/domain/codeSubmit/controller/CodeSubmitController.java @@ -5,7 +5,7 @@ import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; -import swm_nm.morandi.domain.codeSubmit.dto.BaekjoonCookieDto; +import swm_nm.morandi.domain.codeSubmit.dto.BaekjoonUserDto; import swm_nm.morandi.domain.codeSubmit.dto.SubmitCodeDto; import swm_nm.morandi.domain.codeSubmit.service.BaekjoonSubmitService; @@ -24,7 +24,7 @@ public ResponseEntity submit(@RequestBody SubmitCodeDto submitCodeDto) { } @PostMapping("/cookie") - public String loginForSubmit(@RequestBody BaekjoonCookieDto cookieDto) { - return submitService.saveBaekjoonCookie(cookieDto); + public String loginForSubmit(@RequestBody BaekjoonUserDto userDto) { + return submitService.saveBaekjoonInfo(userDto); } } diff --git a/src/main/java/swm_nm/morandi/domain/codeSubmit/dto/BaekjoonCookieDto.java b/src/main/java/swm_nm/morandi/domain/codeSubmit/dto/BaekjoonUserDto.java similarity index 70% rename from src/main/java/swm_nm/morandi/domain/codeSubmit/dto/BaekjoonCookieDto.java rename to src/main/java/swm_nm/morandi/domain/codeSubmit/dto/BaekjoonUserDto.java index 8178ea23..c7fe73ed 100644 --- a/src/main/java/swm_nm/morandi/domain/codeSubmit/dto/BaekjoonCookieDto.java +++ b/src/main/java/swm_nm/morandi/domain/codeSubmit/dto/BaekjoonUserDto.java @@ -6,6 +6,7 @@ @Getter @Setter -public class BaekjoonCookieDto { +public class BaekjoonUserDto { + public String bojId; public String cookie; } diff --git a/src/main/java/swm_nm/morandi/domain/codeSubmit/service/BaekjoonSubmitService.java b/src/main/java/swm_nm/morandi/domain/codeSubmit/service/BaekjoonSubmitService.java index ea3eb8ca..4fa7616b 100644 --- a/src/main/java/swm_nm/morandi/domain/codeSubmit/service/BaekjoonSubmitService.java +++ b/src/main/java/swm_nm/morandi/domain/codeSubmit/service/BaekjoonSubmitService.java @@ -6,13 +6,17 @@ import org.springframework.data.redis.core.RedisTemplate; import org.springframework.http.*; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; import org.springframework.web.client.HttpClientErrorException; import org.springframework.web.client.RestTemplate; import swm_nm.morandi.domain.codeSubmit.constants.CodeVisuabilityConstants; -import swm_nm.morandi.domain.codeSubmit.dto.BaekjoonCookieDto; +import swm_nm.morandi.domain.codeSubmit.dto.BaekjoonUserDto; +import swm_nm.morandi.domain.member.entity.Member; +import swm_nm.morandi.domain.member.repository.MemberRepository; import swm_nm.morandi.global.exception.MorandiException; +import swm_nm.morandi.global.exception.errorcode.MemberErrorCode; import swm_nm.morandi.global.exception.errorcode.SubmitErrorCode; import swm_nm.morandi.domain.codeSubmit.dto.SubmitCodeDto; import swm_nm.morandi.global.utils.SecurityUtils; @@ -30,6 +34,7 @@ public class BaekjoonSubmitService { private final RedisTemplate redisTemplate; + private final MemberRepository memberRepository; //백준 로그인용 쿠키 저장 private String generateKey(Long memberId) { @@ -37,14 +42,22 @@ private String generateKey(Long memberId) { } //Redis에 현재 로그인한 사용자의 백준 제출용 쿠키를 저장 - public String saveBaekjoonCookie(BaekjoonCookieDto baekjoonCookieDto) { + @Transactional + public String saveBaekjoonInfo(BaekjoonUserDto baekjoonUserDto) { Long memberId = SecurityUtils.getCurrentMemberId(); - String key = generateKey(memberId); + Member member = memberRepository.findById(memberId) + .orElseThrow(() -> new MorandiException(MemberErrorCode.MEMBER_NOT_FOUND)); - redisTemplate.opsForValue().set(key, baekjoonCookieDto.getCookie()); + String key = generateKey(memberId); + //Redis에 쿠키 저장 + redisTemplate.opsForValue().set(key, baekjoonUserDto.getCookie()); redisTemplate.expire(key, 12, TimeUnit.HOURS); - return baekjoonCookieDto.getCookie(); + //Member에 백준 아이디 초기화, 수정 + member.setBojId(baekjoonUserDto.getBojId()); + memberRepository.save(member); + + return baekjoonUserDto.getCookie(); } diff --git a/src/main/java/swm_nm/morandi/domain/testDuring/service/SolvedCheckService.java b/src/main/java/swm_nm/morandi/domain/testDuring/service/SolvedCheckService.java index d3480941..bd485b07 100644 --- a/src/main/java/swm_nm/morandi/domain/testDuring/service/SolvedCheckService.java +++ b/src/main/java/swm_nm/morandi/domain/testDuring/service/SolvedCheckService.java @@ -57,6 +57,9 @@ public List isSolvedCheck(TestCheckDto testCheckDto) { public void checkAttemptedProblemResult(Tests test, String bojId) { List attemptProblems = attemptProblemRepository.findAttemptProblemsByTest_TestId(test.getTestId()); + + //TODO + //정답 여부 체크를 한 번의 API호출로 할 수 있을 듯 attemptProblems.stream() .filter(attemptProblem -> !attemptProblem.getIsSolved()) .filter(attemptProblem -> isSolvedProblem(attemptProblem, bojId))