Skip to content

Commit

Permalink
Merge pull request #121 from 22caps/dev
Browse files Browse the repository at this point in the history
병합쓰
  • Loading branch information
GiHoo authored Nov 10, 2024
2 parents d887048 + 075908e commit 7486b69
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@
import com.syu.capsbe.domain.auth.dto.response.SignUpResponseDto;
import com.syu.capsbe.domain.member.Member;
import com.syu.capsbe.domain.member.application.MemberService;
import com.syu.capsbe.domain.solveHistory.PluginSolveHistory;
import com.syu.capsbe.domain.solveHistory.PluginSolveHistoryRepository;
import com.syu.capsbe.global.jwt.JwtProvider;
import com.syu.capsbe.global.jwt.dto.JwtResponseDto;
import java.util.List;
import java.util.Optional;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
Expand All @@ -23,6 +26,7 @@ public class AuthServiceImpl implements AuthService {
private final MemberService memberService;
private final EmailService emailService;
private final JwtProvider jwtProvider;
private final PluginSolveHistoryRepository pluginSolveHistoryRepository;

@Override
@Transactional
Expand Down Expand Up @@ -60,14 +64,49 @@ public SignInEmailResponseDto signInWithEmail(SignInEmailRequestDto signInReques
// member 없을 시 회원가입 후 반환
// 있을 경우 그냥 반환

Member member;
if (findMember.isEmpty()) {
Member member = Member.builder()
member = Member.builder()
.email(signInRequestDto.getEmail())
.build();

memberService.save(member);
Long memberId = memberService.save(member);
} else {
member = findMember.get();
}

return SignInEmailResponseDto.of(signInRequestDto.getEmail());
List<PluginSolveHistory> conversationByMemberId = pluginSolveHistoryRepository.findConversationByMemberId(
member.getId());

List<PluginSolveHistory> grammarByMemberId = pluginSolveHistoryRepository.findGrammarByMemberId(
member.getId());

List<PluginSolveHistory> wordByMemberId = pluginSolveHistoryRepository.findWordByMemberId(
member.getId());


double conversationCorrectRate = 0;
double grammarCorrectRate = 0;
double wordCorrectRate = 0;

if (!conversationByMemberId.isEmpty()) {
conversationCorrectRate = conversationByMemberId.stream()
.filter(PluginSolveHistory::isCorrect)
.count() / (double) conversationByMemberId.size();
}

if (!grammarByMemberId.isEmpty()) {
grammarCorrectRate = grammarByMemberId.stream()
.filter(PluginSolveHistory::isCorrect)
.count() / (double) grammarByMemberId.size();
}

if (!wordByMemberId.isEmpty()) {
wordCorrectRate = wordByMemberId.stream()
.filter(PluginSolveHistory::isCorrect)
.count() / (double) wordByMemberId.size();
}

return SignInEmailResponseDto.of(conversationCorrectRate, grammarCorrectRate, wordCorrectRate);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,22 @@
import lombok.NoArgsConstructor;

@Getter
@Schema(description = "로그인 요청 정보")
@Schema(description = "로그인 응답 정보, 사용자의 정답률 정보를 반환하도록")
@AllArgsConstructor
@NoArgsConstructor
public class SignInEmailResponseDto {

@Schema(description = "회원 Email", example = "[email protected]")
private String email;
// WORD, CONVERSATION, GRAMMAR 정답률 정보
@Schema(description = "문법 문제 정답률", example = "0.5")
private double grammarCorrectRate;

public static SignInEmailResponseDto of(String email) {
return new SignInEmailResponseDto(email);
@Schema(description = "회화 문제 정답률", example = "0.5")
private double conversationCorrectRate;

@Schema(description = "단어 문제 정답률", example = "0.5")
private double wordCorrectRate;

public static SignInEmailResponseDto of(double grammarCorrectRate, double conversationCorrectRate, double wordCorrectRate) {
return new SignInEmailResponseDto(grammarCorrectRate, conversationCorrectRate, wordCorrectRate);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.syu.capsbe.domain.solveHistory;

import com.syu.capsbe.domain.member.Member;
import com.syu.capsbe.domain.problem.ProblemType;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
Expand All @@ -28,11 +31,15 @@ public class PluginSolveHistory {
@JoinColumn(name = "member_id", nullable = false)
private Member member;

@Enumerated(value = EnumType.STRING)
private ProblemType problemType;

private boolean isCorrect;

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

import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

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


// member_id로 조회
@Query("SELECT sh FROM PluginSolveHistory sh WHERE sh.member.id = :memberId AND sh.problemType = 'GRAMMAR'")
List<PluginSolveHistory> findGrammarByMemberId(Long memberId);

@Query("SELECT sh FROM PluginSolveHistory sh WHERE sh.member.id = :memberId AND sh.problemType = 'CONVERSATION'")
List<PluginSolveHistory> findConversationByMemberId(Long memberId);

@Query("SELECT sh FROM PluginSolveHistory sh WHERE sh.member.id = :memberId AND sh.problemType = 'WORD'")
List<PluginSolveHistory> findWordByMemberId(Long memberId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public void submitPluginSolveHistory(PluginSolveHistoryDetailRequestDto request)
Member member = memberService.findByEmail(request.getEmail()).get();

pluginSolveHistoryRepository.save(
new PluginSolveHistory(member, request.isCorrect())
new PluginSolveHistory(member, ProblemType.valueOf(request.getProblemType()), request.isCorrect())
);

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ public class PluginSolveHistoryDetailRequestDto {
@Schema(description = "유저 이메일", example = "[email protected]")
private String email;

@Schema(description = "문제 타입", example = "GRAMMAR")
private String problemType;

@Schema(description = "정답 여부", example = "true")
private boolean isCorrect;
}

0 comments on commit 7486b69

Please sign in to comment.