-
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.
- Loading branch information
Showing
34 changed files
with
532 additions
and
13 deletions.
There are no files selected for viewing
48 changes: 48 additions & 0 deletions
48
api-repo/src/main/kotlin/com/few/api/repo/dao/log/SendArticleEventHistoryDao.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,48 @@ | ||
package com.few.api.repo.dao.log | ||
|
||
import com.few.api.repo.dao.log.command.InsertEventCommand | ||
import com.few.api.repo.dao.log.query.SelectEventByMessageIdAndEventTypeQuery | ||
import com.few.api.repo.dao.log.record.SendArticleEventHistoryRecord | ||
import jooq.jooq_dsl.tables.SendArticleEventHistory | ||
import org.jooq.DSLContext | ||
import org.springframework.stereotype.Repository | ||
|
||
@Repository | ||
class SendArticleEventHistoryDao( | ||
private val dslContext: DSLContext, | ||
) { | ||
|
||
fun insertEvent(command: InsertEventCommand) { | ||
dslContext.insertInto(SendArticleEventHistory.SEND_ARTICLE_EVENT_HISTORY) | ||
.set(SendArticleEventHistory.SEND_ARTICLE_EVENT_HISTORY.MEMBER_ID, command.memberId) | ||
.set(SendArticleEventHistory.SEND_ARTICLE_EVENT_HISTORY.ARTICLE_ID, command.articleId) | ||
.set(SendArticleEventHistory.SEND_ARTICLE_EVENT_HISTORY.MESSAGE_ID, command.messageId) | ||
.set(SendArticleEventHistory.SEND_ARTICLE_EVENT_HISTORY.EVENT_TYPE_CD, command.eventType) | ||
.set(SendArticleEventHistory.SEND_ARTICLE_EVENT_HISTORY.SEND_TYPE_CD, command.sendType) | ||
.execute() | ||
} | ||
|
||
fun selectEventByMessageId(query: SelectEventByMessageIdAndEventTypeQuery): SendArticleEventHistoryRecord? { | ||
return dslContext.select( | ||
SendArticleEventHistory.SEND_ARTICLE_EVENT_HISTORY.MEMBER_ID.`as`( | ||
SendArticleEventHistoryRecord::memberId.name | ||
), | ||
SendArticleEventHistory.SEND_ARTICLE_EVENT_HISTORY.ARTICLE_ID.`as`( | ||
SendArticleEventHistoryRecord::articleId.name | ||
), | ||
SendArticleEventHistory.SEND_ARTICLE_EVENT_HISTORY.MESSAGE_ID.`as`( | ||
SendArticleEventHistoryRecord::messageId.name | ||
), | ||
SendArticleEventHistory.SEND_ARTICLE_EVENT_HISTORY.EVENT_TYPE_CD.`as`( | ||
SendArticleEventHistoryRecord::eventType.name | ||
), | ||
SendArticleEventHistory.SEND_ARTICLE_EVENT_HISTORY.SEND_TYPE_CD.`as`( | ||
SendArticleEventHistoryRecord::sendType.name | ||
) | ||
) | ||
.from(SendArticleEventHistory.SEND_ARTICLE_EVENT_HISTORY) | ||
.where(SendArticleEventHistory.SEND_ARTICLE_EVENT_HISTORY.MESSAGE_ID.eq(query.messageId)) | ||
.and(SendArticleEventHistory.SEND_ARTICLE_EVENT_HISTORY.EVENT_TYPE_CD.eq(query.eventType)) | ||
.fetchOne()?.into(SendArticleEventHistoryRecord::class.java) | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
api-repo/src/main/kotlin/com/few/api/repo/dao/log/command/InsertEventCommand.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,9 @@ | ||
package com.few.api.repo.dao.log.command | ||
|
||
data class InsertEventCommand( | ||
val memberId: Long, | ||
val articleId: Long, | ||
val messageId: String, | ||
val eventType: Byte, | ||
val sendType: Byte, | ||
) |
6 changes: 6 additions & 0 deletions
6
...src/main/kotlin/com/few/api/repo/dao/log/query/SelectEventByMessageIdAndEventTypeQuery.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.log.query | ||
|
||
data class SelectEventByMessageIdAndEventTypeQuery( | ||
val messageId: String, | ||
val eventType: Byte, | ||
) |
9 changes: 9 additions & 0 deletions
9
api-repo/src/main/kotlin/com/few/api/repo/dao/log/record/SendArticleEventHistoryRecord.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,9 @@ | ||
package com.few.api.repo.dao.log.record | ||
|
||
data class SendArticleEventHistoryRecord( | ||
val memberId: Long, | ||
val articleId: Long, | ||
val messageId: String, | ||
val eventType: Byte, | ||
val sendType: Byte, | ||
) |
36 changes: 36 additions & 0 deletions
36
api/src/main/kotlin/com/few/api/domain/article/service/ArticleLogService.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,36 @@ | ||
package com.few.api.domain.article.service | ||
|
||
import com.few.api.domain.article.service.dto.InsertOpenEventDto | ||
import com.few.api.domain.article.service.dto.SelectDeliveryEventByMessageIdDto | ||
import com.few.api.repo.dao.log.SendArticleEventHistoryDao | ||
import com.few.api.repo.dao.log.command.InsertEventCommand | ||
import com.few.api.repo.dao.log.query.SelectEventByMessageIdAndEventTypeQuery | ||
import com.few.api.repo.dao.log.record.SendArticleEventHistoryRecord | ||
import org.springframework.stereotype.Service | ||
|
||
@Service | ||
class ArticleLogService( | ||
private val sendArticleEventHistoryDao: SendArticleEventHistoryDao, | ||
) { | ||
|
||
fun selectDeliveryEventByMessageId(dto: SelectDeliveryEventByMessageIdDto): SendArticleEventHistoryRecord? { | ||
return sendArticleEventHistoryDao.selectEventByMessageId( | ||
SelectEventByMessageIdAndEventTypeQuery( | ||
dto.messageId, | ||
dto.eventType | ||
) | ||
) | ||
} | ||
|
||
fun insertOpenEvent(dto: InsertOpenEventDto) { | ||
sendArticleEventHistoryDao.insertEvent( | ||
InsertEventCommand( | ||
memberId = dto.memberId, | ||
articleId = dto.articleId, | ||
messageId = dto.messageId, | ||
eventType = dto.eventType, | ||
sendType = dto.sendType | ||
) | ||
) | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
api/src/main/kotlin/com/few/api/domain/article/service/ArticleMemberService.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.article.service | ||
|
||
import com.few.api.domain.article.service.dto.ReadMemberByEmailDto | ||
import com.few.api.repo.dao.member.MemberDao | ||
import com.few.api.repo.dao.member.query.SelectMemberByEmailQuery | ||
import org.springframework.stereotype.Service | ||
|
||
@Service | ||
class ArticleMemberService( | ||
private val memberDao: MemberDao, | ||
) { | ||
|
||
fun readMemberByEmail(dto: ReadMemberByEmailDto): Long? { | ||
return memberDao.selectMemberByEmail( | ||
SelectMemberByEmailQuery(dto.email) | ||
)?.memberId | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
api/src/main/kotlin/com/few/api/domain/article/service/dto/InsertOpenEventDto.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,9 @@ | ||
package com.few.api.domain.article.service.dto | ||
|
||
data class InsertOpenEventDto( | ||
val memberId: Long, | ||
val articleId: Long, | ||
val messageId: String, | ||
val eventType: Byte, | ||
val sendType: Byte, | ||
) |
5 changes: 5 additions & 0 deletions
5
api/src/main/kotlin/com/few/api/domain/article/service/dto/ReadMemberByEmailDto.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.article.service.dto | ||
|
||
data class ReadMemberByEmailDto( | ||
val email: String, | ||
) |
6 changes: 6 additions & 0 deletions
6
...c/main/kotlin/com/few/api/domain/article/service/dto/SelectDeliveryEventByMessageIdDto.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.domain.article.service.dto | ||
|
||
data class SelectDeliveryEventByMessageIdDto( | ||
val messageId: String, | ||
val eventType: Byte, | ||
) |
45 changes: 45 additions & 0 deletions
45
api/src/main/kotlin/com/few/api/domain/article/usecase/ReadArticleByEmailUseCase.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,45 @@ | ||
package com.few.api.domain.article.usecase | ||
|
||
import com.few.api.domain.article.service.ArticleLogService | ||
import com.few.api.domain.article.service.ArticleMemberService | ||
import com.few.api.domain.article.service.dto.InsertOpenEventDto | ||
import com.few.api.domain.article.service.dto.ReadMemberByEmailDto | ||
import com.few.api.domain.article.service.dto.SelectDeliveryEventByMessageIdDto | ||
import com.few.api.domain.article.usecase.dto.ReadArticleByEmailUseCaseIn | ||
import com.few.api.web.support.EmailLogEventType | ||
import org.springframework.stereotype.Component | ||
import org.springframework.transaction.annotation.Transactional | ||
import org.webjars.NotFoundException | ||
|
||
@Component | ||
class ReadArticleByEmailUseCase( | ||
private val memberService: ArticleMemberService, | ||
private val articleLogService: ArticleLogService, | ||
) { | ||
|
||
@Transactional | ||
fun execute(useCaseIn: ReadArticleByEmailUseCaseIn) { | ||
val memberId = | ||
memberService.readMemberByEmail(ReadMemberByEmailDto(useCaseIn.destination[0])) | ||
?: throw NotFoundException("member.notfound.email") | ||
|
||
val record = | ||
articleLogService.selectDeliveryEventByMessageId( | ||
SelectDeliveryEventByMessageIdDto( | ||
useCaseIn.messageId, | ||
EmailLogEventType.DELIVERY.code | ||
) | ||
) | ||
?: throw IllegalStateException("event is not found") | ||
|
||
articleLogService.insertOpenEvent( | ||
InsertOpenEventDto( | ||
memberId = memberId, | ||
articleId = record.articleId, | ||
messageId = record.messageId, | ||
eventType = EmailLogEventType.OPEN.code, | ||
sendType = record.sendType | ||
) | ||
) | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
api/src/main/kotlin/com/few/api/domain/article/usecase/dto/ReadArticleByEmailUseCaseIn.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.domain.article.usecase.dto | ||
|
||
import com.few.api.web.support.EmailLogEventType | ||
import com.few.api.web.support.SendType | ||
|
||
data class ReadArticleByEmailUseCaseIn( | ||
val messageId: String, | ||
val destination: List<String>, | ||
val eventType: EmailLogEventType, | ||
val sendType: SendType, | ||
) |
46 changes: 46 additions & 0 deletions
46
api/src/main/kotlin/com/few/api/domain/log/AddEmailLogUseCase.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,46 @@ | ||
package com.few.api.domain.log | ||
|
||
import com.few.api.domain.log.dto.AddEmailLogUseCaseIn | ||
import com.few.api.repo.dao.log.SendArticleEventHistoryDao | ||
import com.few.api.repo.dao.log.command.InsertEventCommand | ||
import com.few.api.repo.dao.log.query.SelectEventByMessageIdAndEventTypeQuery | ||
import com.few.api.repo.dao.member.MemberDao | ||
import com.few.api.repo.dao.member.query.SelectMemberByEmailQuery | ||
import com.few.api.web.support.EmailLogEventType | ||
import org.springframework.stereotype.Component | ||
import org.springframework.transaction.annotation.Transactional | ||
import org.webjars.NotFoundException | ||
|
||
@Component | ||
class AddEmailLogUseCase( | ||
private val memberDao: MemberDao, | ||
private val sendArticleEventHistoryDao: SendArticleEventHistoryDao, | ||
) { | ||
@Transactional | ||
fun execute(useCaseIn: AddEmailLogUseCaseIn) { | ||
val (memberId, _, _, _) = memberDao.selectMemberByEmail( | ||
SelectMemberByEmailQuery(useCaseIn.destination[0]) | ||
) ?: throw NotFoundException("member.notfound.email") | ||
|
||
val record = | ||
sendArticleEventHistoryDao.selectEventByMessageId( | ||
SelectEventByMessageIdAndEventTypeQuery( | ||
useCaseIn.messageId, | ||
EmailLogEventType.SEND.code | ||
) | ||
) | ||
?: throw IllegalStateException("event is not found") | ||
|
||
sendArticleEventHistoryDao.insertEvent( | ||
InsertEventCommand( | ||
memberId = memberId, | ||
articleId = record.articleId, | ||
messageId = record.messageId, | ||
eventType = useCaseIn.eventType.code, | ||
sendType = record.sendType | ||
) | ||
).let { | ||
// TODO("다른 이벤트는 필요시 추가한다.") | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
api/src/main/kotlin/com/few/api/domain/log/dto/AddEmailLogUseCaseIn.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.domain.log.dto | ||
|
||
import com.few.api.web.support.EmailLogEventType | ||
import java.time.LocalDateTime | ||
|
||
data class AddEmailLogUseCaseIn( | ||
val eventType: EmailLogEventType, | ||
val messageId: String, | ||
val destination: List<String>, | ||
val mailTimestamp: LocalDateTime, | ||
) |
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
25 changes: 25 additions & 0 deletions
25
api/src/main/kotlin/com/few/api/domain/subscription/service/SubscriptionLogService.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,25 @@ | ||
package com.few.api.domain.subscription.service | ||
|
||
import com.few.api.domain.subscription.service.dto.InsertSendEventDto | ||
import com.few.api.repo.dao.log.SendArticleEventHistoryDao | ||
import com.few.api.repo.dao.log.command.InsertEventCommand | ||
import com.few.api.web.support.EmailLogEventType | ||
import org.springframework.stereotype.Service | ||
|
||
@Service | ||
class SubscriptionLogService( | ||
private val sendArticleEventHistoryDao: SendArticleEventHistoryDao, | ||
) { | ||
|
||
fun insertSendEvent(dto: InsertSendEventDto) { | ||
sendArticleEventHistoryDao.insertEvent( | ||
InsertEventCommand( | ||
memberId = dto.memberId, | ||
articleId = dto.articleId, | ||
messageId = dto.messageId, | ||
eventType = EmailLogEventType.SEND.code, | ||
sendType = dto.sendType | ||
) | ||
) | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
api/src/main/kotlin/com/few/api/domain/subscription/service/dto/InsertSendEventDto.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 com.few.api.domain.subscription.service.dto | ||
|
||
data class InsertSendEventDto( | ||
val memberId: Long, | ||
val articleId: Long, | ||
val messageId: String, | ||
val sendType: Byte, | ||
) |
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.