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 #184] 채팅 자동 거절 시 수정일 미변경 해결 #188

Merged
merged 12 commits into from
Jan 13, 2025
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
@@ -1,5 +1,6 @@
package com.dnd.gongmuin.chat_inquiry.repository;

import java.time.LocalDateTime;
import java.util.List;

import org.springframework.data.domain.Pageable;
Expand All @@ -14,7 +15,7 @@ public interface ChatInquiryQueryRepository {

List<Long> getAutoRejectedInquirerIds();

void updateChatInquiryStatusRejected();
void updateChatInquiryStatusRejected(LocalDateTime now);

List<RejectedChatInquiryDto> getAutoRejectedChatInquiries();
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,10 @@ public List<RejectedChatInquiryDto> getAutoRejectedChatInquiries() {
.fetch();
}

public void updateChatInquiryStatusRejected() {
public void updateChatInquiryStatusRejected(LocalDateTime now) {
queryFactory.update(chatInquiry)
.set(chatInquiry.status, InquiryStatus.REJECTED)
.set(chatInquiry.updatedAt, now)
.where(
chatInquiry.createdAt.loe(LocalDateTime.now().minusWeeks(1)),
chatInquiry.status.eq(InquiryStatus.PENDING)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.dnd.gongmuin.chat_inquiry.scheduler;

import java.time.LocalDateTime;

import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -17,6 +19,6 @@ public class ChatInquiryScheduler {
@Transactional
@Scheduled(cron = "0 0 0 * * *", zone = "Asia/Seoul")
public void rejectChatInquiry() {
chatInquiryService.rejectChatAuto();
chatInquiryService.rejectChatAuto(LocalDateTime.now());
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.dnd.gongmuin.chat_inquiry.service;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Objects;

Expand Down Expand Up @@ -132,10 +133,10 @@ public RejectChatResponse rejectChat(Long chatInquiryId, Member answerer) {
}

@Transactional
public void rejectChatAuto() {
public void rejectChatAuto(LocalDateTime now) {
List<RejectedChatInquiryDto> rejectedChatInquiryDtos = chatInquiryRepository.getAutoRejectedChatInquiries();
List<Long> rejectedInquirerIds = getRejectedInquirerIds(rejectedChatInquiryDtos);
chatInquiryRepository.updateChatInquiryStatusRejected();
chatInquiryRepository.updateChatInquiryStatusRejected(now);
memberRepository.refundInMemberIds(rejectedInquirerIds, CHAT_REWARD);
creditHistoryService.saveCreditHistoryInMemberIds(
rejectedInquirerIds, CreditType.CHAT_REFUND, CHAT_REWARD
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.dnd.gongmuin.question_post.repository;

import java.time.LocalDateTime;
import java.util.List;

import org.springframework.data.domain.Pageable;
Expand All @@ -23,5 +24,5 @@ Slice<RecQuestionPostResponse> getRecommendQuestionPosts(

List<RefundQuestionPostDto> getRefundQuestionPostDtos();

void updateQuestionPostStatusAnswerClosed();
void updateQuestionPostStatusAnswerClosed(LocalDateTime now);
}
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,11 @@ public List<RefundQuestionPostDto> getRefundQuestionPostDtos() {
}

@Override
public void updateQuestionPostStatusAnswerClosed() {
public void updateQuestionPostStatusAnswerClosed(LocalDateTime now) {
queryFactory
.update(questionPost)
.set(questionPost.status, QuestionPostStatus.ANSWER_CLOSED)
.set(questionPost.updatedAt, now)
hyun2371 marked this conversation as resolved.
Show resolved Hide resolved
.where(
questionPost.createdAt.loe(LocalDateTime.now().minusWeeks(2)),
questionPost.status.eq(QuestionPostStatus.ANSWER_WAITING)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.dnd.gongmuin.question_post.scheduler;

import java.time.LocalDateTime;

import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
Expand All @@ -17,6 +19,6 @@ public class QuestionPostScheduler {
@Transactional
@Scheduled(cron = "0 0 0 * * *", zone = "Asia/Seoul")
public void closeQuestionPost() {
questionPostService.changeQuestionPostStatusAnswerClosed();
questionPostService.changeQuestionPostStatusAnswerClosed(LocalDateTime.now());
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.dnd.gongmuin.question_post.service;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Objects;

Expand Down Expand Up @@ -155,8 +156,8 @@ private void validateIfQuestionPostExists(Long questionPostId) {
}
}

private void validateIfQuestioner(Member member, QuestionPost questionPost){
if (!Objects.equals(member.getId(), questionPost.getMember().getId())){
private void validateIfQuestioner(Member member, QuestionPost questionPost) {
if (!Objects.equals(member.getId(), questionPost.getMember().getId())) {
throw new ValidationException(QuestionPostErrorCode.NOT_AUTHORIZED);
}
}
Expand All @@ -179,9 +180,9 @@ private int getCountByType(Long questionPostId, InteractionType type) {
}

@Transactional
public void changeQuestionPostStatusAnswerClosed() {
public void changeQuestionPostStatusAnswerClosed(LocalDateTime now) {
refundClosedQuestionPosts();
questionPostRepository.updateQuestionPostStatusAnswerClosed();
questionPostRepository.updateQuestionPostStatusAnswerClosed(now);
}

private void refundDeletedQuestionPost(QuestionPost questionPost) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ void updateChatInquiryStatusRejected() {
ReflectionTestUtils.setField(chatInquiries.get(0), "createdAt", LocalDateTime.now().minusWeeks(1));

//when
chatInquiryRepository.updateChatInquiryStatusRejected();
chatInquiryRepository.updateChatInquiryStatusRejected(LocalDateTime.now());

em.flush();
em.clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.BDDMockito.*;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;

Expand Down Expand Up @@ -323,6 +324,8 @@ void rejectChatWithEventPublish() {
@Test
void rejectChatAuto() {
// given
final LocalDateTime now = LocalDateTime.now();

List<RejectedChatInquiryDto> rejectedChatInquiryDtos = List.of(
new RejectedChatInquiryDto(1L, MemberFixture.member(1L), MemberFixture.member(2L)),
new RejectedChatInquiryDto(2L, MemberFixture.member(3L), MemberFixture.member(4L))
Expand All @@ -334,11 +337,11 @@ void rejectChatAuto() {
given(chatInquiryRepository.getAutoRejectedChatInquiries()).willReturn(rejectedChatInquiryDtos);

// when
chatInquiryService.rejectChatAuto();
chatInquiryService.rejectChatAuto(now);

// then
verify(chatInquiryRepository).getAutoRejectedChatInquiries();
verify(chatInquiryRepository).updateChatInquiryStatusRejected();
verify(chatInquiryRepository).updateChatInquiryStatusRejected(now);
verify(memberRepository).refundInMemberIds(rejectedInquirerIds, CHAT_REWARD);
verify(creditHistoryService).saveCreditHistoryInMemberIds(
rejectedInquirerIds, CreditType.CHAT_REFUND, CHAT_REWARD
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ void getAutoChangeStatus() {
ReflectionTestUtils.setField(questionPost3, "createdAt", LocalDateTime.now().minusWeeks(2));

// when
questionPostRepository.updateQuestionPostStatusAnswerClosed();
questionPostRepository.updateQuestionPostStatusAnswerClosed(LocalDateTime.now());

em.flush();
em.clear();
Expand Down
Loading