Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feat] 마이페이지 기능을 일부 구현한다 #25 #31

Merged
merged 17 commits into from
Jan 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.ripple.BE.learning.controller;

import com.ripple.BE.global.dto.response.ApiResponse;
import com.ripple.BE.learning.dto.ConceptDTO;
import com.ripple.BE.learning.dto.ConceptListDTO;
import com.ripple.BE.learning.dto.response.ConceptDetailResponse;
import com.ripple.BE.learning.dto.response.ConceptListResponse;
import com.ripple.BE.learning.service.concept.ConceptService;
import com.ripple.BE.user.domain.CustomUserDetails;
Expand Down Expand Up @@ -59,4 +61,15 @@ public ResponseEntity<ApiResponse<?>> scrapConcept(
conceptService.scrapConcept(currentUser.getId(), conceptId);
return ResponseEntity.status(HttpStatus.OK).body(ApiResponse.EMPTY_RESPONSE);
}

@Operation(summary = "개별 개념 학습 조회", description = "개별 개념 학습을 조회합니다.")
@GetMapping("/learning/{conceptId}")
public ResponseEntity<ApiResponse<Object>> getConcept(
final @PathVariable("conceptId") long conceptId) {

ConceptDTO concept = conceptService.getConcept(conceptId);

return ResponseEntity.status(HttpStatus.OK)
.body(ApiResponse.from(ConceptDetailResponse.toConceptDetailResponse(concept)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ public ResponseEntity<ApiResponse<Object>> startQuiz(
@PostMapping("/{learningSetId}/quizzes/{quizId}")
public ResponseEntity<ApiResponse<Object>> submitAnswer(
final @AuthenticationPrincipal CustomUserDetails currentUser,
final @PathVariable("learningSetId") long learningSetId,
final @PathVariable("quizId") long quizId,
final @RequestBody @Valid SubmitAnswerRequest request) {

Expand Down
9 changes: 9 additions & 0 deletions src/main/java/com/ripple/BE/learning/dto/ConceptDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,13 @@ public static ConceptDTO toConceptDTO(final Map<String, String> excelData) {
Level.valueOf(excelData.get(LEVEL)),
excelData.get(LEARNING_SET_NAME));
}

public static ConceptDTO toScrapConceptDTO(final Concept concept) {
return new ConceptDTO(
concept.getConceptId(),
concept.getName(),
concept.getExplanation(),
concept.getLevel(),
concept.getLearningSet().getName());
}
}
4 changes: 4 additions & 0 deletions src/main/java/com/ripple/BE/learning/dto/ConceptListDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,8 @@ public record ConceptListDTO(List<ConceptDTO> conceptList // 개념 리스트
public static ConceptListDTO toConceptListDTO(final List<Concept> conceptList) {
return new ConceptListDTO(conceptList.stream().map(ConceptDTO::toConceptDTO).toList());
}

public static ConceptListDTO toScrapConceptListDTO(final List<Concept> conceptList) {
return new ConceptListDTO(conceptList.stream().map(ConceptDTO::toScrapConceptDTO).toList());
}
}
11 changes: 11 additions & 0 deletions src/main/java/com/ripple/BE/learning/dto/FailQuizListDTO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.ripple.BE.learning.dto;

import com.ripple.BE.learning.domain.quiz.Quiz;
import java.util.List;

public record FailQuizListDTO(List<QuizDTO> failQuizList) {

public static FailQuizListDTO toFailQuizListDTO(final List<Quiz> quizList) {
return new FailQuizListDTO(quizList.stream().map(QuizDTO::toFailQuizDTO).toList());
}
}
28 changes: 28 additions & 0 deletions src/main/java/com/ripple/BE/learning/dto/QuizDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,32 @@ public static QuizDTO toQuizDTO(AddLevelTestQuizRequest request) {
request.explanation(),
null);
}

public static QuizDTO toFailQuizDTO(final Quiz quiz) {
return new QuizDTO(
quiz.getId(),
quiz.getName(),
null,
null,
null,
null,
null,
null,
null,
quiz.getLearningSet().getName());
}

public static QuizDTO toScrapQuizDTO(final Quiz quiz) {
return new QuizDTO(
quiz.getId(),
quiz.getName(),
null,
null,
quiz.getLevel(),
null,
null,
null,
null,
quiz.getLearningSet().getName());
}
}
4 changes: 4 additions & 0 deletions src/main/java/com/ripple/BE/learning/dto/QuizListDTO.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@ public record QuizListDTO(List<QuizDTO> quizList) {
public static QuizListDTO toQuizListDTO(final List<Quiz> quizList) {
return new QuizListDTO(quizList.stream().map(QuizDTO::toQuizDTO).toList());
}

public static QuizListDTO toQuizScrapListDTO(final List<Quiz> quizList) {
return new QuizListDTO(quizList.stream().map(QuizDTO::toScrapQuizDTO).toList());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.ripple.BE.learning.dto.response;

import com.ripple.BE.learning.dto.ConceptDTO;

public record ConceptDetailResponse(
long id, String name, String explanation, String level, String learningSetName) {
public static ConceptDetailResponse toConceptDetailResponse(ConceptDTO conceptDTO) {
return new ConceptDetailResponse(
conceptDTO.conceptId(),
conceptDTO.name(),
conceptDTO.explanation(),
conceptDTO.level().name(),
conceptDTO.learningSetName());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.ripple.BE.learning.dto.response;

import com.ripple.BE.learning.dto.FailQuizListDTO;
import java.util.List;

public record FailQuizListResponse(List<FailQuizResponse> failQuizList) {
public static FailQuizListResponse toFailQuizListResponse(final FailQuizListDTO failQuizListDTO) {
return new FailQuizListResponse(
failQuizListDTO.failQuizList().stream().map(FailQuizResponse::toFailQuizResponse).toList());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.ripple.BE.learning.dto.response;

import com.ripple.BE.learning.dto.QuizDTO;

public record FailQuizResponse(Long id, String name, String learningSet) {
public static FailQuizResponse toFailQuizResponse(final QuizDTO quizDTO) {
return new FailQuizResponse(quizDTO.id(), quizDTO.name(), quizDTO.learningSetName());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.ripple.BE.learning.dto.response;

import com.ripple.BE.learning.dto.ConceptListDTO;
import java.util.List;

public record ScrapConceptListResponse(List<ScrapConceptResponse> scrapConceptList) {
public static ScrapConceptListResponse toScrapConceptListResponse(ConceptListDTO conceptListDTO) {
return new ScrapConceptListResponse(
conceptListDTO.conceptList().stream()
.map(ScrapConceptResponse::toScrapConceptResponse)
.toList());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.ripple.BE.learning.dto.response;

import com.ripple.BE.learning.dto.ConceptDTO;
import com.ripple.BE.user.domain.type.Level;
import lombok.Builder;

@Builder
public record ScrapConceptResponse(long id, String name, String LearningSetName, Level level) {
public static ScrapConceptResponse toScrapConceptResponse(ConceptDTO conceptDTO) {
return ScrapConceptResponse.builder()
.id(conceptDTO.conceptId())
.name(conceptDTO.name())
.LearningSetName(conceptDTO.learningSetName())
.level(conceptDTO.level())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.ripple.BE.learning.dto.response;

import com.ripple.BE.learning.dto.QuizListDTO;
import java.util.List;

public record ScrapQuizListResponse(List<ScrapQuizResponse> scrapQuizList) {
public static ScrapQuizListResponse toScrapQuizListResponse(final QuizListDTO quizListDTO) {
return new ScrapQuizListResponse(
quizListDTO.quizList().stream().map(ScrapQuizResponse::toScrapQuizResponse).toList());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.ripple.BE.learning.dto.response;

import com.ripple.BE.learning.dto.QuizDTO;
import com.ripple.BE.user.domain.type.Level;
import lombok.Builder;

@Builder
public record ScrapQuizResponse(long quizId, String quizName, String learningSetName, Level level) {

public static ScrapQuizResponse toScrapQuizResponse(QuizDTO quizDTO) {
return builder()
.quizId(quizDTO.id())
.quizName(quizDTO.name())
.learningSetName(quizDTO.learningSetName())
.level(quizDTO.level())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.ripple.BE.learning.exception;

import com.ripple.BE.global.exception.errorcode.ErrorCode;
import com.ripple.BE.learning.exception.errorcode.LearningErrorCode;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

@Getter
@RequiredArgsConstructor
public class LearningException extends RuntimeException {

private final ErrorCode errorCode;
private final LearningErrorCode errorCode;
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.ripple.BE.learning.exception;

import com.ripple.BE.global.exception.errorcode.ErrorCode;
import com.ripple.BE.learning.exception.errorcode.QuizErrorCode;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

@Getter
@RequiredArgsConstructor
public class QuizException extends RuntimeException {

private final ErrorCode errorCode;
private final QuizErrorCode errorCode;
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public enum LearningErrorCode implements ErrorCode {
HttpStatus.INTERNAL_SERVER_ERROR, "Failed to save learning set excel file"),

CONCEPT_NOT_FOUND(HttpStatus.NOT_FOUND, "Concept not found"),
CONCEPT_ALREADY_SCRAP(HttpStatus.BAD_REQUEST, "Concept already scrap"),
QUIZ_PROGRESS_NOT_FOUND(HttpStatus.NOT_FOUND, "Quiz progress not found"),
QUIZ_NOT_FOUND(HttpStatus.NOT_FOUND, "Quiz not found");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
@Getter
@RequiredArgsConstructor
public enum QuizErrorCode implements ErrorCode {
QUIZ_NOT_FOUND(HttpStatus.NOT_FOUND, "Quiz not found");
QUIZ_NOT_FOUND(HttpStatus.NOT_FOUND, "Quiz not found"),
QUIZ_ALREADY_SCRAP(HttpStatus.BAD_REQUEST, "Quiz already scrap");

private final HttpStatus httpStatus;
private final String message;
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.ripple.BE.learning.repository;
package com.ripple.BE.learning.repository.concept;

import com.ripple.BE.learning.domain.concept.Concept;
import com.ripple.BE.learning.domain.learningset.LearningSet;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.ripple.BE.learning.repository.conceptScrap;

import com.ripple.BE.learning.domain.concept.ConceptScrap;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface ConceptScrapRepository
extends JpaRepository<ConceptScrap, Long>, ConceptScrapRepositoryCustom {
Boolean existsByConcept_ConceptIdAndUserId(Long conceptId, Long userId);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

여기 혹시 _ 쓰신 이유 알수 있을까요?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concept클래스의 id가 conceptId로 되어있어서 existByConceptIdAndUserID 이거로는 조회가 안되더라구요!! 필드명 바꾸면 고칠게많을 것 같아서 언더바로 해결했습니다ㅎㅎ..

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.ripple.BE.learning.repository.conceptScrap;

import com.ripple.BE.learning.domain.concept.Concept;
import com.ripple.BE.user.domain.type.Level;
import java.util.List;

public interface ConceptScrapRepositoryCustom {

List<Concept> findConceptsScrappedByUserAndLevel(Long userId, Level level);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.ripple.BE.learning.repository.conceptScrap;

import static com.ripple.BE.learning.domain.concept.QConcept.*;
import static com.ripple.BE.learning.domain.concept.QConceptScrap.*;

import com.querydsl.jpa.impl.JPAQueryFactory;
import com.ripple.BE.learning.domain.concept.Concept;
import com.ripple.BE.user.domain.type.Level;
import java.util.List;
import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
public class ConceptScrapRepositoryCustomImpl implements ConceptScrapRepositoryCustom {

private final JPAQueryFactory queryFactory;

@Override
public List<Concept> findConceptsScrappedByUserAndLevel(Long userId, Level level) {
return queryFactory
.select(concept)
.from(conceptScrap)
.join(conceptScrap.concept, concept)
.where(conceptScrap.user.id.eq(userId), concept.level.eq(level))
.fetch();
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.ripple.BE.learning.repository;
package com.ripple.BE.learning.repository.learningSet;

import com.ripple.BE.learning.domain.learningset.LearningSet;
import org.springframework.data.jpa.repository.JpaRepository;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.ripple.BE.learning.repository;
package com.ripple.BE.learning.repository.learningSet;

import com.ripple.BE.learning.domain.learningset.UserLearningSet;
import com.ripple.BE.user.domain.type.Level;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.ripple.BE.learning.repository;
package com.ripple.BE.learning.repository.quiz;

import com.ripple.BE.learning.domain.learningset.LearningSet;
import com.ripple.BE.learning.domain.quiz.Quiz;
Expand All @@ -9,7 +9,7 @@
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

public interface QuizRepository extends JpaRepository<Quiz, Long> {
public interface QuizRepository extends JpaRepository<Quiz, Long>, QuizRepositoryCustom {

int countByLevel(Level level);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.ripple.BE.learning.repository.quiz;

import com.ripple.BE.learning.domain.quiz.Quiz;
import com.ripple.BE.user.domain.type.Level;
import java.util.List;

public interface QuizRepositoryCustom {

List<Quiz> findFailedQuizzesByUserAndLevel(long userId, Level level);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.ripple.BE.learning.repository.quiz;

import static com.ripple.BE.learning.domain.quiz.QFailQuiz.*;
import static com.ripple.BE.learning.domain.quiz.QQuiz.*;

import com.querydsl.jpa.impl.JPAQueryFactory;
import com.ripple.BE.learning.domain.quiz.Quiz;
import com.ripple.BE.user.domain.type.Level;
import java.util.List;
import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
public class QuizRepositoryCustomImpl implements QuizRepositoryCustom {

private final JPAQueryFactory queryFactory;

@Override
public List<Quiz> findFailedQuizzesByUserAndLevel(long userId, Level level) {
return queryFactory
.select(quiz)
.from(failQuiz)
.join(failQuiz.quiz, quiz)
.where(failQuiz.user.id.eq(userId), quiz.level.eq(level))
.fetch();
}
}
Loading