From 5596e03481e338d7f373cb6d2d0bb30a4e749754 Mon Sep 17 00:00:00 2001 From: Chase Jordan Nel <123620591+Chase-Nel@users.noreply.github.com> Date: Tue, 18 Jul 2023 17:12:17 +0200 Subject: [PATCH 1/7] Added Created Events --- .../challenges/dependency/InquiryTest.kt | 1 - .../dependency/inquiry/InquiryService.kt | 3 +++ .../dependency/notifications/EmailHandler.kt | 1 + .../notifications/InquiryCreatedEvent.kt | 8 ++++++++ .../InquiryCreatedEventListener.kt | 18 ++++++++++++++++++ 5 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 Backend/dependency-kotlin/notifications/src/main/kotlin/com/staffinghub/coding/challenges/dependency/notifications/InquiryCreatedEvent.kt create mode 100644 Backend/dependency-kotlin/notifications/src/main/kotlin/com/staffinghub/coding/challenges/dependency/notifications/InquiryCreatedEventListener.kt diff --git a/Backend/dependency-kotlin/application/src/test/kotlin/com/staffinghub/coding/challenges/dependency/InquiryTest.kt b/Backend/dependency-kotlin/application/src/test/kotlin/com/staffinghub/coding/challenges/dependency/InquiryTest.kt index b4814f5..cf52fbb 100644 --- a/Backend/dependency-kotlin/application/src/test/kotlin/com/staffinghub/coding/challenges/dependency/InquiryTest.kt +++ b/Backend/dependency-kotlin/application/src/test/kotlin/com/staffinghub/coding/challenges/dependency/InquiryTest.kt @@ -17,7 +17,6 @@ import org.springframework.test.context.junit.jupiter.SpringExtension class InquiryTest( @Autowired private val inquiryService: InquiryService, ) { - @SpykBean lateinit var emailHandler: EmailHandler diff --git a/Backend/dependency-kotlin/inquiry/src/main/kotlin/com/staffinghub/coding/challenges/dependency/inquiry/InquiryService.kt b/Backend/dependency-kotlin/inquiry/src/main/kotlin/com/staffinghub/coding/challenges/dependency/inquiry/InquiryService.kt index c105fad..1daf8cc 100644 --- a/Backend/dependency-kotlin/inquiry/src/main/kotlin/com/staffinghub/coding/challenges/dependency/inquiry/InquiryService.kt +++ b/Backend/dependency-kotlin/inquiry/src/main/kotlin/com/staffinghub/coding/challenges/dependency/inquiry/InquiryService.kt @@ -2,15 +2,18 @@ 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 {} @Component + class InquiryService { fun create(inquiry: Inquiry) { logger.info { "User sent inquiry: $inquiry" } +// applicationEventPublisher.publishEvent(InquiryCreatedEvent(this, inquiry)) } } diff --git a/Backend/dependency-kotlin/notifications/src/main/kotlin/com/staffinghub/coding/challenges/dependency/notifications/EmailHandler.kt b/Backend/dependency-kotlin/notifications/src/main/kotlin/com/staffinghub/coding/challenges/dependency/notifications/EmailHandler.kt index e3fa7ee..5eb069c 100644 --- a/Backend/dependency-kotlin/notifications/src/main/kotlin/com/staffinghub/coding/challenges/dependency/notifications/EmailHandler.kt +++ b/Backend/dependency-kotlin/notifications/src/main/kotlin/com/staffinghub/coding/challenges/dependency/notifications/EmailHandler.kt @@ -6,6 +6,7 @@ import org.springframework.stereotype.Component private val logger = KotlinLogging.logger {} + @Component class EmailHandler { fun sendEmail(inquiry: Inquiry) { diff --git a/Backend/dependency-kotlin/notifications/src/main/kotlin/com/staffinghub/coding/challenges/dependency/notifications/InquiryCreatedEvent.kt b/Backend/dependency-kotlin/notifications/src/main/kotlin/com/staffinghub/coding/challenges/dependency/notifications/InquiryCreatedEvent.kt new file mode 100644 index 0000000..1b8e973 --- /dev/null +++ b/Backend/dependency-kotlin/notifications/src/main/kotlin/com/staffinghub/coding/challenges/dependency/notifications/InquiryCreatedEvent.kt @@ -0,0 +1,8 @@ +package com.staffinghub.coding.challenges.dependency.notifications + +import com.staffinghub.coding.challenges.dependency.inquiry.Inquiry +import org.springframework.context.ApplicationEvent + +class InquiryCreatedEvent(source: Any, val inquiry: Inquiry) : ApplicationEvent(source){ + +} diff --git a/Backend/dependency-kotlin/notifications/src/main/kotlin/com/staffinghub/coding/challenges/dependency/notifications/InquiryCreatedEventListener.kt b/Backend/dependency-kotlin/notifications/src/main/kotlin/com/staffinghub/coding/challenges/dependency/notifications/InquiryCreatedEventListener.kt new file mode 100644 index 0000000..990c7a2 --- /dev/null +++ b/Backend/dependency-kotlin/notifications/src/main/kotlin/com/staffinghub/coding/challenges/dependency/notifications/InquiryCreatedEventListener.kt @@ -0,0 +1,18 @@ +package com.staffinghub.coding.challenges.dependency.notifications +import org.springframework.context.event.EventListener +import org.springframework.stereotype.Component + +@Component +class InquiryCreatedEventListener( + private val emailHandler: EmailHandler, + private val pushNotificationHandler: PushNotificationHandler +) { + + @EventListener + fun handleInquiryCreatedEvent(event: InquiryCreatedEvent) { + val inquiry = event.inquiry + + emailHandler.sendEmail(inquiry) + pushNotificationHandler.sendNotification(inquiry) + } +} \ No newline at end of file From a4cacf2e11c2e18a38fcf08263c556c62745df55 Mon Sep 17 00:00:00 2001 From: Chase Jordan Nel <123620591+Chase-Nel@users.noreply.github.com> Date: Wed, 19 Jul 2023 08:34:26 +0200 Subject: [PATCH 2/7] Added Event Listener and Tested --- .../challenges/dependency/inquiry}/InquiryCreatedEvent.kt | 3 +-- .../coding/challenges/dependency/inquiry/InquiryService.kt | 5 ++--- .../dependency/notifications/InquiryCreatedEventListener.kt | 1 + 3 files changed, 4 insertions(+), 5 deletions(-) rename Backend/dependency-kotlin/{notifications/src/main/kotlin/com/staffinghub/coding/challenges/dependency/notifications => inquiry/src/main/kotlin/com/staffinghub/coding/challenges/dependency/inquiry}/InquiryCreatedEvent.kt (51%) diff --git a/Backend/dependency-kotlin/notifications/src/main/kotlin/com/staffinghub/coding/challenges/dependency/notifications/InquiryCreatedEvent.kt b/Backend/dependency-kotlin/inquiry/src/main/kotlin/com/staffinghub/coding/challenges/dependency/inquiry/InquiryCreatedEvent.kt similarity index 51% rename from Backend/dependency-kotlin/notifications/src/main/kotlin/com/staffinghub/coding/challenges/dependency/notifications/InquiryCreatedEvent.kt rename to Backend/dependency-kotlin/inquiry/src/main/kotlin/com/staffinghub/coding/challenges/dependency/inquiry/InquiryCreatedEvent.kt index 1b8e973..838c3b1 100644 --- a/Backend/dependency-kotlin/notifications/src/main/kotlin/com/staffinghub/coding/challenges/dependency/notifications/InquiryCreatedEvent.kt +++ b/Backend/dependency-kotlin/inquiry/src/main/kotlin/com/staffinghub/coding/challenges/dependency/inquiry/InquiryCreatedEvent.kt @@ -1,6 +1,5 @@ -package com.staffinghub.coding.challenges.dependency.notifications +package com.staffinghub.coding.challenges.dependency.inquiry -import com.staffinghub.coding.challenges.dependency.inquiry.Inquiry import org.springframework.context.ApplicationEvent class InquiryCreatedEvent(source: Any, val inquiry: Inquiry) : ApplicationEvent(source){ diff --git a/Backend/dependency-kotlin/inquiry/src/main/kotlin/com/staffinghub/coding/challenges/dependency/inquiry/InquiryService.kt b/Backend/dependency-kotlin/inquiry/src/main/kotlin/com/staffinghub/coding/challenges/dependency/inquiry/InquiryService.kt index 1daf8cc..a9935a9 100644 --- a/Backend/dependency-kotlin/inquiry/src/main/kotlin/com/staffinghub/coding/challenges/dependency/inquiry/InquiryService.kt +++ b/Backend/dependency-kotlin/inquiry/src/main/kotlin/com/staffinghub/coding/challenges/dependency/inquiry/InquiryService.kt @@ -7,13 +7,12 @@ import org.springframework.context.ApplicationEventPublisher private val logger = KotlinLogging.logger {} @Component - -class InquiryService { +class InquiryService (private val applicationEventPublisher: ApplicationEventPublisher) { fun create(inquiry: Inquiry) { logger.info { "User sent inquiry: $inquiry" } -// applicationEventPublisher.publishEvent(InquiryCreatedEvent(this, inquiry)) + applicationEventPublisher.publishEvent(InquiryCreatedEvent(this, inquiry)) } } diff --git a/Backend/dependency-kotlin/notifications/src/main/kotlin/com/staffinghub/coding/challenges/dependency/notifications/InquiryCreatedEventListener.kt b/Backend/dependency-kotlin/notifications/src/main/kotlin/com/staffinghub/coding/challenges/dependency/notifications/InquiryCreatedEventListener.kt index 990c7a2..3292882 100644 --- a/Backend/dependency-kotlin/notifications/src/main/kotlin/com/staffinghub/coding/challenges/dependency/notifications/InquiryCreatedEventListener.kt +++ b/Backend/dependency-kotlin/notifications/src/main/kotlin/com/staffinghub/coding/challenges/dependency/notifications/InquiryCreatedEventListener.kt @@ -1,4 +1,5 @@ package com.staffinghub.coding.challenges.dependency.notifications +import com.staffinghub.coding.challenges.dependency.inquiry.InquiryCreatedEvent import org.springframework.context.event.EventListener import org.springframework.stereotype.Component From 05a540143e812e940c62b9b753ac01784ccbeb15 Mon Sep 17 00:00:00 2001 From: Chase Jordan Nel <123620591+Chase-Nel@users.noreply.github.com> Date: Wed, 19 Jul 2023 08:41:21 +0200 Subject: [PATCH 3/7] Updated White Spaces --- .../challenges/dependency/inquiry/InquiryCreatedEvent.kt | 4 +--- .../challenges/dependency/notifications/EmailHandler.kt | 1 - 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/Backend/dependency-kotlin/inquiry/src/main/kotlin/com/staffinghub/coding/challenges/dependency/inquiry/InquiryCreatedEvent.kt b/Backend/dependency-kotlin/inquiry/src/main/kotlin/com/staffinghub/coding/challenges/dependency/inquiry/InquiryCreatedEvent.kt index 838c3b1..3f369c2 100644 --- a/Backend/dependency-kotlin/inquiry/src/main/kotlin/com/staffinghub/coding/challenges/dependency/inquiry/InquiryCreatedEvent.kt +++ b/Backend/dependency-kotlin/inquiry/src/main/kotlin/com/staffinghub/coding/challenges/dependency/inquiry/InquiryCreatedEvent.kt @@ -2,6 +2,4 @@ package com.staffinghub.coding.challenges.dependency.inquiry import org.springframework.context.ApplicationEvent -class InquiryCreatedEvent(source: Any, val inquiry: Inquiry) : ApplicationEvent(source){ - -} +class InquiryCreatedEvent(source: Any, val inquiry: Inquiry) : ApplicationEvent(source) diff --git a/Backend/dependency-kotlin/notifications/src/main/kotlin/com/staffinghub/coding/challenges/dependency/notifications/EmailHandler.kt b/Backend/dependency-kotlin/notifications/src/main/kotlin/com/staffinghub/coding/challenges/dependency/notifications/EmailHandler.kt index 5eb069c..e3fa7ee 100644 --- a/Backend/dependency-kotlin/notifications/src/main/kotlin/com/staffinghub/coding/challenges/dependency/notifications/EmailHandler.kt +++ b/Backend/dependency-kotlin/notifications/src/main/kotlin/com/staffinghub/coding/challenges/dependency/notifications/EmailHandler.kt @@ -6,7 +6,6 @@ import org.springframework.stereotype.Component private val logger = KotlinLogging.logger {} - @Component class EmailHandler { fun sendEmail(inquiry: Inquiry) { From 4e2b8ce476ce14a40bf3f87627d0522b9cbf2ad0 Mon Sep 17 00:00:00 2001 From: Chase Jordan Nel <123620591+Chase-Nel@users.noreply.github.com> Date: Wed, 19 Jul 2023 09:26:40 +0200 Subject: [PATCH 4/7] Update InquiryTest.kt --- .../com/staffinghub/coding/challenges/dependency/InquiryTest.kt | 1 + 1 file changed, 1 insertion(+) diff --git a/Backend/dependency-kotlin/application/src/test/kotlin/com/staffinghub/coding/challenges/dependency/InquiryTest.kt b/Backend/dependency-kotlin/application/src/test/kotlin/com/staffinghub/coding/challenges/dependency/InquiryTest.kt index cf52fbb..b4814f5 100644 --- a/Backend/dependency-kotlin/application/src/test/kotlin/com/staffinghub/coding/challenges/dependency/InquiryTest.kt +++ b/Backend/dependency-kotlin/application/src/test/kotlin/com/staffinghub/coding/challenges/dependency/InquiryTest.kt @@ -17,6 +17,7 @@ import org.springframework.test.context.junit.jupiter.SpringExtension class InquiryTest( @Autowired private val inquiryService: InquiryService, ) { + @SpykBean lateinit var emailHandler: EmailHandler From 8e845fd2f6f8ee4a4d5678d3fffed8dafba85c7c Mon Sep 17 00:00:00 2001 From: Chase Jordan Nel <123620591+Chase-Nel@users.noreply.github.com> Date: Wed, 19 Jul 2023 09:52:40 +0200 Subject: [PATCH 5/7] Added JavaDocs --- .../dependency/inquiry/InquiryCreatedEvent.kt | 4 ++++ .../challenges/dependency/inquiry/InquiryService.kt | 11 ++++++++++- .../notifications/InquiryCreatedEventListener.kt | 12 +++++++++++- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/Backend/dependency-kotlin/inquiry/src/main/kotlin/com/staffinghub/coding/challenges/dependency/inquiry/InquiryCreatedEvent.kt b/Backend/dependency-kotlin/inquiry/src/main/kotlin/com/staffinghub/coding/challenges/dependency/inquiry/InquiryCreatedEvent.kt index 3f369c2..37b4448 100644 --- a/Backend/dependency-kotlin/inquiry/src/main/kotlin/com/staffinghub/coding/challenges/dependency/inquiry/InquiryCreatedEvent.kt +++ b/Backend/dependency-kotlin/inquiry/src/main/kotlin/com/staffinghub/coding/challenges/dependency/inquiry/InquiryCreatedEvent.kt @@ -2,4 +2,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) + diff --git a/Backend/dependency-kotlin/inquiry/src/main/kotlin/com/staffinghub/coding/challenges/dependency/inquiry/InquiryService.kt b/Backend/dependency-kotlin/inquiry/src/main/kotlin/com/staffinghub/coding/challenges/dependency/inquiry/InquiryService.kt index a9935a9..91475c1 100644 --- a/Backend/dependency-kotlin/inquiry/src/main/kotlin/com/staffinghub/coding/challenges/dependency/inquiry/InquiryService.kt +++ b/Backend/dependency-kotlin/inquiry/src/main/kotlin/com/staffinghub/coding/challenges/dependency/inquiry/InquiryService.kt @@ -6,8 +6,17 @@ 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 (private val applicationEventPublisher: ApplicationEventPublisher) { +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" diff --git a/Backend/dependency-kotlin/notifications/src/main/kotlin/com/staffinghub/coding/challenges/dependency/notifications/InquiryCreatedEventListener.kt b/Backend/dependency-kotlin/notifications/src/main/kotlin/com/staffinghub/coding/challenges/dependency/notifications/InquiryCreatedEventListener.kt index 3292882..e494f74 100644 --- a/Backend/dependency-kotlin/notifications/src/main/kotlin/com/staffinghub/coding/challenges/dependency/notifications/InquiryCreatedEventListener.kt +++ b/Backend/dependency-kotlin/notifications/src/main/kotlin/com/staffinghub/coding/challenges/dependency/notifications/InquiryCreatedEventListener.kt @@ -3,12 +3,22 @@ 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 inquiry = event.inquiry @@ -16,4 +26,4 @@ class InquiryCreatedEventListener( emailHandler.sendEmail(inquiry) pushNotificationHandler.sendNotification(inquiry) } -} \ No newline at end of file +} From bf009ddc8f869717f84cea0a4b885819e7b118ef Mon Sep 17 00:00:00 2001 From: Chase Jordan Nel <123620591+Chase-Nel@users.noreply.github.com> Date: Thu, 20 Jul 2023 08:59:52 +0200 Subject: [PATCH 6/7] Update InquiryCreatedEvent.kt --- .../challenges/dependency/inquiry/InquiryCreatedEvent.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Backend/dependency-kotlin/inquiry/src/main/kotlin/com/staffinghub/coding/challenges/dependency/inquiry/InquiryCreatedEvent.kt b/Backend/dependency-kotlin/inquiry/src/main/kotlin/com/staffinghub/coding/challenges/dependency/inquiry/InquiryCreatedEvent.kt index 37b4448..307659a 100644 --- a/Backend/dependency-kotlin/inquiry/src/main/kotlin/com/staffinghub/coding/challenges/dependency/inquiry/InquiryCreatedEvent.kt +++ b/Backend/dependency-kotlin/inquiry/src/main/kotlin/com/staffinghub/coding/challenges/dependency/inquiry/InquiryCreatedEvent.kt @@ -5,5 +5,4 @@ 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) - +class InquiryCreatedEvent(source: Any, val inquiry: Inquiry) : ApplicationEvent(source) \ No newline at end of file From ea1ce4f9aa31bfb12e24154d2cc308a4b4066175 Mon Sep 17 00:00:00 2001 From: Chase Jordan Nel <123620591+Chase-Nel@users.noreply.github.com> Date: Fri, 21 Jul 2023 11:26:59 +0200 Subject: [PATCH 7/7] Update InquiryCreatedEventListener.kt --- .../notifications/InquiryCreatedEventListener.kt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Backend/dependency-kotlin/notifications/src/main/kotlin/com/staffinghub/coding/challenges/dependency/notifications/InquiryCreatedEventListener.kt b/Backend/dependency-kotlin/notifications/src/main/kotlin/com/staffinghub/coding/challenges/dependency/notifications/InquiryCreatedEventListener.kt index e494f74..c104765 100644 --- a/Backend/dependency-kotlin/notifications/src/main/kotlin/com/staffinghub/coding/challenges/dependency/notifications/InquiryCreatedEventListener.kt +++ b/Backend/dependency-kotlin/notifications/src/main/kotlin/com/staffinghub/coding/challenges/dependency/notifications/InquiryCreatedEventListener.kt @@ -1,4 +1,5 @@ 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 @@ -21,9 +22,9 @@ class InquiryCreatedEventListener( */ @EventListener fun handleInquiryCreatedEvent(event: InquiryCreatedEvent) { - val inquiry = event.inquiry + val inq: Inquiry = event.inquiry - emailHandler.sendEmail(inquiry) - pushNotificationHandler.sendNotification(inquiry) + emailHandler.sendEmail(inq) + pushNotificationHandler.sendNotification(inq) } }