-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: improved code readability and objects nomenclature
- Loading branch information
Showing
34 changed files
with
401 additions
and
304 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 4 additions & 3 deletions
7
...dadapters/adapter/driven/OtpSenderImpl.kt → ...tsandadapters/adapter/driven/OtpSender.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/main/kotlin/io/j0a0m4/portsandadapters/adapter/driver/http/ContactHandlers.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package io.j0a0m4.portsandadapters.adapter.driver.http | ||
|
||
import io.j0a0m4.portsandadapters.adapter.driver.http.request.* | ||
import io.j0a0m4.portsandadapters.adapter.driver.http.response.toResponse | ||
import io.j0a0m4.portsandadapters.domain.usecases.ContactUseCases | ||
import org.springframework.stereotype.Controller | ||
import org.springframework.web.reactive.function.server.* | ||
|
||
@Controller | ||
class ContactHandlers( | ||
val contactPort: ContactUseCases, | ||
val failureHandler: FailureHandler | ||
) { | ||
|
||
suspend fun createOne(request: ServerRequest) = | ||
with(request) { | ||
toContact() | ||
}.let { contact -> | ||
contactPort add contact | ||
}.map { id -> | ||
request locationOf id | ||
}.run { | ||
fold( | ||
onSuccess = { ServerResponse.created(it) }, | ||
onFailure = failureHandler::invoke | ||
) | ||
}.run { | ||
buildAndAwait() | ||
} | ||
|
||
suspend fun getOne(request: ServerRequest) = | ||
with(request) { | ||
pathId | ||
}.let { contactId -> | ||
contactPort findBy contactId | ||
}.map { contact -> | ||
contact.toResponse | ||
}.run { | ||
fold( | ||
onSuccess = { ServerResponse.ok().bodyValueAndAwait(it) }, | ||
onFailure = { failureHandler(it).buildAndAwait() } | ||
) | ||
} | ||
} |
72 changes: 0 additions & 72 deletions
72
src/main/kotlin/io/j0a0m4/portsandadapters/adapter/driver/http/ContactVerificationApi.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/main/kotlin/io/j0a0m4/portsandadapters/adapter/driver/http/OtpHandlers.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package io.j0a0m4.portsandadapters.adapter.driver.http | ||
|
||
import io.j0a0m4.portsandadapters.adapter.driver.http.request.* | ||
import io.j0a0m4.portsandadapters.domain.usecases.OtpUseCases | ||
import org.springframework.stereotype.Controller | ||
import org.springframework.web.reactive.function.server.* | ||
|
||
@Controller | ||
class OtpHandlers( | ||
private val otpPort: OtpUseCases, | ||
private val failureHandler: FailureHandler | ||
) { | ||
suspend fun createOne(request: ServerRequest) = | ||
with(request) { | ||
pathId to sendMethod | ||
}.let { (contactId, method) -> | ||
otpPort.send(contactId, method) | ||
}.run { | ||
ServerResponse.accepted().buildAndAwait() | ||
} | ||
|
||
suspend fun verifyOne(request: ServerRequest) = | ||
with(request) { | ||
toVerifyOtpCommand() | ||
}.let { (contactId, sendMethod, otp) -> | ||
otpPort.verify(contactId, sendMethod, otp) | ||
}.run { | ||
fold( | ||
onSuccess = { ServerResponse.noContent() }, | ||
onFailure = failureHandler::invoke | ||
) | ||
}.run { | ||
buildAndAwait() | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/main/kotlin/io/j0a0m4/portsandadapters/adapter/driver/http/Routes.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package io.j0a0m4.portsandadapters.adapter.driver.http | ||
|
||
import org.springframework.context.annotation.Bean | ||
import org.springframework.context.annotation.Configuration | ||
import org.springframework.http.MediaType.APPLICATION_JSON | ||
import org.springframework.web.reactive.function.server.coRouter | ||
|
||
|
||
@Configuration | ||
class Routes { | ||
|
||
@Bean | ||
fun otpRoutes(handlers: OtpHandlers) = coRouter { | ||
"/api/contact".nest { | ||
accept(APPLICATION_JSON).nest { | ||
POST("/{id}/otp", handlers::createOne) | ||
PATCH("/{id}", handlers::verifyOne) | ||
} | ||
} | ||
} | ||
|
||
@Bean | ||
fun contactRoutes(handler: ContactHandlers) = coRouter { | ||
"/api".nest { | ||
accept(APPLICATION_JSON).nest { | ||
POST("/contact", handler::createOne) | ||
GET("/contact/{id}", handler::getOne) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...pters/domain/usecases/DomainExceptions.kt → ...0m4/portsandadapters/domain/Exceptions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,4 @@ package io.j0a0m4.portsandadapters.domain.model | |
enum class SendMethod { | ||
Email, Phone; | ||
companion object | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/main/kotlin/io/j0a0m4/portsandadapters/domain/model/VerificationCode.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
package io.j0a0m4.portsandadapters.domain.model | ||
|
||
typealias VerificationCode = Int | ||
typealias VerificationCode = Int |
Oops, something went wrong.