Skip to content

Commit

Permalink
Merge pull request #448 from SWM-NM/feat/#447
Browse files Browse the repository at this point in the history
✨ [FEAT] 크롬 익스텐션에서 백준 ID도 함께 보내도록 수정 #447
  • Loading branch information
miiiinju1 authored Oct 12, 2023
2 parents 22f1583 + 4f32b97 commit b687da9
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -24,7 +24,7 @@ public ResponseEntity<String> 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

@Getter
@Setter
public class BaekjoonCookieDto {
public class BaekjoonUserDto {
public String bojId;
public String cookie;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -30,21 +34,30 @@ public class BaekjoonSubmitService {

private final RedisTemplate<String, Object> redisTemplate;

private final MemberRepository memberRepository;
//백준 로그인용 쿠키 저장

private String generateKey(Long memberId) {
return String.format("OnlineJudgeCookie:memberId:%s", 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();
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ public List<AttemptProblemDto> isSolvedCheck(TestCheckDto testCheckDto) {
public void checkAttemptedProblemResult(Tests test, String bojId) {
List<AttemptProblem> attemptProblems = attemptProblemRepository.findAttemptProblemsByTest_TestId(test.getTestId());


//TODO
//정답 여부 체크를 한 번의 API호출로 할 수 있을 듯
attemptProblems.stream()
.filter(attemptProblem -> !attemptProblem.getIsSolved())
.filter(attemptProblem -> isSolvedProblem(attemptProblem, bojId))
Expand Down

0 comments on commit b687da9

Please sign in to comment.