Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v0.1.4 #244

Merged
merged 1 commit into from
Aug 29, 2024
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 @@ -15,10 +15,13 @@
import com.depromeet.stonebed.domain.member.domain.MemberStatus;
import com.depromeet.stonebed.domain.member.domain.Profile;
import com.depromeet.stonebed.domain.member.dto.request.CreateMemberRequest;
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.global.error.ErrorCode;
import com.depromeet.stonebed.global.error.exception.CustomException;
import com.depromeet.stonebed.global.util.MemberUtil;
import java.util.List;
import java.util.Optional;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -33,6 +36,7 @@ public class AuthService {
private final FcmNotificationRepository fcmNotificationRepository;
private final MemberRepository memberRepository;
private final MissionRecordRepository missionRecordRepository;
private final MissionRecordBoostRepository missionRecordBoostRepository;

private final AppleClient appleClient;
private final KakaoClient kakaoClient;
Expand Down Expand Up @@ -131,11 +135,14 @@ public void withdraw() {
* appleClient.withdraw(member.getOauthInfo().getOauthId()); }
*/
validateMemberStatusDelete(member.getStatus());

List<MissionRecord> missionRecords = missionRecordRepository.findAllByMember(member);
member.updateMemberRole(MemberRole.TEMPORARY);
member.updateProfile(Profile.createProfile("", ""));
member.updateOauthId("");
memberRepository.flush();
withdrawMemberRelationByMemberId(member.getId());
withdrawMemberRelationByMemberId(
missionRecords.stream().map(MissionRecord::getId).toList(), member.getId());

jwtTokenService.deleteRefreshToken(member.getId());

Expand Down Expand Up @@ -164,7 +171,8 @@ private void updateMemberNormalStatus(Member member) {
}
}

private void withdrawMemberRelationByMemberId(Long memberId) {
private void withdrawMemberRelationByMemberId(List<Long> recordIds, Long memberId) {
missionRecordBoostRepository.deleteAllByMember(recordIds);
missionRecordRepository.deleteAllByMember(memberId);
fcmNotificationRepository.deleteAllByMember(memberId);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
package com.depromeet.stonebed.domain.missionRecord.dao;

import com.depromeet.stonebed.domain.missionRecord.domain.MissionRecordBoost;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

public interface MissionRecordBoostRepository extends JpaRepository<MissionRecordBoost, Long> {
@Query(
"SELECT SUM(mrb.count) FROM MissionRecordBoost mrb WHERE mrb.missionRecord.id = :missionRecordId")
Long sumBoostCountByMissionRecord(@Param("missionRecordId") Long missionRecordId);

// Delete
@Modifying
@Query("DELETE FROM MissionRecordBoost mrb WHERE mrb.missionRecord.id in (:missionRecordIds)")
void deleteAllByMember(@Param("missionRecordIds") List<Long> missionRecordIds);
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,6 @@ boolean existsByMemberAndMissionHistoryAndStatusAndCreatedAtBetween(
@Modifying
@Query("DELETE FROM MissionRecord mr WHERE mr.member.id = :memberId")
void deleteAllByMember(@Param("memberId") Long memberId);

List<MissionRecord> findAllByMember(Member member);
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.depromeet.stonebed.domain.member.domain.Member;
import com.depromeet.stonebed.domain.member.domain.MemberRole;
import com.depromeet.stonebed.domain.member.domain.MemberStatus;
import com.depromeet.stonebed.domain.missionRecord.dao.MissionRecordBoostRepository;
import com.depromeet.stonebed.domain.missionRecord.dao.MissionRecordRepository;
import com.depromeet.stonebed.global.util.MemberUtil;
import java.util.Optional;
Expand All @@ -35,6 +36,7 @@ class AuthServiceTest extends FixtureMonkeySetUp {

@Mock private FcmNotificationRepository fcmNotificationRepository;
@Mock private MissionRecordRepository missionRecordRepository;
@Mock private MissionRecordBoostRepository missionRecordBoostRepository;

@Mock private MemberUtil memberUtil;

Expand Down
Loading