mirror of https://github.com/usbharu/Hideout.git
Revert "refactor: ID生成を全てIdGenerateServiceで行うように"
This reverts commit 4be4603f
This commit is contained in:
parent
cbdce824e5
commit
8e217c16ec
|
@ -8,9 +8,6 @@ import java.net.URL
|
||||||
@Configuration
|
@Configuration
|
||||||
class SpringConfig {
|
class SpringConfig {
|
||||||
|
|
||||||
@Autowired
|
|
||||||
lateinit var dbConfig: DatabaseConnectConfig
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
lateinit var config: ApplicationConfig
|
lateinit var config: ApplicationConfig
|
||||||
}
|
}
|
||||||
|
@ -19,11 +16,3 @@ class SpringConfig {
|
||||||
data class ApplicationConfig(
|
data class ApplicationConfig(
|
||||||
val url: URL
|
val url: URL
|
||||||
)
|
)
|
||||||
|
|
||||||
@ConfigurationProperties("hideout.database")
|
|
||||||
data class DatabaseConnectConfig(
|
|
||||||
val url: String,
|
|
||||||
val driver: String,
|
|
||||||
val user: String,
|
|
||||||
val password: String
|
|
||||||
)
|
|
||||||
|
|
|
@ -13,6 +13,7 @@ class MongoTimelineRepositoryWrapper(
|
||||||
private val idGenerateService: IdGenerateService
|
private val idGenerateService: IdGenerateService
|
||||||
) :
|
) :
|
||||||
TimelineRepository {
|
TimelineRepository {
|
||||||
|
override suspend fun generateId(): Long = idGenerateService.generateId()
|
||||||
|
|
||||||
override suspend fun save(timeline: Timeline): Timeline {
|
override suspend fun save(timeline: Timeline): Timeline {
|
||||||
return withContext(Dispatchers.IO) {
|
return withContext(Dispatchers.IO) {
|
||||||
|
|
|
@ -6,6 +6,7 @@ import org.springframework.stereotype.Repository
|
||||||
@Suppress("LongParameterList")
|
@Suppress("LongParameterList")
|
||||||
@Repository
|
@Repository
|
||||||
interface PostRepository {
|
interface PostRepository {
|
||||||
|
suspend fun generateId(): Long
|
||||||
suspend fun save(post: Post): Post
|
suspend fun save(post: Post): Post
|
||||||
suspend fun delete(id: Long)
|
suspend fun delete(id: Long)
|
||||||
suspend fun findById(id: Long): Post
|
suspend fun findById(id: Long): Post
|
||||||
|
|
|
@ -11,6 +11,8 @@ import org.springframework.stereotype.Repository
|
||||||
@Repository
|
@Repository
|
||||||
class PostRepositoryImpl(private val idGenerateService: IdGenerateService) : PostRepository {
|
class PostRepositoryImpl(private val idGenerateService: IdGenerateService) : PostRepository {
|
||||||
|
|
||||||
|
override suspend fun generateId(): Long = idGenerateService.generateId()
|
||||||
|
|
||||||
override suspend fun save(post: Post): Post {
|
override suspend fun save(post: Post): Post {
|
||||||
val singleOrNull = Posts.select { Posts.id eq post.id }.singleOrNull()
|
val singleOrNull = Posts.select { Posts.id eq post.id }.singleOrNull()
|
||||||
if (singleOrNull == null) {
|
if (singleOrNull == null) {
|
||||||
|
|
|
@ -5,6 +5,7 @@ import org.springframework.stereotype.Repository
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
interface ReactionRepository {
|
interface ReactionRepository {
|
||||||
|
suspend fun generateId(): Long
|
||||||
suspend fun save(reaction: Reaction): Reaction
|
suspend fun save(reaction: Reaction): Reaction
|
||||||
suspend fun delete(reaction: Reaction): Reaction
|
suspend fun delete(reaction: Reaction): Reaction
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,6 +12,9 @@ class ReactionRepositoryImpl(
|
||||||
private val idGenerateService: IdGenerateService
|
private val idGenerateService: IdGenerateService
|
||||||
) : ReactionRepository {
|
) : ReactionRepository {
|
||||||
|
|
||||||
|
|
||||||
|
override suspend fun generateId(): Long = idGenerateService.generateId()
|
||||||
|
|
||||||
override suspend fun save(reaction: Reaction): Reaction {
|
override suspend fun save(reaction: Reaction): Reaction {
|
||||||
if (Reactions.select { Reactions.id eq reaction.id }.empty()) {
|
if (Reactions.select { Reactions.id eq reaction.id }.empty()) {
|
||||||
Reactions.insert {
|
Reactions.insert {
|
||||||
|
|
|
@ -3,6 +3,7 @@ package dev.usbharu.hideout.repository
|
||||||
import dev.usbharu.hideout.domain.model.hideout.entity.Timeline
|
import dev.usbharu.hideout.domain.model.hideout.entity.Timeline
|
||||||
|
|
||||||
interface TimelineRepository {
|
interface TimelineRepository {
|
||||||
|
suspend fun generateId(): Long
|
||||||
suspend fun save(timeline: Timeline): Timeline
|
suspend fun save(timeline: Timeline): Timeline
|
||||||
suspend fun saveAll(timelines: List<Timeline>): List<Timeline>
|
suspend fun saveAll(timelines: List<Timeline>): List<Timeline>
|
||||||
suspend fun findByUserId(id: Long): List<Timeline>
|
suspend fun findByUserId(id: Long): List<Timeline>
|
||||||
|
|
|
@ -16,7 +16,6 @@ import dev.usbharu.hideout.query.FollowerQueryService
|
||||||
import dev.usbharu.hideout.query.PostQueryService
|
import dev.usbharu.hideout.query.PostQueryService
|
||||||
import dev.usbharu.hideout.query.UserQueryService
|
import dev.usbharu.hideout.query.UserQueryService
|
||||||
import dev.usbharu.hideout.repository.PostRepository
|
import dev.usbharu.hideout.repository.PostRepository
|
||||||
import dev.usbharu.hideout.service.core.IdGenerateService
|
|
||||||
import dev.usbharu.hideout.service.job.JobQueueParentService
|
import dev.usbharu.hideout.service.job.JobQueueParentService
|
||||||
import dev.usbharu.hideout.service.post.PostCreateInterceptor
|
import dev.usbharu.hideout.service.post.PostCreateInterceptor
|
||||||
import dev.usbharu.hideout.service.post.PostService
|
import dev.usbharu.hideout.service.post.PostService
|
||||||
|
@ -50,8 +49,7 @@ class APNoteServiceImpl(
|
||||||
private val postQueryService: PostQueryService,
|
private val postQueryService: PostQueryService,
|
||||||
@Qualifier("activitypub") private val objectMapper: ObjectMapper,
|
@Qualifier("activitypub") private val objectMapper: ObjectMapper,
|
||||||
private val applicationConfig: ApplicationConfig,
|
private val applicationConfig: ApplicationConfig,
|
||||||
private val postService: PostService,
|
private val postService: PostService
|
||||||
private val idGenerateService: IdGenerateService
|
|
||||||
|
|
||||||
) : APNoteService, PostCreateInterceptor {
|
) : APNoteService, PostCreateInterceptor {
|
||||||
|
|
||||||
|
@ -173,7 +171,7 @@ class APNoteServiceImpl(
|
||||||
|
|
||||||
postService.createRemote(
|
postService.createRemote(
|
||||||
Post.of(
|
Post.of(
|
||||||
id = idGenerateService.generateId(),
|
id = postRepository.generateId(),
|
||||||
userId = person.second.id,
|
userId = person.second.id,
|
||||||
overview = null,
|
overview = null,
|
||||||
text = note.content.orEmpty(),
|
text = note.content.orEmpty(),
|
||||||
|
|
|
@ -5,7 +5,6 @@ import dev.usbharu.hideout.domain.model.hideout.entity.Post
|
||||||
import dev.usbharu.hideout.exception.UserNotFoundException
|
import dev.usbharu.hideout.exception.UserNotFoundException
|
||||||
import dev.usbharu.hideout.repository.PostRepository
|
import dev.usbharu.hideout.repository.PostRepository
|
||||||
import dev.usbharu.hideout.repository.UserRepository
|
import dev.usbharu.hideout.repository.UserRepository
|
||||||
import dev.usbharu.hideout.service.core.IdGenerateService
|
|
||||||
import org.springframework.stereotype.Service
|
import org.springframework.stereotype.Service
|
||||||
import java.time.Instant
|
import java.time.Instant
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
@ -14,8 +13,7 @@ import java.util.*
|
||||||
class PostServiceImpl(
|
class PostServiceImpl(
|
||||||
private val postRepository: PostRepository,
|
private val postRepository: PostRepository,
|
||||||
private val userRepository: UserRepository,
|
private val userRepository: UserRepository,
|
||||||
private val timelineService: TimelineService,
|
private val timelineService: TimelineService
|
||||||
private val idGenerateService: IdGenerateService
|
|
||||||
) : PostService {
|
) : PostService {
|
||||||
private val interceptors = Collections.synchronizedList(mutableListOf<PostCreateInterceptor>())
|
private val interceptors = Collections.synchronizedList(mutableListOf<PostCreateInterceptor>())
|
||||||
|
|
||||||
|
@ -38,7 +36,7 @@ class PostServiceImpl(
|
||||||
|
|
||||||
private suspend fun internalCreate(post: PostCreateDto, isLocal: Boolean): Post {
|
private suspend fun internalCreate(post: PostCreateDto, isLocal: Boolean): Post {
|
||||||
val user = userRepository.findById(post.userId) ?: throw UserNotFoundException("${post.userId} was not found")
|
val user = userRepository.findById(post.userId) ?: throw UserNotFoundException("${post.userId} was not found")
|
||||||
val id = idGenerateService.generateId()
|
val id = postRepository.generateId()
|
||||||
val createPost = Post.of(
|
val createPost = Post.of(
|
||||||
id = id,
|
id = id,
|
||||||
userId = post.userId,
|
userId = post.userId,
|
||||||
|
|
|
@ -6,15 +6,13 @@ import dev.usbharu.hideout.domain.model.hideout.entity.Visibility
|
||||||
import dev.usbharu.hideout.query.FollowerQueryService
|
import dev.usbharu.hideout.query.FollowerQueryService
|
||||||
import dev.usbharu.hideout.query.UserQueryService
|
import dev.usbharu.hideout.query.UserQueryService
|
||||||
import dev.usbharu.hideout.repository.TimelineRepository
|
import dev.usbharu.hideout.repository.TimelineRepository
|
||||||
import dev.usbharu.hideout.service.core.IdGenerateService
|
|
||||||
import org.springframework.stereotype.Service
|
import org.springframework.stereotype.Service
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
class TimelineService(
|
class TimelineService(
|
||||||
private val followerQueryService: FollowerQueryService,
|
private val followerQueryService: FollowerQueryService,
|
||||||
private val userQueryService: UserQueryService,
|
private val userQueryService: UserQueryService,
|
||||||
private val timelineRepository: TimelineRepository,
|
private val timelineRepository: TimelineRepository
|
||||||
private val idGenerateService: IdGenerateService
|
|
||||||
) {
|
) {
|
||||||
suspend fun publishTimeline(post: Post, isLocal: Boolean) {
|
suspend fun publishTimeline(post: Post, isLocal: Boolean) {
|
||||||
val findFollowersById = followerQueryService.findFollowersById(post.userId).toMutableList()
|
val findFollowersById = followerQueryService.findFollowersById(post.userId).toMutableList()
|
||||||
|
@ -25,7 +23,7 @@ class TimelineService(
|
||||||
}
|
}
|
||||||
val timelines = findFollowersById.map {
|
val timelines = findFollowersById.map {
|
||||||
Timeline(
|
Timeline(
|
||||||
id = idGenerateService.generateId(),
|
id = timelineRepository.generateId(),
|
||||||
userId = it.id,
|
userId = it.id,
|
||||||
timelineId = 0,
|
timelineId = 0,
|
||||||
postId = post.id,
|
postId = post.id,
|
||||||
|
@ -41,7 +39,7 @@ class TimelineService(
|
||||||
if (post.visibility == Visibility.PUBLIC) {
|
if (post.visibility == Visibility.PUBLIC) {
|
||||||
timelines.add(
|
timelines.add(
|
||||||
Timeline(
|
Timeline(
|
||||||
id = idGenerateService.generateId(),
|
id = timelineRepository.generateId(),
|
||||||
userId = 0,
|
userId = 0,
|
||||||
timelineId = 0,
|
timelineId = 0,
|
||||||
postId = post.id,
|
postId = post.id,
|
||||||
|
|
|
@ -4,20 +4,18 @@ import dev.usbharu.hideout.domain.model.hideout.entity.Reaction
|
||||||
import dev.usbharu.hideout.query.ReactionQueryService
|
import dev.usbharu.hideout.query.ReactionQueryService
|
||||||
import dev.usbharu.hideout.repository.ReactionRepository
|
import dev.usbharu.hideout.repository.ReactionRepository
|
||||||
import dev.usbharu.hideout.service.ap.APReactionService
|
import dev.usbharu.hideout.service.ap.APReactionService
|
||||||
import dev.usbharu.hideout.service.core.IdGenerateService
|
|
||||||
import org.springframework.stereotype.Service
|
import org.springframework.stereotype.Service
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
class ReactionServiceImpl(
|
class ReactionServiceImpl(
|
||||||
private val reactionRepository: ReactionRepository,
|
private val reactionRepository: ReactionRepository,
|
||||||
private val apReactionService: APReactionService,
|
private val apReactionService: APReactionService,
|
||||||
private val reactionQueryService: ReactionQueryService,
|
private val reactionQueryService: ReactionQueryService
|
||||||
private val idGenerateService: IdGenerateService
|
|
||||||
) : ReactionService {
|
) : ReactionService {
|
||||||
override suspend fun receiveReaction(name: String, domain: String, userId: Long, postId: Long) {
|
override suspend fun receiveReaction(name: String, domain: String, userId: Long, postId: Long) {
|
||||||
if (reactionQueryService.reactionAlreadyExist(postId, userId, 0).not()) {
|
if (reactionQueryService.reactionAlreadyExist(postId, userId, 0).not()) {
|
||||||
reactionRepository.save(
|
reactionRepository.save(
|
||||||
Reaction(idGenerateService.generateId(), 0, postId, userId)
|
Reaction(reactionRepository.generateId(), 0, postId, userId)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,7 +25,7 @@ class ReactionServiceImpl(
|
||||||
// delete
|
// delete
|
||||||
reactionQueryService.deleteByPostIdAndUserId(postId, userId)
|
reactionQueryService.deleteByPostIdAndUserId(postId, userId)
|
||||||
} else {
|
} else {
|
||||||
val reaction = Reaction(idGenerateService.generateId(), 0, postId, userId)
|
val reaction = Reaction(reactionRepository.generateId(), 0, postId, userId)
|
||||||
reactionRepository.save(reaction)
|
reactionRepository.save(reaction)
|
||||||
apReactionService.reaction(reaction)
|
apReactionService.reaction(reaction)
|
||||||
}
|
}
|
||||||
|
|
|
@ -90,7 +90,6 @@ class APNoteServiceImplTest {
|
||||||
objectMapper = objectMapper,
|
objectMapper = objectMapper,
|
||||||
applicationConfig = testApplicationConfig,
|
applicationConfig = testApplicationConfig,
|
||||||
postService = mock(),
|
postService = mock(),
|
||||||
idGenerateService = mock()
|
|
||||||
)
|
)
|
||||||
val postEntity = Post.of(
|
val postEntity = Post.of(
|
||||||
1L,
|
1L,
|
||||||
|
@ -125,7 +124,6 @@ class APNoteServiceImplTest {
|
||||||
objectMapper = objectMapper,
|
objectMapper = objectMapper,
|
||||||
applicationConfig = testApplicationConfig,
|
applicationConfig = testApplicationConfig,
|
||||||
postService = mock(),
|
postService = mock(),
|
||||||
idGenerateService = mock()
|
|
||||||
)
|
)
|
||||||
activityPubNoteService.createNoteJob(
|
activityPubNoteService.createNoteJob(
|
||||||
JobProps(
|
JobProps(
|
||||||
|
|
Loading…
Reference in New Issue