Skip to content

Backend Dependency Kotlin Chase #11

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

Open
wants to merge 7 commits 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.staffinghub.coding.challenges.dependency.inquiry

import org.springframework.context.ApplicationEvent

/**
* This class represents an event that is triggered when an inquiry is created.
*/
class InquiryCreatedEvent(source: Any, val inquiry: Inquiry) : ApplicationEvent(source)
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,26 @@ package com.staffinghub.coding.challenges.dependency.inquiry

import mu.KotlinLogging
import org.springframework.stereotype.Component
import org.springframework.context.ApplicationEventPublisher

private val logger = KotlinLogging.logger {}

/**
* This class represents a service responsible for creating inquiries and publishing an event when an inquiry is created.
*/
@Component
class InquiryService {
class InquiryService(private val applicationEventPublisher: ApplicationEventPublisher) {

/**
* Creates an inquiry and publishes an event for the newly created inquiry.
*
* @param inquiry The Inquiry object representing the inquiry to be created.
*/
fun create(inquiry: Inquiry) {
logger.info {
"User sent inquiry: $inquiry"
}
applicationEventPublisher.publishEvent(InquiryCreatedEvent(this, inquiry))
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.staffinghub.coding.challenges.dependency.notifications
import com.staffinghub.coding.challenges.dependency.inquiry.Inquiry
import com.staffinghub.coding.challenges.dependency.inquiry.InquiryCreatedEvent
import org.springframework.context.event.EventListener
import org.springframework.stereotype.Component

/**
* This class is responsible for handling the creation of inquiries and triggering appropriate actions such as sending
* emails and push notifications.
*/
@Component
class InquiryCreatedEventListener(
private val emailHandler: EmailHandler,
private val pushNotificationHandler: PushNotificationHandler
) {

/**
* Listens to the InquiryCreatedEvent and handles it by sending an email and a push notification for the newly
* created inquiry.
*
* @param event The InquiryCreatedEvent object representing the event triggered upon inquiry creation.
*/
@EventListener
fun handleInquiryCreatedEvent(event: InquiryCreatedEvent) {
val inq: Inquiry = event.inquiry

emailHandler.sendEmail(inq)
pushNotificationHandler.sendNotification(inq)
}
}