Skip to content

Commit

Permalink
feat: 문제 제출 후 단건에 대한 저장 로직 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
GiHoo committed Nov 5, 2024
1 parent c1567fc commit ae33b19
Show file tree
Hide file tree
Showing 6 changed files with 84 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.syu.capsbe.domain.solveHistory;

import com.syu.capsbe.domain.member.Member;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@Entity
@Table(name = "plugin_solve_histories")
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class PluginSolveHistory {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "member_id", nullable = false)
private Member member;

private boolean isCorrect;

@Builder
public PluginSolveHistory(Member member, boolean isCorrect) {
this.member = member;
this.isCorrect = false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.syu.capsbe.domain.solveHistory;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface PluginSolveHistoryRepository extends JpaRepository<PluginSolveHistory, Long> {

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.syu.capsbe.domain.solveHistory.application;

import com.syu.capsbe.domain.solveHistory.dto.request.PluginSolveHistoryDetailRequestDto;
import com.syu.capsbe.domain.solveHistory.dto.request.SolveHistoryDetailRequestDto;
import com.syu.capsbe.domain.solveHistory.dto.request.SolveHistoryReviewRequestDto;
import com.syu.capsbe.domain.solveHistory.dto.request.SolveHistorySetUpEmailRequestDto;
Expand Down Expand Up @@ -27,5 +28,5 @@ public interface SolveHistoryService {

SubmissionResponseDto submitReviewSolveHistory(SolveHistoryReviewRequestDto request);

SubmissionResponseDto submitPluginSolveHistory(SolveHistoryDetailRequestDto request);
void submitPluginSolveHistory(PluginSolveHistoryDetailRequestDto request);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@
import com.syu.capsbe.domain.problem.ProblemType;
import com.syu.capsbe.domain.problem.exception.ProblemExistsException;
import com.syu.capsbe.domain.problem.exception.common.ProblemErrorCode;
import com.syu.capsbe.domain.solveHistory.PluginSolveHistory;
import com.syu.capsbe.domain.solveHistory.PluginSolveHistoryRepository;
import com.syu.capsbe.domain.solveHistory.SolveHistory;
import com.syu.capsbe.domain.solveHistory.SolveHistoryDetail;
import com.syu.capsbe.domain.solveHistory.SolveHistoryDetailRepository;
import com.syu.capsbe.domain.solveHistory.SolveHistoryRepository;
import com.syu.capsbe.domain.solveHistory.dto.request.PluginSolveHistoryDetailRequestDto;
import com.syu.capsbe.domain.solveHistory.dto.request.SolveHistoryDetailRequestDto;
import com.syu.capsbe.domain.solveHistory.dto.request.SolveHistoryReviewRequestDto;
import com.syu.capsbe.domain.solveHistory.dto.request.SolveHistorySetUpEmailRequestDto;
Expand All @@ -26,6 +29,7 @@
import java.util.ArrayList;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.security.core.parameters.P;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

Expand All @@ -38,6 +42,7 @@ public class SolveHistoryServiceImpl implements SolveHistoryService {
private final ProblemRepository problemRepository;
private final SolveHistoryRepository solveHistoryRepository;
private final SolveHistoryDetailRepository solveHistoryDetailRepository;
private final PluginSolveHistoryRepository pluginSolveHistoryRepository;

@Override
@Transactional
Expand Down Expand Up @@ -86,13 +91,14 @@ public SubmissionResponseDto submitSolveHistory(SolveHistoryDetailRequestDto req
}

@Override
public SubmissionResponseDto submitPluginSolveHistory(SolveHistoryDetailRequestDto request) {
Problem problem = problemRepository.findById(request.getProblemId())
.orElseThrow(() -> ProblemExistsException.of(ProblemErrorCode.PROBLEM_IS_NOT_EXISTS));
@Transactional
public void submitPluginSolveHistory(PluginSolveHistoryDetailRequestDto request) {
Member member = memberService.findByEmail(request.getEmail()).get();

boolean isCorrect = isCorrectAnswer(problem.getAnswer(), request.getUserAnswer());
pluginSolveHistoryRepository.save(
new PluginSolveHistory(member, request.isCorrect())
);

return SubmissionResponseDto.of(isCorrect, problem.getAnswer());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.syu.capsbe.domain.solveHistory.dto.request;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@Schema(description = "플러그인 풀이 세부 기록 요청 정보")
@AllArgsConstructor
public class PluginSolveHistoryDetailRequestDto {

@Schema(description = "유저 이메일", example = "[email protected]")
private String email;

@Schema(description = "정답 여부", example = "true")
private boolean isCorrect;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.syu.capsbe.domain.member.Member;
import com.syu.capsbe.domain.solveHistory.application.SolveHistoryService;
import com.syu.capsbe.domain.solveHistory.dto.request.PluginSolveHistoryDetailRequestDto;
import com.syu.capsbe.domain.solveHistory.dto.request.SolveHistoryDetailRequestDto;
import com.syu.capsbe.domain.solveHistory.dto.request.SolveHistoryReviewRequestDto;
import com.syu.capsbe.domain.solveHistory.dto.request.SolveHistorySetUpEmailRequestDto;
Expand Down Expand Up @@ -58,12 +59,12 @@ public SubmissionResponseDto submitSolveHistory(
return solveHistoryService.submitSolveHistory(request, member.getId());
}

@GetMapping("/plugin-submit")
@Operation(summary = "문제 풀이 기록 제출", description = "문제 풀이 기록을 제출합니다. 사용자는 모든 문제를 푼 후에 제출할 수 있습니다.")
@ApiResponse(responseCode = "200", description = "문제 풀이 기록 제출 성공")
public SubmissionResponseDto submitSolveHistory(
@RequestBody SolveHistoryDetailRequestDto request) {
return solveHistoryService.submitPluginSolveHistory(request);
@PostMapping("/plugin-submit")
@Operation(summary = "플러그인 문제 풀이 정답 여부 제출", description = "플러그인으로 풀이한 문제의 정답 여부를 제출합니다.")
@ApiResponse(responseCode = "200", description = "정답 제출 완료")
public void submitSolveHistory(
@RequestBody PluginSolveHistoryDetailRequestDto request) {
solveHistoryService.submitPluginSolveHistory(request);
}

@GetMapping("/list")
Expand Down

0 comments on commit ae33b19

Please sign in to comment.