Skip to content
Merged
Show file tree
Hide file tree
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
Expand Up @@ -7,13 +7,12 @@
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Component;

import com.querydsl.core.Tuple;

import kernel360.trackycore.core.common.exception.ErrorCode;
import kernel360.trackycore.core.common.exception.GlobalException;
import kernel360.trackycore.core.domain.entity.QRentEntity;
import kernel360.trackycore.core.domain.entity.BizEntity;
import kernel360.trackycore.core.domain.entity.RentEntity;
import kernel360.trackycore.core.domain.entity.enums.RentStatus;
import kernel360.trackycore.core.infrastructure.repository.BizRepository;
import kernel360.trackyweb.car.infrastructure.repository.CarDomainRepository;
import kernel360.trackyweb.rent.application.dto.request.RentSearchByFilterRequest;
import kernel360.trackyweb.rent.application.dto.response.OverlappingRentResponse;
Expand All @@ -27,6 +26,7 @@ public class RentDomainProvider {

private final RentDomainRepository rentDomainRepository;
private final CarDomainRepository carDomainRepository;
private final BizRepository bizRepository;

public RentEntity save(RentEntity rent) {
return rentDomainRepository.save(rent);
Expand All @@ -37,6 +37,7 @@ public Long count() {
}

public Page<RentEntity> searchRentByFilter(RentSearchByFilterRequest request, String bizUuid) {

return rentDomainRepository.searchRentByFilter(request, bizUuid);
}

Expand All @@ -53,8 +54,10 @@ public Long getTotalRentDurationInMinutes() {
}

public void softDelete(String rentUuid) {

RentEntity rent = rentDomainRepository.findByRentUuid(rentUuid)
.orElseThrow(() -> GlobalException.throwError(ErrorCode.RENT_NOT_FOUND));

rent.updateStatus(RentStatus.DELETED);
}

Expand All @@ -71,11 +74,10 @@ public void validateOverlappingRent(String mdn, LocalDateTime rentStime, LocalDa
}

public List<RentMdnResponse> getRentableMdnList(String bizUuid) {
List<Tuple> tuples = rentDomainRepository.findRentableMdn(bizUuid);
return tuples.stream().map(tuple -> {
return new RentMdnResponse(tuple.get(QRentEntity.rentEntity.car.mdn),
tuple.get(QRentEntity.rentEntity.car.status));
}).toList();
}

BizEntity biz = bizRepository.findByBizUuid(bizUuid)
.orElseThrow(() -> GlobalException.throwError(ErrorCode.BIZ_NOT_FOUND));

return rentDomainRepository.findRentableMdn(biz.getId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@

import org.springframework.data.domain.Page;

import com.querydsl.core.Tuple;

import kernel360.trackycore.core.domain.entity.RentEntity;
import kernel360.trackyweb.rent.application.dto.request.RentSearchByFilterRequest;
import kernel360.trackyweb.rent.application.dto.response.RentMdnResponse;

public interface RentRepositoryCustom {
Page<RentEntity> searchRentByFilter(RentSearchByFilterRequest request, String bizUuid);

List<Tuple> findRentableMdn(String bizUuid);
List<RentMdnResponse> findRentableMdn(Long bizId);

List<RentEntity> findDelayedRents(String bizUuid, LocalDateTime now);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import org.springframework.stereotype.Repository;

import com.querydsl.core.BooleanBuilder;
import com.querydsl.core.Tuple;
import com.querydsl.core.types.Projections;
import com.querydsl.jpa.impl.JPAQuery;
import com.querydsl.jpa.impl.JPAQueryFactory;

Expand All @@ -22,6 +22,7 @@
import kernel360.trackycore.core.domain.entity.enums.CarStatus;
import kernel360.trackycore.core.domain.entity.enums.RentStatus;
import kernel360.trackyweb.rent.application.dto.request.RentSearchByFilterRequest;
import kernel360.trackyweb.rent.application.dto.response.RentMdnResponse;
import lombok.RequiredArgsConstructor;

@Repository
Expand Down Expand Up @@ -60,14 +61,18 @@ public Page<RentEntity> searchRentByFilter(RentSearchByFilterRequest request, St
}

@Override
public List<Tuple> findRentableMdn(String bizUuid) {
public List<RentMdnResponse> findRentableMdn(Long bizId) {

return queryFactory
.select(rentEntity.car.mdn, rentEntity.car.status)
.select(
Projections.constructor(
RentMdnResponse.class,
rentEntity.car.mdn, rentEntity.car.status
))
.distinct()
.from(rentEntity)
.where(
rentEntity.car.biz.bizUuid.eq(bizUuid),
rentEntity.car.biz.id.eq(bizId),
rentEntity.car.status.ne(CarStatus.CLOSED),
rentEntity.car.status.ne(CarStatus.DELETED)
)
Expand Down