-
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.
- Loading branch information
Showing
21 changed files
with
114 additions
and
175 deletions.
There are no files selected for viewing
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
38 changes: 38 additions & 0 deletions
38
applications/report-app/src/main/kotlin/com/initialcapacity/reportapp/Application.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,38 @@ | ||
package com.initialcapacity.reportapp | ||
|
||
import com.initialcapacity.database.DatabaseTemplate | ||
import com.initialcapacity.database.dataSource | ||
import com.initialcapacity.stripe.StripeGateway | ||
import com.initialcapacity.subscriptions.SubscriptionsGateway | ||
import com.initialcapacity.subscriptions.SubscriptionsService | ||
import com.stripe.Stripe | ||
import io.ktor.server.application.* | ||
import io.ktor.server.engine.* | ||
import io.ktor.server.netty.* | ||
import io.ktor.server.routing.* | ||
|
||
fun Application.module(databaseUrl: String, stripeApiKey: String) { | ||
Stripe.apiKey = stripeApiKey | ||
|
||
val stripeSupport = StripeGateway() | ||
val template = DatabaseTemplate(dataSource(databaseUrl)) | ||
val gateway = SubscriptionsGateway(template) | ||
val subscriptionsService = SubscriptionsService(stripeSupport, gateway) | ||
|
||
routing { | ||
subscriptions(subscriptionsService) | ||
} | ||
} | ||
|
||
fun main() { | ||
embeddedServer(Netty, port = 8080, host = "0.0.0.0", module = { | ||
module( | ||
databaseUrl = requiredEnvironmentVariable("DATABASE_URL"), | ||
stripeApiKey = requiredEnvironmentVariable("STRIPE_API_KEY") | ||
) | ||
}).start(wait = true) | ||
} | ||
|
||
fun requiredEnvironmentVariable(value: String): String { | ||
return System.getenv()[value] ?: throw RuntimeException("missing configuration: $value") | ||
} |
14 changes: 14 additions & 0 deletions
14
applications/report-app/src/main/kotlin/com/initialcapacity/reportapp/SubscriptionsRoutes.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,14 @@ | ||
package com.initialcapacity.reportapp | ||
|
||
import com.initialcapacity.subscriptions.SubscriptionsService | ||
import io.ktor.server.application.call | ||
import io.ktor.server.response.respondText | ||
import io.ktor.server.routing.Route | ||
import io.ktor.server.routing.get | ||
|
||
fun Route.subscriptions(service: SubscriptionsService) { | ||
get("/") { | ||
val list = service.list() | ||
call.respondText("hi! found=${list.size} subscriptions") | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...ions/report-app/src/test/kotlin/test/initialcapacity/reportapp/SubscriptionsRoutesTest.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,17 @@ | ||
package test.initialcapacity.reportapp | ||
|
||
import io.ktor.client.request.get | ||
import io.ktor.client.statement.bodyAsText | ||
import io.ktor.http.HttpStatusCode | ||
import org.junit.Test | ||
import kotlin.test.assertContains | ||
import kotlin.test.assertEquals | ||
|
||
class SubscriptionsRoutesTest { | ||
@Test | ||
fun testList() = testApp { | ||
val response = client.get("/") | ||
assertEquals(HttpStatusCode.OK, response.status) | ||
assertContains(response.bodyAsText(), "hi!") | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
applications/report-app/src/test/kotlin/test/initialcapacity/reportapp/TestSupport.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,20 @@ | ||
package test.initialcapacity.reportapp | ||
|
||
import com.initialcapacity.reportapp.module | ||
import com.stripe.Stripe | ||
import io.ktor.server.testing.ApplicationTestBuilder | ||
import io.ktor.server.testing.testApplication | ||
|
||
fun testApp(block: suspend ApplicationTestBuilder.() -> Unit) { | ||
Stripe.overrideApiBase("http://localhost:12111") | ||
|
||
testApplication { | ||
application { | ||
module( | ||
databaseUrl = "jdbc:postgresql://localhost/example_test?user=initialdev&password=initialdev", | ||
stripeApiKey = "sk_test_xxxxxxxxxxxxxxxxxxxxxxxx" | ||
) | ||
} | ||
block() | ||
} | ||
} |
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
...com/initialcapacity/worker/Application.kt → ...itialcapacity/reportworker/Application.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,4 +1,4 @@ | ||
package com.initialcapacity.worker | ||
package com.initialcapacity.reportworker | ||
|
||
import org.slf4j.LoggerFactory | ||
|
||
|
4 changes: 2 additions & 2 deletions
4
...initialcapacity/worker/ApplicationTest.kt → ...lcapacity/reportworker/ApplicationTest.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
20 changes: 0 additions & 20 deletions
20
applications/webapp/src/main/kotlin/com/initialcapacity/webapp/Application.kt
This file was deleted.
Oops, something went wrong.
35 changes: 0 additions & 35 deletions
35
applications/webapp/src/test/kotlin/test/initialcapacity/webapp/ApplicationTest.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
4 changes: 2 additions & 2 deletions
4
...ts/database-support/src/test/kotlin/test/initialcapacity/database/DatabaseTemplateTest.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
4 changes: 2 additions & 2 deletions
4
...nts/subscriptions/src/test/kotlin/test/initialcapacity/stripe/SubscriptionsGatewayTest.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 was deleted.
Oops, something went wrong.
33 changes: 0 additions & 33 deletions
33
components/web/src/main/kotlin/com.initialcapacity.web/BasicWeb.kt
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.