Skip to content

Commit

Permalink
Merge pull request #425 from UPbrella/dev
Browse files Browse the repository at this point in the history
�v1.3.2 release-dev
  • Loading branch information
birdieHyun authored Dec 19, 2023
2 parents 463d70d + 1a3024d commit ab47a38
Showing 1 changed file with 16 additions and 20 deletions.
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();
}

}

0 comments on commit ab47a38

Please sign in to comment.