Skip to content

Commit

Permalink
v0.1.1
Browse files Browse the repository at this point in the history
v0.1.1
  • Loading branch information
char-yb authored Aug 26, 2024
2 parents d161000 + 78d6bb7 commit e80c6de
Show file tree
Hide file tree
Showing 13 changed files with 143 additions and 24 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,6 @@ logs
*.DS_Store
/src/main/generated
.*-database

### 멀티모듈 임시 주석 ###
walwal-*
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ public SocialClientResponse authenticateFromProvider(OAuthProvider provider, Str
public AuthTokenResponse socialLogin(
OAuthProvider oAuthProvider, String oauthId, String email) {
Optional<Member> memberOptional =
memberRepository.findByOauthInfoOauthProviderAndOauthInfoOauthId(
oAuthProvider.getValue(), oauthId);
memberRepository.findByMemberOauthInfo(oAuthProvider.getValue(), email);

return memberOptional
.map(
Expand All @@ -67,7 +66,8 @@ public AuthTokenResponse socialLogin(
? getTemporaryLoginResponse(member)
: getLoginResponse(member);
member.updateLastLoginAt();
updateMemberStatus(member);
member.updateOauthId(oauthId);
updateMemberNormalStatus(member);
return AuthTokenResponse.of(
tokenPair, member.getRole() == MemberRole.TEMPORARY);
})
Expand Down Expand Up @@ -132,6 +132,7 @@ public void withdraw() {
validateMemberStatusDelete(member.getStatus());
member.updateMemberRole(MemberRole.TEMPORARY);
member.updateProfile(Profile.createProfile("", ""));
member.updateOauthId("");
memberRepository.flush();
withdrawMemberRelationByMemberId(member.getId());

Expand All @@ -156,7 +157,7 @@ private Member registerMember(Member member, CreateMemberRequest request) {
return member;
}

private void updateMemberStatus(Member member) {
private void updateMemberNormalStatus(Member member) {
if (member.getStatus() == MemberStatus.DELETED) {
member.updateStatus(MemberStatus.NORMAL);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public SocialClientResponse authenticateFromKakao(String token) {
(request, response) -> {
if (!response.getStatusCode().is2xxSuccessful()) {
throw new CustomException(
ErrorCode.APPLE_TOKEN_CLIENT_FAILED);
ErrorCode.KAKAO_TOKEN_CLIENT_FAILED);
}
return Objects.requireNonNull(
response.bodyTo(KakaoAuthResponse.class));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
Expand All @@ -26,8 +27,14 @@ public class MemberController {

@Operation(summary = "내 정보 조회", description = "내 정보를 조회하는 API입니다.")
@GetMapping("/me")
public MemberInfoResponse memberInfo() {
return memberService.findMemberInfo();
public MemberInfoResponse memberMyInfo() {
return memberService.findMemberMyInfo();
}

@Operation(summary = "회원 정보 조회", description = "회원 정보를 조회하는 API입니다.")
@GetMapping("/{memberId}")
public MemberInfoResponse memberInfo(@PathVariable("memberId") Long memberId) {
return memberService.findMemberInfo(memberId);
}

@Operation(summary = "회원 프로필 변경", description = "회원 프로필을 변경합니다.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,17 @@ public class MemberService {
private final MemberUtil memberUtil;

@Transactional(readOnly = true)
public MemberInfoResponse findMemberInfo() {
public MemberInfoResponse findMemberMyInfo() {
Member currentMember = memberUtil.getCurrentMember();
return MemberInfoResponse.from(currentMember);
}

@Transactional(readOnly = true)
public MemberInfoResponse findMemberInfo(Long memberId) {
Member member = memberUtil.getMemberByMemberId(memberId);
return MemberInfoResponse.from(member);
}

@Transactional(readOnly = true)
public void checkNickname(NicknameCheckRequest request) {
memberUtil.checkNickname(request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,16 @@
import com.depromeet.stonebed.domain.member.domain.Member;
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

public interface MemberRepository extends JpaRepository<Member, Long>, MemberRepositoryCustom {
Optional<Member> findByOauthInfoOauthProviderAndOauthInfoOauthId(
String oauthProvider, String oauthId);

@Query(
"SELECT m FROM Member m WHERE m.oauthInfo.oauthProvider = :provider AND m.oauthInfo.oauthEmail = :email")
Optional<Member> findByMemberOauthInfo(
@Param("provider") String oauthProvider, @Param("email") String email);

Optional<Member> findByOauthInfoOauthProviderAndOauthInfoOauthEmail(
String oauthProvider, String email);
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,11 @@
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.SQLDelete;
import org.hibernate.annotations.SQLRestriction;

@Getter
@Entity
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@SQLDelete(sql = "UPDATE member SET status = 'DELETED' WHERE member_id = ?")
@SQLRestriction("status != 'DELETED'")
public class Member extends BaseTimeEntity {

@Id
Expand Down Expand Up @@ -121,4 +119,8 @@ public void updateMemberRole(MemberRole memberRole) {
public void updateStatus(MemberStatus status) {
this.status = status;
}

public void updateOauthId(String oauthId) {
this.oauthInfo.oauthId = oauthId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
public class OauthInfo {

@Schema(description = "소셜 ID", example = "123487892")
private String oauthId;
public String oauthId;

@Schema(description = "소셜 제공자", example = "APPLE")
private String oauthProvider;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ public class MissionRecordService {

private static final DateTimeFormatter DATE_FORMATTER =
DateTimeFormatter.ofPattern("yyyy-MM-dd");
private static final LocalDateTime endOfYesterday =
LocalDate.now().minusDays(1).atTime(23, 59, 59);

public MissionRecordIdResponse startMission(Long missionId) {
final Member member = memberUtil.getCurrentMember();
Expand Down Expand Up @@ -232,6 +230,7 @@ public MissionRecordCompleteTotal getTotalMissionRecords(Long memberId) {
}

public void expiredMissionsToNotCompletedUpdate() {
LocalDateTime endOfYesterday = LocalDate.now().minusDays(1).atTime(23, 59, 59);
missionRecordRepository.updateExpiredMissionsToNotCompleted(endOfYesterday);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,16 @@ public List<MissionRecord> findByMemberIdAndCreatedAtFromWithPagination(
}

@Override
public void updateExpiredMissionsToNotCompleted(LocalDateTime endOfYesterday) {
public void updateExpiredMissionsToNotCompleted(LocalDateTime currentTime) {
queryFactory
.update(missionRecord)
.set(missionRecord.status, MissionRecordStatus.NOT_COMPLETED)
.set(missionRecord.updatedAt, LocalDateTime.now())
.where(
missionRecord
.status
.eq(MissionRecordStatus.IN_PROGRESS)
.and(missionRecord.createdAt.before(endOfYesterday)))
.and(missionRecord.createdAt.before(currentTime)))
.execute();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,7 @@ void setUp() {
// given
OAuthProvider provider = OAuthProvider.KAKAO;

when(memberRepository.findByOauthInfoOauthProviderAndOauthInfoOauthId(
provider.getValue(), oauthId))
when(memberRepository.findByMemberOauthInfo(provider.getValue(), email))
.thenReturn(Optional.of(member));
when(jwtTokenService.generateTokenPair(member.getId(), MemberRole.USER))
.thenReturn(new TokenPairResponse("accessToken", "refreshToken"));
Expand All @@ -75,8 +74,7 @@ void setUp() {
// given
OAuthProvider provider = OAuthProvider.APPLE;

when(memberRepository.findByOauthInfoOauthProviderAndOauthInfoOauthId(
provider.getValue(), oauthId))
when(memberRepository.findByMemberOauthInfo(provider.getValue(), email))
.thenReturn(Optional.of(member));
when(jwtTokenService.generateTokenPair(member.getId(), MemberRole.USER))
.thenReturn(new TokenPairResponse("accessToken", "refreshToken"));
Expand All @@ -95,8 +93,7 @@ void setUp() {
TokenPairResponse temporaryTokenPair = new TokenPairResponse("accessToken", "refreshToken");
Member newMember = Member.createOAuthMember(provider, oauthId, email);

when(memberRepository.findByOauthInfoOauthProviderAndOauthInfoOauthId(
provider.getValue(), oauthId))
when(memberRepository.findByMemberOauthInfo(provider.getValue(), email))
.thenReturn(Optional.empty());
when(memberRepository.save(any(Member.class))).thenReturn(newMember);
when(jwtTokenService.generateTemporaryTokenPair(any(Member.class)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class MemberServiceTest extends FixtureMonkeySetUp {
when(memberUtil.getCurrentMember()).thenReturn(member);

// when
MemberInfoResponse result = memberService.findMemberInfo();
MemberInfoResponse result = memberService.findMemberMyInfo();

// then
assertNotNull(result);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@
import com.depromeet.stonebed.domain.fcm.application.FcmNotificationService;
import com.depromeet.stonebed.domain.member.domain.Member;
import com.depromeet.stonebed.domain.mission.dao.MissionRepository;
import com.depromeet.stonebed.domain.mission.domain.Mission;
import com.depromeet.stonebed.domain.missionHistory.dao.MissionHistoryRepository;
import com.depromeet.stonebed.domain.missionHistory.domain.MissionHistory;
import com.depromeet.stonebed.domain.missionRecord.dao.MissionRecordBoostRepository;
import com.depromeet.stonebed.domain.missionRecord.dao.MissionRecordRepository;
import com.depromeet.stonebed.domain.missionRecord.domain.MissionRecord;
import com.depromeet.stonebed.domain.missionRecord.domain.MissionRecordBoost;
import com.depromeet.stonebed.domain.missionRecord.domain.MissionRecordStatus;
import com.depromeet.stonebed.domain.missionRecord.dto.response.MissionRecordCalendarResponse;
import com.depromeet.stonebed.domain.missionRecord.dto.response.MissionRecordCompleteTotal;
import com.depromeet.stonebed.domain.missionRecord.dto.response.MissionTabResponse;
import com.depromeet.stonebed.global.error.ErrorCode;
import com.depromeet.stonebed.global.error.exception.CustomException;
import com.depromeet.stonebed.global.util.MemberUtil;
Expand Down Expand Up @@ -259,4 +262,96 @@ class MissionRecordServiceTest extends FixtureMonkeySetUp {
verify(missionRecordRepository).findById(missionRecord.getId());
verify(missionRecordBoostRepository).save(any(MissionRecordBoost.class));
}

@Test
void 미션탭_상태_미션_완료() {
// Given
Long missionId = 1L;
Member member = fixtureMonkey.giveMeOne(Member.class);
Mission mission = fixtureMonkey.giveMeBuilder(Mission.class).set("id", missionId).sample();
MissionHistory missionHistory =
fixtureMonkey.giveMeBuilder(MissionHistory.class).set("mission", mission).sample();
MissionRecord missionRecord =
fixtureMonkey
.giveMeBuilder(MissionRecord.class)
.set("member", member)
.set("missionHistory", missionHistory)
.set("status", MissionRecordStatus.COMPLETED)
.sample();

when(memberUtil.getCurrentMember()).thenReturn(member);
when(missionRepository.findById(missionId)).thenReturn(Optional.of(mission));
when(missionHistoryRepository.findLatestOneByMissionIdRaisePet(
missionId, mission.getRaisePet()))
.thenReturn(Optional.of(missionHistory));
when(missionRecordRepository.findByMemberAndMissionHistory(member, missionHistory))
.thenReturn(Optional.of(missionRecord));

// When
MissionTabResponse response = missionRecordService.getMissionTabStatus(missionId);

// Then
then(response).isNotNull();
then(response.imageUrl()).isEqualTo(missionRecord.getImageUrl());
then(response.status()).isEqualTo(MissionRecordStatus.COMPLETED);

verify(memberUtil).getCurrentMember();
verify(missionRepository).findById(missionId);
verify(missionHistoryRepository)
.findLatestOneByMissionIdRaisePet(missionId, mission.getRaisePet());
verify(missionRecordRepository).findByMemberAndMissionHistory(member, missionHistory);
}

@Test
void 미션탭_상태_미션_진행중() {
// Given
Long missionId = 1L;
Member member = fixtureMonkey.giveMeOne(Member.class);
Mission mission = fixtureMonkey.giveMeBuilder(Mission.class).set("id", missionId).sample();
MissionHistory missionHistory =
fixtureMonkey.giveMeBuilder(MissionHistory.class).set("mission", mission).sample();

when(memberUtil.getCurrentMember()).thenReturn(member);
when(missionRepository.findById(missionId)).thenReturn(Optional.of(mission));
when(missionHistoryRepository.findLatestOneByMissionIdRaisePet(
missionId, mission.getRaisePet()))
.thenReturn(Optional.of(missionHistory));
when(missionRecordRepository.findByMemberAndMissionHistory(member, missionHistory))
.thenReturn(Optional.empty());

// When
MissionTabResponse response = missionRecordService.getMissionTabStatus(missionId);

// Then
then(response).isNotNull();
then(response.imageUrl()).isNull();
then(response.status()).isEqualTo(MissionRecordStatus.NOT_COMPLETED);

verify(memberUtil).getCurrentMember();
verify(missionRepository).findById(missionId);
verify(missionHistoryRepository)
.findLatestOneByMissionIdRaisePet(missionId, mission.getRaisePet());
verify(missionRecordRepository).findByMemberAndMissionHistory(member, missionHistory);
}

@Test
void 미션탭_상태_미션_시작안함() {
// Given
Long missionId = 1L;

when(missionRepository.findById(missionId)).thenReturn(Optional.empty());

// When & Then
CustomException exception =
org.junit.jupiter.api.Assertions.assertThrows(
CustomException.class,
() -> missionRecordService.getMissionTabStatus(missionId));

then(exception.getErrorCode()).isEqualTo(ErrorCode.MISSION_NOT_FOUND);

verify(missionRepository).findById(missionId);
verify(missionHistoryRepository, never())
.findLatestOneByMissionIdRaisePet(anyLong(), any());
verify(missionRecordRepository, never()).findByMemberAndMissionHistory(any(), any());
}
}

0 comments on commit e80c6de

Please sign in to comment.