-
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.
feat: unclassified Vaccination Discord Webhook
- Loading branch information
Showing
8 changed files
with
118 additions
and
4 deletions.
There are no files selected for viewing
Submodule API-CONFIG
updated
from e3e273 to 12cbc6
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,24 @@ | ||
package kr.co.vacgom.api | ||
|
||
import kr.co.vacgom.api.global.presentation.GlobalPath.BASE_V3 | ||
import kr.co.vacgom.api.user.application.UserTokenService | ||
import kr.co.vacgom.api.user.repository.UserRepository | ||
import org.springframework.http.ResponseEntity | ||
import org.springframework.web.bind.annotation.PostMapping | ||
import org.springframework.web.bind.annotation.RequestMapping | ||
import org.springframework.web.bind.annotation.RestController | ||
|
||
@RestController | ||
@RequestMapping(BASE_V3 + "/TEST") | ||
class TestController( | ||
private val userRepository: UserRepository, | ||
private val userTokenService: UserTokenService | ||
) { | ||
|
||
@PostMapping | ||
fun test(): ResponseEntity<String> { | ||
val user = userRepository.findAll().get(0) | ||
val accessToken = userTokenService.createAccessToken(user.id, user.role) | ||
return ResponseEntity.ok(accessToken) | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
src/main/kotlin/kr/co/vacgom/api/global/discord/DiscordSender.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,65 @@ | ||
package kr.co.vacgom.api.global.discord | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper | ||
import kr.co.vacgom.api.baby.domain.Baby | ||
import kr.co.vacgom.api.vaccine.domain.UnclassifiedVaccination | ||
import org.springframework.beans.factory.annotation.Value | ||
import org.springframework.http.HttpEntity | ||
import org.springframework.http.HttpHeaders | ||
import org.springframework.http.MediaType | ||
import org.springframework.stereotype.Component | ||
import org.springframework.web.client.RestTemplate | ||
import java.time.LocalDateTime | ||
import java.time.format.DateTimeFormatter | ||
|
||
@Component | ||
class DiscordSender( | ||
@Value("\${discord.deployWebhookURL}") | ||
private val webhookURL: String, | ||
|
||
@Value("\${discord.welcomeWebhookURL}") | ||
private val welcomeURL: String, | ||
|
||
private val objectMapper: ObjectMapper, | ||
|
||
private val restTemplate: RestTemplate | ||
) { | ||
fun sendVaccinationError( | ||
baby: Baby, | ||
unclassifiedVaccination: UnclassifiedVaccination | ||
) { | ||
val headers = HttpHeaders() | ||
headers.contentType = MediaType.APPLICATION_JSON | ||
|
||
val now = LocalDateTime.now() | ||
val formatter = DateTimeFormatter.ofPattern("yyyy년 MM월 dd일 HH시 mm분 ss초") | ||
val formattedNow = now.format(formatter) | ||
|
||
val embeds = mapOf( | ||
"title" to "**[ \uD83D\uDEA8 긴급 \uD83D\uDEA8 ] ERR-001** 미분류 백신 추가 필요", | ||
"description" to "**미분류 백신** : ${unclassifiedVaccination.name}\n\n" + | ||
"**요청시간** : " + formattedNow + "\n\n" + | ||
"**LOG**\n\n" + | ||
"```json\n{\n" + | ||
"\t\"id\" : ${unclassifiedVaccination.id},\n" + | ||
"\t\"name\" : ${unclassifiedVaccination.name},\n" + | ||
"\t\"doseRound\" : ${unclassifiedVaccination.doseRound},\n" + | ||
"\t\"doseRoundDescription\" : ${unclassifiedVaccination.doseRoundDescription},\n" + | ||
"\t\"vaccinatedAt\" : ${unclassifiedVaccination.vaccinatedAt},\n" + | ||
"\t\"facility\" : ${unclassifiedVaccination.facility},\n" + | ||
"\t\"manufacturer\" : ${unclassifiedVaccination.manufacturer},\n" + | ||
"\t\"productName\" : ${unclassifiedVaccination.productName},\n" + | ||
"\t\"lotNumber\" : ${unclassifiedVaccination.lotNumber},\n" + | ||
"\t\"babyId\" : ${unclassifiedVaccination.baby.id}\n}```", | ||
"color" to "15548997" | ||
) | ||
val payload = mapOf( | ||
"content" to null, | ||
"embeds" to listOf(embeds) | ||
) | ||
|
||
val jsonPayload = objectMapper.writeValueAsString(payload) | ||
val entity = HttpEntity(jsonPayload, headers) | ||
restTemplate.postForLocation(webhookURL, entity) | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/kotlin/kr/co/vacgom/api/global/discord/RestTemplateConfig.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 kr.co.vacgom.api.global.discord | ||
|
||
import org.springframework.context.annotation.Bean | ||
import org.springframework.context.annotation.Configuration | ||
import org.springframework.web.client.RestTemplate | ||
|
||
@Configuration | ||
class RestTemplateConfig { | ||
|
||
@Bean | ||
fun restTemplate(): RestTemplate { | ||
return RestTemplate() | ||
} | ||
} |
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