Skip to content

Commit

Permalink
♻️:: 매칭하기 리팩토링
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyoil2 committed Dec 29, 2023
1 parent 9957439 commit c21fa40
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ public MatchScoreResponse bothMatch(String username1, String username2) {
User user2 = userRepository.findByUsername(username2)
.orElseThrow(()->UserNotFoundException.EXCEPTION);

if(me.getStudentId().substring(0, 1).equals(user1.getStudentId().substring(0,1))) return 0;
else {
if(!me.getStudentId().substring(0, 1).equals(user1.getStudentId().substring(0,1))) {
Long grade = Long.parseLong(user1.getStudentId().substring(0, 1));
Long classNumber = Long.parseLong(user1.getStudentId().substring(1, 2));

Expand All @@ -39,8 +38,7 @@ public MatchScoreResponse bothMatch(String username1, String username2) {
schoolClass.addCandy(100);
}

if(me.getStudentId().substring(0, 1).equals(user2.getStudentId().substring(0,1))) return 0;
else {
if(!me.getStudentId().substring(0, 1).equals(user2.getStudentId().substring(0,1))) {
Long grade = Long.parseLong(user2.getStudentId().substring(0, 1));
Long classNumber = Long.parseLong(user2.getStudentId().substring(1, 2));

Expand All @@ -49,12 +47,12 @@ public MatchScoreResponse bothMatch(String username1, String username2) {
schoolClass.addCandy(100);
}

int socialScore, knowledgeScore, emotionScore, decisionScore;
int socialScore = 100 - Math.abs(user1.getSocialTypeScore() - user2.getSocialTypeScore());
int knowledgeScore = 100 - Math.abs(user1.getKnowledgeTypeScore() - user2.getKnowledgeTypeScore());
int emotionScore = 100 - Math.abs(user1.getEmotionTypeScore() - user2.getEmotionTypeScore());
int decisionScore = 100 - Math.abs(user1.getDecisionTypeScore() - user2.getDecisionTypeScore());

socialScore = 100 - Math.abs(user1.getSocialTypeScore() - user2.getSocialTypeScore());
knowledgeScore = 100 - Math.abs(user1.getKnowledgeTypeScore() - user2.getKnowledgeTypeScore());
emotionScore = 100 - Math.abs(user1.getEmotionTypeScore() - user2.getEmotionTypeScore());
decisionScore = 100 - Math.abs(user1.getDecisionTypeScore() - user2.getDecisionTypeScore());
int matchScore = (socialScore + knowledgeScore + emotionScore + decisionScore)/4;

return new MatchScoreResponse(matchScore);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.example.asterbackend.domain.user.schoolClass.facade.SchoolClassFacade;
import com.example.asterbackend.domain.user.user.entity.User;
import com.example.asterbackend.domain.user.user.facade.UserFacade;
import com.example.asterbackend.domain.user.user.presentation.dto.response.MatchScoreResponse;
import com.example.asterbackend.domain.user.user.repository.UserRepository;
import com.example.asterbackend.global.exception.user.UserNotFoundException;
import lombok.RequiredArgsConstructor;
Expand All @@ -25,8 +26,8 @@ public MatchScoreResponse whoMatch(String username) {
User user = userRepository.findByUsername(username)
.orElseThrow(()-> UserNotFoundException.EXCEPTION);

if(me.getStudentId().substring(0, 1).equals(user.getStudentId().substring(0,1))) return 0;
else {
if(!me.getStudentId().substring(0, 1).equals(user.getStudentId().substring(0,1))){

Long grade = Long.parseLong(user.getStudentId().substring(0, 1));
Long classNumber = Long.parseLong(user.getStudentId().substring(1, 2));

Expand All @@ -35,12 +36,12 @@ public MatchScoreResponse whoMatch(String username) {
schoolClass.addCandy(100);
}

int socialScore, knowledgeScore, emotionScore, decisionScore;
int socialScore = 100 - Math.abs(me.getSocialTypeScore() - user.getSocialTypeScore());
int knowledgeScore = 100 - Math.abs(me.getKnowledgeTypeScore() - user.getKnowledgeTypeScore());
int emotionScore = 100 - Math.abs(me.getEmotionTypeScore() - user.getEmotionTypeScore());
int decisionScore = 100 - Math.abs(me.getDecisionTypeScore() - user.getDecisionTypeScore());

socialScore = 100 - Math.abs(me.getSocialTypeScore() - user.getSocialTypeScore());
knowledgeScore = 100 - Math.abs(me.getKnowledgeTypeScore() - user.getKnowledgeTypeScore());
emotionScore = 100 - Math.abs(me.getEmotionTypeScore() - user.getEmotionTypeScore());
decisionScore = 100 - Math.abs(me.getDecisionTypeScore() - user.getDecisionTypeScore());
int matchScore = (socialScore + knowledgeScore + emotionScore + decisionScore)/4;

return new MatchScoreResponse(matchScore);
}
Expand Down

0 comments on commit c21fa40

Please sign in to comment.