Skip to content

Commit

Permalink
schedule first
Browse files Browse the repository at this point in the history
  • Loading branch information
Marc Gorzala committed Mar 28, 2024
1 parent 5ce9645 commit 375ca11
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package net.dancier.kikeriki.adapter.out.infomail;

import net.dancier.kikeriki.application.port.ScheduleInfomailCheckPort;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Component
public class InfomailAdapter implements ScheduleInfomailCheckPort {

Logger log = LoggerFactory.getLogger(InfomailAdapter.class);

@Override
public void schedule(LocalDateTime when, String dancerId) {
log.info("Scheduling check!!!");
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import lombok.RequiredArgsConstructor;
import net.dancier.kikeriki.application.domain.model.messages.EmailSendingRequestedCommand;
import net.dancier.kikeriki.application.port.DancierSendMailPort;
import net.dancier.kikeriki.application.port.SendMailPort;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
Expand All @@ -11,9 +11,9 @@

@RequiredArgsConstructor
@Component
public class DancierSendMailAdapter implements DancierSendMailPort {
public class SendMailAdapter implements SendMailPort {

public static final Logger log = LoggerFactory.getLogger(DancierSendMailAdapter.class);
public static final Logger log = LoggerFactory.getLogger(SendMailAdapter.class);

public final MailOutboxJpaRepository mailOutboxJpaRepository;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

import lombok.RequiredArgsConstructor;
import net.dancier.kikeriki.application.domain.model.messages.EmailSendingRequestedCommand;
import net.dancier.kikeriki.application.port.DancierSendMailPort;
import net.dancier.kikeriki.application.port.SendMailPort;
import net.dancier.kikeriki.application.port.ScheduleInfomailCheckPort;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.event.EventListener;
Expand All @@ -14,7 +15,7 @@ public class EmailSendingRequestedApplicationEventListener {

private final static Logger log = LoggerFactory.getLogger(EmailSendingRequestedApplicationEventListener.class);

private final DancierSendMailPort sendMailPort;
private final SendMailPort sendMailPort;

@EventListener
public void handle(EmailSendingRequestedCommand command) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
package net.dancier.kikeriki.application;

import jakarta.transaction.Transactional;
import lombok.RequiredArgsConstructor;
import net.dancier.kikeriki.application.domain.model.messages.MessagePostedEvent;
import net.dancier.kikeriki.application.domain.model.messages.MessageReadEvent;
import net.dancier.kikeriki.application.domain.model.state.State;
import net.dancier.kikeriki.application.domain.model.state.UnreadChatMessage;
import net.dancier.kikeriki.application.port.ScheduleInfomailCheckPort;
import net.dancier.kikeriki.application.port.StatePort;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.time.temporal.TemporalAmount;
import java.time.temporal.TemporalField;

@RequiredArgsConstructor
@Component
public class InfoMailRelatedApplicationEventListener {
Expand All @@ -19,13 +25,16 @@ public class InfoMailRelatedApplicationEventListener {

private final StatePort statePort;

private final ScheduleInfomailCheckPort scheduleInfomailCheckPort;

@EventListener
@Transactional
public void handle(MessagePostedEvent messagePostedEvent) {
for (String recipientId: messagePostedEvent.getRecipients()) {
State state = statePort.get(recipientId);
state.addUnreadChatMessage(UnreadChatMessage.of(messagePostedEvent.getMessageId(), messagePostedEvent.getCreatedAt()));
scheduleInfomailCheckPort.schedule(LocalDateTime.now().plusMinutes(30),recipientId);
statePort.save(state.toDto(),recipientId);
// schedule check in 30 minutes
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.time.LocalDateTime;

public interface ScheduleInfomailCheck {
public interface ScheduleInfomailCheckPort {
void schedule(LocalDateTime when, String dancerId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import net.dancier.kikeriki.application.domain.model.messages.EmailSendingRequestedCommand;

public interface DancierSendMailPort {
public interface SendMailPort {

void schedule(EmailSendingRequestedCommand emailSendingRequestedCommand);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package net.dancier.kikeriki;

import net.dancier.kikeriki.adapter.out.mail.MailOutboxJpaEntity;
import net.dancier.kikeriki.adapter.out.mail.MailOutboxJpaRepository;
import net.dancier.kikeriki.application.domain.model.messages.EmailSendingRequestedCommand;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -11,15 +9,12 @@
import org.springframework.mail.javamail.JavaMailSender;

import java.time.Duration;
import java.util.List;
import java.util.UUID;

import static org.assertj.core.api.Assertions.assertThat;
import static org.awaitility.Awaitility.await;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;


class SchedulingAndSendingMailWorks extends NeededInfrastructureBaseTestClass {

@Autowired
Expand Down

0 comments on commit 375ca11

Please sign in to comment.