mirror of https://github.com/usbharu/Hideout.git
refactor: UserEntityを削除
This commit is contained in:
parent
50b9e3178c
commit
07cf2c7c9d
|
@ -1,5 +1,6 @@
|
||||||
package dev.usbharu.hideout.domain.model
|
package dev.usbharu.hideout.domain.model
|
||||||
|
|
||||||
|
import dev.usbharu.hideout.repository.Users
|
||||||
import org.jetbrains.exposed.sql.ResultRow
|
import org.jetbrains.exposed.sql.ResultRow
|
||||||
import org.jetbrains.exposed.sql.Table
|
import org.jetbrains.exposed.sql.Table
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,6 @@
|
||||||
package dev.usbharu.hideout.domain.model
|
package dev.usbharu.hideout.domain.model
|
||||||
|
|
||||||
import org.h2.mvstore.type.LongDataType
|
|
||||||
import org.jetbrains.exposed.dao.id.LongIdTable
|
|
||||||
import org.jetbrains.exposed.sql.ResultRow
|
|
||||||
import org.jetbrains.exposed.sql.Table
|
|
||||||
import java.time.Instant
|
|
||||||
import java.time.LocalDateTime
|
import java.time.LocalDateTime
|
||||||
import java.time.ZoneId
|
|
||||||
|
|
||||||
data class User(
|
data class User(
|
||||||
val id:Long,
|
val id:Long,
|
||||||
|
@ -22,63 +16,3 @@ data class User(
|
||||||
val privateKey:String? = null,
|
val privateKey:String? = null,
|
||||||
val createdAt:LocalDateTime
|
val createdAt:LocalDateTime
|
||||||
)
|
)
|
||||||
|
|
||||||
data class UserEntity(
|
|
||||||
val id: Long,
|
|
||||||
val name: String,
|
|
||||||
val domain: String,
|
|
||||||
val screenName: String,
|
|
||||||
val description: String,
|
|
||||||
val inbox: String,
|
|
||||||
val outbox: String,
|
|
||||||
val url: String
|
|
||||||
) {
|
|
||||||
constructor(id: Long, user: User) : this(
|
|
||||||
id,
|
|
||||||
user.name,
|
|
||||||
user.domain,
|
|
||||||
user.screenName,
|
|
||||||
user.description,
|
|
||||||
user.inbox,
|
|
||||||
user.outbox,
|
|
||||||
user.url
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
object Users : Table("users") {
|
|
||||||
val id = long("id").uniqueIndex()
|
|
||||||
val name = varchar("name", length = 64)
|
|
||||||
val domain = varchar("domain", length = 255)
|
|
||||||
val screenName = varchar("screen_name", length = 64)
|
|
||||||
val description = varchar("description", length = 600)
|
|
||||||
val password = varchar("password", length = 255).nullable()
|
|
||||||
val inbox = varchar("inbox", length = 255).uniqueIndex()
|
|
||||||
val outbox = varchar("outbox", length = 255).uniqueIndex()
|
|
||||||
val url = varchar("url", length = 255).uniqueIndex()
|
|
||||||
val publicKey = varchar("public_key", length = 10000)
|
|
||||||
val privateKey = varchar("private_key", length = 10000)
|
|
||||||
val createdAt = long("created_at")
|
|
||||||
|
|
||||||
override val primaryKey: PrimaryKey = PrimaryKey(id)
|
|
||||||
init {
|
|
||||||
uniqueIndex(name, domain)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
fun ResultRow.toUser(): User {
|
|
||||||
return User(
|
|
||||||
this[Users.id],
|
|
||||||
this[Users.name],
|
|
||||||
this[Users.domain],
|
|
||||||
this[Users.screenName],
|
|
||||||
this[Users.description],
|
|
||||||
this[Users.password],
|
|
||||||
this[Users.inbox],
|
|
||||||
this[Users.outbox],
|
|
||||||
this[Users.url],
|
|
||||||
this[Users.publicKey],
|
|
||||||
this[Users.privateKey],
|
|
||||||
LocalDateTime.ofInstant(Instant.ofEpochMilli((this[Users.createdAt])), ZoneId.systemDefault())
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package dev.usbharu.hideout.domain.model
|
package dev.usbharu.hideout.domain.model
|
||||||
|
|
||||||
|
import dev.usbharu.hideout.repository.Users
|
||||||
import org.jetbrains.exposed.dao.id.LongIdTable
|
import org.jetbrains.exposed.dao.id.LongIdTable
|
||||||
import org.jetbrains.exposed.sql.ReferenceOption
|
import org.jetbrains.exposed.sql.ReferenceOption
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package dev.usbharu.hideout.domain.model
|
package dev.usbharu.hideout.domain.model
|
||||||
|
|
||||||
|
import dev.usbharu.hideout.repository.Users
|
||||||
import org.jetbrains.exposed.dao.id.LongIdTable
|
import org.jetbrains.exposed.dao.id.LongIdTable
|
||||||
|
|
||||||
object UsersFollowers : LongIdTable("users_followers") {
|
object UsersFollowers : LongIdTable("users_followers") {
|
||||||
|
|
|
@ -1,32 +1,31 @@
|
||||||
package dev.usbharu.hideout.repository
|
package dev.usbharu.hideout.repository
|
||||||
|
|
||||||
import dev.usbharu.hideout.domain.model.User
|
import dev.usbharu.hideout.domain.model.User
|
||||||
import dev.usbharu.hideout.domain.model.UserEntity
|
|
||||||
|
|
||||||
interface IUserRepository {
|
interface IUserRepository {
|
||||||
suspend fun create(user: User): UserEntity
|
suspend fun create(user: User): User
|
||||||
|
|
||||||
suspend fun findById(id: Long): UserEntity?
|
suspend fun findById(id: Long): User?
|
||||||
|
|
||||||
suspend fun findByIds(ids: List<Long>): List<UserEntity>
|
suspend fun findByIds(ids: List<Long>): List<User>
|
||||||
|
|
||||||
suspend fun findByName(name: String): UserEntity?
|
suspend fun findByName(name: String): User?
|
||||||
|
|
||||||
suspend fun findByNameAndDomains(names: List<Pair<String,String>>): List<UserEntity>
|
suspend fun findByNameAndDomains(names: List<Pair<String,String>>): List<User>
|
||||||
|
|
||||||
suspend fun findByUrl(url:String):UserEntity?
|
suspend fun findByUrl(url:String): User?
|
||||||
|
|
||||||
suspend fun findByUrls(urls: List<String>): List<UserEntity>
|
suspend fun findByUrls(urls: List<String>): List<User>
|
||||||
|
|
||||||
suspend fun update(userEntity: UserEntity)
|
suspend fun update(userEntity: User)
|
||||||
|
|
||||||
suspend fun delete(id: Long)
|
suspend fun delete(id: Long)
|
||||||
|
|
||||||
suspend fun findAll(): List<User>
|
suspend fun findAll(): List<User>
|
||||||
|
|
||||||
suspend fun findAllByLimitAndByOffset(limit: Int, offset: Long = 0): List<UserEntity>
|
suspend fun findAllByLimitAndByOffset(limit: Int, offset: Long = 0): List<User>
|
||||||
|
|
||||||
suspend fun createFollower(id: Long, follower: Long)
|
suspend fun createFollower(id: Long, follower: Long)
|
||||||
suspend fun deleteFollower(id: Long, follower: Long)
|
suspend fun deleteFollower(id: Long, follower: Long)
|
||||||
suspend fun findFollowersById(id: Long): List<UserEntity>
|
suspend fun findFollowersById(id: Long): List<User>
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,9 @@ import org.jetbrains.exposed.sql.*
|
||||||
import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
|
import org.jetbrains.exposed.sql.SqlExpressionBuilder.eq
|
||||||
import org.jetbrains.exposed.sql.transactions.experimental.newSuspendedTransaction
|
import org.jetbrains.exposed.sql.transactions.experimental.newSuspendedTransaction
|
||||||
import org.jetbrains.exposed.sql.transactions.transaction
|
import org.jetbrains.exposed.sql.transactions.transaction
|
||||||
|
import java.time.Instant
|
||||||
|
import java.time.LocalDateTime
|
||||||
|
import java.time.ZoneId
|
||||||
|
|
||||||
class UserRepository(private val database: Database) : IUserRepository {
|
class UserRepository(private val database: Database) : IUserRepository {
|
||||||
init {
|
init {
|
||||||
|
@ -17,25 +20,14 @@ class UserRepository(private val database: Database) : IUserRepository {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun ResultRow.toUserEntity(): UserEntity {
|
private fun ResultRow.toUserEntity(): User = toUser()
|
||||||
return UserEntity(
|
|
||||||
this[Users.id],
|
|
||||||
this[Users.name],
|
|
||||||
this[Users.domain],
|
|
||||||
this[Users.screenName],
|
|
||||||
this[Users.description],
|
|
||||||
this[Users.inbox],
|
|
||||||
this[Users.outbox],
|
|
||||||
this[Users.url],
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
suspend fun <T> query(block: suspend () -> T): T =
|
suspend fun <T> query(block: suspend () -> T): T =
|
||||||
newSuspendedTransaction(Dispatchers.IO) { block() }
|
newSuspendedTransaction(Dispatchers.IO) { block() }
|
||||||
|
|
||||||
override suspend fun create(user: User): UserEntity {
|
override suspend fun create(user: User): User {
|
||||||
return query {
|
return query {
|
||||||
UserEntity(Users.insert {
|
Users.insert {
|
||||||
it[name] = user.name
|
it[name] = user.name
|
||||||
it[domain] = user.domain
|
it[domain] = user.domain
|
||||||
it[screenName] = user.screenName
|
it[screenName] = user.screenName
|
||||||
|
@ -43,7 +35,8 @@ class UserRepository(private val database: Database) : IUserRepository {
|
||||||
it[inbox] = user.inbox
|
it[inbox] = user.inbox
|
||||||
it[outbox] = user.outbox
|
it[outbox] = user.outbox
|
||||||
it[url] = user.url
|
it[url] = user.url
|
||||||
}[Users.id], user)
|
}
|
||||||
|
return@query user
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,7 +49,7 @@ class UserRepository(private val database: Database) : IUserRepository {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun findById(id: Long): UserEntity? {
|
override suspend fun findById(id: Long): User? {
|
||||||
return query {
|
return query {
|
||||||
Users.select { Users.id eq id }.map {
|
Users.select { Users.id eq id }.map {
|
||||||
it.toUserEntity()
|
it.toUserEntity()
|
||||||
|
@ -64,7 +57,7 @@ class UserRepository(private val database: Database) : IUserRepository {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun findByIds(ids: List<Long>): List<UserEntity> {
|
override suspend fun findByIds(ids: List<Long>): List<User> {
|
||||||
return query {
|
return query {
|
||||||
Users.select { Users.id inList ids }.map {
|
Users.select { Users.id inList ids }.map {
|
||||||
it.toUserEntity()
|
it.toUserEntity()
|
||||||
|
@ -72,7 +65,7 @@ class UserRepository(private val database: Database) : IUserRepository {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun findByName(name: String): UserEntity? {
|
override suspend fun findByName(name: String): User? {
|
||||||
return query {
|
return query {
|
||||||
Users.select { Users.name eq name }.map {
|
Users.select { Users.name eq name }.map {
|
||||||
it.toUserEntity()
|
it.toUserEntity()
|
||||||
|
@ -80,7 +73,7 @@ class UserRepository(private val database: Database) : IUserRepository {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun findByNameAndDomains(names: List<Pair<String, String>>): List<UserEntity> {
|
override suspend fun findByNameAndDomains(names: List<Pair<String, String>>): List<User> {
|
||||||
return query {
|
return query {
|
||||||
val selectAll = Users.selectAll()
|
val selectAll = Users.selectAll()
|
||||||
names.forEach { (name, domain) ->
|
names.forEach { (name, domain) ->
|
||||||
|
@ -90,19 +83,19 @@ class UserRepository(private val database: Database) : IUserRepository {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun findByUrl(url: String): UserEntity? {
|
override suspend fun findByUrl(url: String): User? {
|
||||||
return query {
|
return query {
|
||||||
Users.select { Users.url eq url }.singleOrNull()?.toUserEntity()
|
Users.select { Users.url eq url }.singleOrNull()?.toUserEntity()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun findByUrls(urls: List<String>): List<UserEntity> {
|
override suspend fun findByUrls(urls: List<String>): List<User> {
|
||||||
return query {
|
return query {
|
||||||
Users.select { Users.url inList urls }.map { it.toUserEntity() }
|
Users.select { Users.url inList urls }.map { it.toUserEntity() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun findFollowersById(id: Long): List<UserEntity> {
|
override suspend fun findFollowersById(id: Long): List<User> {
|
||||||
return query {
|
return query {
|
||||||
val followers = Users.alias("FOLLOWERS")
|
val followers = Users.alias("FOLLOWERS")
|
||||||
Users.innerJoin(
|
Users.innerJoin(
|
||||||
|
@ -127,22 +120,26 @@ class UserRepository(private val database: Database) : IUserRepository {
|
||||||
)
|
)
|
||||||
.select { Users.id eq id }
|
.select { Users.id eq id }
|
||||||
.map {
|
.map {
|
||||||
UserEntity(
|
User(
|
||||||
id = it[followers[Users.id]],
|
id = it[followers[Users.id]],
|
||||||
name = it[followers[Users.name]],
|
name = it[followers[Users.name]],
|
||||||
domain = it[followers[Users.domain]],
|
domain = it[followers[Users.domain]],
|
||||||
screenName = it[followers[Users.screenName]],
|
screenName = it[followers[Users.screenName]],
|
||||||
description = it[followers[Users.description]],
|
description = it[followers[Users.description]],
|
||||||
|
password = it[followers[Users.password]],
|
||||||
inbox = it[followers[Users.inbox]],
|
inbox = it[followers[Users.inbox]],
|
||||||
outbox = it[followers[Users.outbox]],
|
outbox = it[followers[Users.outbox]],
|
||||||
url = it[followers[Users.url]],
|
url = it[followers[Users.url]],
|
||||||
|
publicKey = it[followers[Users.publicKey]],
|
||||||
|
privateKey = it[followers[Users.privateKey]],
|
||||||
|
createdAt = LocalDateTime.ofInstant(Instant.ofEpochMilli(it[followers[Users.createdAt]]), ZoneId.systemDefault())
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
override suspend fun update(userEntity: UserEntity) {
|
override suspend fun update(userEntity: User) {
|
||||||
return query {
|
return query {
|
||||||
Users.update({ Users.id eq userEntity.id }) {
|
Users.update({ Users.id eq userEntity.id }) {
|
||||||
it[name] = userEntity.name
|
it[name] = userEntity.name
|
||||||
|
@ -174,9 +171,46 @@ class UserRepository(private val database: Database) : IUserRepository {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun findAllByLimitAndByOffset(limit: Int, offset: Long): List<UserEntity> {
|
override suspend fun findAllByLimitAndByOffset(limit: Int, offset: Long): List<User> {
|
||||||
return query {
|
return query {
|
||||||
Users.selectAll().limit(limit, offset).map { it.toUserEntity() }
|
Users.selectAll().limit(limit, offset).map { it.toUserEntity() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
object Users : Table("users") {
|
||||||
|
val id = long("id").uniqueIndex()
|
||||||
|
val name = varchar("name", length = 64)
|
||||||
|
val domain = varchar("domain", length = 255)
|
||||||
|
val screenName = varchar("screen_name", length = 64)
|
||||||
|
val description = varchar("description", length = 600)
|
||||||
|
val password = varchar("password", length = 255).nullable()
|
||||||
|
val inbox = varchar("inbox", length = 255).uniqueIndex()
|
||||||
|
val outbox = varchar("outbox", length = 255).uniqueIndex()
|
||||||
|
val url = varchar("url", length = 255).uniqueIndex()
|
||||||
|
val publicKey = varchar("public_key", length = 10000)
|
||||||
|
val privateKey = varchar("private_key", length = 10000)
|
||||||
|
val createdAt = long("created_at")
|
||||||
|
|
||||||
|
override val primaryKey: PrimaryKey = PrimaryKey(id)
|
||||||
|
init {
|
||||||
|
uniqueIndex(name, domain)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun ResultRow.toUser(): User {
|
||||||
|
return User(
|
||||||
|
this[Users.id],
|
||||||
|
this[Users.name],
|
||||||
|
this[Users.domain],
|
||||||
|
this[Users.screenName],
|
||||||
|
this[Users.description],
|
||||||
|
this[Users.password],
|
||||||
|
this[Users.inbox],
|
||||||
|
this[Users.outbox],
|
||||||
|
this[Users.url],
|
||||||
|
this[Users.publicKey],
|
||||||
|
this[Users.privateKey],
|
||||||
|
LocalDateTime.ofInstant(Instant.ofEpochMilli((this[Users.createdAt])), ZoneId.systemDefault())
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
|
@ -4,7 +4,6 @@ import dev.usbharu.hideout.config.Config
|
||||||
import dev.usbharu.hideout.domain.model.User
|
import dev.usbharu.hideout.domain.model.User
|
||||||
import dev.usbharu.hideout.domain.model.UserAuthentication
|
import dev.usbharu.hideout.domain.model.UserAuthentication
|
||||||
import dev.usbharu.hideout.domain.model.UserAuthenticationEntity
|
import dev.usbharu.hideout.domain.model.UserAuthenticationEntity
|
||||||
import dev.usbharu.hideout.domain.model.UserEntity
|
|
||||||
import dev.usbharu.hideout.exception.UserNotFoundException
|
import dev.usbharu.hideout.exception.UserNotFoundException
|
||||||
import dev.usbharu.hideout.repository.IUserAuthRepository
|
import dev.usbharu.hideout.repository.IUserAuthRepository
|
||||||
import dev.usbharu.hideout.repository.IUserRepository
|
import dev.usbharu.hideout.repository.IUserRepository
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package dev.usbharu.hideout.service.impl
|
package dev.usbharu.hideout.service.impl
|
||||||
|
|
||||||
import dev.usbharu.hideout.domain.model.User
|
import dev.usbharu.hideout.domain.model.User
|
||||||
import dev.usbharu.hideout.domain.model.UserEntity
|
|
||||||
import dev.usbharu.hideout.exception.UserNotFoundException
|
import dev.usbharu.hideout.exception.UserNotFoundException
|
||||||
import dev.usbharu.hideout.repository.IUserRepository
|
import dev.usbharu.hideout.repository.IUserRepository
|
||||||
import java.lang.Integer.min
|
import java.lang.Integer.min
|
||||||
|
@ -9,7 +8,7 @@ import java.lang.Integer.min
|
||||||
class UserService(private val userRepository: IUserRepository) {
|
class UserService(private val userRepository: IUserRepository) {
|
||||||
|
|
||||||
private val maxLimit = 100
|
private val maxLimit = 100
|
||||||
suspend fun findAll(limit: Int? = maxLimit, offset: Long? = 0): List<UserEntity> {
|
suspend fun findAll(limit: Int? = maxLimit, offset: Long? = 0): List<User> {
|
||||||
|
|
||||||
return userRepository.findAllByLimitAndByOffset(
|
return userRepository.findAllByLimitAndByOffset(
|
||||||
min(limit ?: maxLimit, maxLimit),
|
min(limit ?: maxLimit, maxLimit),
|
||||||
|
@ -17,36 +16,36 @@ class UserService(private val userRepository: IUserRepository) {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun findById(id: Long): UserEntity {
|
suspend fun findById(id: Long): User {
|
||||||
return userRepository.findById(id) ?: throw UserNotFoundException("$id was not found.")
|
return userRepository.findById(id) ?: throw UserNotFoundException("$id was not found.")
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun findByIds(ids: List<Long>): List<UserEntity> {
|
suspend fun findByIds(ids: List<Long>): List<User> {
|
||||||
return userRepository.findByIds(ids)
|
return userRepository.findByIds(ids)
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun findByName(name: String): UserEntity {
|
suspend fun findByName(name: String): User {
|
||||||
return userRepository.findByName(name)
|
return userRepository.findByName(name)
|
||||||
?: throw UserNotFoundException("$name was not found.")
|
?: throw UserNotFoundException("$name was not found.")
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun findByNameAndDomains(names: List<Pair<String,String>>): List<UserEntity> {
|
suspend fun findByNameAndDomains(names: List<Pair<String,String>>): List<User> {
|
||||||
return userRepository.findByNameAndDomains(names)
|
return userRepository.findByNameAndDomains(names)
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun findByUrl(url: String): UserEntity {
|
suspend fun findByUrl(url: String): User {
|
||||||
return userRepository.findByUrl(url) ?: throw UserNotFoundException("$url was not found.")
|
return userRepository.findByUrl(url) ?: throw UserNotFoundException("$url was not found.")
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun findByUrls(urls: List<String>): List<UserEntity> {
|
suspend fun findByUrls(urls: List<String>): List<User> {
|
||||||
return userRepository.findByUrls(urls)
|
return userRepository.findByUrls(urls)
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun create(user: User): UserEntity {
|
suspend fun create(user: User): User {
|
||||||
return userRepository.create(user)
|
return userRepository.create(user)
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun findFollowersById(id: Long): List<UserEntity> {
|
suspend fun findFollowersById(id: Long): List<User> {
|
||||||
return userRepository.findFollowersById(id)
|
return userRepository.findFollowersById(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
package dev.usbharu.hideout.plugins
|
package dev.usbharu.hideout.plugins
|
||||||
|
|
||||||
import dev.usbharu.hideout.domain.model.ap.JsonLd
|
|
||||||
import dev.usbharu.hideout.domain.model.User
|
import dev.usbharu.hideout.domain.model.User
|
||||||
import dev.usbharu.hideout.domain.model.UserAuthentication
|
import dev.usbharu.hideout.domain.model.UserAuthentication
|
||||||
import dev.usbharu.hideout.domain.model.UserAuthenticationEntity
|
import dev.usbharu.hideout.domain.model.UserAuthenticationEntity
|
||||||
import dev.usbharu.hideout.domain.model.UserEntity
|
import dev.usbharu.hideout.domain.model.ap.JsonLd
|
||||||
import dev.usbharu.hideout.repository.IUserAuthRepository
|
import dev.usbharu.hideout.repository.IUserAuthRepository
|
||||||
import dev.usbharu.hideout.repository.IUserRepository
|
import dev.usbharu.hideout.repository.IUserRepository
|
||||||
import dev.usbharu.hideout.service.impl.UserAuthService
|
import dev.usbharu.hideout.service.impl.UserAuthService
|
||||||
|
@ -17,41 +16,55 @@ import org.junit.jupiter.api.Test
|
||||||
import java.security.KeyPairGenerator
|
import java.security.KeyPairGenerator
|
||||||
import java.security.interfaces.RSAPrivateKey
|
import java.security.interfaces.RSAPrivateKey
|
||||||
import java.security.interfaces.RSAPublicKey
|
import java.security.interfaces.RSAPublicKey
|
||||||
|
import java.time.LocalDateTime
|
||||||
|
|
||||||
class ActivityPubKtTest {
|
class ActivityPubKtTest {
|
||||||
@Test
|
@Test
|
||||||
fun HttpSignTest(): Unit = runBlocking {
|
fun HttpSignTest(): Unit = runBlocking {
|
||||||
|
|
||||||
val ktorKeyMap = KtorKeyMap(UserAuthService(object : IUserRepository {
|
val ktorKeyMap = KtorKeyMap(UserAuthService(object : IUserRepository {
|
||||||
override suspend fun create(user: User): UserEntity {
|
override suspend fun create(user: User): User {
|
||||||
TODO("Not yet implemented")
|
TODO("Not yet implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun findById(id: Long): UserEntity? {
|
override suspend fun findById(id: Long): User? {
|
||||||
TODO("Not yet implemented")
|
TODO("Not yet implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun findByIds(ids: List<Long>): List<UserEntity> {
|
override suspend fun findByIds(ids: List<Long>): List<User> {
|
||||||
TODO("Not yet implemented")
|
TODO("Not yet implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun findByName(name: String): UserEntity? {
|
override suspend fun findByName(name: String): User? {
|
||||||
return UserEntity(1, "test", "localhost", "test", "","","","")
|
return User(
|
||||||
|
1,
|
||||||
|
"test",
|
||||||
|
"localhost",
|
||||||
|
"test",
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
null,
|
||||||
|
LocalDateTime.now()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun findByNameAndDomains(names: List<Pair<String, String>>): List<UserEntity> {
|
override suspend fun findByNameAndDomains(names: List<Pair<String, String>>): List<User> {
|
||||||
TODO("Not yet implemented")
|
TODO("Not yet implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun findByUrl(url: String): UserEntity? {
|
override suspend fun findByUrl(url: String): User? {
|
||||||
TODO("Not yet implemented")
|
TODO("Not yet implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun findByUrls(urls: List<String>): List<UserEntity> {
|
override suspend fun findByUrls(urls: List<String>): List<User> {
|
||||||
TODO("Not yet implemented")
|
TODO("Not yet implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun update(userEntity: UserEntity) {
|
override suspend fun update(userEntity: User) {
|
||||||
TODO("Not yet implemented")
|
TODO("Not yet implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,7 +76,7 @@ class ActivityPubKtTest {
|
||||||
TODO("Not yet implemented")
|
TODO("Not yet implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun findAllByLimitAndByOffset(limit: Int, offset: Long): List<UserEntity> {
|
override suspend fun findAllByLimitAndByOffset(limit: Int, offset: Long): List<User> {
|
||||||
TODO("Not yet implemented")
|
TODO("Not yet implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,7 +88,7 @@ class ActivityPubKtTest {
|
||||||
TODO("Not yet implemented")
|
TODO("Not yet implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun findFollowersById(id: Long): List<UserEntity> {
|
override suspend fun findFollowersById(id: Long): List<User> {
|
||||||
TODO("Not yet implemented")
|
TODO("Not yet implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,6 @@ package dev.usbharu.hideout.plugins
|
||||||
import dev.usbharu.hideout.domain.model.User
|
import dev.usbharu.hideout.domain.model.User
|
||||||
import dev.usbharu.hideout.domain.model.UserAuthentication
|
import dev.usbharu.hideout.domain.model.UserAuthentication
|
||||||
import dev.usbharu.hideout.domain.model.UserAuthenticationEntity
|
import dev.usbharu.hideout.domain.model.UserAuthenticationEntity
|
||||||
import dev.usbharu.hideout.domain.model.UserEntity
|
|
||||||
import dev.usbharu.hideout.repository.IUserAuthRepository
|
import dev.usbharu.hideout.repository.IUserAuthRepository
|
||||||
import dev.usbharu.hideout.repository.IUserRepository
|
import dev.usbharu.hideout.repository.IUserRepository
|
||||||
import dev.usbharu.hideout.service.impl.UserAuthService
|
import dev.usbharu.hideout.service.impl.UserAuthService
|
||||||
|
@ -12,41 +11,54 @@ import org.junit.jupiter.api.Test
|
||||||
import java.security.KeyPairGenerator
|
import java.security.KeyPairGenerator
|
||||||
import java.security.interfaces.RSAPrivateKey
|
import java.security.interfaces.RSAPrivateKey
|
||||||
import java.security.interfaces.RSAPublicKey
|
import java.security.interfaces.RSAPublicKey
|
||||||
|
import java.time.LocalDateTime
|
||||||
|
|
||||||
class KtorKeyMapTest {
|
class KtorKeyMapTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun getPrivateKey() {
|
fun getPrivateKey() {
|
||||||
val ktorKeyMap = KtorKeyMap(UserAuthService(object : IUserRepository {
|
val ktorKeyMap = KtorKeyMap(UserAuthService(object : IUserRepository {
|
||||||
override suspend fun create(user: User): UserEntity {
|
override suspend fun create(user: User): User {
|
||||||
TODO("Not yet implemented")
|
TODO("Not yet implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun findById(id: Long): UserEntity? {
|
override suspend fun findById(id: Long): User? {
|
||||||
TODO("Not yet implemented")
|
TODO("Not yet implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun findByIds(ids: List<Long>): List<UserEntity> {
|
override suspend fun findByIds(ids: List<Long>): List<User> {
|
||||||
TODO("Not yet implemented")
|
TODO("Not yet implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun findByName(name: String): UserEntity? {
|
override suspend fun findByName(name: String): User? {
|
||||||
return UserEntity(1, "test", "localhost", "test", "","","","")
|
return User(
|
||||||
|
1,
|
||||||
|
"test",
|
||||||
|
"localhost",
|
||||||
|
"test",
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
"",
|
||||||
|
createdAt = LocalDateTime.now()
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun findByNameAndDomains(names: List<Pair<String, String>>): List<UserEntity> {
|
override suspend fun findByNameAndDomains(names: List<Pair<String, String>>): List<User> {
|
||||||
TODO("Not yet implemented")
|
TODO("Not yet implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun findByUrl(url: String): UserEntity? {
|
override suspend fun findByUrl(url: String): User? {
|
||||||
TODO("Not yet implemented")
|
TODO("Not yet implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun findByUrls(urls: List<String>): List<UserEntity> {
|
override suspend fun findByUrls(urls: List<String>): List<User> {
|
||||||
TODO("Not yet implemented")
|
TODO("Not yet implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun update(userEntity: UserEntity) {
|
override suspend fun update(userEntity: User) {
|
||||||
TODO("Not yet implemented")
|
TODO("Not yet implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,7 +70,7 @@ class KtorKeyMapTest {
|
||||||
TODO("Not yet implemented")
|
TODO("Not yet implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun findAllByLimitAndByOffset(limit: Int, offset: Long): List<UserEntity> {
|
override suspend fun findAllByLimitAndByOffset(limit: Int, offset: Long): List<User> {
|
||||||
TODO("Not yet implemented")
|
TODO("Not yet implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,7 +82,7 @@ class KtorKeyMapTest {
|
||||||
TODO("Not yet implemented")
|
TODO("Not yet implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun findFollowersById(id: Long): List<UserEntity> {
|
override suspend fun findFollowersById(id: Long): List<User> {
|
||||||
TODO("Not yet implemented")
|
TODO("Not yet implemented")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
package dev.usbharu.hideout.repository
|
package dev.usbharu.hideout.repository
|
||||||
|
|
||||||
import dev.usbharu.hideout.domain.model.User
|
import dev.usbharu.hideout.domain.model.User
|
||||||
import dev.usbharu.hideout.domain.model.Users
|
|
||||||
import dev.usbharu.hideout.domain.model.UsersFollowers
|
import dev.usbharu.hideout.domain.model.UsersFollowers
|
||||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||||
import kotlinx.coroutines.test.runTest
|
import kotlinx.coroutines.test.runTest
|
||||||
|
|
|
@ -6,7 +6,7 @@ package dev.usbharu.hideout.service.activitypub
|
||||||
import com.fasterxml.jackson.module.kotlin.readValue
|
import com.fasterxml.jackson.module.kotlin.readValue
|
||||||
import dev.usbharu.hideout.config.Config
|
import dev.usbharu.hideout.config.Config
|
||||||
import dev.usbharu.hideout.config.ConfigData
|
import dev.usbharu.hideout.config.ConfigData
|
||||||
import dev.usbharu.hideout.domain.model.UserEntity
|
import dev.usbharu.hideout.domain.model.User
|
||||||
import dev.usbharu.hideout.domain.model.ap.*
|
import dev.usbharu.hideout.domain.model.ap.*
|
||||||
import dev.usbharu.hideout.domain.model.job.ReceiveFollowJob
|
import dev.usbharu.hideout.domain.model.job.ReceiveFollowJob
|
||||||
import dev.usbharu.hideout.service.impl.UserService
|
import dev.usbharu.hideout.service.impl.UserService
|
||||||
|
@ -23,6 +23,7 @@ import org.junit.jupiter.api.Test
|
||||||
import org.mockito.ArgumentMatchers.anyString
|
import org.mockito.ArgumentMatchers.anyString
|
||||||
import org.mockito.kotlin.*
|
import org.mockito.kotlin.*
|
||||||
import utils.JsonObjectMapper
|
import utils.JsonObjectMapper
|
||||||
|
import java.time.LocalDateTime
|
||||||
|
|
||||||
class ActivityPubFollowServiceImplTest {
|
class ActivityPubFollowServiceImplTest {
|
||||||
@Test
|
@Test
|
||||||
|
@ -88,7 +89,7 @@ class ActivityPubFollowServiceImplTest {
|
||||||
}
|
}
|
||||||
val userService = mock<UserService> {
|
val userService = mock<UserService> {
|
||||||
onBlocking { findByUrls(any()) } doReturn listOf(
|
onBlocking { findByUrls(any()) } doReturn listOf(
|
||||||
UserEntity(
|
User(
|
||||||
id = 1L,
|
id = 1L,
|
||||||
name = "test",
|
name = "test",
|
||||||
domain = "example.com",
|
domain = "example.com",
|
||||||
|
@ -96,9 +97,11 @@ class ActivityPubFollowServiceImplTest {
|
||||||
description = "This user is test user.",
|
description = "This user is test user.",
|
||||||
inbox = "https://example.com/inbox",
|
inbox = "https://example.com/inbox",
|
||||||
outbox = "https://example.com/outbox",
|
outbox = "https://example.com/outbox",
|
||||||
url = "https://example.com"
|
url = "https://example.com",
|
||||||
|
publicKey = "",
|
||||||
|
createdAt = LocalDateTime.now()
|
||||||
),
|
),
|
||||||
UserEntity(
|
User(
|
||||||
id = 2L,
|
id = 2L,
|
||||||
name = "follower",
|
name = "follower",
|
||||||
domain = "follower.example.com",
|
domain = "follower.example.com",
|
||||||
|
@ -106,7 +109,9 @@ class ActivityPubFollowServiceImplTest {
|
||||||
description = "This user is test follower user.",
|
description = "This user is test follower user.",
|
||||||
inbox = "https://follower.example.com/inbox",
|
inbox = "https://follower.example.com/inbox",
|
||||||
outbox = "https://follower.example.com/outbox",
|
outbox = "https://follower.example.com/outbox",
|
||||||
url = "https://follower.example.com"
|
url = "https://follower.example.com",
|
||||||
|
publicKey = "",
|
||||||
|
createdAt = LocalDateTime.now()
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
onBlocking { addFollowers(any(), any()) } doReturn Unit
|
onBlocking { addFollowers(any(), any()) } doReturn Unit
|
||||||
|
|
|
@ -6,7 +6,7 @@ package dev.usbharu.hideout.service.activitypub
|
||||||
import dev.usbharu.hideout.config.Config
|
import dev.usbharu.hideout.config.Config
|
||||||
import dev.usbharu.hideout.config.ConfigData
|
import dev.usbharu.hideout.config.ConfigData
|
||||||
import dev.usbharu.hideout.domain.model.PostEntity
|
import dev.usbharu.hideout.domain.model.PostEntity
|
||||||
import dev.usbharu.hideout.domain.model.UserEntity
|
import dev.usbharu.hideout.domain.model.User
|
||||||
import dev.usbharu.hideout.domain.model.job.DeliverPostJob
|
import dev.usbharu.hideout.domain.model.job.DeliverPostJob
|
||||||
import dev.usbharu.hideout.service.impl.UserService
|
import dev.usbharu.hideout.service.impl.UserService
|
||||||
import dev.usbharu.hideout.service.job.JobQueueParentService
|
import dev.usbharu.hideout.service.job.JobQueueParentService
|
||||||
|
@ -20,13 +20,14 @@ import org.junit.jupiter.api.Test
|
||||||
import org.mockito.Mockito.eq
|
import org.mockito.Mockito.eq
|
||||||
import org.mockito.kotlin.*
|
import org.mockito.kotlin.*
|
||||||
import utils.JsonObjectMapper
|
import utils.JsonObjectMapper
|
||||||
|
import java.time.LocalDateTime
|
||||||
import kotlin.test.assertEquals
|
import kotlin.test.assertEquals
|
||||||
|
|
||||||
class ActivityPubNoteServiceImplTest {
|
class ActivityPubNoteServiceImplTest {
|
||||||
@Test
|
@Test
|
||||||
fun `createPost 新しい投稿`() = runTest {
|
fun `createPost 新しい投稿`() = runTest {
|
||||||
val followers = listOf<UserEntity>(
|
val followers = listOf<User>(
|
||||||
UserEntity(
|
User(
|
||||||
2L,
|
2L,
|
||||||
"follower",
|
"follower",
|
||||||
"follower.example.com",
|
"follower.example.com",
|
||||||
|
@ -34,9 +35,12 @@ class ActivityPubNoteServiceImplTest {
|
||||||
"test follower user",
|
"test follower user",
|
||||||
"https://follower.example.com/inbox",
|
"https://follower.example.com/inbox",
|
||||||
"https://follower.example.com/outbox",
|
"https://follower.example.com/outbox",
|
||||||
"https://follower.example.com"
|
"https://follower.example.com",
|
||||||
|
"",
|
||||||
|
publicKey = "",
|
||||||
|
createdAt = LocalDateTime.now()
|
||||||
),
|
),
|
||||||
UserEntity(
|
User(
|
||||||
3L,
|
3L,
|
||||||
"follower2",
|
"follower2",
|
||||||
"follower2.example.com",
|
"follower2.example.com",
|
||||||
|
@ -44,11 +48,14 @@ class ActivityPubNoteServiceImplTest {
|
||||||
"test follower2 user",
|
"test follower2 user",
|
||||||
"https://follower2.example.com/inbox",
|
"https://follower2.example.com/inbox",
|
||||||
"https://follower2.example.com/outbox",
|
"https://follower2.example.com/outbox",
|
||||||
"https:.//follower2.example.com"
|
"https://follower2.example.com",
|
||||||
|
"",
|
||||||
|
publicKey = "",
|
||||||
|
createdAt = LocalDateTime.now()
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
val userService = mock<UserService> {
|
val userService = mock<UserService> {
|
||||||
onBlocking { findById(eq(1L)) } doReturn UserEntity(
|
onBlocking { findById(eq(1L)) } doReturn User(
|
||||||
1L,
|
1L,
|
||||||
"test",
|
"test",
|
||||||
"example.com",
|
"example.com",
|
||||||
|
@ -56,7 +63,10 @@ class ActivityPubNoteServiceImplTest {
|
||||||
"test user",
|
"test user",
|
||||||
"https://example.com/inbox",
|
"https://example.com/inbox",
|
||||||
"https://example.com/outbox",
|
"https://example.com/outbox",
|
||||||
"https:.//example.com"
|
"https:.//example.com",
|
||||||
|
"",
|
||||||
|
publicKey = "",
|
||||||
|
createdAt = LocalDateTime.now()
|
||||||
)
|
)
|
||||||
onBlocking { findFollowersById(eq(1L)) } doReturn followers
|
onBlocking { findFollowersById(eq(1L)) } doReturn followers
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue