-
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.
Browse files
Browse the repository at this point in the history
* fix: 새로운 구독이 되지 않는 문제 해결 * feat: api/client 패키지 구성 추가 * feat: ClientConfig 구현 * feat: DiscordBodyProperty 추가 * feat: announceWorkbookSubscription 구현 * feat: @EnableAsync 활성화 * feat: countAllSubscriptionStatus 구현 * feat: readWorkbookTitle 구현 * feat: WorkbookSubscriptionEvent 구현 * feat: WorkbookSubscriptionEvent 발행 추가 * feat: 테스트에 추가된 api/client 구성 추가 * refactor: WorkbookSubscriptionStatus 필드 명 수정 - id -> workbookId - subHistory -> isActiveSub * refactor: selectAllWorkbookSubscriptionStatus -> selectTopWorkbookSubscriptionStatus 수정 * refactor: SubscribeWorkbookUseCase 구독/재구독 로직 수정 * feat: 디스코드 훅 전송 응답 로그 추가
- Loading branch information
1 parent
6a73076
commit 606b325
Showing
17 changed files
with
242 additions
and
29 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
6 changes: 6 additions & 0 deletions
6
.../main/kotlin/com/few/api/repo/dao/subscription/record/CountAllSubscriptionStatusRecord.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,6 @@ | ||
package com.few.api.repo.dao.subscription.record | ||
|
||
data class CountAllSubscriptionStatusRecord( | ||
val totalSubscriptions: Long, | ||
val activeSubscriptions: Long | ||
) |
4 changes: 2 additions & 2 deletions
4
...po/src/main/kotlin/com/few/api/repo/dao/subscription/record/WorkbookSubscriptionStatus.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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
package com.few.api.repo.dao.subscription.record | ||
|
||
data class WorkbookSubscriptionStatus( | ||
val id: Long, | ||
val subHistory: Boolean, | ||
val workbookId: Long, | ||
val isActiveSub: Boolean, | ||
val day: Int | ||
) |
24 changes: 24 additions & 0 deletions
24
api/src/main/kotlin/com/few/api/client/config/ClientConfig.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,24 @@ | ||
package com.few.api.client.config | ||
|
||
import org.springframework.beans.factory.annotation.Value | ||
import org.springframework.boot.web.client.RestTemplateBuilder | ||
import org.springframework.context.annotation.Bean | ||
import org.springframework.context.annotation.Configuration | ||
import org.springframework.web.client.RestTemplate | ||
import java.time.Duration | ||
|
||
@Configuration | ||
class ClientConfig { | ||
|
||
@Bean | ||
fun restTemplate( | ||
restTemplateBuilder: RestTemplateBuilder, | ||
@Value("\${client.timeout.connect}") connectTimeout: Int, | ||
@Value("\${client.timeout.read}") readTimeout: Int | ||
): RestTemplate { | ||
return restTemplateBuilder | ||
.setConnectTimeout(Duration.ofSeconds(connectTimeout.toLong())) | ||
.setReadTimeout(Duration.ofSeconds(readTimeout.toLong())) | ||
.build() | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
api/src/main/kotlin/com/few/api/client/config/properties/DiscordBodyProperty.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,11 @@ | ||
package com.few.api.client.config.properties | ||
|
||
data class DiscordBodyProperty( | ||
val content: String, | ||
val embeds: List<Embed> | ||
) | ||
|
||
data class Embed( | ||
val title: String, | ||
val description: String | ||
) |
50 changes: 50 additions & 0 deletions
50
api/src/main/kotlin/com/few/api/client/subscription/SubscriptionClient.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,50 @@ | ||
package com.few.api.client.subscription | ||
|
||
import com.few.api.client.config.properties.DiscordBodyProperty | ||
import com.few.api.client.config.properties.Embed | ||
import com.few.api.client.subscription.dto.WorkbookSubscriptionArgs | ||
import org.apache.juli.logging.LogFactory | ||
import org.springframework.beans.factory.annotation.Value | ||
import org.springframework.http.HttpEntity | ||
import org.springframework.http.HttpMethod | ||
import org.springframework.stereotype.Service | ||
import org.springframework.web.client.RestTemplate | ||
|
||
@Service | ||
class SubscriptionClient( | ||
private val restTemplate: RestTemplate, | ||
@Value("\${webhook.discord}") private val discordWebhook: String | ||
) { | ||
private val log = LogFactory.getLog(SubscriptionClient::class.java) | ||
|
||
fun announceWorkbookSubscription(args: WorkbookSubscriptionArgs) { | ||
args.let { | ||
DiscordBodyProperty( | ||
content = "🎉 신규 구독 알림 ", | ||
embeds = listOf( | ||
Embed( | ||
title = "Total Subscriptions", | ||
description = it.totalSubscriptions.toString() | ||
), | ||
Embed( | ||
title = "Active Subscriptions", | ||
description = it.activeSubscriptions.toString() | ||
), | ||
Embed( | ||
title = "Workbook Title", | ||
description = it.workbookTitle | ||
) | ||
) | ||
) | ||
}.let { body -> | ||
restTemplate.exchange( | ||
discordWebhook, | ||
HttpMethod.POST, | ||
HttpEntity(body), | ||
String::class.java | ||
).let { res -> | ||
log.info("Discord webhook response: ${res.statusCode}") | ||
} | ||
} | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
api/src/main/kotlin/com/few/api/client/subscription/dto/WorkbookSubscriptionArgs.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,7 @@ | ||
package com.few.api.client.subscription.dto | ||
|
||
data class WorkbookSubscriptionArgs( | ||
val totalSubscriptions: Long, | ||
val activeSubscriptions: Long, | ||
val workbookTitle: 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
37 changes: 37 additions & 0 deletions
37
...rc/main/kotlin/com/few/api/domain/subscription/event/WorkbookSubscriptionEventListener.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.few.api.domain.subscription.event | ||
|
||
import com.few.api.client.subscription.SubscriptionClient | ||
import com.few.api.client.subscription.dto.WorkbookSubscriptionArgs | ||
import com.few.api.domain.subscription.event.dto.WorkbookSubscriptionEvent | ||
import com.few.api.domain.subscription.service.WorkbookService | ||
import com.few.api.domain.subscription.service.dto.ReadWorkbookTitleDto | ||
import com.few.api.repo.dao.subscription.SubscriptionDao | ||
import org.springframework.context.event.EventListener | ||
import org.springframework.scheduling.annotation.Async | ||
import org.springframework.stereotype.Component | ||
|
||
@Component | ||
class WorkbookSubscriptionEventListener( | ||
private val subscriptionDao: SubscriptionDao, | ||
private val subscriptionClient: SubscriptionClient, | ||
private val workbookService: WorkbookService | ||
) { | ||
|
||
@Async | ||
@EventListener | ||
fun handleWorkbookSubscriptionEvent(event: WorkbookSubscriptionEvent) { | ||
val title = ReadWorkbookTitleDto(event.workbookId).let { dto -> | ||
workbookService.readWorkbookTitle(dto) | ||
?: throw RuntimeException("Workbook not found") | ||
} | ||
subscriptionDao.countAllSubscriptionStatus().let { record -> | ||
WorkbookSubscriptionArgs( | ||
totalSubscriptions = record.totalSubscriptions, | ||
activeSubscriptions = record.activeSubscriptions, | ||
workbookTitle = title | ||
).let { args -> | ||
subscriptionClient.announceWorkbookSubscription(args) | ||
} | ||
} | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
api/src/main/kotlin/com/few/api/domain/subscription/event/dto/WorkbookSubscriptionEvent.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,5 @@ | ||
package com.few.api.domain.subscription.event.dto | ||
|
||
data class WorkbookSubscriptionEvent( | ||
val workbookId: Long | ||
) |
18 changes: 18 additions & 0 deletions
18
api/src/main/kotlin/com/few/api/domain/subscription/service/WorkbookService.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,18 @@ | ||
package com.few.api.domain.subscription.service | ||
|
||
import com.few.api.domain.subscription.service.dto.ReadWorkbookTitleDto | ||
import com.few.api.repo.dao.workbook.WorkbookDao | ||
import com.few.api.repo.dao.workbook.query.SelectWorkBookRecordQuery | ||
import org.springframework.stereotype.Service | ||
|
||
@Service | ||
class WorkbookService( | ||
private val workbookDao: WorkbookDao | ||
) { | ||
|
||
fun readWorkbookTitle(dto: ReadWorkbookTitleDto): String? { | ||
return SelectWorkBookRecordQuery(dto.workbookId).let { query -> | ||
workbookDao.selectWorkBook(query)?.title | ||
} | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
api/src/main/kotlin/com/few/api/domain/subscription/service/dto/ReadWorkbookTitleDto.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,5 @@ | ||
package com.few.api.domain.subscription.service.dto | ||
|
||
data class ReadWorkbookTitleDto( | ||
val workbookId: Long | ||
) |
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,7 @@ | ||
client: | ||
timeout: | ||
connect: 5000 | ||
read: 5000 | ||
|
||
webhook: | ||
discord: ${WEBHOOK_DISCORD} |
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 @@ | ||
client: | ||
timeout: | ||
connect: ${TIMEOUT_CONNECT:5000} | ||
read: ${TIMEOUT_READ:5000} | ||
|
||
webhook: | ||
discord: ${WEBHOOK_DISCORD} |
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