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

🚀 좋아요 요청 및 취소 기능 작성 #55

Merged
merged 14 commits into from
Jan 9, 2024
Merged

Conversation

shoeone96
Copy link
Collaborator

✅ 요구사항

  • 좋아요 요청 및 취소 api 작성
  • 좋아요 기능 test 코드 작성

🚀 주요 변경사항

  • api 추가
    • api 요청 시 처음 좋아요를 누르면 좋아요 객체를 생성, 두 번째 이후부터는 좋아요의 status를 수정하는 방식으로 적용
    • LikeController 생성
      • LikeRequest 생성
      • LikeResponse 생성
    • LikeService 생성
    • LikeRepository 생성
    • Like entity class 생성
  • 상황별로 발생할 수 있는 test 코드 작성
    • LikeControllerTest
    • LikeServiceTest
    • LikeRepositoryTest

💡 기타사항

  • 추후 like count와 isLike 여부를 post에 담아 보내줄 수 있게 refactoring 예정
  • 동시성 문제가 likeCount를 Post table에 넣고 업데이트 할 때 발생하는데 현재의 로직(매 요청 시 like table에서 like count를 읽는)에서는 발생하지 않을 것으로 짐작됨

Copy link

github-actions bot commented Jan 8, 2024

📑 Jacoco 테스트 결과

Overall Project 96.49% -0.22% 🍏
Files changed 96.62% 🍏

File Coverage
LikeRequest.java 100% 🍏
LikeResponse.java 100% 🍏
LikeController.java 100% 🍏
Like.java 100% 🍏
LikeService.java 92.65% -7.35% 🍏

Copy link
Member

@Sehee-Lee-01 Sehee-Lee-01 left a comment

Choose a reason for hiding this comment

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

깔끔하게 작성해주셔서 보기 편했던 것 같습니다! 몇 개 코맨트만 남겨놓았습니다!


@ParameterizedTest
@NullSource
@DisplayName("post가 null 인 경우 좋아요 객체를 생성 시 예외가 발생한다.")
Copy link
Member

Choose a reason for hiding this comment

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

DisplayName에 post가 아니라 user가 들어가야하는 것 같습니다!

}

private WeatherDto weatherDtoGenerator() {
return new WeatherDto(0.0, -10.0, 10.0, 1, 1);
Copy link
Member

Choose a reason for hiding this comment

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

weatherDtoGenerator() 중복 줄이기에 좋은 것 같습니다👍
post 테스트 부분도 개선해보도록 하겠습니다!

혹시 저는 저 WeatherDto를 상수로 놓았는데 혹시 이 방법은 어떻게 생각하시나요? 수정 제안이 아니라 의견이 궁금해서 여쭤봅니다!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

혹시 다른 방법이 안보이는데 어디를 참고하면 될까요?

Copy link
Member

@Sehee-Lee-01 Sehee-Lee-01 Jan 9, 2024

Choose a reason for hiding this comment

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

앗 코드랑 같이 보여드릴 걸 그랬네요! 지금 수정 중인 코드에서 작성한 코드입니다!

    static final TemperatureArrangeDto TEMPERATURE_ARRANGE_DTO = new TemperatureArrangeDto(-10.0, 10.0);
    static final TemperatureArrange TEMPERATURE_ARRANGE = TemperatureArrange.from(TEMPERATURE_ARRANGE_DTO);

저는 이런 방식으로 작성을 해놓았습니다!

Copy link
Member

Choose a reason for hiding this comment

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

지금은 WeatherDto가 TemperatureArrangeDto로 이름이 변경되었습니다!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

괜찮은 방법인 것 같아 도입하고 push 했습니다!

Copy link
Member

@Sehee-Lee-01 Sehee-Lee-01 Jan 9, 2024

Choose a reason for hiding this comment

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

앗!!!!!! 이따가 이야기 나눠보죠,,전 중원님 방식도 괜찮은 것 같아서,,, 제 방식만 공유해본 것이엇는데 수정한다면 제가 맞추겠습니다!

Copy link

github-actions bot commented Jan 9, 2024

📑 Jacoco 테스트 결과

Overall Project 96.49% -0.22% 🍏
Files changed 96.62% 🍏

File Coverage
LikeRequest.java 100% 🍏
LikeResponse.java 100% 🍏
LikeController.java 100% 🍏
Like.java 100% 🍏
LikeService.java 92.65% -7.35% 🍏

Copy link

github-actions bot commented Jan 9, 2024

📑 Jacoco 테스트 결과

Overall Project 96.49% -0.22% 🍏
Files changed 96.62% 🍏

File Coverage
LikeRequest.java 100% 🍏
LikeResponse.java 100% 🍏
LikeController.java 100% 🍏
Like.java 100% 🍏
LikeService.java 92.65% -7.35% 🍏

Copy link

github-actions bot commented Jan 9, 2024

📑 Jacoco 테스트 결과

Overall Project 96.49% -0.22% 🍏
Files changed 96.62% 🍏

File Coverage
LikeRequest.java 100% 🍏
LikeResponse.java 100% 🍏
LikeController.java 100% 🍏
Like.java 100% 🍏
LikeService.java 92.65% -7.35% 🍏

Copy link
Collaborator

@ASak1104 ASak1104 left a comment

Choose a reason for hiding this comment

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

고생하셨습니다! 스타일만 조금 수정하면 좋을 것 같아요


private final LikeService likeService;

@PostMapping("")
Copy link
Collaborator

Choose a reason for hiding this comment

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

mapping이 별도로 필요 없으면 안쓰는 것도 좋을 것 같아요

Suggested change
@PostMapping("")
@PostMapping

import jakarta.validation.constraints.NotNull;

public record LikeRequest(
@Min(value = 1)
Copy link
Collaborator

Choose a reason for hiding this comment

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

@Positive를 쓰는 것도 좋을 것 같아요


@Transactional
public LikeResponse requestLike(Long userId, Long postId) {

Copy link
Collaborator

Choose a reason for hiding this comment

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

여기 개행은 없어도 될 것 같아요!

Comment on lines 42 to 43
static Faker faker = new Faker();
static final WeatherDto weatherDto = new WeatherDto(0.0, -10.0, 10.0, 1, 1);
Copy link
Collaborator

Choose a reason for hiding this comment

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

통일성을 위해 faker에도 final 키워드 쓰는 것도 좋을 것 같아요

Comment on lines +161 to +162


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

github-actions bot commented Jan 9, 2024

📑 Jacoco 테스트 결과

Overall Project 96.49% -0.22% 🍏
Files changed 96.62% 🍏

File Coverage
LikeRequest.java 100% 🍏
LikeResponse.java 100% 🍏
LikeController.java 100% 🍏
Like.java 100% 🍏
LikeService.java 92.65% -7.35% 🍏

@Sehee-Lee-01 Sehee-Lee-01 merged commit d9932a7 into feature Jan 9, 2024
1 check passed
@Sehee-Lee-01 Sehee-Lee-01 deleted the feature-like branch January 9, 2024 11:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants