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

Dependency solution #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
5 changes: 4 additions & 1 deletion Backend/dependency/inquiry/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@ sourceCompatibility = 1.8
repositories { mavenCentral() }

dependencies {
implementation 'org.projectlombok:lombok:1.18.26'
compile('org.springframework.boot:spring-boot-starter')
testCompile('org.springframework.boot:spring-boot-starter-test')
}

dependencyManagement {
imports { mavenBom("org.springframework.boot:spring-boot-dependencies:${springBootVersion}") }
imports {
mavenBom("org.springframework.boot:spring-boot-dependencies:${springBootVersion}")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.staffinghub.coding.challenges.dependency.inquiry;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.util.Date;

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class CreateInquiryEvent {
private Date date;
private Inquiry inquiry;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,31 @@

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
* The inquiry service is used to create new inquiries.
*/
@Component
public class InquiryService {

private final ApplicationEventPublisher events;

private static final Logger LOG = LoggerFactory.getLogger(InquiryService.class);

public InquiryService(ApplicationEventPublisher events) {
this.events = events;
}

/**
* Create a new inquiry.
* @param inquiry incoming inquiry to create of type {@link Inquiry}
*/
public void create(final Inquiry inquiry) {
LOG.info("User sent inquiry: {}", inquiry);
events.publishEvent(new CreateInquiryEvent(new Date(), inquiry));
}

}
}
17 changes: 14 additions & 3 deletions Backend/dependency/notifications/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
buildscript {
repositories { mavenCentral() }
repositories {
mavenCentral()
maven {
url "https://repo.spring.io/milestone/"
}
}
}

plugins { id "io.spring.dependency-management" version "1.0.5.RELEASE" }
Expand All @@ -14,14 +19,20 @@ jar {
}
sourceCompatibility = 1.8

repositories { mavenCentral() }
repositories { mavenCentral()
maven {
url "https://repo.spring.io/milestone/"
}}

dependencies {
implementation 'org.projectlombok:lombok:1.18.26'
compile project(":inquiry")
compile('org.springframework.boot:spring-boot-starter')
testCompile('org.springframework.boot:spring-boot-starter-test')
}

dependencyManagement {
imports { mavenBom("org.springframework.boot:spring-boot-dependencies:${springBootVersion}") }
imports {
mavenBom("org.springframework.boot:spring-boot-dependencies:${springBootVersion}")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.staffinghub.coding.challenges.dependency.notifications;

import com.staffinghub.coding.challenges.dependency.inquiry.CreateInquiryEvent;
import com.staffinghub.coding.challenges.dependency.inquiry.InquiryService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/**
* Notification service sends email and push notifications based off of incoming events.
*/
@Component
public class NotificationService {

private EmailHandler emailHandler;
private PushNotificationHandler pushNotificationHandler;
private static final Logger LOG = LoggerFactory.getLogger(InquiryService.class);

public NotificationService(EmailHandler emailHandler, PushNotificationHandler pushNotificationHandler) {
this.emailHandler = emailHandler;
this.pushNotificationHandler = pushNotificationHandler;
}

/**
* Process create Inquiry event to send emails and push notifications.
* @param event incoming Inquiry event of type {@link CreateInquiryEvent}
*/
@Async
@EventListener
public void notificationEvent(CreateInquiryEvent event) {
LOG.info("Received notification by event for inquiry {} in date {}.",
event.getInquiry(),
event.getDate());
emailHandler.sendEmail(event.getInquiry());
pushNotificationHandler.sendNotification(event.getInquiry());
}
}