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

fix(.plan): 리마인드 메세지 정보 조회 시 프록시 오류 발생 문제 수정 #187

Closed
wants to merge 1 commit into from
Closed
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
@@ -0,0 +1,51 @@
package me.ajaja.module.plan.adapter.out.persistence;

import static me.ajaja.module.plan.adapter.out.persistence.model.QPlanEntity.*;
import static me.ajaja.module.user.adapter.out.persistence.model.QUserEntity.*;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.querydsl.core.types.dsl.BooleanExpression;
import com.querydsl.jpa.impl.JPAQueryFactory;

import lombok.RequiredArgsConstructor;
import me.ajaja.global.common.TimeValue;
import me.ajaja.module.plan.application.port.out.FindRemindablePlanPort;
import me.ajaja.module.plan.domain.RemindDate;
import me.ajaja.module.plan.mapper.PlanMapper;
import me.ajaja.module.remind.application.model.RemindMessageInfo;

@Repository
@RequiredArgsConstructor
public class FindRemindablePlanAdapter implements FindRemindablePlanPort {
private final JPAQueryFactory queryFactory;
private final PlanMapper planMapper;

@Override
public List<RemindMessageInfo> findAllPlansByTime(String remindTime, String remindType, TimeValue time) {
return queryFactory.select(planEntity, userEntity.remindEmail, userEntity.phoneNumber,
userEntity.remindType)
.from(planEntity)
.join(userEntity).on(userEntity.id.eq(planEntity.userId))
.where(planEntity.canRemind
.and(userEntity.deleted.isFalse())
.and(planEntity.remindTime.eq(remindTime).and(isRemindable(time)))
.and(userEntity.remindType.eq(remindType).or(userEntity.remindType.eq("BOTH")))
)
.fetch().stream()
.map(t -> planMapper.toModel(
t.get(planEntity),
t.get(userEntity.remindType),
t.get(userEntity.remindEmail),
t.get(userEntity.phoneNumber)))
.toList();
}

private BooleanExpression isRemindable(TimeValue time) {
RemindDate today = new RemindDate(time.getMonth(), time.getDate());
return planEntity.createdAt.year().eq(time.getYear())
.andAnyOf(planEntity.messages.any().remindDate.eq(today));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package me.ajaja.module.plan.application.port.out;

import java.util.List;

import me.ajaja.global.common.TimeValue;
import me.ajaja.module.remind.application.model.RemindMessageInfo;

public interface FindRemindablePlanPort {
List<RemindMessageInfo> findAllPlansByTime(String remindTime, String remindType, TimeValue time);
}
Original file line number Diff line number Diff line change
@@ -1,53 +1,28 @@
package me.ajaja.module.remind.adapter.out.persistence;

import static me.ajaja.module.plan.adapter.out.persistence.model.QPlanEntity.*;
import static me.ajaja.module.user.adapter.out.persistence.model.QUserEntity.*;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.querydsl.core.types.dsl.BooleanExpression;
import com.querydsl.jpa.impl.JPAQueryFactory;
import org.springframework.transaction.annotation.Transactional;

import lombok.RequiredArgsConstructor;
import me.ajaja.global.common.TimeValue;
import me.ajaja.module.plan.domain.RemindDate;
import me.ajaja.module.plan.mapper.PlanMapper;
import me.ajaja.module.plan.application.port.out.FindRemindablePlanPort;
import me.ajaja.module.remind.application.port.out.FindRemindableTargetPort;
import me.ajaja.module.remind.domain.Remind;
import me.ajaja.module.remind.mapper.RemindMapper;

@Repository
@Transactional(readOnly = true)
@RequiredArgsConstructor
public class FindRemindableTargetAdapter implements FindRemindableTargetPort {
private final JPAQueryFactory queryFactory;
private final PlanMapper planMapper;
private final FindRemindablePlanPort findRemindablePlanPort;
private final RemindMapper mapper;

@Override
public List<Remind> findAllRemindablePlan(String remindTime, String remindType, TimeValue time) {
return queryFactory.select(planEntity, userEntity.remindEmail, userEntity.phoneNumber,
userEntity.remindType)
.from(planEntity)
.join(userEntity).on(userEntity.id.eq(planEntity.userId))
.where(planEntity.canRemind
.and(planEntity.remindTime.eq(remindTime).and(isRemindable(time)))
.and(userEntity.remindType.eq(remindType).or(userEntity.remindType.eq("BOTH")))
)
.fetch().stream()
.map(t -> planMapper.toModel(
t.get(planEntity),
t.get(userEntity.remindType),
t.get(userEntity.remindEmail),
t.get(userEntity.phoneNumber)))
return findRemindablePlanPort.findAllPlansByTime(remindTime, remindType, time).stream()
.map(info -> mapper.toDomain(info, time))
.toList();
}

private BooleanExpression isRemindable(TimeValue time) {
RemindDate today = new RemindDate(time.getMonth(), time.getDate());
return planEntity.createdAt.year().eq(time.getYear())
.andAnyOf(planEntity.messages.any().remindDate.eq(today));
}
}
Loading