diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index 40961cb..cdd260a 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -1,7 +1,7 @@ plugins { `kotlin-dsl` kotlin("jvm") version "1.4.10" - id("com.github.johnrengelman.shadow") version "6.1.0" + id("com.github.johnrengelman.shadow") version "6.1.0" apply false } repositories { @@ -12,4 +12,5 @@ repositories { dependencies { implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.4.10") implementation("com.github.jengelman.gradle.plugins:shadow:6.1.0") + implementation("org.jlleitschuh.gradle:ktlint-gradle:9.4.1") } diff --git a/buildSrc/src/main/kotlin/be/simplenotes/base.gradle.kts b/buildSrc/src/main/kotlin/be/simplenotes/base.gradle.kts index 59d3f73..ff0befb 100644 --- a/buildSrc/src/main/kotlin/be/simplenotes/base.gradle.kts +++ b/buildSrc/src/main/kotlin/be/simplenotes/base.gradle.kts @@ -6,6 +6,7 @@ plugins { java kotlin("jvm") `java-library` + id("org.jlleitschuh.gradle.ktlint") } repositories { @@ -21,6 +22,7 @@ version = "1.0-SNAPSHOT" dependencies { implementation(kotlin("stdlib-jdk8")) + implementation(platform("org.jetbrains.kotlin:kotlin-bom:1.4.10")) } tasks.withType { diff --git a/simplenotes-app/src/main/kotlin/be/simplenotes/app/api/ApiNoteController.kt b/simplenotes-app/src/main/kotlin/be/simplenotes/app/api/ApiNoteController.kt index 2705d8f..08220b8 100644 --- a/simplenotes-app/src/main/kotlin/be/simplenotes/app/api/ApiNoteController.kt +++ b/simplenotes-app/src/main/kotlin/be/simplenotes/app/api/ApiNoteController.kt @@ -2,10 +2,10 @@ package be.simplenotes.app.api import be.simplenotes.app.extensions.auto import be.simplenotes.app.utils.parseSearchTerms -import be.simplenotes.types.PersistedNote -import be.simplenotes.types.PersistedNoteMetadata import be.simplenotes.domain.usecases.NoteService import be.simplenotes.types.LoggedInUser +import be.simplenotes.types.PersistedNote +import be.simplenotes.types.PersistedNoteMetadata import kotlinx.serialization.Contextual import kotlinx.serialization.Serializable import kotlinx.serialization.json.Json @@ -28,7 +28,7 @@ class ApiNoteController(private val noteService: NoteService, private val json: ) } - fun notes(request: Request, loggedInUser: LoggedInUser): Response { + fun notes(@Suppress("UNUSED_PARAMETER") request: Request, loggedInUser: LoggedInUser): Response { val notes = noteService.paginatedNotes(loggedInUser.userId, page = 1).notes return persistedNotesMetadataLens(notes, Response(OK)) } @@ -40,12 +40,15 @@ class ApiNoteController(private val noteService: NoteService, private val json: fun update(request: Request, loggedInUser: LoggedInUser): Response { val content = noteContentLens(request) - return noteService.update(loggedInUser.userId, uuidLens(request), content).fold({ - Response(BAD_REQUEST) - }, { - if (it == null) Response(NOT_FOUND) - else Response(OK) - }) + return noteService.update(loggedInUser.userId, uuidLens(request), content).fold( + { + Response(BAD_REQUEST) + }, + { + if (it == null) Response(NOT_FOUND) + else Response(OK) + } + ) } fun search(request: Request, loggedInUser: LoggedInUser): Response { @@ -61,7 +64,6 @@ class ApiNoteController(private val noteService: NoteService, private val json: private val persistedNotesMetadataLens = json.auto>().toLens() private val persistedNoteLens = json.auto().toLens() private val uuidLens = Path.uuid().of("uuid") - } @Serializable diff --git a/simplenotes-app/src/main/kotlin/be/simplenotes/app/controllers/HealthCheckController.kt b/simplenotes-app/src/main/kotlin/be/simplenotes/app/controllers/HealthCheckController.kt index ca8c388..90cebac 100644 --- a/simplenotes-app/src/main/kotlin/be/simplenotes/app/controllers/HealthCheckController.kt +++ b/simplenotes-app/src/main/kotlin/be/simplenotes/app/controllers/HealthCheckController.kt @@ -7,6 +7,6 @@ import org.http4k.core.Status.Companion.OK import org.http4k.core.Status.Companion.SERVICE_UNAVAILABLE class HealthCheckController(private val dbHealthCheck: DbHealthCheck) { - fun healthCheck(request: Request) = + fun healthCheck(@Suppress("UNUSED_PARAMETER") request: Request) = if (dbHealthCheck.isOk()) Response(OK) else Response(SERVICE_UNAVAILABLE) } diff --git a/simplenotes-app/src/main/kotlin/be/simplenotes/app/controllers/NoteController.kt b/simplenotes-app/src/main/kotlin/be/simplenotes/app/controllers/NoteController.kt index e3e25c4..1b3de56 100644 --- a/simplenotes-app/src/main/kotlin/be/simplenotes/app/controllers/NoteController.kt +++ b/simplenotes-app/src/main/kotlin/be/simplenotes/app/controllers/NoteController.kt @@ -3,12 +3,12 @@ package be.simplenotes.app.controllers import be.simplenotes.app.extensions.html import be.simplenotes.app.extensions.redirect import be.simplenotes.app.utils.parseSearchTerms -import be.simplenotes.views.NoteView import be.simplenotes.domain.usecases.NoteService import be.simplenotes.domain.usecases.markdown.InvalidMeta import be.simplenotes.domain.usecases.markdown.MissingMeta import be.simplenotes.domain.usecases.markdown.ValidationError import be.simplenotes.types.LoggedInUser +import be.simplenotes.views.NoteView import org.http4k.core.Method import org.http4k.core.Request import org.http4k.core.Response @@ -33,8 +33,16 @@ class NoteController( return noteService.create(loggedInUser.userId, markdownForm).fold( { val html = when (it) { - MissingMeta -> view.noteEditor(loggedInUser, error = "Missing note metadata", textarea = markdownForm) - InvalidMeta -> view.noteEditor(loggedInUser, error = "Invalid note metadata", textarea = markdownForm) + MissingMeta -> view.noteEditor( + loggedInUser, + error = "Missing note metadata", + textarea = markdownForm + ) + InvalidMeta -> view.noteEditor( + loggedInUser, + error = "Invalid note metadata", + textarea = markdownForm + ) is ValidationError -> view.noteEditor( loggedInUser, validationErrors = it.validationErrors, @@ -105,8 +113,16 @@ class NoteController( return noteService.update(loggedInUser.userId, note.uuid, markdownForm).fold( { val html = when (it) { - MissingMeta -> view.noteEditor(loggedInUser, error = "Missing note metadata", textarea = markdownForm) - InvalidMeta -> view.noteEditor(loggedInUser, error = "Invalid note metadata", textarea = markdownForm) + MissingMeta -> view.noteEditor( + loggedInUser, + error = "Missing note metadata", + textarea = markdownForm + ) + InvalidMeta -> view.noteEditor( + loggedInUser, + error = "Invalid note metadata", + textarea = markdownForm + ) is ValidationError -> view.noteEditor( loggedInUser, validationErrors = it.validationErrors, diff --git a/simplenotes-app/src/main/kotlin/be/simplenotes/app/controllers/SettingsController.kt b/simplenotes-app/src/main/kotlin/be/simplenotes/app/controllers/SettingsController.kt index 9e16ee3..fedfde9 100644 --- a/simplenotes-app/src/main/kotlin/be/simplenotes/app/controllers/SettingsController.kt +++ b/simplenotes-app/src/main/kotlin/be/simplenotes/app/controllers/SettingsController.kt @@ -2,11 +2,11 @@ package be.simplenotes.app.controllers import be.simplenotes.app.extensions.html import be.simplenotes.app.extensions.redirect -import be.simplenotes.views.SettingView import be.simplenotes.domain.usecases.UserService import be.simplenotes.domain.usecases.users.delete.DeleteError import be.simplenotes.domain.usecases.users.delete.DeleteForm import be.simplenotes.types.LoggedInUser +import be.simplenotes.views.SettingView import org.http4k.core.* import org.http4k.core.body.form import org.http4k.core.cookie.invalidateCookie @@ -67,7 +67,10 @@ class SettingsController( Response(Status.OK) .with(attachment("$filename.json", "application/json")) .body(userService.exportAsJson(loggedInUser.userId)) - } else Response(Status.OK).body(userService.exportAsJson(loggedInUser.userId)).header("Content-Type", "application/json") + } else Response(Status.OK).body(userService.exportAsJson(loggedInUser.userId)).header( + "Content-Type", + "application/json" + ) } private fun Request.deleteForm(loggedInUser: LoggedInUser) = diff --git a/simplenotes-app/src/main/kotlin/be/simplenotes/app/controllers/UserController.kt b/simplenotes-app/src/main/kotlin/be/simplenotes/app/controllers/UserController.kt index bb98ed9..6e9d32a 100644 --- a/simplenotes-app/src/main/kotlin/be/simplenotes/app/controllers/UserController.kt +++ b/simplenotes-app/src/main/kotlin/be/simplenotes/app/controllers/UserController.kt @@ -3,14 +3,14 @@ package be.simplenotes.app.controllers import be.simplenotes.app.extensions.html import be.simplenotes.app.extensions.isSecure import be.simplenotes.app.extensions.redirect -import be.simplenotes.views.UserView +import be.simplenotes.config.JwtConfig import be.simplenotes.domain.usecases.UserService import be.simplenotes.domain.usecases.users.login.* import be.simplenotes.domain.usecases.users.register.InvalidRegisterForm import be.simplenotes.domain.usecases.users.register.RegisterForm import be.simplenotes.domain.usecases.users.register.UserExists -import be.simplenotes.config.JwtConfig import be.simplenotes.types.LoggedInUser +import be.simplenotes.views.UserView import org.http4k.core.Method.GET import org.http4k.core.Request import org.http4k.core.Response diff --git a/simplenotes-app/src/main/kotlin/be/simplenotes/app/extensions/Http4kExtensions.kt b/simplenotes-app/src/main/kotlin/be/simplenotes/app/extensions/Http4kExtensions.kt index cd2916e..7c70770 100644 --- a/simplenotes-app/src/main/kotlin/be/simplenotes/app/extensions/Http4kExtensions.kt +++ b/simplenotes-app/src/main/kotlin/be/simplenotes/app/extensions/Http4kExtensions.kt @@ -23,7 +23,8 @@ fun Request.isSecure() = header("X-Forwarded-Proto")?.contains("https") ?: false val bodyLens = httpBodyRoot( listOf(Meta(true, "body", ParamMeta.ObjectParam, "body")), - ContentType.APPLICATION_JSON.withNoDirectives(), ContentNegotiation.StrictNoDirective + ContentType.APPLICATION_JSON.withNoDirectives(), + ContentNegotiation.StrictNoDirective ).map( { it.payload.asString() }, { Body(it) } diff --git a/simplenotes-app/src/main/kotlin/be/simplenotes/app/filters/AuthFilter.kt b/simplenotes-app/src/main/kotlin/be/simplenotes/app/filters/AuthFilter.kt index b080de4..7f1c118 100644 --- a/simplenotes-app/src/main/kotlin/be/simplenotes/app/filters/AuthFilter.kt +++ b/simplenotes-app/src/main/kotlin/be/simplenotes/app/filters/AuthFilter.kt @@ -25,7 +25,7 @@ class AuthFilter( JwtSource.Header -> it.bearerTokenHeader() JwtSource.Cookie -> it.bearerTokenCookie() } - val jwtPayload = token?.let { token -> extractor(token) } + val jwtPayload = token?.let { extractor(token) } when { jwtPayload != null -> { ctx[it][authKey] = jwtPayload diff --git a/simplenotes-app/src/main/kotlin/be/simplenotes/app/jetty/Jetty.kt b/simplenotes-app/src/main/kotlin/be/simplenotes/app/jetty/Jetty.kt index 644ebec..4d89fae 100644 --- a/simplenotes-app/src/main/kotlin/be/simplenotes/app/jetty/Jetty.kt +++ b/simplenotes-app/src/main/kotlin/be/simplenotes/app/jetty/Jetty.kt @@ -12,9 +12,12 @@ import org.http4k.servlet.asServlet class Jetty(private val port: Int, private val server: Server) : ServerConfig { constructor(port: Int = 8000) : this(port, http(port)) - constructor(port: Int, vararg inConnectors: ConnectorBuilder) : this(port, Server().apply { - inConnectors.forEach { addConnector(it(this)) } - }) + constructor(port: Int, vararg inConnectors: ConnectorBuilder) : this( + port, + Server().apply { + inConnectors.forEach { addConnector(it(this)) } + } + ) override fun toServer(httpHandler: HttpHandler): Http4kServer { server.insertHandler(httpHandler.toJettyHandler()) diff --git a/simplenotes-app/src/main/kotlin/be/simplenotes/app/modules/ServerModule.kt b/simplenotes-app/src/main/kotlin/be/simplenotes/app/modules/ServerModule.kt index 0f5707f..cc474ab 100644 --- a/simplenotes-app/src/main/kotlin/be/simplenotes/app/modules/ServerModule.kt +++ b/simplenotes-app/src/main/kotlin/be/simplenotes/app/modules/ServerModule.kt @@ -10,7 +10,6 @@ import be.simplenotes.app.jetty.Jetty import be.simplenotes.app.routes.Router import be.simplenotes.app.utils.StaticFileResolver import be.simplenotes.app.utils.StaticFileResolverImpl -import be.simplenotes.views.ErrorView import be.simplenotes.config.ServerConfig import org.eclipse.jetty.server.ServerConnector import org.http4k.core.Filter diff --git a/simplenotes-app/src/main/kotlin/be/simplenotes/app/serialization/LocaleDateTimeSerializer.kt b/simplenotes-app/src/main/kotlin/be/simplenotes/app/serialization/LocalDateTimeSerializer.kt similarity index 100% rename from simplenotes-app/src/main/kotlin/be/simplenotes/app/serialization/LocaleDateTimeSerializer.kt rename to simplenotes-app/src/main/kotlin/be/simplenotes/app/serialization/LocalDateTimeSerializer.kt diff --git a/simplenotes-app/src/main/kotlin/be/simplenotes/app/serialization/UuidSerializer.kt b/simplenotes-app/src/main/kotlin/be/simplenotes/app/serialization/UuidSerializer.kt index a0012e3..1e87d0e 100644 --- a/simplenotes-app/src/main/kotlin/be/simplenotes/app/serialization/UuidSerializer.kt +++ b/simplenotes-app/src/main/kotlin/be/simplenotes/app/serialization/UuidSerializer.kt @@ -10,7 +10,7 @@ import java.util.* internal class UuidSerializer : KSerializer { override val descriptor: SerialDescriptor - get() = PrimitiveSerialDescriptor("LocalDateTime", PrimitiveKind.STRING) + get() = PrimitiveSerialDescriptor("UUID", PrimitiveKind.STRING) override fun serialize(encoder: Encoder, value: UUID) { encoder.encodeString(value.toString()) diff --git a/simplenotes-app/src/test/kotlin/be/simplenotes/app/filters/AuthFilterTest.kt b/simplenotes-app/src/test/kotlin/be/simplenotes/app/filters/AuthFilterTest.kt index 30ecc74..8461c94 100644 --- a/simplenotes-app/src/test/kotlin/be/simplenotes/app/filters/AuthFilterTest.kt +++ b/simplenotes-app/src/test/kotlin/be/simplenotes/app/filters/AuthFilterTest.kt @@ -1,8 +1,8 @@ package be.simplenotes.app.filters +import be.simplenotes.config.JwtConfig import be.simplenotes.domain.security.JwtPayloadExtractor import be.simplenotes.domain.security.SimpleJwt -import be.simplenotes.config.JwtConfig import be.simplenotes.types.LoggedInUser import com.natpryce.hamkrest.assertion.assertThat import org.http4k.core.* diff --git a/simplenotes-app/src/test/kotlin/be/simplenotes/app/utils/SearchTermsParserKtTest.kt b/simplenotes-app/src/test/kotlin/be/simplenotes/app/utils/SearchTermsParserKtTest.kt index 8a22d2d..b739900 100644 --- a/simplenotes-app/src/test/kotlin/be/simplenotes/app/utils/SearchTermsParserKtTest.kt +++ b/simplenotes-app/src/test/kotlin/be/simplenotes/app/utils/SearchTermsParserKtTest.kt @@ -30,7 +30,9 @@ internal class SearchTermsParserKtTest { createResult("tag:'example' title:'other' end", title = "other", tag = "example", all = "end"), createResult( "tag:'example abc' title:'other with words' this is the end ", - title = "other with words", tag = "example abc", all = "this is the end" + title = "other with words", + tag = "example abc", + all = "this is the end" ), ) diff --git a/simplenotes-domain/src/main/kotlin/be/simplenotes/domain/security/JwtPayload.kt b/simplenotes-domain/src/main/kotlin/be/simplenotes/domain/security/JwtPayloadExtractor.kt similarity index 100% rename from simplenotes-domain/src/main/kotlin/be/simplenotes/domain/security/JwtPayload.kt rename to simplenotes-domain/src/main/kotlin/be/simplenotes/domain/security/JwtPayloadExtractor.kt diff --git a/simplenotes-domain/src/main/kotlin/be/simplenotes/domain/usecases/export/ExportUseCaseImpl.kt b/simplenotes-domain/src/main/kotlin/be/simplenotes/domain/usecases/export/ExportUseCaseImpl.kt index 2513e2c..14a9a9a 100644 --- a/simplenotes-domain/src/main/kotlin/be/simplenotes/domain/usecases/export/ExportUseCaseImpl.kt +++ b/simplenotes-domain/src/main/kotlin/be/simplenotes/domain/usecases/export/ExportUseCaseImpl.kt @@ -1,7 +1,7 @@ package be.simplenotes.domain.usecases.export -import be.simplenotes.types.ExportedNote import be.simplenotes.persistance.repositories.NoteRepository +import be.simplenotes.types.ExportedNote import kotlinx.serialization.builtins.ListSerializer import kotlinx.serialization.json.Json import org.apache.commons.compress.archivers.zip.ZipArchiveEntry @@ -31,7 +31,6 @@ internal class ExportUseCaseImpl(private val noteRepository: NoteRepository, pri } } - class ZipOutput : AutoCloseable { val outputStream = ByteArrayOutputStream() private val zipOutputStream = ZipArchiveOutputStream(outputStream) diff --git a/simplenotes-domain/src/main/kotlin/be/simplenotes/domain/usecases/users/delete/DeleteUseCaseImpl.kt b/simplenotes-domain/src/main/kotlin/be/simplenotes/domain/usecases/users/delete/DeleteUseCaseImpl.kt index cf8cd52..d5eddce 100644 --- a/simplenotes-domain/src/main/kotlin/be/simplenotes/domain/usecases/users/delete/DeleteUseCaseImpl.kt +++ b/simplenotes-domain/src/main/kotlin/be/simplenotes/domain/usecases/users/delete/DeleteUseCaseImpl.kt @@ -12,14 +12,15 @@ internal class DeleteUseCaseImpl( private val userRepository: UserRepository, private val passwordHash: PasswordHash, private val searcher: NoteSearcher, - ) : DeleteUseCase { +) : DeleteUseCase { override fun delete(form: DeleteForm) = either.eager { val user = !UserValidations.validateDelete(form) val persistedUser = !userRepository.find(user.username).rightIfNotNull { DeleteError.Unregistered } !Either.conditionally( passwordHash.verify(user.password, persistedUser.password), { DeleteError.WrongPassword }, - { Unit }) + { Unit } + ) !Either.conditionally(userRepository.delete(persistedUser.id), { DeleteError.Unregistered }, { Unit }) searcher.dropIndex(persistedUser.id) } diff --git a/simplenotes-domain/src/main/kotlin/be/simplenotes/domain/usecases/users/register/RegisterUseCaseImpl.kt b/simplenotes-domain/src/main/kotlin/be/simplenotes/domain/usecases/users/register/RegisterUseCaseImpl.kt index 11e2139..15657f4 100644 --- a/simplenotes-domain/src/main/kotlin/be/simplenotes/domain/usecases/users/register/RegisterUseCaseImpl.kt +++ b/simplenotes-domain/src/main/kotlin/be/simplenotes/domain/usecases/users/register/RegisterUseCaseImpl.kt @@ -3,10 +3,10 @@ package be.simplenotes.domain.usecases.users.register import arrow.core.Either import arrow.core.filterOrElse import arrow.core.leftIfNull -import be.simplenotes.types.PersistedUser import be.simplenotes.domain.security.PasswordHash import be.simplenotes.domain.validation.UserValidations import be.simplenotes.persistance.repositories.UserRepository +import be.simplenotes.types.PersistedUser internal class RegisterUseCaseImpl( private val userRepository: UserRepository, diff --git a/simplenotes-domain/src/main/kotlin/be/simplenotes/domain/usecases/users/register/RegisterUsecase.kt b/simplenotes-domain/src/main/kotlin/be/simplenotes/domain/usecases/users/register/RegisterUsecase.kt index c9d635a..8f47d38 100644 --- a/simplenotes-domain/src/main/kotlin/be/simplenotes/domain/usecases/users/register/RegisterUsecase.kt +++ b/simplenotes-domain/src/main/kotlin/be/simplenotes/domain/usecases/users/register/RegisterUsecase.kt @@ -1,8 +1,8 @@ package be.simplenotes.domain.usecases.users.register import arrow.core.Either -import be.simplenotes.types.PersistedUser import be.simplenotes.domain.usecases.users.login.LoginForm +import be.simplenotes.types.PersistedUser import io.konform.validation.ValidationErrors sealed class RegisterError diff --git a/simplenotes-domain/src/main/kotlin/be/simplenotes/domain/validation/UserValidations.kt b/simplenotes-domain/src/main/kotlin/be/simplenotes/domain/validation/UserValidations.kt index 59bf6da..e7d5191 100644 --- a/simplenotes-domain/src/main/kotlin/be/simplenotes/domain/validation/UserValidations.kt +++ b/simplenotes-domain/src/main/kotlin/be/simplenotes/domain/validation/UserValidations.kt @@ -3,13 +3,13 @@ package be.simplenotes.domain.validation import arrow.core.Either import arrow.core.left import arrow.core.right -import be.simplenotes.types.User import be.simplenotes.domain.usecases.users.delete.DeleteError import be.simplenotes.domain.usecases.users.delete.DeleteForm import be.simplenotes.domain.usecases.users.login.InvalidLoginForm import be.simplenotes.domain.usecases.users.login.LoginForm import be.simplenotes.domain.usecases.users.register.InvalidRegisterForm import be.simplenotes.domain.usecases.users.register.RegisterForm +import be.simplenotes.types.User import io.konform.validation.Validation import io.konform.validation.jsonschema.maxLength import io.konform.validation.jsonschema.minLength diff --git a/simplenotes-domain/src/test/kotlin/be/simplenotes/domain/security/LoggedInUserExtractorTest.kt b/simplenotes-domain/src/test/kotlin/be/simplenotes/domain/security/LoggedInUserExtractorTest.kt index 94b6116..8c4255a 100644 --- a/simplenotes-domain/src/test/kotlin/be/simplenotes/domain/security/LoggedInUserExtractorTest.kt +++ b/simplenotes-domain/src/test/kotlin/be/simplenotes/domain/security/LoggedInUserExtractorTest.kt @@ -1,7 +1,7 @@ package be.simplenotes.domain.security -import be.simplenotes.domain.usecases.users.login.Token import be.simplenotes.config.JwtConfig +import be.simplenotes.domain.usecases.users.login.Token import be.simplenotes.types.LoggedInUser import com.auth0.jwt.JWT import com.auth0.jwt.algorithms.Algorithm diff --git a/simplenotes-domain/src/test/kotlin/be/simplenotes/domain/usecases/users/login/LoginUseCaseImplTest.kt b/simplenotes-domain/src/test/kotlin/be/simplenotes/domain/usecases/users/login/LoginUseCaseImplTest.kt index e401cc3..27f4ee4 100644 --- a/simplenotes-domain/src/test/kotlin/be/simplenotes/domain/usecases/users/login/LoginUseCaseImplTest.kt +++ b/simplenotes-domain/src/test/kotlin/be/simplenotes/domain/usecases/users/login/LoginUseCaseImplTest.kt @@ -1,12 +1,12 @@ package be.simplenotes.domain.usecases.users.login -import be.simplenotes.types.PersistedUser +import be.simplenotes.config.JwtConfig import be.simplenotes.domain.security.BcryptPasswordHash import be.simplenotes.domain.security.SimpleJwt -import be.simplenotes.persistance.repositories.UserRepository -import be.simplenotes.config.JwtConfig import be.simplenotes.domain.testutils.isLeftOfType import be.simplenotes.domain.testutils.isRight +import be.simplenotes.persistance.repositories.UserRepository +import be.simplenotes.types.PersistedUser import com.natpryce.hamkrest.assertion.assertThat import io.mockk.* import org.junit.jupiter.api.BeforeEach diff --git a/simplenotes-domain/src/test/kotlin/be/simplenotes/domain/usecases/users/register/RegisterUseCaseImplTest.kt b/simplenotes-domain/src/test/kotlin/be/simplenotes/domain/usecases/users/register/RegisterUseCaseImplTest.kt index 6e23345..f292c67 100644 --- a/simplenotes-domain/src/test/kotlin/be/simplenotes/domain/usecases/users/register/RegisterUseCaseImplTest.kt +++ b/simplenotes-domain/src/test/kotlin/be/simplenotes/domain/usecases/users/register/RegisterUseCaseImplTest.kt @@ -1,10 +1,10 @@ package be.simplenotes.domain.usecases.users.register -import be.simplenotes.types.PersistedUser import be.simplenotes.domain.security.BcryptPasswordHash import be.simplenotes.domain.testutils.isLeftOfType import be.simplenotes.domain.testutils.isRight import be.simplenotes.persistance.repositories.UserRepository +import be.simplenotes.types.PersistedUser import com.natpryce.hamkrest.assertion.assertThat import com.natpryce.hamkrest.equalTo import io.mockk.* diff --git a/simplenotes-persistance/src/main/kotlin/be/simplenotes/persistance/HealthCheck.kt b/simplenotes-persistance/src/main/kotlin/be/simplenotes/persistance/HealthCheck.kt index c061924..30ebd68 100644 --- a/simplenotes-persistance/src/main/kotlin/be/simplenotes/persistance/HealthCheck.kt +++ b/simplenotes-persistance/src/main/kotlin/be/simplenotes/persistance/HealthCheck.kt @@ -1,8 +1,8 @@ package be.simplenotes.persistance +import be.simplenotes.config.DataSourceConfig import be.simplenotes.persistance.utils.DbType import be.simplenotes.persistance.utils.type -import be.simplenotes.config.DataSourceConfig import me.liuwj.ktorm.database.Database import me.liuwj.ktorm.database.asIterable import me.liuwj.ktorm.database.use diff --git a/simplenotes-persistance/src/main/kotlin/be/simplenotes/persistance/Migrations.kt b/simplenotes-persistance/src/main/kotlin/be/simplenotes/persistance/Migrations.kt index dcd9add..1e4ac3e 100644 --- a/simplenotes-persistance/src/main/kotlin/be/simplenotes/persistance/Migrations.kt +++ b/simplenotes-persistance/src/main/kotlin/be/simplenotes/persistance/Migrations.kt @@ -1,8 +1,8 @@ package be.simplenotes.persistance +import be.simplenotes.config.DataSourceConfig import be.simplenotes.persistance.utils.DbType import be.simplenotes.persistance.utils.type -import be.simplenotes.config.DataSourceConfig import org.flywaydb.core.Flyway import javax.sql.DataSource diff --git a/simplenotes-persistance/src/main/kotlin/be/simplenotes/persistance/converters/NoteConverter.kt b/simplenotes-persistance/src/main/kotlin/be/simplenotes/persistance/converters/NoteConverter.kt index 9ba4d97..8643b39 100644 --- a/simplenotes-persistance/src/main/kotlin/be/simplenotes/persistance/converters/NoteConverter.kt +++ b/simplenotes-persistance/src/main/kotlin/be/simplenotes/persistance/converters/NoteConverter.kt @@ -10,7 +10,6 @@ import org.mapstruct.ReportingPolicy import java.time.LocalDateTime import java.util.* - /** * This is an abstract class because kotlin default methods in interface are not seen as default in kapt * @see [KT-25960](https://youtrack.jetbrains.com/issue/KT-25960) @@ -35,7 +34,11 @@ internal abstract class NoteConverter { fun toPersistedNote(entity: NoteEntity, tags: Tags) = PersistedNote( NoteMetadata(title = entity.title, tags = tags), - entity.markdown, entity.html, entity.updatedAt, entity.uuid, entity.public + entity.markdown, + entity.html, + entity.updatedAt, + entity.uuid, + entity.public ) @Mappings( @@ -46,15 +49,15 @@ internal abstract class NoteConverter { abstract fun toExportedNote(entity: NoteEntity, tags: Tags): ExportedNote fun toEntity(note: Note, uuid: UUID, userId: Int, updatedAt: LocalDateTime) = NoteEntity { - this.title = note.meta.title - this.markdown = note.markdown - this.html = note.html - this.uuid = uuid - this.deleted = false - this.public = false - this.user.id = userId - this.updatedAt = updatedAt - } + this.title = note.meta.title + this.markdown = note.markdown + this.html = note.html + this.uuid = uuid + this.deleted = false + this.public = false + this.user.id = userId + this.updatedAt = updatedAt + } @Mappings( Mapping(target = ".", source = "note"), @@ -73,7 +76,6 @@ internal abstract class NoteConverter { @Mapping(target = "deleted", source = "trash") abstract fun toEntity(exportedNote: ExportedNote): NoteEntity - } typealias Tags = List diff --git a/simplenotes-persistance/src/main/kotlin/be/simplenotes/persistance/notes/NoteRepositoryImpl.kt b/simplenotes-persistance/src/main/kotlin/be/simplenotes/persistance/notes/NoteRepositoryImpl.kt index c2297e4..45b86e1 100644 --- a/simplenotes-persistance/src/main/kotlin/be/simplenotes/persistance/notes/NoteRepositoryImpl.kt +++ b/simplenotes-persistance/src/main/kotlin/be/simplenotes/persistance/notes/NoteRepositoryImpl.kt @@ -1,11 +1,11 @@ package be.simplenotes.persistance.notes +import be.simplenotes.persistance.converters.NoteConverter +import be.simplenotes.persistance.repositories.NoteRepository import be.simplenotes.types.ExportedNote import be.simplenotes.types.Note import be.simplenotes.types.PersistedNote import be.simplenotes.types.PersistedNoteMetadata -import be.simplenotes.persistance.converters.NoteConverter -import be.simplenotes.persistance.repositories.NoteRepository import me.liuwj.ktorm.database.Database import me.liuwj.ktorm.dsl.* import me.liuwj.ktorm.entity.* @@ -211,5 +211,4 @@ internal class NoteRepositoryImpl(private val db: Database, private val converte .filter { it.noteUuid inList map { note -> note.uuid } } .groupByTo(HashMap(), { it.note.uuid }, { it.name }) } - } diff --git a/simplenotes-persistance/src/main/kotlin/be/simplenotes/persistance/users/UserRepositoryImpl.kt b/simplenotes-persistance/src/main/kotlin/be/simplenotes/persistance/users/UserRepositoryImpl.kt index b99c830..a07b9ec 100644 --- a/simplenotes-persistance/src/main/kotlin/be/simplenotes/persistance/users/UserRepositoryImpl.kt +++ b/simplenotes-persistance/src/main/kotlin/be/simplenotes/persistance/users/UserRepositoryImpl.kt @@ -1,9 +1,9 @@ package be.simplenotes.persistance.users -import be.simplenotes.types.PersistedUser -import be.simplenotes.types.User import be.simplenotes.persistance.converters.UserConverter import be.simplenotes.persistance.repositories.UserRepository +import be.simplenotes.types.PersistedUser +import be.simplenotes.types.User import me.liuwj.ktorm.database.Database import me.liuwj.ktorm.dsl.* import me.liuwj.ktorm.entity.any diff --git a/simplenotes-persistance/src/test/kotlin/be/simplenotes/persistance/converters/NoteConverterTest.kt b/simplenotes-persistance/src/test/kotlin/be/simplenotes/persistance/converters/NoteConverterTest.kt index 1711494..dee1786 100644 --- a/simplenotes-persistance/src/test/kotlin/be/simplenotes/persistance/converters/NoteConverterTest.kt +++ b/simplenotes-persistance/src/test/kotlin/be/simplenotes/persistance/converters/NoteConverterTest.kt @@ -26,10 +26,14 @@ internal class NoteConverterTest { } val tags = listOf("a", "b") val note = converter.toNote(entity, tags) - val expectedNote = Note(NoteMetadata( - title = "title", - tags = tags, - ), markdown = "md", html = "html") + val expectedNote = Note( + NoteMetadata( + title = "title", + tags = tags, + ), + markdown = "md", + html = "html" + ) assertThat(note).isEqualTo(expectedNote) } @@ -77,7 +81,6 @@ internal class NoteConverterTest { ) assertThat(note).isEqualTo(expectedNote) } - } @Nested @@ -162,7 +165,5 @@ internal class NoteConverterTest { .hasFieldOrPropertyWithValue("updatedAt", exportedNote.updatedAt) .hasFieldOrPropertyWithValue("deleted", true) } - } - } diff --git a/simplenotes-persistance/src/test/kotlin/be/simplenotes/persistance/converters/UserConverterTest.kt b/simplenotes-persistance/src/test/kotlin/be/simplenotes/persistance/converters/UserConverterTest.kt index 9b42f1e..062ac93 100644 --- a/simplenotes-persistance/src/test/kotlin/be/simplenotes/persistance/converters/UserConverterTest.kt +++ b/simplenotes-persistance/src/test/kotlin/be/simplenotes/persistance/converters/UserConverterTest.kt @@ -1,8 +1,8 @@ package be.simplenotes.persistance.converters +import be.simplenotes.persistance.users.UserEntity import be.simplenotes.types.PersistedUser import be.simplenotes.types.User -import be.simplenotes.persistance.users.UserEntity import org.assertj.core.api.Assertions.assertThat import org.junit.jupiter.api.Test import org.mapstruct.factory.Mappers diff --git a/simplenotes-persistance/src/test/kotlin/be/simplenotes/persistance/notes/NoteRepositoryImplTest.kt b/simplenotes-persistance/src/test/kotlin/be/simplenotes/persistance/notes/NoteRepositoryImplTest.kt index 73198b6..acb178a 100644 --- a/simplenotes-persistance/src/test/kotlin/be/simplenotes/persistance/notes/NoteRepositoryImplTest.kt +++ b/simplenotes-persistance/src/test/kotlin/be/simplenotes/persistance/notes/NoteRepositoryImplTest.kt @@ -1,14 +1,13 @@ package be.simplenotes.persistance.notes +import be.simplenotes.config.DataSourceConfig import be.simplenotes.persistance.DbMigrations import be.simplenotes.persistance.converters.NoteConverter import be.simplenotes.persistance.migrationModule import be.simplenotes.persistance.persistanceModule -import be.simplenotes.config.DataSourceConfig import be.simplenotes.persistance.repositories.NoteRepository import be.simplenotes.persistance.repositories.UserRepository import be.simplenotes.types.* -import be.simplenotes.types.* import me.liuwj.ktorm.database.Database import me.liuwj.ktorm.dsl.eq import me.liuwj.ktorm.entity.filter diff --git a/simplenotes-persistance/src/test/kotlin/be/simplenotes/persistance/users/UserRepositoryImplTest.kt b/simplenotes-persistance/src/test/kotlin/be/simplenotes/persistance/users/UserRepositoryImplTest.kt index cd9909c..f35e169 100644 --- a/simplenotes-persistance/src/test/kotlin/be/simplenotes/persistance/users/UserRepositoryImplTest.kt +++ b/simplenotes-persistance/src/test/kotlin/be/simplenotes/persistance/users/UserRepositoryImplTest.kt @@ -1,11 +1,11 @@ package be.simplenotes.persistance.users -import be.simplenotes.types.User -import be.simplenotes.persistance.repositories.UserRepository +import be.simplenotes.config.DataSourceConfig import be.simplenotes.persistance.DbMigrations import be.simplenotes.persistance.migrationModule import be.simplenotes.persistance.persistanceModule -import be.simplenotes.config.DataSourceConfig +import be.simplenotes.persistance.repositories.UserRepository +import be.simplenotes.types.User import me.liuwj.ktorm.database.* import me.liuwj.ktorm.dsl.* import me.liuwj.ktorm.entity.* diff --git a/simplenotes-search/src/main/kotlin/be/simplenotes/search/NoteSearcherImpl.kt b/simplenotes-search/src/main/kotlin/be/simplenotes/search/NoteSearcherImpl.kt index a0debab..5fcce1c 100644 --- a/simplenotes-search/src/main/kotlin/be/simplenotes/search/NoteSearcherImpl.kt +++ b/simplenotes-search/src/main/kotlin/be/simplenotes/search/NoteSearcherImpl.kt @@ -1,7 +1,7 @@ package be.simplenotes.search -import be.simplenotes.types.PersistedNote import be.simplenotes.search.utils.rmdir +import be.simplenotes.types.PersistedNote import org.apache.lucene.analysis.standard.StandardAnalyzer import org.apache.lucene.document.Document import org.apache.lucene.index.* diff --git a/simplenotes-search/src/test/kotlin/be/simplenotes/search/NoteSearcherImplTest.kt b/simplenotes-search/src/test/kotlin/be/simplenotes/search/NoteSearcherImplTest.kt index 9945fd8..5cc0778 100644 --- a/simplenotes-search/src/test/kotlin/be/simplenotes/search/NoteSearcherImplTest.kt +++ b/simplenotes-search/src/test/kotlin/be/simplenotes/search/NoteSearcherImplTest.kt @@ -24,12 +24,14 @@ internal class NoteSearcherImplTest { content: String = "", uuid: UUID = UUID.randomUUID(), ): PersistedNote { - val note = PersistedNote(NoteMetadata(title, tags), + val note = PersistedNote( + NoteMetadata(title, tags), markdown = content, html = "", LocalDateTime.MIN, uuid, - public = false) + public = false + ) searcher.indexNote(1, note) return note } diff --git a/simplenotes-views/src/main/kotlin/be/simplenotes/views/NoteView.kt b/simplenotes-views/src/main/kotlin/be/simplenotes/views/NoteView.kt index 8c7fc30..c14b720 100644 --- a/simplenotes-views/src/main/kotlin/be/simplenotes/views/NoteView.kt +++ b/simplenotes-views/src/main/kotlin/be/simplenotes/views/NoteView.kt @@ -1,7 +1,6 @@ package be.simplenotes.views import be.simplenotes.types.LoggedInUser -import be.simplenotes.views.components.noteListHeader import be.simplenotes.types.PersistedNote import be.simplenotes.types.PersistedNoteMetadata import be.simplenotes.views.components.* @@ -38,7 +37,9 @@ class NoteView(styles: String) : View(styles) { |tags: [] |--- | - """.trimMargin("|") + """.trimMargin( + "|" + ) } submitButton("Save") } @@ -128,7 +129,7 @@ class NoteView(styles: String) : View(styles) { +"You are viewing a public note " } - hr { } + hr { } } div("flex items-center justify-between mb-4") { @@ -151,7 +152,7 @@ class NoteView(styles: String) : View(styles) { +"/notes/public/${note.uuid}" } } - hr { } + hr { } } } @@ -182,8 +183,9 @@ class NoteView(styles: String) : View(styles) { button( type = ButtonType.submit, name = if (note.public) "private" else "public", - classes = "font-semibold border-b-4 ${if (!note.public) "border-teal-200" else "border-green-500"}" + - " p-2 rounded-r bg-teal-200 text-gray-800" + classes = "font-semibold border-b-4 " + + if (!note.public) "border-teal-200" else "border-green-500" + + " p-2 rounded-r bg-teal-200 text-gray-800" ) { +"Public" } diff --git a/simplenotes-views/src/main/kotlin/be/simplenotes/views/SettingView.kt b/simplenotes-views/src/main/kotlin/be/simplenotes/views/SettingView.kt index 8c18203..cdc736f 100644 --- a/simplenotes-views/src/main/kotlin/be/simplenotes/views/SettingView.kt +++ b/simplenotes-views/src/main/kotlin/be/simplenotes/views/SettingView.kt @@ -28,9 +28,11 @@ class SettingView(styles: String) : View(styles) { section("m-4 p-2 bg-gray-800 rounded flex flex-wrap justify-around items-end") { form(classes = "m-2", method = FormMethod.post, action = "/export") { - button(name = "display", + button( + name = "display", classes = "inline btn btn-teal block", - type = submit) { +"Display my data" } + type = submit + ) { +"Display my data" } } form(classes = "m-2", method = FormMethod.post, action = "/export") { diff --git a/simplenotes-views/src/main/kotlin/be/simplenotes/views/View.kt b/simplenotes-views/src/main/kotlin/be/simplenotes/views/View.kt index 959cd42..5275a56 100644 --- a/simplenotes-views/src/main/kotlin/be/simplenotes/views/View.kt +++ b/simplenotes-views/src/main/kotlin/be/simplenotes/views/View.kt @@ -22,7 +22,7 @@ abstract class View(private val styles: String) { meta(name = "viewport", content = "width=device-width, initial-scale=1") title("$title - SimpleNotes") description?.let { meta(name = "description", content = it) } - link(rel = "preload", href = "/recursive-0.0.1.woff2"){ + link(rel = "preload", href = "/recursive-0.0.1.woff2") { attributes["as"] = "font" attributes["type"] = "font/woff2" attributes["crossorigin"] = "anonymous" diff --git a/simplenotes-views/src/main/kotlin/be/simplenotes/views/extensions/KotlinxHtmlExtensions.kt b/simplenotes-views/src/main/kotlin/be/simplenotes/views/extensions/KotlinxHtmlExtensions.kt index 0212341..4bb9323 100644 --- a/simplenotes-views/src/main/kotlin/be/simplenotes/views/extensions/KotlinxHtmlExtensions.kt +++ b/simplenotes-views/src/main/kotlin/be/simplenotes/views/extensions/KotlinxHtmlExtensions.kt @@ -4,7 +4,9 @@ import kotlinx.html.* internal class SUMMARY(consumer: TagConsumer<*>) : HTMLTag( - "summary", consumer, emptyMap(), + "summary", + consumer, + emptyMap(), inlineTag = true, emptyTag = false ), diff --git a/simplenotes-views/src/main/kotlin/be/simplenotes/views/utils/PrettyDate.kt b/simplenotes-views/src/main/kotlin/be/simplenotes/views/utils/PrettyDate.kt index 40fdbf3..9b89a74 100644 --- a/simplenotes-views/src/main/kotlin/be/simplenotes/views/utils/PrettyDate.kt +++ b/simplenotes-views/src/main/kotlin/be/simplenotes/views/utils/PrettyDate.kt @@ -7,4 +7,6 @@ import java.util.* private val prettyTime = PrettyTime() -internal fun LocalDateTime.toTimeAgo(): String = prettyTime.format(Date.from(atZone(ZoneId.systemDefault()).toInstant())) +internal fun LocalDateTime.toTimeAgo(): String = prettyTime.format( + Date.from(atZone(ZoneId.systemDefault()).toInstant()) +)