Skip to content

Commit

Permalink
Merge pull request #77 from hellokitty-coding-club/refactor/#76-patch…
Browse files Browse the repository at this point in the history
…-enums

Refactor/#76 patch enums
  • Loading branch information
ray-yhc authored Sep 5, 2023
2 parents d98d4ba + 40f548b commit acfcf15
Show file tree
Hide file tree
Showing 16 changed files with 106 additions and 67 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package swm.hkcc.LGTM.app.modules.auth.constants;

import swm.hkcc.LGTM.app.modules.auth.exception.UnspecifiedMemberType;
import swm.hkcc.LGTM.app.modules.member.domain.Member;

public enum MemberType {
JUNIOR, SENIOR;

public static MemberType getType(Member member) {
if (member.getSenior() != null) {
return SENIOR;
} else if (member.getJunior() != null) {
return JUNIOR;
} else {
throw new UnspecifiedMemberType();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public SignInResponse githubSignIn(GithubUserInfo githubUserInfo) {
.accessToken(createAccessToken(updatedMember))
.refreshToken(refreshToken)
.profileImageUrl(githubUserInfo.getAvatar_url())
.memberType(memberService.getMemberType(updatedMember.getMemberId()))
.memberType(memberService.getMemberType(updatedMember.getMemberId()).toString())
.build();
}

Expand Down Expand Up @@ -177,7 +177,7 @@ private SignUpResponse buildSignUpResponse(Member member) {
.githubId(member.getGithubId())
.accessToken(createAccessToken(member))
.refreshToken(member.getRefreshToken())
.memberType(memberService.getMemberType(member.getMemberId()))
.memberType(memberService.getMemberType(member.getMemberId()).toString())
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import swm.hkcc.LGTM.app.modules.auth.exception.UnspecifiedMemberType;
import swm.hkcc.LGTM.app.modules.auth.constants.MemberType;
import swm.hkcc.LGTM.app.modules.member.domain.Member;
import swm.hkcc.LGTM.app.modules.member.exception.NotExistMember;
import swm.hkcc.LGTM.app.modules.member.repository.JuniorRepository;
import swm.hkcc.LGTM.app.modules.member.repository.MemberRepository;
import swm.hkcc.LGTM.app.modules.member.repository.SeniorRepository;

import java.util.Optional;

Expand All @@ -20,8 +18,6 @@ public class MemberService {
private static final String SENIOR = "SENIOR";

private final MemberRepository memberRepository;
private final JuniorRepository juniorRepository;
private final SeniorRepository seniorRepository;

public Boolean updateDeviceToken(Long memberId, Optional<String> deviceToken) {
deviceToken.ifPresent(memberRepository::eraseDeviceToken);
Expand All @@ -35,23 +31,10 @@ public Boolean updateDeviceToken(Long memberId, Optional<String> deviceToken) {
return true;
}

public String getMemberType(Long memberId) {
if (isJunior(memberId)) {
return JUNIOR;
}
else if (isSenior(memberId)) {
return SENIOR;
}
else {
throw new UnspecifiedMemberType();
}
}

private boolean isJunior(Long memberId) {
return juniorRepository.existsByMember_MemberId(memberId);
}
public MemberType getMemberType(Long memberId) {
Member member = memberRepository.findById(memberId)
.orElseThrow(NotExistMember::new);

private boolean isSenior(Long memberId) {
return seniorRepository.existsByMember_MemberId(memberId);
return MemberType.getType(member);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@
@Getter
@ToString
public enum MissionStatus {
RECRUITING("참가자 모집중"),
MISSION_PROCEEDING("미션 진행중"),
MISSION_FINISHED("미션 종료");
RECRUITING("참가자 모집중", 1),
MISSION_PROCEEDING("미션 진행중", 2),
MISSION_FINISHED("미션 종료", 3);

private final String status;
private final int sequence;

MissionStatus(String status) {
MissionStatus(String status, int sequence) {
this.status = status;
this.sequence = sequence;
}



// todo : https://developia.tistory.com/30
@JsonCreator
public static MissionStatus from(String status) {
Expand All @@ -36,4 +36,8 @@ public String getValue() {
return this.status;
}

public boolean isFinished() {
return this.sequence >= MISSION_FINISHED.sequence;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;
import swm.hkcc.LGTM.app.modules.auth.constants.MemberType;
import swm.hkcc.LGTM.app.modules.mission.constant.MissionContentType;
import swm.hkcc.LGTM.app.modules.mission.domain.MissionContentData;
import swm.hkcc.LGTM.app.modules.mission.dto.MissionEmptyViewTypeDto;
Expand All @@ -21,13 +22,13 @@ public class MissionItemHolder {

private final MissionService missionService;

public Function<Long, MissionContentData> getMissionListFunction(MissionContentType missionContentType, String memberType) {
public Function<Long, MissionContentData> getMissionListFunction(MissionContentType missionContentType, MemberType memberType) {
return switch (missionContentType) {
case TOTAL_MISSION_LIST_V1 -> missionService::getTotalMissions;
case RECOMMENDED_MISSION_LIST_V1 -> missionService::getRecommendMissions;
case ON_GOING_MISSION_LIST_V1 -> switch (memberType) {
case "JUNIOR" -> missionService::getJuniorOngoingMissions;
case "SENIOR" -> missionService::getSeniorOngoingMissions;
case JUNIOR -> missionService::getJuniorOngoingMissions;
case SENIOR -> missionService::getSeniorOngoingMissions;
default -> null;
};
default -> null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package swm.hkcc.LGTM.app.modules.mission.domain.mapper;

import swm.hkcc.LGTM.app.modules.auth.constants.MemberType;
import swm.hkcc.LGTM.app.modules.member.domain.Member;
import swm.hkcc.LGTM.app.modules.member.domain.Senior;
import swm.hkcc.LGTM.app.modules.mission.domain.Mission;
Expand Down Expand Up @@ -39,7 +40,7 @@ public static MissionDetailsDto missionToMissionDetailDto(Mission mission, List<
.build();
}

public static MissionDetailViewResponse missionAndMemberToDetailView(Mission mission, boolean isScraped, Senior missionWriter, List<TechTag> techTagList, int currentPeopleNumber, String memberType, boolean isParticipated) {
public static MissionDetailViewResponse missionAndMemberToDetailView(Mission mission, boolean isScraped, Senior missionWriter, List<TechTag> techTagList, int currentPeopleNumber, MemberType memberType, boolean isParticipated) {
Member member = missionWriter.getMember();
boolean isClosed = mission.getMissionStatus().equals(MISSION_FINISHED);
return MissionDetailViewResponse.builder()
Expand All @@ -57,7 +58,7 @@ public static MissionDetailViewResponse missionAndMemberToDetailView(Mission mis
.recommendTo(mission.getRecommendTo())
.notRecommendTo(mission.getNotRecommendTo())
.isScraped(isScraped)
.memberType(memberType)
.memberType(memberType.toString())
.memberProfile(MemberProfile.builder()
.memberId(member.getMemberId())
.nickName(member.getNickName())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package swm.hkcc.LGTM.app.modules.mission.repository;

import com.querydsl.core.types.dsl.BooleanExpression;
import com.querydsl.core.types.dsl.Expressions;
import com.querydsl.jpa.impl.JPAQueryFactory;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Repository;
import swm.hkcc.LGTM.app.modules.mission.domain.Mission;
import swm.hkcc.LGTM.app.modules.mission.domain.MissionStatus;
import swm.hkcc.LGTM.app.modules.registration.domain.PersonalStatus;
import swm.hkcc.LGTM.app.modules.registration.domain.ProcessStatus;

import java.util.List;

Expand Down Expand Up @@ -83,7 +84,18 @@ private BooleanExpression isMemberParticipating(Long memberId) {
}

private BooleanExpression isNotCompleted() {
return missionRegistration.status.ne(PersonalStatus.MISSION_FINISHED);
return missionRegistration.status.ne(ProcessStatus.MISSION_FINISHED)
.and(missionRegistration.status.ne(ProcessStatus.FEEDBACK_REVIEWED));

// BooleanExpression expression = Expressions.asBoolean(true).isTrue();
//
// for (ProcessStatus status : ProcessStatus.values()) {
// if (status.isCompleted()) {
// expression = expression.and(missionRegistration.status.ne(status));
// }
// }
//
// return expression;
}

private BooleanExpression isMissionNotFinished() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import swm.hkcc.LGTM.app.modules.auth.constants.MemberType;
import swm.hkcc.LGTM.app.modules.member.service.MemberService;
import swm.hkcc.LGTM.app.modules.mission.constant.MissionContentType;
import swm.hkcc.LGTM.app.modules.mission.domain.MissionContentData;
Expand Down Expand Up @@ -45,7 +46,7 @@ public ServerDrivenScreenResponse getHomeScreen(Long memberId, int version) {

private void processMissionContentType(Long memberId, MissionContentType missionContentType, List<ServerDrivenContent> serverDrivenContentList) {
if (missionContentType.getViewType() == ViewType.ITEM) {
String memberType = memberService.getMemberType(memberId);
MemberType memberType = memberService.getMemberType(memberId);
Function<Long, MissionContentData> missionListFunction = missionItemHolder.getMissionListFunction(missionContentType, memberType);
MissionContentData missionContentData = missionListFunction.apply(memberId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import swm.hkcc.LGTM.app.modules.auth.constants.MemberType;
import swm.hkcc.LGTM.app.modules.member.domain.Senior;
import swm.hkcc.LGTM.app.modules.member.exception.NotExistMember;
import swm.hkcc.LGTM.app.modules.member.repository.MemberRepository;
Expand Down Expand Up @@ -104,7 +105,7 @@ public MissionDetailViewResponse getMissionDetail(Long memberId, Long missionId)

List<TechTag> techTagList = techTagPerMissionRepository.findTechTagsByMissionId(mission.getMissionId());
int currentPeopleNumber = missionRegistrationRepository.countByMission_MissionId(mission.getMissionId());
String memberType = memberService.getMemberType(memberId);
MemberType memberType = memberService.getMemberType(memberId);
boolean isParticipated = checkMemberIsParticipated(memberId, missionId, memberType);

return missionAndMemberToDetailView(mission, isScraped, missionWriter, techTagList, currentPeopleNumber, memberType, isParticipated);
Expand Down Expand Up @@ -137,8 +138,8 @@ public MissionContentData getRecommendMissions(Long memberId) {
return MissionContentData.of(missionDetailsDtos);
}

private boolean checkMemberIsParticipated(Long memberId, Long missionId, String memberType) {
if (memberType.equals("JUNIOR")) {
private boolean checkMemberIsParticipated(Long memberId, Long missionId, MemberType memberType) {
if (memberType.equals(MemberType.JUNIOR)) {
return missionRegistrationRepository.existsByMissionIdAndMemberId(missionId, memberId);
}
return missionRepository.existsByMissionIdAndWriter_MemberId(missionId, memberId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class MissionRegistration extends BaseEntity implements Serializable {

@Enumerated(EnumType.STRING)
@Column(nullable = false)
private PersonalStatus status;
private ProcessStatus status;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "mission_id")
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package swm.hkcc.LGTM.app.modules.registration.domain;

import lombok.Getter;

@Getter
public enum ProcessStatus {
WAITING_FOR_PAYMENT("입금 대기중", 0),
PAYMENT_CONFIRMATION("입금 확인중", 1),
MISSION_PROCEEDING("미션 수행중", 2),
CODE_REVIEW("코드 리뷰 작성", 3),
MISSION_FINISHED("미션 완료!", 4),
FEEDBACK_REVIEWED("리뷰 완료!", 5);

private final String status;
private final int sequence;

ProcessStatus(String status, int sequence) {
this.status = status;
this.sequence = sequence;
}

public boolean isPayed() {
return this.sequence >= MISSION_PROCEEDING.sequence;
}

public boolean isPullRequestCreated() {
return this.sequence >= CODE_REVIEW.sequence;
}

public boolean isCompleted() {
return this.sequence >= MISSION_FINISHED.sequence;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import swm.hkcc.LGTM.app.global.constant.ResponseCode;
import swm.hkcc.LGTM.app.modules.auth.constants.TokenType;
import swm.hkcc.LGTM.app.modules.auth.utils.jwt.TokenProvider;
import swm.hkcc.LGTM.app.modules.auth.constants.MemberType;
import swm.hkcc.LGTM.app.modules.member.domain.Authority;
import swm.hkcc.LGTM.app.modules.member.domain.Bank;
import swm.hkcc.LGTM.app.modules.member.domain.Member;
Expand Down Expand Up @@ -121,7 +122,7 @@ void createMission() throws Exception {
given(missionRegistrationRepository.countByMission_MissionId(anyLong())).willReturn(5);
given(missionRepository.existsByMissionIdAndWriter_MemberId(anyLong(), anyLong())).willReturn(true);
given(missionRegistrationRepository.existsByMissionIdAndMemberId(anyLong(), anyLong())).willReturn(true);
given(memberService.getMemberType(anyLong())).willReturn("JUNIOR");
given(memberService.getMemberType(anyLong())).willReturn(MemberType.JUNIOR);
given(memberRepository.findOneByGithubId(anyString())).willReturn(Optional.ofNullable(mockMember));

// when
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import swm.hkcc.LGTM.app.modules.auth.constants.MemberType;
import swm.hkcc.LGTM.app.modules.mission.constant.MissionContentType;
import swm.hkcc.LGTM.app.modules.mission.domain.MissionContentData;
import swm.hkcc.LGTM.app.modules.mission.dto.MissionDetailsDto;
Expand Down Expand Up @@ -41,7 +42,7 @@ void getMissionListFunction() {
MissionContentType totalMissionContentType = MissionContentType.TOTAL_MISSION_LIST_V1;
MissionContentType onGoingMissionContentType = MissionContentType.ON_GOING_MISSION_LIST_V1;
MissionContentType recommendedMissionContentType = MissionContentType.RECOMMENDED_MISSION_LIST_V1;
String memberType = "JUNIOR";
MemberType memberType = MemberType.JUNIOR;
// Simulate the expected behavior of the missionService mock
MissionContentData<MissionDto> onGoingMissionData = Mockito.mock(MissionContentData.class);
MissionContentData<MissionDetailsDto> totalMissionData = Mockito.mock(MissionContentData.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import swm.hkcc.LGTM.app.modules.mission.domain.Mission;
import swm.hkcc.LGTM.app.modules.mission.domain.MissionStatus;
import swm.hkcc.LGTM.app.modules.registration.domain.MissionRegistration;
import swm.hkcc.LGTM.app.modules.registration.domain.PersonalStatus;
import swm.hkcc.LGTM.app.modules.registration.domain.ProcessStatus;
import swm.hkcc.LGTM.app.modules.registration.repository.MissionRegistrationRepository;

import java.time.LocalDate;
Expand Down Expand Up @@ -109,13 +109,13 @@ void tearDown() {
void getOnGoingMissions() {
// Given
MissionRegistration registration1 = MissionRegistration.builder()
.status(PersonalStatus.WAITING_FOR_PAYMENT)
.status(ProcessStatus.WAITING_FOR_PAYMENT)
.mission(mission1)
.junior(member)
.build();

MissionRegistration registration3 = MissionRegistration.builder()
.status(PersonalStatus.MISSION_PROCEEDING)
.status(ProcessStatus.MISSION_PROCEEDING)
.mission(mission3)
.junior(member)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import swm.hkcc.LGTM.app.modules.auth.constants.MemberType;
import swm.hkcc.LGTM.app.modules.member.service.MemberService;
import swm.hkcc.LGTM.app.modules.mission.constant.MissionContentType;
import swm.hkcc.LGTM.app.modules.mission.domain.MissionContentData;
Expand Down Expand Up @@ -52,7 +53,7 @@ void getHomeScreen_WithNonEmptyContents() {
// given
Long memberId = 1L;
int version = 1;
String memberType = "JUNIOR";
MemberType memberType = MemberType.JUNIOR;

List<MissionContentType> mockMissionContentTypeList = List.of(
MissionContentType.ON_GOING_MISSION_TITLE_V1,
Expand Down

0 comments on commit acfcf15

Please sign in to comment.