Skip to content
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
Expand Up @@ -17,6 +17,7 @@ public enum ErrorType {
MEMBER_NOT_FOUND(HttpStatus.NOT_FOUND, "01-001", "사용자를 찾을 수 없습니다."),
NICKNAME_DUPLICATED(HttpStatus.BAD_REQUEST, "01-002", "이미 존재하는 닉네임입니다."),


// category (02)
CATEGORY_NOT_FOUND(HttpStatus.NOT_FOUND, "02-001", "해당하는 카테고리가 존재하지 않습니다."),
CHILD_CATEGORY_DOES_NOT_EXIXT(HttpStatus.NOT_FOUND, "02-002", "하위 카테고리가 존재하지 않습니다."),
Expand All @@ -26,6 +27,7 @@ public enum ErrorType {

// quiz progress(04)
NO_QUIZ_IN_PROGRESS(HttpStatus.BAD_REQUEST, "04-001", "진행중인 퀴즈가 없습니다."),

; // 커스텀 에러 작성

private final HttpStatus status;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public static ResponseEntity<ApiResponse<Void>> error(ErrorType errorType) {
return ResponseEntity.status(errorType.getStatus())
.body(ApiResponse.<Void>builder()
.status(errorType.getStatus().value())
.message(errorType.getMessage())
.errorCode(errorType.getErrorCode())
.build());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ public interface QuizProgressRepository extends JpaRepository<QuizProgress, Long
List<QuizProgress> findByMemberId(Long memberId);
// List<QuizProgress> findByMemberId(Long memberId);
Optional<QuizProgress> findByMemberIdAndCategoryId(Long memberId, Long categoryId);

Optional<QuizProgress> findByMemberIdAndNotIsCompleted(Long memberId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import com.hiearth.fullquiz.global.exception.FullquizException;
import com.hiearth.fullquiz.repository.MemberRepository;
import com.hiearth.fullquiz.web.dto.MemberResponse;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Size;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
Expand Down
13 changes: 11 additions & 2 deletions src/main/java/com/hiearth/fullquiz/service/QuizServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
@Service
//@AllArgsConstructor
@RequiredArgsConstructor

@Transactional
public class QuizServiceImpl implements QuizSevice{

private final CategoryRepository categoryRepository;
Expand All @@ -34,7 +36,6 @@ public class QuizServiceImpl implements QuizSevice{
private final MemberRepository memberRepository;

@Override
@Transactional
public TotalQuizResponse getQuizzes(Long memberId, String categoryName) {

Category category = categoryRepository.findByName(categoryName)
Expand Down Expand Up @@ -82,14 +83,15 @@ public TotalQuizResponse getQuizzes(Long memberId, String categoryName) {
}

@Override
@Transactional
public void checkAnswer(Long quizId, Long memberId, CheckAnswerDTO checkAnswerDTO) {


Quiz quiz = quizRepository.findById(quizId)
.orElseThrow(() -> new FullquizException(ErrorType.QUIZ_NOT_FOUND));
Member member = memberRepository.findById(memberId)
.orElseThrow(() -> new FullquizException(ErrorType.MEMBER_NOT_FOUND));


memberQuizRepository.save(
MemberQuiz.builder()
.member(member)
Expand All @@ -98,6 +100,7 @@ public void checkAnswer(Long quizId, Long memberId, CheckAnswerDTO checkAnswerDT
.build()
);


List<QuizProgress> quizProgresses = quizProgressRepository
.findByMemberId(memberId);

Expand All @@ -111,9 +114,12 @@ public void checkAnswer(Long quizId, Long memberId, CheckAnswerDTO checkAnswerDT
}

@Override
@Transactional(readOnly = true)
public List<QuizResponse> resumeQuiz(Long quizProgressId) {

QuizProgress quizProgress = quizProgressRepository.findById(quizProgressId)
.orElseThrow(() -> new FullquizException(ErrorType.NO_QUIZ_IN_PROGRESS));

List<Quiz> quizzes = quizRepository.findAllById(quizProgress.getQuizIds());

if (quizzes.isEmpty()) {
Expand All @@ -131,8 +137,10 @@ public List<QuizResponse> resumeQuiz(Long quizProgressId) {
}

@Override
@Transactional(readOnly = true)
public QuizProgressDTO getQuizProgress(Long memberId) {


List<QuizProgress> quizProgresses = quizProgressRepository.findByMemberId(memberId);
if(quizProgresses.isEmpty()){
throw new FullquizException(ErrorType.NO_QUIZ_IN_PROGRESS);
Expand All @@ -153,6 +161,7 @@ public QuizProgressDTO getQuizProgress(Long memberId) {
}

@Override
@Transactional(readOnly = true)
public List<StatusResponse> getMyStatus(String nickname) {
Member member = memberRepository.findByNickname(nickname)
.orElseThrow(() -> new FullquizException(ErrorType.MEMBER_NOT_FOUND));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
import com.hiearth.fullquiz.web.dto.UserRanking;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

@Service
@AllArgsConstructor
@Transactional(readOnly = true)
public class RankingServiceImpl implements RankingService{

private final RankingRepository rankingRepository;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
package com.hiearth.fullquiz.service.request;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import lombok.Getter;

@Getter
public class MemberCreateDTO {

@NotNull(message = "닉네임은 필수입니다.")
@Size(min = 2, max = 7, message = "닉네임은 2자 이상, 7자 이하로 입력해주세요.")
private String nickname;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.hiearth.fullquiz.global.response.ApiResponse;
import com.hiearth.fullquiz.service.MemberService;
import com.hiearth.fullquiz.service.request.MemberCreateDTO;
import jakarta.validation.constraints.Size;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
Expand All @@ -19,7 +20,7 @@ public ResponseEntity<?> registerMember(@RequestBody MemberCreateDTO memberCreat
}

@GetMapping("/api/members")
public ResponseEntity<?> checkDuplicateNickname(@RequestParam String nickname) {
public ResponseEntity<?> checkDuplicateNickname(@RequestParam @Size(min = 2, max = 7, message = "닉네임은 2자 이상, 7자 이하로 입력해주세요.") String nickname) {
return ApiResponse.ok(memberService.existsByNickname(nickname));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.hiearth.fullquiz.web.dto.StatusResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.constraints.Size;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
Expand All @@ -27,7 +28,7 @@ public class QuizController {

@Operation(summary = "퀴즈 불러오기", description = "카테고리 선택 시 퀴즈 리스트를 반환합니다.")
@PostMapping("/api/members/{memberId}/quizzes")
public ResponseEntity<?> getQuizzes(@RequestParam String nickname,
public ResponseEntity<?> getQuizzes(@RequestParam @Size(min = 2, max = 7, message = "닉네임은 2자 이상, 7자 이하로 입력해주세요.") String nickname,
@RequestParam("category") String category) {
log.info("nickname : {} " + nickname);
return ApiResponse.ok(quizService.getQuizzes(memberService.findByNickname(nickname).getId(), category));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
import com.hiearth.fullquiz.web.dto.CategoriesResponse;
import com.hiearth.fullquiz.web.dto.RankingResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.constraints.Size;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
Expand All @@ -22,7 +24,7 @@ public class RankingController {
private final RankingService rankingService;

@GetMapping("/rank")
public ResponseEntity<ApiResponse<RankingResponse>> getRanking (String nickname) {
public ResponseEntity<ApiResponse<RankingResponse>> getRanking (@RequestParam @Size(min = 2, max = 7, message = "닉네임은 2자 이상, 7자 이하로 입력해주세요.") String nickname) {
return ApiResponse.ok(rankingService.getRanking(nickname));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
public class MemberRequest {

@NotBlank(message = "닉네임은 필수입니다.")
@Size(max = 15, message = "닉네임은 15자 이하로 입력해주세요.")
@Size(min = 2, max = 7, message = "닉네임은 2자 이상, 7자 이하로 입력해주세요.")
private String nickname;
}