From 7141c7bc6abc1b87b4af3a4a7c896faac4ebdf5c Mon Sep 17 00:00:00 2001 From: usbharu <64310155+usbharu@users.noreply.github.com> Date: Mon, 29 Jan 2024 20:17:15 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20=E4=B8=8D=E8=A6=81=E3=81=AB?= =?UTF-8?q?=E3=81=AA=E3=81=A3=E3=81=9F=E9=96=A2=E6=95=B0=E3=82=92=E5=89=8A?= =?UTF-8?q?=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../model/MastodonNotificationRepository.kt | 11 ----- .../ExposedMastodonNotificationRepository.kt | 29 ------------ ...goMastodonNotificationRepositoryWrapper.kt | 31 ------------ .../notification/NotificationApiService.kt | 11 ----- .../NotificationApiServiceImpl.kt | 47 ------------------- 5 files changed, 129 deletions(-) diff --git a/src/main/kotlin/dev/usbharu/hideout/mastodon/domain/model/MastodonNotificationRepository.kt b/src/main/kotlin/dev/usbharu/hideout/mastodon/domain/model/MastodonNotificationRepository.kt index a89ffdca..e1294843 100644 --- a/src/main/kotlin/dev/usbharu/hideout/mastodon/domain/model/MastodonNotificationRepository.kt +++ b/src/main/kotlin/dev/usbharu/hideout/mastodon/domain/model/MastodonNotificationRepository.kt @@ -8,17 +8,6 @@ interface MastodonNotificationRepository { suspend fun deleteById(id: Long) suspend fun findById(id: Long): MastodonNotification? - @Suppress("LongParameterList", "FunctionMaxLength") - suspend fun findByUserIdAndMaxIdAndMinIdAndSinceIdAndInTypesAndInSourceActorId( - loginUser: Long, - maxId: Long?, - minId: Long?, - sinceId: Long?, - limit: Int, - typesTmp: MutableList, - accountId: List - ): List - suspend fun findByUserIdAndInTypesAndInSourceActorId( loginUser: Long, types: List, diff --git a/src/main/kotlin/dev/usbharu/hideout/mastodon/infrastructure/exposedrepository/ExposedMastodonNotificationRepository.kt b/src/main/kotlin/dev/usbharu/hideout/mastodon/infrastructure/exposedrepository/ExposedMastodonNotificationRepository.kt index 6181f3ef..bc62b656 100644 --- a/src/main/kotlin/dev/usbharu/hideout/mastodon/infrastructure/exposedrepository/ExposedMastodonNotificationRepository.kt +++ b/src/main/kotlin/dev/usbharu/hideout/mastodon/infrastructure/exposedrepository/ExposedMastodonNotificationRepository.kt @@ -62,35 +62,6 @@ class ExposedMastodonNotificationRepository : MastodonNotificationRepository, Ab MastodonNotifications.select { MastodonNotifications.id eq id }.singleOrNull()?.toMastodonNotification() } - override suspend fun findByUserIdAndMaxIdAndMinIdAndSinceIdAndInTypesAndInSourceActorId( - loginUser: Long, - maxId: Long?, - minId: Long?, - sinceId: Long?, - limit: Int, - typesTmp: MutableList, - accountId: List - ): List = query { - val query = MastodonNotifications.select { - MastodonNotifications.userId eq loginUser - } - - if (maxId != null) { - query.andWhere { MastodonNotifications.id lessEq maxId } - } - if (minId != null) { - query.andWhere { MastodonNotifications.id greaterEq minId } - } - if (sinceId != null) { - query.andWhere { MastodonNotifications.id greaterEq sinceId } - } - val result = query - .limit(limit) - .orderBy(Timelines.createdAt, SortOrder.DESC) - - return@query result.map { it.toMastodonNotification() } - } - override suspend fun findByUserIdAndInTypesAndInSourceActorId( loginUser: Long, types: List, diff --git a/src/main/kotlin/dev/usbharu/hideout/mastodon/infrastructure/mongorepository/MongoMastodonNotificationRepositoryWrapper.kt b/src/main/kotlin/dev/usbharu/hideout/mastodon/infrastructure/mongorepository/MongoMastodonNotificationRepositoryWrapper.kt index 06f4dadd..fae487d5 100644 --- a/src/main/kotlin/dev/usbharu/hideout/mastodon/infrastructure/mongorepository/MongoMastodonNotificationRepositoryWrapper.kt +++ b/src/main/kotlin/dev/usbharu/hideout/mastodon/infrastructure/mongorepository/MongoMastodonNotificationRepositoryWrapper.kt @@ -28,37 +28,6 @@ class MongoMastodonNotificationRepositoryWrapper( override suspend fun findById(id: Long): MastodonNotification? = mongoMastodonNotificationRepository.findById(id).getOrNull() - override suspend fun findByUserIdAndMaxIdAndMinIdAndSinceIdAndInTypesAndInSourceActorId( - loginUser: Long, - maxId: Long?, - minId: Long?, - sinceId: Long?, - limit: Int, - typesTmp: MutableList, - accountId: List - ): List { - val query = Query() - - if (maxId != null) { - val criteria = Criteria.where("id").lte(maxId) - query.addCriteria(criteria) - } - - if (minId != null) { - val criteria = Criteria.where("id").gte(minId) - query.addCriteria(criteria) - } - if (sinceId != null) { - val criteria = Criteria.where("id").gte(sinceId) - query.addCriteria(criteria) - } - - query.limit(limit) - query.with(Sort.by(Sort.Direction.DESC, "createdAt")) - - return mongoTemplate.find(query, MastodonNotification::class.java) - } - override suspend fun findByUserIdAndInTypesAndInSourceActorId( loginUser: Long, types: List, diff --git a/src/main/kotlin/dev/usbharu/hideout/mastodon/service/notification/NotificationApiService.kt b/src/main/kotlin/dev/usbharu/hideout/mastodon/service/notification/NotificationApiService.kt index c336ccc6..d6b312be 100644 --- a/src/main/kotlin/dev/usbharu/hideout/mastodon/service/notification/NotificationApiService.kt +++ b/src/main/kotlin/dev/usbharu/hideout/mastodon/service/notification/NotificationApiService.kt @@ -6,17 +6,6 @@ import dev.usbharu.hideout.domain.mastodon.model.generated.Notification import dev.usbharu.hideout.mastodon.domain.model.NotificationType interface NotificationApiService { - @Suppress("LongParameterList") - suspend fun notifications( - loginUser: Long, - maxId: Long?, - minId: Long?, - sinceId: Long?, - limit: Int, - types: List, - excludeTypes: List, - accountId: List - ): List suspend fun notifications( loginUser: Long, diff --git a/src/main/kotlin/dev/usbharu/hideout/mastodon/service/notification/NotificationApiServiceImpl.kt b/src/main/kotlin/dev/usbharu/hideout/mastodon/service/notification/NotificationApiServiceImpl.kt index 528c454c..789d164b 100644 --- a/src/main/kotlin/dev/usbharu/hideout/mastodon/service/notification/NotificationApiServiceImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/mastodon/service/notification/NotificationApiServiceImpl.kt @@ -19,53 +19,6 @@ class NotificationApiServiceImpl( private val statusQueryService: StatusQueryService ) : NotificationApiService { - override suspend fun notifications( - loginUser: Long, - maxId: Long?, - minId: Long?, - sinceId: Long?, - limit: Int, - types: List, - excludeTypes: List, - accountId: List - ): List = transaction.transaction { - val typesTmp = mutableListOf() - - typesTmp.addAll(types) - typesTmp.removeAll(excludeTypes) - - val mastodonNotifications = - mastodonNotificationRepository.findByUserIdAndMaxIdAndMinIdAndSinceIdAndInTypesAndInSourceActorId( - loginUser, - maxId, - minId, - sinceId, - limit, - typesTmp, - accountId - ) - - val accounts = accountService.findByIds( - mastodonNotifications.map { - it.accountId - } - ).associateBy { it.id.toLong() } - - val statuses = statusQueryService.findByPostIds(mastodonNotifications.mapNotNull { it.statusId }) - .associateBy { it.id.toLong() } - - mastodonNotifications.map { - Notification( - id = it.id.toString(), - type = convertNotificationType(it.type), - createdAt = it.createdAt.toString(), - account = accounts.getValue(it.accountId), - status = statuses[it.statusId], - report = null, - relationshipSeveranceEvent = null - ) - } - } override suspend fun notifications( loginUser: Long,