-
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
1 parent
e994ed2
commit cddba70
Showing
9 changed files
with
85 additions
and
5 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
7 changes: 5 additions & 2 deletions
7
...c/SpringThymeleafCoroutinesApplication.kt → ...main/kotlin/concept/stc/STCApplication.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,17 +1,20 @@ | ||
package concept.stc | ||
|
||
import concept.stc.config.OmdbApiConfigProperties | ||
import org.springframework.boot.autoconfigure.SpringBootApplication | ||
import org.springframework.boot.context.properties.EnableConfigurationProperties | ||
import org.springframework.boot.runApplication | ||
|
||
/** | ||
* Application entry point. | ||
*/ | ||
@SpringBootApplication | ||
class SpringThymeleafCoroutinesApplication | ||
@EnableConfigurationProperties(OmdbApiConfigProperties::class) | ||
class STCApplication | ||
|
||
/** | ||
* Application entry point. | ||
*/ | ||
fun main(args: Array<String>) { | ||
runApplication<SpringThymeleafCoroutinesApplication>(args = args) | ||
runApplication<STCApplication>(args = args) | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/kotlin/concept/stc/config/OmdbApiConfigProperties.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,15 @@ | ||
package concept.stc.config | ||
|
||
import org.springframework.boot.context.properties.ConfigurationProperties | ||
|
||
/** | ||
* Config definition for Open Movie Database (OMDB) API properties. | ||
* | ||
* @property baseUrl the api base url. | ||
* @property apiKey the api key. | ||
*/ | ||
@ConfigurationProperties(prefix = "omdb") | ||
data class OmdbApiConfigProperties( | ||
val baseUrl: String, | ||
val apiKey: String | ||
) |
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,32 @@ | ||
package concept.stc.data.remote | ||
|
||
import concept.stc.config.OmdbApiConfigProperties | ||
import kotlinx.coroutines.reactive.awaitFirst | ||
import org.springframework.stereotype.Component | ||
import org.springframework.web.reactive.function.client.WebClient | ||
|
||
/** | ||
* Api client for external API. | ||
* | ||
* @param configProperties the API config properties. | ||
*/ | ||
@Component | ||
class ApiClient( | ||
private val configProperties: OmdbApiConfigProperties | ||
) { | ||
|
||
private val webClient = WebClient.create(configProperties.baseUrl) | ||
|
||
/** | ||
* Get movies list from the external API. | ||
* | ||
* @param query the search query. | ||
*/ | ||
suspend fun getMovies(query: String) { | ||
webClient.get() | ||
.uri("/?apikey={apiKey}&s={query}", configProperties.apiKey, query) | ||
.retrieve() | ||
.bodyToMono(String::class.java) | ||
.awaitFirst() | ||
} | ||
} |
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,6 @@ | ||
spring.config.import=optional:secrets.properties | ||
omdb.base-url=https://www.omdbapi.com | ||
|
||
spring.application.name=spring-thymeleaf-coroutines | ||
logging.level.org.springframework.jdbc.datasource.init.ScriptUtils=debug | ||
spring.jpa.hibernate.ddl-auto=none | ||
spring.jpa.hibernate.ddl-auto=none |
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
24 changes: 24 additions & 0 deletions
24
src/test/kotlin/concept/stc/config/OmdbApiConfigIntegrationTest.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,24 @@ | ||
package concept.stc.config | ||
|
||
import org.springframework.beans.factory.annotation.Autowired | ||
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase | ||
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase.Replace | ||
import org.springframework.boot.test.context.SpringBootTest | ||
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment | ||
import kotlin.test.Test | ||
import kotlin.test.assertTrue | ||
|
||
@SpringBootTest(webEnvironment = WebEnvironment.NONE) | ||
@AutoConfigureTestDatabase(replace = Replace.ANY) | ||
class OmdbApiConfigIntegrationTest { | ||
|
||
@Autowired | ||
private lateinit var configProperties: OmdbApiConfigProperties | ||
|
||
@Test | ||
fun `when getting properties, given config, then values are not empty`() { | ||
assertTrue(configProperties.baseUrl.isNotEmpty()) | ||
// Be sure that "secrets.properties" contains the api key | ||
// assertTrue(configProperties.apiKey.isNotEmpty()) | ||
} | ||
} |
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