Skip to content

Commit 0c36115

Browse files
authored
release: 1.2.7 (#137)
2 parents 792fa17 + cdaef58 commit 0c36115

File tree

5 files changed

+97
-39
lines changed

5 files changed

+97
-39
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package org.gitanimals.core
2+
3+
import org.springframework.http.HttpMethod
4+
import org.springframework.http.HttpStatus
5+
import org.springframework.http.client.ClientHttpResponse
6+
import org.springframework.web.client.ResponseErrorHandler
7+
import java.net.URI
8+
9+
10+
class HttpClientErrorHandler : ResponseErrorHandler {
11+
12+
override fun hasError(response: ClientHttpResponse): Boolean {
13+
return response.statusCode.isError
14+
}
15+
16+
override fun handleError(url: URI, method: HttpMethod, response: ClientHttpResponse) {
17+
val body = response.body.bufferedReader().use { it.readText() }
18+
when {
19+
response.statusCode.isSameCodeAs(HttpStatus.UNAUTHORIZED) ->
20+
throw AuthorizationException(body)
21+
22+
response.statusCode.is4xxClientError ->
23+
throw IllegalArgumentException(body)
24+
25+
else -> error(body)
26+
}
27+
}
28+
}

src/main/kotlin/org/gitanimals/inbox/app/IdentityApi.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package org.gitanimals.inbox.app
22

3+
import org.springframework.web.service.annotation.GetExchange
4+
35
fun interface IdentityApi {
46

7+
@GetExchange("/users")
58
fun getUserByToken(token: String): UserResponse
69

710
data class UserResponse(
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package org.gitanimals.inbox.infra
2+
3+
import org.gitanimals.core.HttpClientErrorHandler
4+
import org.gitanimals.core.filter.MDCFilter
5+
import org.gitanimals.inbox.app.IdentityApi
6+
import org.slf4j.MDC
7+
import org.springframework.beans.factory.annotation.Value
8+
import org.springframework.context.annotation.Bean
9+
import org.springframework.context.annotation.Configuration
10+
import org.springframework.web.client.RestClient
11+
import org.springframework.web.client.support.RestClientAdapter
12+
import org.springframework.web.service.invoker.HttpServiceProxyFactory
13+
14+
@Configuration
15+
class InboxHttpClientConfigurer(
16+
@Value("\${internal.secret}") private val internalSecret: String,
17+
) {
18+
19+
@Bean
20+
fun inboxIdentityApi(token: String): IdentityApi {
21+
val restClient = RestClient
22+
.builder()
23+
.requestInterceptor { request, body, execution ->
24+
request.headers.add(MDCFilter.TRACE_ID, MDC.get(MDCFilter.TRACE_ID))
25+
if (request.uri.path.startsWith("/internals")) {
26+
request.headers.add(
27+
INTERNAL_SECRET_KEY,
28+
internalSecret
29+
)
30+
}
31+
execution.execute(request, body)
32+
}
33+
.defaultStatusHandler(inboxHttpClientErrorHandler())
34+
.baseUrl("https://api.gitanimals.org")
35+
.build()
36+
37+
val httpServiceProxyFactory = HttpServiceProxyFactory
38+
.builderFor(RestClientAdapter.create(restClient))
39+
.build()
40+
41+
return httpServiceProxyFactory.createClient(IdentityApi::class.java)
42+
}
43+
44+
@Bean
45+
fun inboxHttpClientErrorHandler(): HttpClientErrorHandler = HttpClientErrorHandler()
46+
47+
private companion object {
48+
private const val INTERNAL_SECRET_KEY = "Internal-Secret"
49+
}
50+
}

src/main/kotlin/org/gitanimals/inbox/infra/RestIdentityApi.kt

Lines changed: 0 additions & 36 deletions
This file was deleted.

src/test/kotlin/org/gitanimals/quiz/domain/infra/SlackNotificationTest.kt

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package org.gitanimals.quiz.domain.infra
22

33
import com.fasterxml.jackson.databind.ObjectMapper
44
import io.kotest.core.spec.style.StringSpec
5+
import org.gitanimals.notification.domain.Notification
56
import org.gitanimals.notification.infra.GitAnimalsNewQuizCreatedSlackNotification
67

78

@@ -33,9 +34,21 @@ internal class SlackNotificationTest : StringSpec({
3334

3435
// when
3536
slackNotificationWithToken.notifyWithActions(
36-
"xb test",
37-
whenApprovedButtonClicked,
38-
whenNotApprovedButtonClicked,
37+
message = "xb test",
38+
actions = listOf(
39+
Notification.ActionRequest(
40+
id = "approve_action",
41+
style = Notification.ActionRequest.Style.PRIMARY,
42+
name = "Approve",
43+
interaction = whenApprovedButtonClicked,
44+
),
45+
Notification.ActionRequest(
46+
id = "delete_action",
47+
style = Notification.ActionRequest.Style.DANGER,
48+
name = "Deny",
49+
interaction = whenNotApprovedButtonClicked,
50+
)
51+
),
3952
)
4053
}
4154
})

0 commit comments

Comments
 (0)