-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
merge: (#672) 서버 버그 발생시 slack 으로 메세지 송신
- Loading branch information
Showing
15 changed files
with
180 additions
and
15 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
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
dms-core/src/main/kotlin/team/aliens/dms/domain/bug/service/SendBugService.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 team.aliens.dms.domain.bug.service | ||
|
||
import team.aliens.dms.domain.bug.model.BugReport | ||
|
||
interface SendBugService { | ||
|
||
fun sendBugReport(bugReport: BugReport) | ||
} |
15 changes: 15 additions & 0 deletions
15
dms-core/src/main/kotlin/team/aliens/dms/domain/bug/service/SendBugServiceImpl.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 team.aliens.dms.domain.bug.service | ||
|
||
import team.aliens.dms.common.annotation.Service | ||
import team.aliens.dms.domain.bug.model.BugReport | ||
import team.aliens.dms.domain.bug.spi.SendBugPort | ||
|
||
@Service | ||
class SendBugServiceImpl( | ||
private val sendBugPort: SendBugPort | ||
) : SendBugService { | ||
|
||
override fun sendBugReport(bugReport: BugReport) { | ||
sendBugPort.sendBugReport(bugReport) | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
dms-core/src/main/kotlin/team/aliens/dms/domain/bug/spi/SendBugPort.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 team.aliens.dms.domain.bug.spi | ||
|
||
import team.aliens.dms.domain.bug.model.BugReport | ||
|
||
interface SendBugPort { | ||
|
||
fun sendBugReport(bugReport: BugReport) | ||
} |
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
110 changes: 110 additions & 0 deletions
110
dms-infrastructure/src/main/kotlin/team/aliens/dms/thirdparty/slack/SlackAdapter.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,110 @@ | ||
package team.aliens.dms.thirdparty.slack | ||
|
||
import com.slack.api.Slack | ||
import com.slack.api.model.block.Blocks.divider | ||
import com.slack.api.model.block.Blocks.header | ||
import com.slack.api.model.block.Blocks.image | ||
import com.slack.api.model.block.Blocks.section | ||
import com.slack.api.model.block.LayoutBlock | ||
import com.slack.api.model.block.composition.BlockCompositions.markdownText | ||
import com.slack.api.model.block.composition.BlockCompositions.plainText | ||
import com.slack.api.model.block.composition.OptionObject | ||
import com.slack.api.model.block.element.BlockElements.staticSelect | ||
import com.slack.api.webhook.Payload | ||
import jakarta.servlet.http.HttpServletRequest | ||
import jakarta.servlet.http.HttpServletResponse | ||
import org.springframework.beans.factory.annotation.Value | ||
import org.springframework.stereotype.Component | ||
import team.aliens.dms.domain.bug.model.BugReport | ||
import team.aliens.dms.domain.bug.spi.SendBugPort | ||
import java.lang.Exception | ||
|
||
@Component | ||
class SlackAdapter( | ||
@Value("\${slack.url}") | ||
private val url: String, | ||
|
||
) : SendBugPort { | ||
|
||
private val slack = Slack.getInstance() | ||
|
||
override fun sendBugReport(bugReport: BugReport) { | ||
val blocks = toMutableBlocks( | ||
header { it.text(plainText("버그 제보가 들어왔습니다.")) }, | ||
section { it.text(plainText("제보자 : ${bugReport.studentId}")) }, | ||
section { it.text(plainText("OS : ${bugReport.developmentArea.name}")) }, | ||
section { it.text(plainText("message : ${bugReport.content}")) } | ||
) | ||
|
||
blocks | ||
.addImages(bugReport.attachmentUrls?.attachmentUrls ?: emptyList()) | ||
.addSelectProgress() | ||
.sendBug() | ||
} | ||
|
||
fun sendServerBug(request: HttpServletRequest, response: HttpServletResponse, exception: Exception) { | ||
val blocks = toMutableBlocks( | ||
header { it.text(plainText("서버에 예외가 발생했습니다.")) }, | ||
section { it.text(plainText("requested info : <${request.method}> ${request.requestURL}")) }, | ||
section { it.text(plainText("exception class : ${exception.javaClass.name}")) }, | ||
section { it.text(plainText("exception message : ${exception.message}")) }, | ||
) | ||
|
||
blocks | ||
.addSelectProgress() | ||
.sendBug() | ||
} | ||
|
||
private fun toMutableBlocks(vararg blocks: LayoutBlock): MutableList<LayoutBlock> { | ||
return blocks.toMutableList() | ||
} | ||
|
||
private fun MutableList<LayoutBlock>.addSelectProgress(): MutableList<LayoutBlock> { | ||
this.addAll( | ||
listOf( | ||
divider(), | ||
section { section -> | ||
section.text(markdownText("현재 버그 상황을 선택 해주세요.")) | ||
section.accessory( | ||
staticSelect { | ||
it.placeholder(plainText("Select a progress status")) | ||
it.options( | ||
listOf( | ||
OptionObject.builder().text(plainText("미해결")).value("not-in-progress").build(), | ||
OptionObject.builder().text(plainText("해결중")).value("in-progress").build(), | ||
OptionObject.builder().text(plainText("해결됨")).value("solved").build(), | ||
OptionObject.builder().text(plainText("논외")).value("out-of-topic").build(), | ||
) | ||
) | ||
it.initialOption( | ||
OptionObject.builder().text(plainText("미해결")).value("not-in-progress").build() | ||
) | ||
} | ||
) | ||
}, | ||
divider() | ||
) | ||
) | ||
|
||
return this | ||
} | ||
|
||
private fun MutableList<LayoutBlock>.addImages(attachmentUrls: List<String>): MutableList<LayoutBlock> { | ||
this.addAll( | ||
attachmentUrls.map { url -> | ||
image { it.imageUrl(url).altText("bug image") } | ||
} | ||
) | ||
|
||
return this | ||
} | ||
|
||
private fun MutableList<LayoutBlock>.sendBug() { | ||
slack.send( | ||
url, | ||
Payload.builder() | ||
.blocks(this) | ||
.build() | ||
) | ||
} | ||
} |
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