Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
orieasy1 committed Nov 23, 2024
2 parents a0bc268 + bfdcead commit 4263020
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package com.jojoidu.book.easy.practice.controller;

import com.jojoidu.book.easy.global.dto.ApiResponse;
import com.jojoidu.book.easy.global.util.SecurityUtil;
import com.jojoidu.book.easy.practice.dto.PracticeSubmitRequest;
import com.jojoidu.book.easy.practice.dto.PracticeSubmitResponse;
import com.jojoidu.book.easy.practice.dto.ProblemListResDto;
import com.jojoidu.book.easy.practice.dto.ProblemResponse;
import com.jojoidu.book.easy.practice.service.PracticeService;
import io.swagger.v3.oas.annotations.Operation;
Expand Down Expand Up @@ -39,4 +41,11 @@ public ResponseEntity<ApiResponse<PracticeSubmitResponse>> submitPractice(
PracticeSubmitResponse response = practiceService.submitPractice(storeId, request);
return ResponseEntity.ok(ApiResponse.success(response));
}

@GetMapping("/completed")
@Operation(summary = "실습 완료 목록", description = "유저의 실습 완료 기록을 받아옵니다.")
public ResponseEntity<ApiResponse<ProblemListResDto>> getCompletedList() {
Long userId = SecurityUtil.getCurrentUserId();
return ResponseEntity.ok(ApiResponse.success(practiceService.getCompletedList(userId)));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.jojoidu.book.easy.practice.dto;

import java.util.List;

import com.jojoidu.book.easy.practice.entity.SolveResult;

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

@Data
@AllArgsConstructor
@NoArgsConstructor
public class ProblemListResDto {
@Schema(description = "해결한 문제 목록")
List<ProblemResDto> problems;

public static ProblemListResDto from(List<SolveResult> problems) {
return new ProblemListResDto(problems.stream().map(ProblemResDto::new).toList());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.jojoidu.book.easy.practice.dto;

import java.time.LocalDate;

import com.jojoidu.book.easy.practice.entity.SolveResult;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
public class ProblemResDto {
@Schema(description = "문제 ID", example = "1")
private Long problemId;
@Schema(description = "문제 이름", example = "문제입니다.")
private String problem;
@Schema(description = "문제 완료 날짜", example = "2021-08-01")
private LocalDate solvedDate;

public ProblemResDto(SolveResult solveResult) {
this.problemId = solveResult.getProblem().getId();
this.problem = solveResult.getProblem().getProblem();
this.solvedDate = solveResult.getSolvedDate().toLocalDate();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.jojoidu.book.easy.practice.repository;

import java.util.List;
import java.util.Optional;

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

import com.jojoidu.book.easy.practice.entity.SolveResult;

public interface SolveResultRepository extends JpaRepository<SolveResult, Long>{
Optional<List<SolveResult>> findByUserId(Long userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@

import com.jojoidu.book.easy.practice.dto.PracticeSubmitRequest;
import com.jojoidu.book.easy.practice.dto.PracticeSubmitResponse;
import com.jojoidu.book.easy.practice.dto.ProblemListResDto;
import com.jojoidu.book.easy.practice.dto.ProblemResponse;
import com.jojoidu.book.easy.practice.entity.Problem;
import com.jojoidu.book.easy.practice.entity.Solution;
import com.jojoidu.book.easy.practice.entity.SolveResult;
import com.jojoidu.book.easy.practice.exception.ProblemErrorCode;
import com.jojoidu.book.easy.practice.exception.ProblemException;
import com.jojoidu.book.easy.practice.exception.SolutionErrorCode;
import com.jojoidu.book.easy.practice.exception.SolutionException;
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 lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

Expand All @@ -22,6 +26,7 @@ public class PracticeService {

private final ProblemRepository problemRepository;
private final SolutionRepository solutionRepository;
private final SolveResultRepository solveResultRepository;

public ProblemResponse getProblemByStoreId(Long storeId) {
Problem problem = problemRepository.findByStoreId(storeId)
Expand Down Expand Up @@ -138,4 +143,9 @@ private boolean gradeQuantities(List<PracticeSubmitRequest.Answer.Menu> submitte

return true; // 모두 일치하면 true
}

public ProblemListResDto getCompletedList(Long userId) {
List<SolveResult> solveResults = solveResultRepository.findByUserId(userId).orElseThrow();
return ProblemListResDto.from(solveResults);
}
}
2 changes: 1 addition & 1 deletion src/main/resources/static/login/kakao/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ document.addEventListener('DOMContentLoaded', function () {

if (code) {
console.log('Authorization code:', code);
fetch(`http://localhost:8080/login/oauth2/kakao?code=${code}`, {
fetch(`http://localhost:8080/api/v1/login/oauth2/kakao?code=${code}`, {
method: 'POST'
}).then(response => response.json())
.then(data => {
Expand Down

0 comments on commit 4263020

Please sign in to comment.