-
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.
Merge pull request #20 from Lukinhasssss/feature/video-rest-client
Automated PR from feature/video-rest-client
- Loading branch information
Showing
21 changed files
with
507 additions
and
35 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
8 changes: 8 additions & 0 deletions
8
.../main/kotlin/com/lukinhasssss/catalogo/infrastructure/configuration/annotations/Videos.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,8 @@ | ||
package com.lukinhasssss.catalogo.infrastructure.configuration.annotations | ||
|
||
import org.springframework.beans.factory.annotation.Qualifier | ||
|
||
@Qualifier("Video") | ||
@Target(AnnotationTarget.FUNCTION, AnnotationTarget.VALUE_PARAMETER) | ||
@Retention(AnnotationRetention.RUNTIME) | ||
annotation class Videos |
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
7 changes: 7 additions & 0 deletions
7
infrastructure/src/main/kotlin/com/lukinhasssss/catalogo/infrastructure/video/VideoClient.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,7 @@ | ||
package com.lukinhasssss.catalogo.infrastructure.video | ||
|
||
import com.lukinhasssss.catalogo.infrastructure.video.models.VideoDTO | ||
|
||
fun interface VideoClient { | ||
fun videoOfId(videoId: String?): VideoDTO? | ||
} |
48 changes: 48 additions & 0 deletions
48
...ructure/src/main/kotlin/com/lukinhasssss/catalogo/infrastructure/video/VideoRestClient.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,48 @@ | ||
package com.lukinhasssss.catalogo.infrastructure.video | ||
|
||
import com.lukinhasssss.catalogo.infrastructure.authentication.GetClientCredentials | ||
import com.lukinhasssss.catalogo.infrastructure.configuration.annotations.Videos | ||
import com.lukinhasssss.catalogo.infrastructure.utils.HttpClient | ||
import com.lukinhasssss.catalogo.infrastructure.video.models.VideoDTO | ||
import io.github.resilience4j.bulkhead.annotation.Bulkhead | ||
import io.github.resilience4j.circuitbreaker.annotation.CircuitBreaker | ||
import io.github.resilience4j.retry.annotation.Retry | ||
import org.springframework.cache.annotation.CacheConfig | ||
import org.springframework.cache.annotation.Cacheable | ||
import org.springframework.http.HttpHeaders | ||
import org.springframework.stereotype.Component | ||
import org.springframework.web.client.RestClient | ||
|
||
private const val VIDEO_CACHE_NAME = "admin-videos" | ||
private const val VIDEO_CACHE_KEY = "#videoId" | ||
|
||
@Component | ||
@CacheConfig(cacheNames = [VIDEO_CACHE_NAME]) | ||
class VideoRestClient( | ||
@Videos private val restClient: RestClient, | ||
private val getClientCredentials: GetClientCredentials | ||
) : VideoClient, HttpClient { | ||
|
||
companion object { | ||
const val NAMESPACE = "videos" | ||
} | ||
|
||
override fun namespace(): String = NAMESPACE | ||
|
||
// Resilience4j default order: Bulkhead -> TimeLimiter -> RateLimiter -> CircuitBreaker -> Retry | ||
@Retry(name = NAMESPACE) | ||
@Bulkhead(name = NAMESPACE) | ||
@CircuitBreaker(name = NAMESPACE) | ||
@Cacheable(key = VIDEO_CACHE_KEY, unless = "#result == null") | ||
override fun videoOfId(videoId: String?): VideoDTO? = doGet(videoId) { | ||
getClientCredentials.retrieve().let { token -> | ||
restClient.get() | ||
.uri("/{id}", videoId) | ||
.header(HttpHeaders.AUTHORIZATION, "Bearer $token") | ||
.retrieve() | ||
.onStatus(isNotFound(), notFoundHandler(videoId)) | ||
.onStatus(is5xx(), serverErrorHandler(videoId)) | ||
.body(VideoDTO::class.java) | ||
} | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...ructure/src/main/kotlin/com/lukinhasssss/catalogo/infrastructure/video/models/VideoDTO.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,22 @@ | ||
package com.lukinhasssss.catalogo.infrastructure.video.models | ||
|
||
data class VideoDTO( | ||
val id: String, | ||
val title: String, | ||
val description: String, | ||
val yearLaunched: Int, | ||
val rating: String, | ||
val duration: Double, | ||
val opened: Boolean, | ||
val published: Boolean, | ||
val banner: String? = null, | ||
val thumbnail: String? = null, | ||
val thumbnailHalf: String? = null, | ||
val trailer: String? = null, | ||
val video: String? = null, | ||
val categoriesId: Set<String>, | ||
val castMembersId: Set<String>, | ||
val genresId: Set<String>, | ||
val createdAt: String, | ||
val updatedAt: 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
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
Oops, something went wrong.