-
Notifications
You must be signed in to change notification settings - Fork 7
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
[BE] 로그 중복 작성 제거, 비즈니스 로직 내 로그 추가(#608) #610
Changes from all commits
20f2324
96eda7b
81d6168
70aab4c
c9f508d
7d00764
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -3,10 +3,12 @@ | |||||
import corea.exception.CoreaException; | ||||||
import corea.exception.ExceptionType; | ||||||
import corea.participation.domain.Participation; | ||||||
import lombok.extern.slf4j.Slf4j; | ||||||
|
||||||
import java.util.ArrayList; | ||||||
import java.util.List; | ||||||
|
||||||
@Slf4j | ||||||
public class ParticipationFilter { | ||||||
|
||||||
private final List<Participation> participations; | ||||||
|
@@ -51,6 +53,7 @@ private List<Participation> findPRSubmittedParticipation(PullRequestInfo pullReq | |||||
|
||||||
private void invalidateIfNotSubmitPR(PullRequestInfo pullRequestInfo, Participation participation) { | ||||||
if (!hasSubmittedPR(pullRequestInfo, participation)) { | ||||||
log.warn("매칭에 실패 했습니다. 방 id={},사용자 id={},사용자 깃허브 닉네임={}",participation.getRoomsId(),participation.getMembersId(),participation.getMember().getUsername()); | ||||||
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.
Suggested change
|
||||||
participation.invalidate(); | ||||||
} | ||||||
} | ||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
|
||
import corea.exception.CoreaException; | ||
import corea.exception.ExceptionType; | ||
import corea.participation.domain.ParticipationStatus; | ||
|
||
public enum MemberRole { | ||
|
||
|
@@ -22,4 +23,11 @@ public static MemberRole from(String role) { | |
public boolean isReviewer() { | ||
return this == REVIEWER; | ||
} | ||
|
||
public ParticipationStatus getParticipationStatus() { | ||
return switch (this) { | ||
case REVIEWER,REVIEWEE,BOTH -> ParticipationStatus.PARTICIPATED; | ||
case NONE -> ParticipationStatus.NOT_PARTICIPATED; | ||
}; | ||
} | ||
Comment on lines
+27
to
+32
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. break 없이 잘 동작하는가 싶었는데, 람다라 괜찮군요. 구두로 물어봤으니 해결했습니당~ |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package corea.participation.service; | ||
|
||
import corea.exception.CoreaException; | ||
import corea.exception.ExceptionType; | ||
import corea.member.domain.Member; | ||
import corea.member.domain.MemberRole; | ||
import corea.participation.domain.Participation; | ||
import corea.participation.domain.ParticipationStatus; | ||
import corea.participation.repository.ParticipationRepository; | ||
import corea.room.domain.Room; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Slf4j | ||
@Component | ||
@RequiredArgsConstructor | ||
@Transactional | ||
public class ParticipationWriter { | ||
|
||
private final ParticipationRepository participationRepository; | ||
|
||
public Participation create(Room room, Member member, MemberRole memberRole, ParticipationStatus participationStatus) { | ||
|
||
return create(room, member, memberRole, participationStatus, room.getMatchingSize()); | ||
} | ||
|
||
public Participation create(Room room, Member member, MemberRole memberRole, int matchingSize) { | ||
return create(room, member, memberRole, memberRole.getParticipationStatus(), matchingSize); | ||
} | ||
|
||
private Participation create(Room room, Member member, MemberRole memberRole, ParticipationStatus participationStatus, int matchingSize) { | ||
Participation participation = participationRepository.save(new Participation(room, member, memberRole, participationStatus, matchingSize)); | ||
participation.participate(); | ||
logCreateParticipation(participation); | ||
return participation; | ||
} | ||
|
||
// TODO 객체 두개를 넣어서 삭제하는 방향으로 변경 해야합니다. | ||
// 현재, 로직상 cancel 호출 시, 의도하지 않는 room 조회문 발생 | ||
public void delete(long roomId, long memberId) { | ||
Participation participation = participationRepository.findByRoomIdAndMemberId(roomId, memberId) | ||
.orElseThrow(() -> new CoreaException(ExceptionType.NOT_ALREADY_APPLY)); | ||
participation.cancel(); | ||
logDeleteParticipation(participation); | ||
participationRepository.delete(participation); | ||
} | ||
|
||
private void logCreateParticipation(Participation participation) { | ||
log.info("방에 참가했습니다. id={}, 방 id={}, 참가한 사용자 id={}, 역할={}, 원하는 매칭 인원={}", participation.getId(), participation.getRoomsId(), participation.getMembersId(), participation.getMemberRole(), participation.getMatchingSize()); | ||
} | ||
|
||
private void logDeleteParticipation(Participation participation) { | ||
log.info("참여를 취소했습니다. 방 id={}, 참가한 사용자 id={}", participation.getRoomsId(), participation.getMembersId()); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
import corea.participation.domain.Participation; | ||
import corea.participation.domain.ParticipationStatus; | ||
import corea.participation.repository.ParticipationRepository; | ||
import corea.participation.service.ParticipationWriter; | ||
import corea.room.domain.Room; | ||
import corea.room.dto.*; | ||
import corea.room.repository.RoomRepository; | ||
|
@@ -39,7 +40,7 @@ public class RoomService { | |
private final ParticipationRepository participationRepository; | ||
private final FailedMatchingRepository failedMatchingRepository; | ||
private final RoomAutomaticService roomAutomaticService; | ||
|
||
private final ParticipationWriter participationWriter; | ||
|
||
@Transactional | ||
public RoomResponse create(long memberId, RoomCreateRequest request) { | ||
|
@@ -48,7 +49,9 @@ public RoomResponse create(long memberId, RoomCreateRequest request) { | |
Member manager = memberRepository.findById(memberId) | ||
.orElseThrow(() -> new CoreaException(ExceptionType.MEMBER_NOT_FOUND)); | ||
Room room = roomRepository.save(request.toEntity(manager)); | ||
Participation participation = new Participation(room, manager); | ||
log.info("방을 생성했습니다. 방 생성자 id={}, 요청한 사용자 id={}", room.getManagerId(), memberId); | ||
|
||
Participation participation = participationWriter.create(room, manager, MemberRole.REVIEWER, ParticipationStatus.MANAGER); | ||
|
||
participationRepository.save(participation); | ||
roomAutomaticService.createAutomatic(room); | ||
|
@@ -107,6 +110,7 @@ public void delete(long roomId, long memberId) { | |
Room room = getRoom(roomId); | ||
validateDeletionAuthority(room, memberId); | ||
|
||
log.info("방을 삭제했습니다. 방 id={}, 사용자 iD={}", roomId, memberId); | ||
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. 변경된 부분이 아니여서 이곳에 커멘트 남길게요. RoomService에서 ParticipationWriter를 잘 사용하고 있는가에 대한 커멘트입니다. 개인적으로 리팩터링으로 수고하고 있다는거 잘 알지만 👍, 약간 우려된 부분이 ParticipationWriter에서 나온 것 같아 글 남겨봐요! 현재 Room과 Participation이 저희 서비스상 많은 연관관계를 가지지만 방을 삭제할 때, 막상 RoomService에서는 ParticipationWriter의 delete 메서드를 활용하기 어려운 구조라 생각해요. 제가 느낄 수 있는 한가지 ParticipationWriter의 장점으로는 방을 참여할 때, participation.participate();를 같이 호출해주어 개발자로 하여금 휴먼 에러를 방지한다?? 정도가 있겠네요. 근데 이 장점도 저희의 처음 코드였던 Room을 생성할 때 초기 참여자 수를 1로 하고, 저장한다면 똑같이 해결되고 오히려 지금 코드보다 깔끔해진다 느껴집니다. 전에 조이썬한테 제가 먼저 이러한 구조로 바꿔보는거 좋을 것 같다고 동영상을 추천해줬던 것 같아요. 근데 나중에 다시 이 방식을 도입한 사람들에게 의견을 들었을 때, 큰 장점을 못 느꼈다는 말도 들었고, 솔직히 말하자면 ParitipationWriter는 필요해서 나온 느낌이 아니라 그냥 써보고 싶어서 만든 느낌이랄까요?? 다른 영역에서 자주 사용되는 Room이나 Member 같은 경우는 다음과 같이 사용하면 의미가 있다 느껴지네요~ 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.
사실, 해당 부분이 Writer 가 분리되는 이유라고 생각해요.
해당 내용도, 엔티티 라면 비즈니스 변화에 의존되지 않게 코드를 사용해야 한다고 생각해요 ( 저는 이런 관점에서 Reader / Writer 의 필요성을 명확하게 느낀거 같아요. 추가로, 지금 당장은 그냥 로직을 넣은게 다지만, ( 사실 이거 하나로도 만족스럽긴 해요 전 - 에러 일괄적 관리 + 로그 관리 )
해당 부분 역시도 DB 의 원자성과 비슷하다고 생각해요. 이들은 물론 다 제 의견이니 더 생각 달아줘도 좋습니당 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.
ParticipationWriter에 대한 조이썬 의견 궁금했는데, 좋습니다~! 팀 안에서도 로그는 엔티티 내부가 아닌 Writer, Service로 한정하도록 컨벤션 정해봐도 좋을듯 하네요!
저도 이 부분 동의합니다! 저도 앞으로 리팩토링 할때는 최대한 Service가 Repo를 의존하지 않는 방향으로 같이 리팩터링 해보겠습니다~ 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.
가볍게 추가만 하자면 저도 이 말에 동의하는 것 같습니다~ 이번에 기본 참여자를 1로 설정한다는 건 물론 지금 단계에서는 깔끔한 코드처럼 보이고 실제로 깔끔한 코드를 작성할 수 있게 해주지만, 그런 관점에서 전체적으로 이런 방향의 리팩터링이 이루어지고 전체 코드의 구조가 일관적이 된다고 하면 더할 나위 없겠네요. 그런데 조금만 덧붙이자면... 이런 리팩터링이 이루어졌을 때 이전에 테스트하던 메서드가 주석 처리 되는 경우가 종종 있는 것 같아요. 그 때는 가능하다면 이 테스트가 주석 처리된 이유도 함께 적어주셨으면 좋겠습니다. 이번에 베타 테스트로 QA하면서도 느꼈지만 테스트가 잘 작성되었다면 사전에 확인할 수 있었을 것 같은 오류가 꽤 많더라고요. 그런 관점에서 보았을 때 리팩터링 이후 이전 테스트 로직이 비활성화되는 건 조금 의문스럽게 느껴지는 것 같아요. (그렇다면 이 로직이 정확히 이전과 똑같이 동작하는지는 뭘 보고 확신할 수 있지?) 리팩터링은 기본적으로 '이전의 로직과 동일한 동작을 하지만 로직만 교체되는 일'인 만큼 "이전에 테스트하던 걸 왜 이제는 테스트하지 않아도 되는 지"에 대해 코드를 보는 사람도 한 눈에 알 수 있으면 바뀐 이후에도 오류가 나지 않을 수 있을 거라는 확신이 더 강해질 것 같기 때문입니다~~! 이번에 생성자 관련해서 남긴 리뷰도 같은 결이었던 것 같아요! 리팩터링은 정말 너무너무 귀찮고 힘든 일인 걸 알고 있기 때문에 다들 고생하고 계신 거 너무 잘 알고 있습니다~~ 만! 요약: 리팩터링할 때 테스트도 신경 쓰자 (작성자도 리뷰어도 다같이) (뭐라하는 거 아님!!) 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. 말 안했던 건 제 잘못인거 같네용. 주석한 사유는 그전 PR 에 남겼으므로 생략하겠습니다. |
||
roomRepository.delete(room); | ||
participationRepository.deleteAllByRoomId(roomId); | ||
roomAutomaticService.deleteAutomatic(room); | ||
|
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.
👍