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
|
||||
class SpringConfig {
|
||||
|
||||
@Autowired
|
||||
lateinit var dbConfig: DatabaseConnectConfig
|
||||
|
||||
@Autowired
|
||||
lateinit var config: ApplicationConfig
|
||||
}
|
||||
|
@ -19,11 +16,3 @@ class SpringConfig {
|
|||
data class ApplicationConfig(
|
||||
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
|
||||
) :
|
||||
TimelineRepository {
|
||||
override suspend fun generateId(): Long = idGenerateService.generateId()
|
||||
|
||||
override suspend fun save(timeline: Timeline): Timeline {
|
||||
return withContext(Dispatchers.IO) {
|
||||
|
|
|
@ -6,6 +6,7 @@ import org.springframework.stereotype.Repository
|
|||
@Suppress("LongParameterList")
|
||||
@Repository
|
||||
interface PostRepository {
|
||||
suspend fun generateId(): Long
|
||||
suspend fun save(post: Post): Post
|
||||
suspend fun delete(id: Long)
|
||||
suspend fun findById(id: Long): Post
|
||||
|
|
|
@ -11,6 +11,8 @@ import org.springframework.stereotype.Repository
|
|||
@Repository
|
||||
class PostRepositoryImpl(private val idGenerateService: IdGenerateService) : PostRepository {
|
||||
|
||||
override suspend fun generateId(): Long = idGenerateService.generateId()
|
||||
|
||||
override suspend fun save(post: Post): Post {
|
||||
val singleOrNull = Posts.select { Posts.id eq post.id }.singleOrNull()
|
||||
if (singleOrNull == null) {
|
||||
|
|
|
@ -5,6 +5,7 @@ import org.springframework.stereotype.Repository
|
|||
|
||||
@Repository
|
||||
interface ReactionRepository {
|
||||
suspend fun generateId(): Long
|
||||
suspend fun save(reaction: Reaction): Reaction
|
||||
suspend fun delete(reaction: Reaction): Reaction
|
||||
}
|
||||
|
|
|
@ -12,6 +12,9 @@ class ReactionRepositoryImpl(
|
|||
private val idGenerateService: IdGenerateService
|
||||
) : ReactionRepository {
|
||||
|
||||
|
||||
override suspend fun generateId(): Long = idGenerateService.generateId()
|
||||
|
||||
override suspend fun save(reaction: Reaction): Reaction {
|
||||
if (Reactions.select { Reactions.id eq reaction.id }.empty()) {
|
||||
Reactions.insert {
|
||||
|
|
|
@ -3,6 +3,7 @@ package dev.usbharu.hideout.repository
|
|||
import dev.usbharu.hideout.domain.model.hideout.entity.Timeline
|
||||
|
||||
interface TimelineRepository {
|
||||
suspend fun generateId(): Long
|
||||
suspend fun save(timeline: Timeline): Timeline
|
||||
suspend fun saveAll(timelines: List<Timeline>): 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.UserQueryService
|
||||
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.post.PostCreateInterceptor
|
||||
import dev.usbharu.hideout.service.post.PostService
|
||||
|
@ -50,8 +49,7 @@ class APNoteServiceImpl(
|
|||
private val postQueryService: PostQueryService,
|
||||
@Qualifier("activitypub") private val objectMapper: ObjectMapper,
|
||||
private val applicationConfig: ApplicationConfig,
|
||||
private val postService: PostService,
|
||||
private val idGenerateService: IdGenerateService
|
||||
private val postService: PostService
|
||||
|
||||
) : APNoteService, PostCreateInterceptor {
|
||||
|
||||
|
@ -173,7 +171,7 @@ class APNoteServiceImpl(
|
|||
|
||||
postService.createRemote(
|
||||
Post.of(
|
||||
id = idGenerateService.generateId(),
|
||||
id = postRepository.generateId(),
|
||||
userId = person.second.id,
|
||||
overview = null,
|
||||
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.repository.PostRepository
|
||||
import dev.usbharu.hideout.repository.UserRepository
|
||||
import dev.usbharu.hideout.service.core.IdGenerateService
|
||||
import org.springframework.stereotype.Service
|
||||
import java.time.Instant
|
||||
import java.util.*
|
||||
|
@ -14,8 +13,7 @@ import java.util.*
|
|||
class PostServiceImpl(
|
||||
private val postRepository: PostRepository,
|
||||
private val userRepository: UserRepository,
|
||||
private val timelineService: TimelineService,
|
||||
private val idGenerateService: IdGenerateService
|
||||
private val timelineService: TimelineService
|
||||
) : PostService {
|
||||
private val interceptors = Collections.synchronizedList(mutableListOf<PostCreateInterceptor>())
|
||||
|
||||
|
@ -38,7 +36,7 @@ class PostServiceImpl(
|
|||
|
||||
private suspend fun internalCreate(post: PostCreateDto, isLocal: Boolean): Post {
|
||||
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(
|
||||
id = id,
|
||||
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.UserQueryService
|
||||
import dev.usbharu.hideout.repository.TimelineRepository
|
||||
import dev.usbharu.hideout.service.core.IdGenerateService
|
||||
import org.springframework.stereotype.Service
|
||||
|
||||
@Service
|
||||
class TimelineService(
|
||||
private val followerQueryService: FollowerQueryService,
|
||||
private val userQueryService: UserQueryService,
|
||||
private val timelineRepository: TimelineRepository,
|
||||
private val idGenerateService: IdGenerateService
|
||||
private val timelineRepository: TimelineRepository
|
||||
) {
|
||||
suspend fun publishTimeline(post: Post, isLocal: Boolean) {
|
||||
val findFollowersById = followerQueryService.findFollowersById(post.userId).toMutableList()
|
||||
|
@ -25,7 +23,7 @@ class TimelineService(
|
|||
}
|
||||
val timelines = findFollowersById.map {
|
||||
Timeline(
|
||||
id = idGenerateService.generateId(),
|
||||
id = timelineRepository.generateId(),
|
||||
userId = it.id,
|
||||
timelineId = 0,
|
||||
postId = post.id,
|
||||
|
@ -41,7 +39,7 @@ class TimelineService(
|
|||
if (post.visibility == Visibility.PUBLIC) {
|
||||
timelines.add(
|
||||
Timeline(
|
||||
id = idGenerateService.generateId(),
|
||||
id = timelineRepository.generateId(),
|
||||
userId = 0,
|
||||
timelineId = 0,
|
||||
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.repository.ReactionRepository
|
||||
import dev.usbharu.hideout.service.ap.APReactionService
|
||||
import dev.usbharu.hideout.service.core.IdGenerateService
|
||||
import org.springframework.stereotype.Service
|
||||
|
||||
@Service
|
||||
class ReactionServiceImpl(
|
||||
private val reactionRepository: ReactionRepository,
|
||||
private val apReactionService: APReactionService,
|
||||
private val reactionQueryService: ReactionQueryService,
|
||||
private val idGenerateService: IdGenerateService
|
||||
private val reactionQueryService: ReactionQueryService
|
||||
) : ReactionService {
|
||||
override suspend fun receiveReaction(name: String, domain: String, userId: Long, postId: Long) {
|
||||
if (reactionQueryService.reactionAlreadyExist(postId, userId, 0).not()) {
|
||||
reactionRepository.save(
|
||||
Reaction(idGenerateService.generateId(), 0, postId, userId)
|
||||
Reaction(reactionRepository.generateId(), 0, postId, userId)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -27,7 +25,7 @@ class ReactionServiceImpl(
|
|||
// delete
|
||||
reactionQueryService.deleteByPostIdAndUserId(postId, userId)
|
||||
} else {
|
||||
val reaction = Reaction(idGenerateService.generateId(), 0, postId, userId)
|
||||
val reaction = Reaction(reactionRepository.generateId(), 0, postId, userId)
|
||||
reactionRepository.save(reaction)
|
||||
apReactionService.reaction(reaction)
|
||||
}
|
||||
|
|
|
@ -90,7 +90,6 @@ class APNoteServiceImplTest {
|
|||
objectMapper = objectMapper,
|
||||
applicationConfig = testApplicationConfig,
|
||||
postService = mock(),
|
||||
idGenerateService = mock()
|
||||
)
|
||||
val postEntity = Post.of(
|
||||
1L,
|
||||
|
@ -125,7 +124,6 @@ class APNoteServiceImplTest {
|
|||
objectMapper = objectMapper,
|
||||
applicationConfig = testApplicationConfig,
|
||||
postService = mock(),
|
||||
idGenerateService = mock()
|
||||
)
|
||||
activityPubNoteService.createNoteJob(
|
||||
JobProps(
|
||||
|
|
Loading…
Reference in New Issue