Skip to content

Commit 59ba6df

Browse files
authored
v0.1.9
v0.1.9
2 parents f004315 + 0ee25df commit 59ba6df

File tree

6 files changed

+113
-9
lines changed

6 files changed

+113
-9
lines changed

sseudam-clients/notification/src/main/kotlin/com/sseudam/client/discord/DiscordClientSender.kt

Lines changed: 98 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package com.sseudam.client.discord
22

3+
import com.sseudam.common.GeoJson
34
import com.sseudam.notification.discord.DiscordClient
5+
import com.sseudam.report.ReportType
6+
import com.sseudam.report.SpotReport
7+
import com.sseudam.suggestion.SpotSuggestion
48
import com.sseudam.user.UserProfile
59
import org.springframework.core.env.Environment
610
import org.springframework.retry.annotation.Backoff
@@ -14,20 +18,27 @@ class DiscordClientSender(
1418
private val discordWebhookClient: DiscordWebhookClient,
1519
private val discordWebhookProperties: DiscordWebhookProperties,
1620
) : DiscordClient {
21+
companion object {
22+
const val ADMIN_URL = "https://sseudam-admin.vercel.app"
23+
}
24+
25+
private val environmentName: String
26+
get() {
27+
val env = environment.getProperty("spring.profiles.active")
28+
return when (env) {
29+
"prod" -> "운영"
30+
"staging" -> "스테이징"
31+
"dev" -> "개발"
32+
else -> "그 외 환경"
33+
}
34+
}
35+
1736
@Retryable(
1837
maxAttempts = 3,
1938
backoff = Backoff(delay = 1000, multiplier = 2.0),
2039
retryFor = [Exception::class],
2140
)
2241
override fun sendCreateUserMessage(userProfile: UserProfile) {
23-
val environment = environment.getProperty("spring.profiles.active")
24-
val environmentName =
25-
when (environment) {
26-
"prod" -> "운영"
27-
"staging" -> "스테이징"
28-
"dev" -> "개발"
29-
else -> "그 외 환경"
30-
}
3142
val content =
3243
"""
3344
## 🎉 쓰담 새 회원 가입 알림 ($environmentName)
@@ -40,4 +51,83 @@ class DiscordClientSender(
4051
val message = DiscordMessagePayload(content)
4152
discordWebhookClient.sendMessage(URI.create(discordWebhookProperties.userChannel), message)
4253
}
54+
55+
@Retryable(
56+
maxAttempts = 3,
57+
backoff = Backoff(delay = 1000, multiplier = 2.0),
58+
retryFor = [Exception::class],
59+
)
60+
override fun sendReportMessage(report: SpotReport.Info) {
61+
val reportMessageByType = "**신고 내용:** ${
62+
when (report.reportType) {
63+
ReportType.POINT -> {
64+
when (val point = report.point) {
65+
is GeoJson.Point -> {
66+
val coords = point.coordinates
67+
if (coords.size >= 2) {
68+
"${coords[0]}, ${coords[1]} (경도, 위도)"
69+
} else {
70+
"좌표 정보 없음"
71+
}
72+
}
73+
else -> "좌표 정보 없음"
74+
}
75+
}
76+
ReportType.NAME -> report.spotName
77+
ReportType.KIND -> report.trashType.displayName
78+
ReportType.PHOTO -> report.imageUrl
79+
}
80+
}로 수정 요청"
81+
val content =
82+
"""
83+
## 🚨 신고 접수 알림 ($environmentName)
84+
85+
**신고 ID:** ${report.id}
86+
**신고 유형:** ${report.reportType.displayName} (${report.reportType.name})
87+
$reportMessageByType
88+
**신고자 ID:** ${report.userId}
89+
**신고 일시:** ${report.createdAt.toLocalDate()} ${report.createdAt.toLocalTime()}
90+
91+
확인하러 가기 -> $ADMIN_URL/reports/trash-cans
92+
""".trimIndent()
93+
94+
val message = DiscordMessagePayload(content)
95+
discordWebhookClient.sendMessage(URI.create(discordWebhookProperties.reportChannel), message)
96+
}
97+
98+
@Retryable(
99+
maxAttempts = 3,
100+
backoff = Backoff(delay = 1000, multiplier = 2.0),
101+
retryFor = [Exception::class],
102+
)
103+
override fun sendSuggestionMessage(suggestion: SpotSuggestion.Info) {
104+
val pointCoordinate =
105+
when (val point = suggestion.point) {
106+
is GeoJson.Point -> point.coordinates
107+
else -> emptyList()
108+
}
109+
val coordinateText =
110+
if (pointCoordinate.size >= 2) {
111+
"${pointCoordinate[0]}, ${pointCoordinate[1]} (경도, 위도)"
112+
} else {
113+
"좌표 정보 없음"
114+
}
115+
val content =
116+
"""
117+
## 💡 제보 접수 알림 ($environmentName)
118+
**제보 ID:** ${suggestion.id}
119+
**제보된 주소:** ${suggestion.address.site}
120+
**제보된 장소 이름:** ${suggestion.spotName}
121+
**제보된 장소 좌표:** $coordinateText
122+
**제보된 쓰레기통 타입:** ${suggestion.trashType.displayName}
123+
**제보자 ID:** ${suggestion.userId}
124+
**제보 일시:** ${suggestion.createdAt.toLocalDate()} ${suggestion.createdAt.toLocalTime()}
125+
확인하러 가기 -> $ADMIN_URL/suggestions/trash-cans
126+
""".trimIndent()
127+
val message = DiscordMessagePayload(content)
128+
discordWebhookClient.sendMessage(
129+
URI.create(discordWebhookProperties.suggestionChannel),
130+
message,
131+
)
132+
}
43133
}

sseudam-core/core-api/src/test/kotlin/com/sseudam/domain/trashspot/TrashSpotFacadeTest.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import com.sseudam.common.GeoJson
66
import com.sseudam.fixture.trashspot.TrashSpotFixture
77
import com.sseudam.suggestion.SpotSuggestion
88
import com.sseudam.suggestion.SuggestionService
9+
import com.sseudam.suggestion.SuggestionStatus
910
import com.sseudam.trashspot.TrashSpotFacade
1011
import com.sseudam.trashspot.TrashSpotLocation
1112
import com.sseudam.trashspot.TrashSpotService
@@ -56,6 +57,7 @@ class TrashSpotFacadeTest :
5657
address = spot.address,
5758
trashType = spot.trashType,
5859
imageUrl = "",
60+
status = SuggestionStatus.WAITING,
5961
createdAt = LocalDateTime.now(),
6062
)
6163
val userProfile = UserProfile(id = 123L, key = "k", email = "[email protected]", name = "u", nickname = "nick", createdAt = LocalDateTime.now())
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
package com.sseudam.notification.discord
22

3+
import com.sseudam.report.SpotReport
4+
import com.sseudam.suggestion.SpotSuggestion
35
import com.sseudam.user.UserProfile
46

57
interface DiscordClient {
68
fun sendCreateUserMessage(userProfile: UserProfile)
9+
10+
fun sendReportMessage(report: SpotReport.Info)
11+
12+
fun sendSuggestionMessage(suggestion: SpotSuggestion.Info)
713
}

sseudam-core/core-domain/src/main/kotlin/com/sseudam/report/ReportFacade.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.sseudam.report
22

33
import com.sseudam.common.ImageS3Caller
44
import com.sseudam.common.S3ImageUrl
5+
import com.sseudam.notification.discord.DiscordClient
56
import com.sseudam.pet.PetPointAction
67
import com.sseudam.pet.event.PetEventPublisher
78
import com.sseudam.support.Cache
@@ -15,6 +16,7 @@ class ReportFacade(
1516
private val reportService: ReportService,
1617
private val trashSpotService: TrashSpotService,
1718
private val trashSpotImageService: TrashSpotImageService,
19+
private val discordClient: DiscordClient,
1820
private val imageS3Caller: ImageS3Caller,
1921
private val petEventPublisher: PetEventPublisher,
2022
private val txAdvice: TxAdvice,
@@ -58,6 +60,7 @@ class ReportFacade(
5860
reportService.appendReport(imageUrl, create).apply {
5961
Cache.delete("user:${create.userId}:histories")
6062
}
63+
discordClient.sendReportMessage(spotReport)
6164
petEventPublisher.publish(create.userId, PetPointAction.REPORT)
6265

6366
return@write spotReport to presignedUrl

sseudam-core/core-domain/src/main/kotlin/com/sseudam/suggestion/SpotSuggestion.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class SpotSuggestion {
5252
val address: Address,
5353
val trashType: TrashType,
5454
val imageUrl: String,
55-
val status: SuggestionStatus = SuggestionStatus.WAITING,
55+
val status: SuggestionStatus,
5656
val createdAt: LocalDateTime,
5757
)
5858

sseudam-core/core-domain/src/main/kotlin/com/sseudam/suggestion/SuggestionFacade.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.sseudam.suggestion
22

33
import com.sseudam.common.S3ImageUrl
4+
import com.sseudam.notification.discord.DiscordClient
45
import com.sseudam.support.Cache
56
import com.sseudam.trashspot.TrashSpotService
67
import org.springframework.stereotype.Service
@@ -9,6 +10,7 @@ import org.springframework.stereotype.Service
910
class SuggestionFacade(
1011
private val suggestionService: SuggestionService,
1112
private val trashSpotService: TrashSpotService,
13+
private val discordClient: DiscordClient,
1214
) {
1315
fun validateSpotSuggestion(name: String): Boolean {
1416
suggestionService.validateSpotSuggestionName(name)
@@ -24,6 +26,7 @@ class SuggestionFacade(
2426
.apply {
2527
Cache.delete("user:${create.userId}:histories")
2628
}
29+
discordClient.sendSuggestionMessage(suggestionInfo)
2730
return suggestionInfo to s3ImageUrl
2831
}
2932
}

0 commit comments

Comments
 (0)