-
Notifications
You must be signed in to change notification settings - Fork 0
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
[FEAT] 회원 데일리 루틴 삭제 #37
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
72b25ea
[FEAT] 회원 데일리 루틴 삭제
thguss 50956d8
Merge branch 'develop' into feature/#35-routine-delete-api
thguss 6edf91d
[FEAT] 회원 데일리 루틴 삭제
thguss ecdeb16
Merge branch 'feature/#28-routine-post-api' into feature/#35-routine-…
thguss cb7b071
[ADD] 예외 처리 추가
thguss a6cc0a0
[TEST] 회원 데일리 루틴 삭제 테스트
thguss 003d92b
[CHORE] 충돌 해결
thguss 4a89a54
[CHORE] 충돌 해결
thguss 5051c6c
[FIX] null 예외 대응
thguss 834a75c
[FIX] 코드 스타일 통일
thguss File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
...ava/com/soptie/server/memberRoutine/repository/CompletedMemberDailyRoutineRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.soptie.server.memberRoutine.repository; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import com.soptie.server.memberRoutine.entity.daily.CompletedMemberDailyRoutine; | ||
|
||
public interface CompletedMemberDailyRoutineRepository extends JpaRepository<CompletedMemberDailyRoutine, Long> { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,9 @@ | |
import com.soptie.server.member.repository.MemberRepository; | ||
import com.soptie.server.memberRoutine.dto.MemberDailyRoutineRequest; | ||
import com.soptie.server.memberRoutine.dto.MemberDailyRoutineResponse; | ||
import com.soptie.server.memberRoutine.entity.daily.CompletedMemberDailyRoutine; | ||
import com.soptie.server.memberRoutine.entity.daily.MemberDailyRoutine; | ||
import com.soptie.server.memberRoutine.repository.CompletedMemberDailyRoutineRepository; | ||
import com.soptie.server.memberRoutine.repository.MemberDailyRoutineRepository; | ||
import com.soptie.server.routine.entity.daily.DailyRoutine; | ||
import com.soptie.server.routine.repository.daily.routine.DailyRoutineRepository; | ||
|
@@ -26,6 +28,7 @@ public class MemberDailyRoutineServiceImpl implements MemberDailyRoutineService | |
private final MemberDailyRoutineRepository memberDailyRoutineRepository; | ||
private final MemberRepository memberRepository; | ||
private final DailyRoutineRepository dailyRoutineRepository; | ||
private final CompletedMemberDailyRoutineRepository completedMemberDailyRoutineRepository; | ||
|
||
@Override | ||
@Transactional | ||
|
@@ -37,13 +40,43 @@ public MemberDailyRoutineResponse createMemberDailyRoutine(long memberId, Member | |
return MemberDailyRoutineResponse.of(savedMemberRoutine.getId()); | ||
} | ||
|
||
private DailyRoutine findRoutine(Long id) { | ||
return dailyRoutineRepository.findById(id) | ||
.orElseThrow(() -> new EntityNotFoundException(INVALID_ROUTINE.getMessage())); | ||
} | ||
|
||
@Override | ||
@Transactional | ||
public void deleteMemberDailyRoutine(long memberId, Long routineId) { | ||
val member = findMember(memberId); | ||
val routine = findMemberRoutine(routineId); | ||
checkRoutineForMember(member, routine); | ||
deleteMemberRoutine(routine); | ||
} | ||
|
||
private Member findMember(Long id) { | ||
return memberRepository.findById(id) | ||
.orElseThrow(() -> new EntityNotFoundException(INVALID_MEMBER.getMessage())); | ||
.orElseThrow(() -> new EntityNotFoundException(INVALID_MEMBER.getMeesage())); | ||
} | ||
|
||
private DailyRoutine findRoutine(Long id) { | ||
return dailyRoutineRepository.findById(id) | ||
private MemberDailyRoutine findMemberRoutine(Long id) { | ||
return memberDailyRoutineRepository.findById(id) | ||
.orElseThrow(() -> new EntityNotFoundException(INVALID_ROUTINE.getMessage())); | ||
} | ||
|
||
private void checkRoutineForMember(Member member, MemberDailyRoutine routine) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 체크와 동시에 예외도 터뜨리고 있는데 이럴 시, 메서드명에 예외도 터뜨림을 알려줘야 할까요....?? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 논의 완료! |
||
if (!member.getDailyRoutines().contains(routine)) { | ||
throw new IllegalStateException(INACCESSIBLE_ROUTINE.getMeesage()); | ||
} | ||
} | ||
|
||
private void deleteMemberRoutine(MemberDailyRoutine routine) { | ||
moveCompletedRoutine(routine); | ||
memberDailyRoutineRepository.delete(routine); | ||
} | ||
|
||
private void moveCompletedRoutine(MemberDailyRoutine routine) { | ||
val completedRoutine = new CompletedMemberDailyRoutine(routine); | ||
completedMemberDailyRoutineRepository.save(completedRoutine); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"/routine/{routineId}" 말고 "/{routineId}"는 좀 그럴려나요??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
자원의 표현성으로 의논 완료!