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

v1.3.2 release #426

Merged
merged 1 commit into from
Dec 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
package upbrella.be.store.repository;

import com.querydsl.jpa.JPAExpressions;
import com.querydsl.jpa.impl.JPAQueryFactory;
import lombok.RequiredArgsConstructor;
import upbrella.be.store.dto.response.QStoreMetaWithUmbrellaCount;
import upbrella.be.store.dto.response.StoreMetaWithUmbrellaCount;
import upbrella.be.store.entity.QStoreMeta;
import upbrella.be.umbrella.entity.QUmbrella;

import java.util.List;

import static upbrella.be.store.entity.QBusinessHour.businessHour;
import static upbrella.be.store.entity.QClassification.classification;
import static upbrella.be.store.entity.QStoreMeta.storeMeta;
import static upbrella.be.umbrella.entity.QUmbrella.umbrella;

@RequiredArgsConstructor
public class StoreMetaRepositoryImpl implements StoreMetaRepositoryCustom {
Expand All @@ -20,24 +19,21 @@ public class StoreMetaRepositoryImpl implements StoreMetaRepositoryCustom {
@Override
public List<StoreMetaWithUmbrellaCount> findAllStoresByClassification(long classificationId) {

QStoreMetaWithUmbrellaCount storeMetaWithUmbrellaCount = new QStoreMetaWithUmbrellaCount(
storeMeta,
umbrella.id.countDistinct().as("rentableUmbrellasCount")
);

QStoreMeta storeMeta = QStoreMeta.storeMeta;
QUmbrella umbrella = QUmbrella.umbrella;

return queryFactory
.select(storeMetaWithUmbrellaCount)
.from(umbrella)
.rightJoin(umbrella.storeMeta, storeMeta)
.leftJoin(storeMeta.classification, classification).fetchJoin()
.where(storeMeta.deleted.eq(false)
.and(storeMeta.classification.id.eq(classificationId))
.and(umbrella.rentable.eq(true))
.and(umbrella.missed.eq(false))
.and(umbrella.deleted.eq(false)))
.distinct()
.groupBy(storeMeta)
.select(new QStoreMetaWithUmbrellaCount(
storeMeta,
JPAExpressions.select(umbrella.count())
.from(umbrella)
.where(umbrella.storeMeta.id.eq(storeMeta.id),
umbrella.rentable.isTrue(),
umbrella.missed.isFalse(),
umbrella.deleted.isFalse())))
.from(storeMeta)
.where(storeMeta.classification.id.eq(classificationId))
.fetch();
}

}