add IdUtils
This commit is contained in:
parent
5017e66dad
commit
1b9b549208
@ -1,2 +1,10 @@
|
||||
package com.insanusmokrassar.postssystem.core.utils
|
||||
|
||||
import com.insanusmokrassar.postssystem.core.content.ContentId
|
||||
import com.insanusmokrassar.postssystem.core.post.PostId
|
||||
import java.util.*
|
||||
|
||||
private fun generateId() = UUID.randomUUID().toString()
|
||||
|
||||
internal fun generatePostId(): PostId = generateId()
|
||||
internal fun generateContentId(): ContentId = generateId()
|
||||
|
@ -2,16 +2,13 @@ package com.insanusmokrassar.postssystem.core.api
|
||||
|
||||
import com.insanusmokrassar.postssystem.core.content.*
|
||||
import com.insanusmokrassar.postssystem.core.content.api.ContentAPI
|
||||
import com.insanusmokrassar.postssystem.core.utils.generateContentId
|
||||
import com.insanusmokrassar.postssystem.core.utils.pagination.*
|
||||
import kotlinx.coroutines.channels.BroadcastChannel
|
||||
import kotlinx.coroutines.channels.Channel
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.asFlow
|
||||
import kotlinx.serialization.ImplicitReflectionSerializer
|
||||
import java.util.*
|
||||
|
||||
@ImplicitReflectionSerializer
|
||||
private fun generateId(): ContentId = UUID.randomUUID().toString()
|
||||
|
||||
@ImplicitReflectionSerializer
|
||||
class InMemoryContentAPI(
|
||||
@ -32,7 +29,7 @@ class InMemoryContentAPI(
|
||||
|
||||
override suspend fun createContent(content: Content): RegisteredContent? {
|
||||
return RegisteredContent(
|
||||
generateId(),
|
||||
generateContentId(),
|
||||
content
|
||||
).also { registeredContent ->
|
||||
contents[registeredContent.id] = registeredContent
|
||||
|
@ -3,6 +3,7 @@ package com.insanusmokrassar.postssystem.core.api
|
||||
import com.insanusmokrassar.postssystem.core.content.ContentId
|
||||
import com.insanusmokrassar.postssystem.core.post.*
|
||||
import com.insanusmokrassar.postssystem.core.post.api.PostsAPI
|
||||
import com.insanusmokrassar.postssystem.core.utils.generatePostId
|
||||
import com.insanusmokrassar.postssystem.core.utils.pagination.*
|
||||
import kotlinx.coroutines.channels.BroadcastChannel
|
||||
import kotlinx.coroutines.channels.Channel.Factory.BUFFERED
|
||||
@ -12,9 +13,6 @@ import kotlinx.serialization.ImplicitReflectionSerializer
|
||||
import org.joda.time.DateTime
|
||||
import java.util.*
|
||||
|
||||
@ImplicitReflectionSerializer
|
||||
private fun generateId(): PostId = UUID.randomUUID().toString()
|
||||
|
||||
/**
|
||||
* Thread-unsafe sample realization of [PostsAPI]
|
||||
*/
|
||||
@ -39,7 +37,7 @@ class InMemoryPostsAPI(
|
||||
|
||||
override suspend fun createPost(post: Post): RegisteredPost? {
|
||||
return SimpleRegisteredPost(
|
||||
generateId(),
|
||||
generatePostId(),
|
||||
post.content
|
||||
).also { newPost ->
|
||||
posts[newPost.id] = newPost
|
||||
|
Loading…
Reference in New Issue
Block a user