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

[feat] 마이페이지 - 사용자가 제보한 가게 API #84

Merged
merged 8 commits into from
Jul 17, 2024

Conversation

PicturePark1101
Copy link
Contributor

@PicturePark1101 PicturePark1101 commented Jul 16, 2024

Related Issue 📌

close #59

Description ✔️

  • 마이페이지 - 사용자가 제보한 가게 API입니다.

To Reviewers

###작성한 JPQL

사용자의 report를 FK값 userId로 찾고, 연관된 store와 storeImage를 fetch join으로 가져왔습니다. 정렬은 생성일 내림차순으로 했습니다.

  @Query("select r from Report r join fetch r.store join fetch r.store.images where r.user.id = :userId and r.store.isDeleted = false order by r.createdAt desc")
  List<Report> findAllByUserIdWithStoreAndStoreImage(@Param("userId") Long userId);

service

유저가 서로 다른 대학에 같은 가게를 제보했을 경우 가게가 중복으로 나오기 때문에 distinct()를 통해 중복제거를 해주었습니다.

    @Transactional(readOnly = true)
    public UserStoresReportedGetResponse findUserStoreReported(final Long userId) {
        return UserStoresReportedGetResponse.of(reportFinder.findAllByUserId(userId).stream().map(Report::getStore).distinct().toList());
    }

실행쿼리

Hibernate: 
    select
        r1_0.report_id,
        r1_0.created_at,
        s1_0.store_id,
        s1_0.category,
        s1_0.created_at,
        s1_0.heart_count,
        i1_0.store_id,
        i1_0.store_image_id,
        i1_0.created_at,
        i1_0.image_url,
        s1_0.is_deleted,
        s1_0.lowest_price,
        s1_0.name,
        s1_0.latitude,
        s1_0.longitude,
        s1_0.updated_at,
        r1_0.university_id,
        r1_0.user_id 
    from
        report r1_0 
    join
        store s1_0 
            on s1_0.store_id=r1_0.store_id 
    join
        store_image i1_0 
            on s1_0.store_id=i1_0.store_id 
    where
        r1_0.user_id=? 
        and s1_0.is_deleted=false

@PicturePark1101 PicturePark1101 self-assigned this Jul 16, 2024
@PicturePark1101 PicturePark1101 changed the title [feat] 마이페이지 - 사용자가 제보한 API [feat] 마이페이지 - 사용자가 제보한 가게 API Jul 16, 2024
@@ -14,4 +15,8 @@ public class ReportFinder {
public long getReportCount() {
Copy link
Member

Choose a reason for hiding this comment

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

제 생각에는 long 보다는 int로 받는 것이 더 좋아보여요.


@Transactional(readOnly = true)
public UserStoresReportedGetResponse findUserStoreReported(final Long userId) {
return UserStoresReportedGetResponse.of(reportFinder.findAllByUserId(userId).stream().map(Report::getStore).distinct().toList());
Copy link
Member

Choose a reason for hiding this comment

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

hibernate 6 부터는 항상 distinct 가 적용된다고 합니다! distinct() 생략해도 될 것 같아요

@PicturePark1101 PicturePark1101 merged commit adaf0bd into develop Jul 17, 2024
1 check passed
@kgy1008 kgy1008 deleted the feat/59 branch December 2, 2024 05:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[feat] 사용자가 제보한 식당 화면 API
2 participants