Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
rowing0328 committed Nov 4, 2024
2 parents fdc1e81 + 785ff71 commit d131452
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 36 deletions.
15 changes: 8 additions & 7 deletions .github/workflows/gradle-build-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ on:
push:
branches: [ "main" ]
pull_request:
types: [closed]
branches: [ "main" ]

jobs:
build_and_deploy:
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
permissions:
contents: read
Expand All @@ -29,7 +31,6 @@ jobs:
run: |
mkdir -p ./src/test/resources/properties
echo "${{ secrets.TEST_ENV_FILE }}" > ./src/test/resources/properties/test-env.properties
- name: Setup Gradle
uses: gradle/actions/setup-gradle@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0

Expand All @@ -52,7 +53,7 @@ jobs:
tags: |
${{ secrets.DOCKER_USERNAME }}/jdk-21-spring-boot-3.3.1:${{ github.sha }}
${{ secrets.DOCKER_USERNAME }}/jdk-21-spring-boot-3.3.1:latest
- name: SSH to Remote Server and Deploy
uses: appleboy/ssh-action@v1.0.3
with:
Expand All @@ -65,14 +66,14 @@ jobs:
docker-compose -f /home/ubuntu/itzip/docker-compose.yml pull
docker-compose -f /home/ubuntu/itzip/docker-compose.yml up -d
docker system prune -a -f
- name: Send Success Discord Notification
if: success()
run: |
curl -H "Content-Type: application/json" \
-d '{"content": "**배포 성공!** :rocket: \n빌드 및 배포 과정이 성공적으로 완료되었습니다."}' \
${{ secrets.DISCORD_WEBHOOK_URL }}
- name: Send Failure Discord Notification
if: failure()
run: |
Expand All @@ -85,11 +86,11 @@ jobs:
if [ "${{ steps.docker_build.outcome }}" == "failure" ]; then
outcome_message+="Docker 빌드 단계에서 오류 발생. "
fi
if [ "${{ steps.deploy.outcome }}" == "failure" ]; then
outcome_message+="배포 단계에서 오류 발생. "
fi
curl -H "Content-Type: application/json" \
-d '{"content": "**배포 실패!** :x: \n빌드 및 배포 과정에서 오류가 발생했습니다. \n오류 내용: '"${outcome_message}"'"}' \
-d '{"content": "**배포 실패!** :x: \n빌드 및 배포 과정에서 오류가 발생했습니다. \n오류 내용: '"${outcome_message}"'"}' \
${{ secrets.DISCORD_WEBHOOK_URL }}
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ public SolvedUserResponse updateUserSolvedProfileAndProblem(CustomUserDetails cu
//사용자가 푼 문제들 저장
saveUserSolvedProblem.saveUserSolvedProblem(solvedacUser.getUserId());

//사용자 기존 사진 삭제
cloudStorageService.imageDelete(solvedacUser.getProfileImageUrl(), solvedAcProfileDir);
//사용자 기존 사진 삭제(사진이 있는 경우)
if (solvedacUser.getProfileImageUrl() != null) {
cloudStorageService.imageDelete(solvedacUser.getProfileImageUrl(), solvedAcProfileDir);
}

//업데이트된 사용자 정보를 저장하고 return
return SolvedUserResponse.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,14 @@ public SolvedacUser saveSolvedUser(Long userId, String username) {
if (response.statusCode() == 400) {
throw new RestApiException(CommonExceptionCode.NOT_FOUND_SOLVEDAC_USERNAME);
}
Image image = new Image();

MultipartFile multipartFile = downloadImageAsMultipartFile(jsonObject.get("profileImageUrl").getAsString(), username);
//사용자 사진이 있을경우에만 저장
if (jsonObject.get("profileImageUrl") != null && !jsonObject.get("profileImageUrl").isJsonNull()){
MultipartFile multipartFile = downloadImageAsMultipartFile(jsonObject.get("profileImageUrl").getAsString(), username);

Image image = cloudStorageService.imageUpload(multipartFile, solvedAcProfileDir);
image = cloudStorageService.imageUpload(multipartFile, solvedAcProfileDir);
}

SolvedacUserEntity solvedacUserEntity = SolvedacUserEntity.builder()
.userId(userId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ public PagedModel<EntityModel<QuizDetailResponse>> getFilteredAndSortedQuizzes(
@Parameter(description = "퀴즈 난이도 입력칸 1~3") @RequestParam(required = false) Integer difficulty,
@Parameter(description = "카테고리 식별값 입력칸") @RequestParam(required = false) Long categoryId,
@Parameter(description = "NEWEST 새로운 순, OLDEST 오래된 순, RECOMMENED 추천순 아무것도 없으면 새로운순") @RequestParam(required = false, defaultValue = "NEWEST") SortBy sortBy,
@Parameter(description = "사용자 식별값 입력칸") @RequestParam(required = false) Long userId,
@Parameter(description = "사용자가 푼 문제를 포함 하는지 true면 포함 false면 미포함") @RequestParam(required = false, defaultValue = "false") boolean inUserSolved,
@Parameter(description = "문제 페이지 0부터 시작") @RequestParam(defaultValue = "0") int page,
@Parameter(description = "가져올 문제 수") @RequestParam(defaultValue = "10") int size,
Expand All @@ -61,7 +60,6 @@ public PagedModel<EntityModel<QuizDetailResponse>> getFilteredAndSortedQuizzes(
.difficulty(difficulty)
.categoryId(categoryId)
.sortBy(sortBy)
.userId(userId)
.inUserSolved(inUserSolved)
.page(page)
.size(size)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ public class QuizQueryRequest {
private Long categoryId;
//NEWEST, OLDEST
private SortBy sortBy;
//사용자 식별값 입력칸
private Long userId;
//사용자가 푼문제를 포함하는지 ture면 포함 false면 미포함
private boolean inUserSolved;
//문제 페이지 0부터 시작
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class QuizUserSolvedMapping{
//사용자의 정답 여부
@Column(name = "user_quiz_status", length = 10)
@Enumerated(EnumType.STRING)
private UserQuizStatus isCorrect;
private UserQuizStatus userQuizStatus;

/**
* 문제 아이디(`problemId`)를 기준으로 `QuizUserSolvedMapping` 객체의 동등성을 정의
Expand Down Expand Up @@ -85,6 +85,6 @@ public QuizUserSolvedMapping updateTimeStampAndIsCorrect(LocalDateTime timeStamp
* @return 준점수가 업데이트된 새로운 객체를 생성한다.
*/
public QuizUserSolvedMapping updateGivenPoints(Integer givenPoints) {
return new QuizUserSolvedMapping(this.id, this.user, this.problemId, this.timeStamp, givenPoints, this.isCorrect);
return new QuizUserSolvedMapping(this.id, this.user, this.problemId, this.timeStamp, givenPoints, this.userQuizStatus);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import darkoverload.itzip.feature.jwt.infrastructure.CustomUserDetails;
import darkoverload.itzip.feature.user.domain.User;
import darkoverload.itzip.feature.user.entity.UserEntity;
import darkoverload.itzip.feature.user.repository.UserRepository;
import darkoverload.itzip.feature.user.service.UserService;
import darkoverload.itzip.global.config.response.code.CommonExceptionCode;
import darkoverload.itzip.global.config.response.exception.RestApiException;
Expand Down Expand Up @@ -55,11 +54,11 @@ public UserQuizStatus checkAnswer(QuizAnswerRequest quizAnswerRequest, CustomUse
.problemId(quizAnswerRequest.getQuizId())
.timeStamp(LocalDateTime.now())
.givenPoints(0) // 기본 점수 설정
.isCorrect(UserQuizStatus.UNSOLVED) // 기본 상태 설정
.userQuizStatus(UserQuizStatus.UNSOLVED) // 기본 상태 설정
.build());

//이미 문제를 맞췄을 경우 또 못 풀게 함
if (quizUserSolvedMapping.getIsCorrect().equals(UserQuizStatus.CORRECT)) {
if (quizUserSolvedMapping.getUserQuizStatus().equals(UserQuizStatus.CORRECT)) {
throw new RestApiException(CommonExceptionCode.ALREADY_CORRECT);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import darkoverload.itzip.feature.jwt.infrastructure.CustomUserDetails;
import darkoverload.itzip.feature.user.domain.User;
import darkoverload.itzip.feature.user.entity.UserEntity;
import darkoverload.itzip.feature.user.repository.UserRepository;
import darkoverload.itzip.feature.user.service.UserService;
import darkoverload.itzip.global.config.response.code.CommonExceptionCode;
import darkoverload.itzip.global.config.response.exception.RestApiException;
Expand Down Expand Up @@ -53,7 +52,7 @@ public Integer givenPointToQuiz(QuizPointRequest quizPointRequest, CustomUserDet
);

//문제 정답을 맞췄는지 확인
if (!quizUserSolvedMapping.getIsCorrect().equals(UserQuizStatus.CORRECT)) {
if (!quizUserSolvedMapping.getUserQuizStatus().equals(UserQuizStatus.CORRECT)) {
throw new RestApiException(CommonExceptionCode.ANSWER_NOT_CORRECT);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,17 @@ public PagedModel<EntityModel<QuizDetailResponse>> findQuizzesByQuery(QuizQueryR
// 사용자가 푼 문제의 Id값들만 저장할 리스트 초기화
List<String> solvedProblemIds = new ArrayList<>();

// 사용자가 있으면 사용자가 푼 문제를 가져옴
if (quizQueryRequest.getUserId() != null) {
//사용자를 찾고 사용자가 없을시 사용자가 없음 예외 출력
UserEntity userEntity = userService.findByEmail(customUserDetails.getEmail())
.map(User::convertToEntity)
.orElseThrow(() -> new RestApiException(CommonExceptionCode.NOT_FOUND_USER));
//사용자를 찾고 사용자가 없을시 사용자가 없음 예외 출력
UserEntity userEntity = userService.findByEmail(customUserDetails.getEmail())
.map(User::convertToEntity)
.orElseThrow(() -> new RestApiException(CommonExceptionCode.NOT_FOUND_USER));

//사용자가 푼문제매핑 테이블 list로 받아옴
solvedProblemsEntity = quizUserSolvedMappingRepository.findAllByUser(userEntity);
// 사용자가 푼 문제의 problemId를 리스트로 추출
solvedProblemIds = solvedProblemsEntity.stream()
.map(QuizUserSolvedMapping::getProblemId)
.toList();
}
//사용자가 푼문제매핑 테이블 list로 받아옴
solvedProblemsEntity = quizUserSolvedMappingRepository.findAllByUser(userEntity);
// 사용자가 푼 문제의 problemId를 리스트로 추출
solvedProblemIds = solvedProblemsEntity.stream()
.map(QuizUserSolvedMapping::getProblemId)
.toList();
//사용자가 푼문제들을 HashSet으로 만들어서 빠른 검색을 할수 있게함 key는 problemid값
Set<QuizUserSolvedMapping> solvedProblemsSet = new HashSet<>(solvedProblemsEntity);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public QuizDetailResponse documentsToResponse(QuizDocument quizDocument, Set<Qui
// 사용자가 이 문제를 풀었는지, 그리고 맞췄는지 여부를 확인하여 UserQuizStatus를 설정한다.
UserQuizStatus userQuizStatus = solvedProblemsSet.stream()
.filter(solvedProblem -> solvedProblem.getProblemId().equals(quizDocument.getId().toString()))
.map(QuizUserSolvedMapping::getIsCorrect)
.map(QuizUserSolvedMapping::getUserQuizStatus)
.findFirst()
.orElse(UserQuizStatus.UNSOLVED);

Expand Down

0 comments on commit d131452

Please sign in to comment.