diff --git a/src/main/kotlin/dev/usbharu/hideout/core/domain/model/relationship/RelationshipRepository.kt b/src/main/kotlin/dev/usbharu/hideout/core/domain/model/relationship/RelationshipRepository.kt index ff1dc1cc..4780d30d 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/domain/model/relationship/RelationshipRepository.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/domain/model/relationship/RelationshipRepository.kt @@ -54,7 +54,7 @@ interface RelationshipRepository { suspend fun countByTargetIdAndFollowing(targetId: Long, following: Boolean): Int - suspend fun countByUserIdAndFollowing(targetId: Long, following: Boolean): Int + suspend fun countByUserIdAndFollowing(userId: Long, following: Boolean): Int @Suppress("FunctionMaxLength") suspend fun findByTargetIdAndFollowRequestAndIgnoreFollowRequest( diff --git a/src/main/kotlin/dev/usbharu/hideout/core/domain/model/relationship/RelationshipRepositoryImpl.kt b/src/main/kotlin/dev/usbharu/hideout/core/domain/model/relationship/RelationshipRepositoryImpl.kt index ebf46d50..481c3dd6 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/domain/model/relationship/RelationshipRepositoryImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/domain/model/relationship/RelationshipRepositoryImpl.kt @@ -92,11 +92,31 @@ class RelationshipRepositoryImpl : RelationshipRepository, AbstractRepository() .map { it.toRelationships() } } + override suspend fun countByTargetIdAndFollowing(targetId: Long, following: Boolean): Int = query { + return@query Relationships + .selectAll() + .where { + Relationships.targetActorId eq targetId and (Relationships.following eq following) + } + .count() + .toInt() + } + + override suspend fun countByUserIdAndFollowing(userId: Long, following: Boolean): Int = query { + return@query Relationships + .selectAll() + .where { + Relationships.actorId eq userId and (Relationships.following eq following) + } + .count() + .toInt() + } + override suspend fun findByTargetIdAndFollowRequestAndIgnoreFollowRequest( targetId: Long, followRequest: Boolean, ignoreFollowRequest: Boolean, - page: Page.PageByMaxId + page: Page.PageByMaxId, ): PaginationList = query { val query = Relationships.selectAll().where { Relationships.targetActorId.eq(targetId).and(Relationships.followRequest.eq(followRequest)) @@ -115,7 +135,7 @@ class RelationshipRepositoryImpl : RelationshipRepository, AbstractRepository() override suspend fun findByActorIdAndMuting( actorId: Long, muting: Boolean, - page: Page.PageByMaxId + page: Page.PageByMaxId, ): PaginationList = query { val query = Relationships.selectAll().where { Relationships.actorId.eq(actorId).and(Relationships.muting.eq(muting)) } diff --git a/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/PostRepositoryImpl.kt b/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/PostRepositoryImpl.kt index 76b9b82b..ce2ec9ea 100644 --- a/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/PostRepositoryImpl.kt +++ b/src/main/kotlin/dev/usbharu/hideout/core/infrastructure/exposedrepository/PostRepositoryImpl.kt @@ -133,6 +133,14 @@ class PostRepositoryImpl( .selectAll().where { Posts.actorId eq actorId }.let(postQueryMapper::map) } + override suspend fun countByActorId(actorId: Long): Int = query { + return@query Posts + .selectAll() + .where { Posts.actorId eq actorId } + .count() + .toInt() + } + override suspend fun delete(id: Long): Unit = query { Posts.deleteWhere { Posts.id eq id } } diff --git a/src/test/kotlin/dev/usbharu/hideout/core/service/user/ActorServiceTest.kt b/src/test/kotlin/dev/usbharu/hideout/core/service/user/ActorServiceTest.kt index 0ff56011..e0eac4e4 100644 --- a/src/test/kotlin/dev/usbharu/hideout/core/service/user/ActorServiceTest.kt +++ b/src/test/kotlin/dev/usbharu/hideout/core/service/user/ActorServiceTest.kt @@ -62,7 +62,8 @@ class ActorServiceTest { reactionRepository = mock(), relationshipRepository = mock(), postService = mock(), - apSendDeleteService = mock() + apSendDeleteService = mock(), + postRepository = mock() ) userService.createLocalUser(UserCreateDto("test", "testUser", "XXXXXXXXXXXXX", "test")) verify(actorRepository, times(1)).save(any()) @@ -100,7 +101,8 @@ class ActorServiceTest { reactionRepository = mock(), relationshipRepository = mock(), postService = mock(), - apSendDeleteService = mock() + apSendDeleteService = mock(), + postRepository = mock() ) val user = RemoteUserCreateDto( name = "test",