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

Refactor/#461 같은 멤버가 등록중인 노래에 같은 부분을 킬링파트로 등록시 추가 데이터를 저장하지 않는 기능 구현 #469

Merged
merged 9 commits into from
Sep 27, 2023

Conversation

splitCoding
Copy link
Collaborator

📝작업 내용

VotingSong -> VotingSongParts -> Member 로의 많은 N+1 쿼리가 예상되기에

boolean existsByVotingSongAndMemberAndStartSecondAndLength(final VotingSong votingSong,
                                                               final Member member,
                                                               final int startSecond,
                                                               final PartLength length);

해당 메서드를 사용해서 확인했습니다.😊

💬리뷰 참고사항

추후에 해당 쿼리에 대한 분석과 인덱스 적용 여부에 대해서 파악해야 됩니다!!😁

멤버가 같은 파트를 등록했을 때는 200(OK), 아닌 경우에는 201(CREATED) 를 사용해서 클라이언트에게 전달하려 했으나 이 부분에 대해서 추후 프론트 팀원들과의 논의가 필요할 것 같습니다!!🫡

#️⃣연관된 이슈

close #461

@splitCoding splitCoding added [ 🌙 BE ] 백엔드 크루들의 멋진 개발 이야기 하나둘셋 야! 🔨 Refactor 꾸준한 개선이 더 나은 애플리케이션을 만든다 labels Sep 26, 2023
@splitCoding splitCoding self-assigned this Sep 26, 2023
@github-actions
Copy link

github-actions bot commented Sep 26, 2023

Unit Test Results

  84 files    84 suites   12s ⏱️
318 tests 318 ✔️ 0 💤 0
321 runs  321 ✔️ 0 💤 0

Results for commit 62521fe.

♻️ This comment has been updated with latest results.


private Member findMemberThrowIfNotExist(final Long memberId) {
return memberRepository.findById(memberId)
.orElseThrow(MemberNotExistException::new);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MemberException.MemberNotExistException 과 같이 바꿔주세요~!

Comment on lines +58 to +59
final Map<String, String> errorProperties = Map.of("VotingSongId", String.valueOf(votingSongId));
return new VotingSongException.VotingSongNotExistException(errorProperties);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💬 예외를 던질 때, 바로 Map을 주입했던 기존 코드에서는 어떤 식으로 예외를 던지는지 한 번 더 들어가봐야 되더라구요. 그래서 변수를 한 번 추출했습니다.

베로 의견) 통일성이 조금 깨지는 것 같습니다.


private boolean isMemberSamePartExist(final VotingSongPart votingSongPart) {
return votingSongPartRepository.existsByVotingSongAndMemberAndStartSecondAndLength(
votingSongPart.getVotingSong(),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

파라미터로 VotingSong을 받아오는 것이 나을 것 같아요. -> VotingSongPart의 getVotingSong NONE으로 설정합시다!

@@ -48,7 +48,6 @@ public class VotingSongPart {

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "voting_song_id", foreignKey = @ForeignKey(name = "none"), updatable = false, nullable = false)
@Getter(AccessLevel.NONE)
private VotingSong votingSong;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

위 코멘트와 동일한 내용입니다

Copy link
Collaborator

@Cyma-s Cyma-s left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

간단한 리뷰 남겨봤씁니다!
시간 되실 때 반영해주세요 :) 크지 않은 변경 사항이라 Approve 하겠습니다!

.contentType(ContentType.JSON)
.body(request)
.header("Authorization", "Bearer " + accessToken)
.when().log().all().post("/voting-songs/" + votingSong.getId() + "/parts")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

post("/voting-songs/{songId}/parts", votingSong.getId()) 로 적어도 동일하게 작동했던 것 같아요!

}

private void voteToExistPart(final VotingSong votingSong, final VotingSongPart votingSongPart) {
private boolean isMemberSameVoteExist(final Member member, final VotingSongPart votingSongPart) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

existSameVoteByMember 라는 메서드 이름은 어떤가요?

@@ -27,8 +29,15 @@ public interface VotingSongPartApi {
description = "파트 수집 중인 노래의 id",
required = true
)
@Parameter(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

굿굿 👍👍👍👍👍

final boolean isVoteExist = voteRepository.existsByMemberAndVotingSongPart(member, votingSongPart);

//then
Assertions.assertThat(isVoteExist).isTrue();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assertthat static import 해주세요!!

RestAssured.given().log().all()
.contentType(ContentType.JSON)
.body(request)
.header("Authorization", "Bearer " + accessToken)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HttpHeaders.AUTHORIZATION 를 사용해보는 건 어떨까요?

RestAssured.given().log().all()
.contentType(ContentType.JSON)
.body(request)
.header("Authorization", "Bearer " + accessToken)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Copy link
Collaborator

@somsom13 somsom13 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

베로가 다 리뷰를 남겨주기도 했고 의도한 로직대로 돌아가는 것 같아서 approve 합니다~

@Autowired
private VotingSongPartRepository votingSongPartRepository;

@Autowired
private VotingSongRepository votingSongRepository;
private static VotingSong SAVED_SONG;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이거 위의 필드랑 한 줄만 뛰고, static을 일반 필드보다 위로 올리면 더 깔끔할 것 같습니다 ㅎㅎ

@splitCoding splitCoding merged commit 77b5dd8 into main Sep 27, 2023
@splitCoding splitCoding deleted the refactor/#461 branch September 27, 2023 10:19
@splitCoding splitCoding restored the refactor/#461 branch September 27, 2023 10:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[ 🌙 BE ] 백엔드 크루들의 멋진 개발 이야기 하나둘셋 야! 🔨 Refactor 꾸준한 개선이 더 나은 애플리케이션을 만든다
Projects
Status: Done
3 participants