-
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 #289 from wafflestudio/develop
Release
- Loading branch information
Showing
17 changed files
with
278 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.wafflestudio.snu4t.handler | ||
|
||
import com.wafflestudio.snu4t.common.client.AppVersion | ||
import com.wafflestudio.snu4t.common.dto.OkResponse | ||
import com.wafflestudio.snu4t.feedback.dto.FeedbackPostRequestDto | ||
import com.wafflestudio.snu4t.feedback.service.FeedbackService | ||
import com.wafflestudio.snu4t.middleware.SnuttRestApiNoAuthMiddleware | ||
import org.springframework.stereotype.Component | ||
import org.springframework.web.reactive.function.server.ServerRequest | ||
import org.springframework.web.reactive.function.server.ServerResponse | ||
import org.springframework.web.reactive.function.server.awaitBody | ||
|
||
@Component | ||
class FeedbackHandler( | ||
private val feedbackService: FeedbackService, | ||
snuttRestApiNoAuthMiddleware: SnuttRestApiNoAuthMiddleware, | ||
) : ServiceHandler(snuttRestApiNoAuthMiddleware) { | ||
suspend fun postFeedback(req: ServerRequest): ServerResponse = | ||
handle(req) { | ||
val body = req.awaitBody<FeedbackPostRequestDto>() | ||
val clientInfo = req.clientInfo!! | ||
feedbackService.addGithubIssue( | ||
email = body.email, | ||
message = body.message, | ||
osType = clientInfo.osType, | ||
osVersion = clientInfo.osVersion, | ||
appVersion = clientInfo.appVersion ?: AppVersion("Unknown"), | ||
deviceModel = clientInfo.deviceModel ?: "Unknown", | ||
) | ||
OkResponse() | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.wafflestudio.snu4t.router.docs | ||
|
||
import com.wafflestudio.snu4t.common.dto.OkResponse | ||
import com.wafflestudio.snu4t.feedback.dto.FeedbackPostRequestDto | ||
import io.swagger.v3.oas.annotations.Operation | ||
import io.swagger.v3.oas.annotations.media.Content | ||
import io.swagger.v3.oas.annotations.media.Schema | ||
import io.swagger.v3.oas.annotations.parameters.RequestBody | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse | ||
import org.springdoc.core.annotations.RouterOperation | ||
import org.springdoc.core.annotations.RouterOperations | ||
import org.springframework.http.MediaType | ||
import org.springframework.web.bind.annotation.RequestMethod | ||
|
||
@RouterOperations( | ||
RouterOperation( | ||
path = "/v1/feedback", | ||
method = [RequestMethod.POST], | ||
produces = [MediaType.APPLICATION_JSON_VALUE], | ||
operation = | ||
Operation( | ||
operationId = "postFeedback", | ||
requestBody = | ||
RequestBody( | ||
content = [ | ||
Content( | ||
schema = Schema(implementation = FeedbackPostRequestDto::class), | ||
mediaType = MediaType.APPLICATION_JSON_VALUE, | ||
), | ||
], | ||
), | ||
responses = [ | ||
ApiResponse( | ||
responseCode = "200", | ||
content = [Content(schema = Schema(implementation = OkResponse::class))], | ||
), | ||
], | ||
), | ||
), | ||
) | ||
annotation class FeedbackDocs() |
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
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,29 @@ | ||
package com.wafflestudio.snu4t.common.github.api | ||
|
||
import org.springframework.context.annotation.Bean | ||
import org.springframework.context.annotation.Configuration | ||
import org.springframework.http.HttpHeaders.ACCEPT | ||
import org.springframework.http.HttpHeaders.USER_AGENT | ||
import org.springframework.web.reactive.function.client.WebClient | ||
|
||
@Configuration | ||
class GithubRestApiConfig { | ||
companion object { | ||
const val GITHUB_API_BASE_URI = "https://api.github.com" | ||
} | ||
|
||
@Bean | ||
fun githubRestApi(): GithubRestApi = | ||
WebClient.builder().baseUrl(GITHUB_API_BASE_URI) | ||
.defaultHeaders { | ||
it.setAll( | ||
mapOf( | ||
ACCEPT to "application/vnd.github.v3+json", | ||
USER_AGENT to "snutt-timetable", | ||
), | ||
) | ||
} | ||
.build().let(::GithubRestApi) | ||
} | ||
|
||
class GithubRestApi(webClient: WebClient) : WebClient by webClient |
37 changes: 37 additions & 0 deletions
37
core/src/main/kotlin/common/github/client/GithubRestApiClient.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,37 @@ | ||
package com.wafflestudio.snu4t.common.github.client | ||
|
||
import com.wafflestudio.snu4t.common.extension.post | ||
import com.wafflestudio.snu4t.common.github.api.GithubRestApi | ||
import com.wafflestudio.snu4t.common.github.dto.GithubIssue | ||
import org.springframework.http.HttpHeaders.AUTHORIZATION | ||
import org.springframework.stereotype.Service | ||
|
||
interface GithubRestApiClient { | ||
suspend fun addRepoIssue( | ||
repoOwner: String, | ||
repoName: String, | ||
token: String, | ||
issue: GithubIssue, | ||
) | ||
} | ||
|
||
@Service | ||
class GithubRestApiClientImpl( | ||
private val githubRestApi: GithubRestApi, | ||
) : GithubRestApiClient { | ||
override suspend fun addRepoIssue( | ||
repoOwner: String, | ||
repoName: String, | ||
token: String, | ||
issue: GithubIssue, | ||
) { | ||
githubRestApi.post<Any>( | ||
uri = "/repos/$repoOwner/$repoName/issues", | ||
body = issue, | ||
headers = | ||
mapOf( | ||
AUTHORIZATION to "token $token", | ||
), | ||
) | ||
} | ||
} |
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.wafflestudio.snu4t.common.github.dto | ||
|
||
data class GithubIssue( | ||
val title: String, | ||
val body: String, | ||
val labels: List<String> = listOf(), | ||
) |
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.wafflestudio.snu4t.feedback.dto | ||
|
||
data class FeedbackDto( | ||
val email: String, | ||
val platform: String, | ||
val appVersion: String, | ||
val deviceModel: String, | ||
val currentSeoulTime: String, | ||
val profileName: String, | ||
val message: String, | ||
) { | ||
fun toGithubIssueBody() = | ||
""" | ||
이메일: `$email` | ||
플랫폼/디바이스: $platform / $deviceModel | ||
버전: $appVersion | ||
프로필: $profileName | ||
날짜/시간(UTC+9): $currentSeoulTime | ||
$message | ||
""".trimIndent() | ||
} |
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,6 @@ | ||
package com.wafflestudio.snu4t.feedback.dto | ||
|
||
data class FeedbackPostRequestDto( | ||
val email: String, | ||
val message: 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,73 @@ | ||
package com.wafflestudio.snu4t.feedback.service | ||
|
||
import com.wafflestudio.snu4t.common.client.AppVersion | ||
import com.wafflestudio.snu4t.common.client.OsType | ||
import com.wafflestudio.snu4t.common.github.client.GithubRestApiClient | ||
import com.wafflestudio.snu4t.common.github.dto.GithubIssue | ||
import com.wafflestudio.snu4t.config.PhaseUtils | ||
import com.wafflestudio.snu4t.feedback.dto.FeedbackDto | ||
import org.springframework.beans.factory.annotation.Value | ||
import org.springframework.stereotype.Service | ||
import java.time.Instant | ||
import java.time.ZoneId | ||
import java.time.ZonedDateTime | ||
import java.time.format.DateTimeFormatter | ||
|
||
interface FeedbackService { | ||
suspend fun addGithubIssue( | ||
email: String, | ||
message: String, | ||
osType: OsType, | ||
osVersion: String?, | ||
appVersion: AppVersion, | ||
deviceModel: String, | ||
) | ||
} | ||
|
||
@Service | ||
class FeedbackServiceImpl( | ||
@Value("\${github.feedback.token}") private val token: String, | ||
@Value("\${github.feedback.repo.owner}") private val repoOwner: String, | ||
@Value("\${github.feedback.repo.name}") private val repoName: String, | ||
private val githubRestApiClient: GithubRestApiClient, | ||
) : FeedbackService { | ||
override suspend fun addGithubIssue( | ||
email: String, | ||
message: String, | ||
osType: OsType, | ||
osVersion: String?, | ||
appVersion: AppVersion, | ||
deviceModel: String, | ||
) { | ||
val osTypeString = osType.toString().lowercase() | ||
val platform = osVersion?.let { "$osTypeString ($osVersion)" } ?: osTypeString | ||
val currentSeoulTime = | ||
DateTimeFormatter.ISO_LOCAL_DATE_TIME.format( | ||
ZonedDateTime.ofInstant( | ||
Instant.now(), | ||
ZoneId.of("Asia/Seoul"), | ||
), | ||
) | ||
val profileName = PhaseUtils.getPhase().name.lowercase() | ||
githubRestApiClient.addRepoIssue( | ||
repoOwner = repoOwner, | ||
repoName = repoName, | ||
token = token, | ||
issue = | ||
GithubIssue( | ||
title = message, | ||
body = | ||
FeedbackDto( | ||
email = email, | ||
platform = platform, | ||
appVersion = appVersion.toString(), | ||
deviceModel = deviceModel, | ||
currentSeoulTime = currentSeoulTime, | ||
profileName = profileName, | ||
message = message, | ||
).toGithubIssueBody(), | ||
labels = listOf(osTypeString), | ||
), | ||
) | ||
} | ||
} |
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.