Skip to content

Commit

Permalink
Feat: Set Practice summit
Browse files Browse the repository at this point in the history
  • Loading branch information
Hawardshin committed Nov 23, 2024
1 parent 4263020 commit ad329e8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,8 @@ public ResponseEntity<ApiResponse<ProblemResponse>> getProblem(
@PostMapping("/{storeId}/submit")
@Operation(summary = "실습 채점", description = "주어진 메뉴와 옵션, 수량을 기준으로 실습 채점을 수행합니다.")
public ResponseEntity<ApiResponse<PracticeSubmitResponse>> submitPractice(
@Parameter(description = "Store ID", example = "1") @PathVariable Long storeId,
@RequestBody PracticeSubmitRequest request) {
System.out.println("request = " + request.getProblemId());

PracticeSubmitResponse response = practiceService.submitPractice(storeId, request);
PracticeSubmitResponse response = practiceService.submitPractice(SecurityUtil.getCurrentUserId(), request);
return ResponseEntity.ok(ApiResponse.success(response));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,14 @@
import com.jojoidu.book.easy.practice.repository.ProblemRepository;
import com.jojoidu.book.easy.practice.repository.SolutionRepository;
import com.jojoidu.book.easy.practice.repository.SolveResultRepository;
import com.jojoidu.book.easy.user.exception.UserErrorCode;
import com.jojoidu.book.easy.user.exception.UserException;
import com.jojoidu.book.easy.user.repository.UserRepository;

import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@RequiredArgsConstructor
Expand All @@ -27,15 +31,15 @@ public class PracticeService {
private final ProblemRepository problemRepository;
private final SolutionRepository solutionRepository;
private final SolveResultRepository solveResultRepository;

private final UserRepository userRepository;
public ProblemResponse getProblemByStoreId(Long storeId) {
Problem problem = problemRepository.findByStoreId(storeId)
.orElseThrow(() -> new ProblemException(ProblemErrorCode.PROBLEM_NOT_FOUND));

return new ProblemResponse(problem.getId(), problem.getProblem());
}

public PracticeSubmitResponse submitPractice(Long storeId, PracticeSubmitRequest request) {
public PracticeSubmitResponse submitPractice(Long userId, PracticeSubmitRequest request) {
Solution solution = solutionRepository.findById(request.getProblemId())
.orElseThrow(() -> new SolutionException((SolutionErrorCode.SOLUTION_NOT_FOUND)));

Expand All @@ -47,6 +51,21 @@ public PracticeSubmitResponse submitPractice(Long storeId, PracticeSubmitRequest
boolean optionResult = gradeOptions(submittedMenus, correctMenus);
boolean amountResult = gradeQuantities(submittedMenus, correctMenus);

// 현재 날짜를 문자열로 변환
LocalDateTime solvedDate = LocalDateTime.now();
Problem problem = problemRepository.findById(request.getProblemId()).orElseThrow();
// SolveResult 저장
SolveResult solveResult = SolveResult.builder()
.user(userRepository.findById(userId).orElseThrow(() -> new UserException(UserErrorCode.USER_NOT_FOUND))) // User 객체를 받아서 저장
.problem(problem) // Solution의 Problem 정보 매핑
.menuResult(menuResult)
.optionResult(optionResult)
.amountResult(amountResult)
.solvedDate(solvedDate)
.build();

solveResultRepository.save(solveResult);

// 결과 반환
return new PracticeSubmitResponse(
request.getProblemId(),
Expand Down

0 comments on commit ad329e8

Please sign in to comment.