refactoring: Masive refactor to build the V2
Tests / lint (push) Has been skipped
Tests / test (push) Has been skipped
Tests / build (push) Failing after 14m50s

This commit is contained in:
2026-07-28 23:46:52 +02:00
parent f3b848ea93
commit 9c9d057f0a
59 changed files with 315 additions and 753 deletions
@@ -19,6 +19,6 @@ class UserEventStoreRepository(
}
override fun save(user: User) {
eventStore.publish(user.recordedEvents)
eventStore.append(user.recordedEvents)
}
}
@@ -11,9 +11,8 @@ data class User(
val username: String,
val password: String,
val version: Int,
val recordedEvents: Set<UserEvent>,
) {
val recordedEvents: Set<UserEvent> = emptySet()
companion object {
fun createNewUser(
username: String,
@@ -27,6 +26,7 @@ data class User(
username = event.username,
password = event.password,
version = event.version,
recordedEvents = setOf(event),
)
fun loadFromHistory(events: Set<UserEvent>): User? =
@@ -4,7 +4,9 @@ import eventDemo.libs.eventSource.EventId
import eventDemo.sharedKernel.UserId
import kotlinx.datetime.Clock
import kotlinx.datetime.Instant
import kotlinx.serialization.Serializable
@Serializable
class NewUserCreatedEvent(
val username: String,
val password: String,
@@ -2,5 +2,7 @@ package eventDemo.contexts.auth.domain.events
import eventDemo.libs.eventSource.Event
import eventDemo.sharedKernel.UserId
import kotlinx.serialization.Serializable
@Serializable
sealed interface UserEvent : Event<UserId>
@@ -5,7 +5,7 @@ import eventDemo.contexts.auth.application.eventStores.UserRepository
import eventDemo.contexts.auth.application.ports.UserEventStore
import eventDemo.contexts.auth.application.ports.UserProjectionRepository
import eventDemo.contexts.auth.infrastructure.persistence.eventStore.UserEventStoreInPostgresql
import eventDemo.contexts.auth.infrastructure.persistence.projection.UsedProjectionRepositoryInPostgresql
import eventDemo.contexts.auth.infrastructure.persistence.projection.UserProjectionRepositoryInPostgresql
import org.koin.core.module.Module
import org.koin.core.module.dsl.singleOf
import org.koin.dsl.bind
@@ -13,5 +13,5 @@ import org.koin.dsl.bind
fun Module.configureAuthDi() {
singleOf(::UserEventStoreRepository) bind UserRepository::class
singleOf(::UserEventStoreInPostgresql) bind UserEventStore::class
singleOf(::UsedProjectionRepositoryInPostgresql) bind UserProjectionRepository::class
singleOf(::UserProjectionRepositoryInPostgresql) bind UserProjectionRepository::class
}
@@ -2,7 +2,6 @@ package eventDemo.contexts.auth.infrastructure.configure
import eventDemo.configuration.configuration
import eventDemo.contexts.auth.application.eventStores.UserEventStoreRepository
import eventDemo.contexts.auth.application.eventStores.UserRepository
import eventDemo.contexts.auth.application.ports.UserProjectionRepository
import eventDemo.contexts.auth.infrastructure.rest.createUserRoute
import eventDemo.contexts.auth.infrastructure.rest.loginRoute
@@ -12,11 +12,7 @@ import io.ktor.server.auth.authentication
import io.ktor.server.auth.jwt.JWTPrincipal
import io.ktor.server.auth.jwt.jwt
import io.ktor.server.response.respond
import io.ktor.server.routing.post
import io.ktor.server.routing.routing
import kotlinx.serialization.json.Json
import java.util.Date
import java.util.UUID
fun Application.configureKtorAuth() {
val jwtSecret = environment.config.configuration.jwtSecret
@@ -18,5 +18,5 @@ class UserEventStoreInPostgresql(
dataSource,
{ Json.encodeToString(it) },
{ Json.decodeFromString(it) },
"auth.user_event_store",
"auth.user_event_stream",
)
@@ -7,7 +7,7 @@ import eventDemo.sharedKernel.UserId
import java.util.UUID
import javax.sql.DataSource
class UsedProjectionRepositoryInPostgresql(
class UserProjectionRepositoryInPostgresql(
val dataSource: DataSource,
) : UserProjectionRepository {
override fun getByUsername(username: String): UserProjection? =
@@ -1,7 +1,5 @@
package eventDemo.contexts.auth.infrastructure.rest
import com.password4j.Hash
import com.password4j.Password
import eventDemo.contexts.auth.application.eventStores.UserRepository
import eventDemo.contexts.auth.domain.User
import eventDemo.contexts.auth.infrastructure.hashPassword