Skip to content

Commit

Permalink
Merge pull request #181 from detached/dependabot/gradle/io.micronaut.…
Browse files Browse the repository at this point in the history
…application-4.1.2

Bump io.micronaut.application from 3.7.10 to 4.1.2
  • Loading branch information
detached authored Nov 3, 2023
2 parents b578c84 + 7b05d5e commit 3de633b
Show file tree
Hide file tree
Showing 18 changed files with 79 additions and 49 deletions.
43 changes: 22 additions & 21 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import org.jooq.meta.jaxb.Property

plugins {
id("org.jetbrains.kotlin.jvm") version "1.9.10"
id("org.jetbrains.kotlin.kapt") version "1.9.10"
id("org.jetbrains.kotlin.plugin.allopen") version "1.9.10"
id("com.google.devtools.ksp") version "1.9.10-1.0.13"
id("com.github.johnrengelman.shadow") version "8.1.1"
id("io.micronaut.application") version "3.7.10"
id("io.micronaut.application") version "4.1.2"
id("io.micronaut.aot") version "4.1.2"
id("nu.studer.jooq") version "8.2.1"
id("com.github.node-gradle.node") version "7.0.1"
id("org.jlleitschuh.gradle.ktlint") version "11.6.1"
Expand All @@ -17,12 +18,11 @@ version = "1.0"
group = "de.w3is"

val kotlinVersion = "1.9.10"
val micronautVersion = "3.7.4"
val micronautVersion = "4.1.6"
val postgresqlJdbcVersion = "42.6.0"
val jooqVersion = "3.18.7"
val nodeVersion = "18.12.0"
val nodeNpmVersion = "8.19.2"
val javaxTransactionApiVersion = "1.3"
val assertKVersion = "0.27.0"
val thumbnailatorVersion = "0.4.20"
val commonsTextVersion = "1.11.0"
Expand All @@ -37,17 +37,14 @@ repositories {
dependencies {
jooqGenerator("org.jooq:jooq-meta-extensions:$jooqVersion")

kapt("io.micronaut:micronaut-http-validation")
ksp("io.micronaut.serde:micronaut-serde-processor")

implementation("org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion")
implementation("org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion")
implementation("jakarta.annotation:jakarta.annotation-api")
implementation("javax.transaction:javax.transaction-api:$javaxTransactionApiVersion")
implementation("jakarta.transaction:jakarta.transaction-api")

implementation("io.micronaut.kotlin:micronaut-kotlin-runtime")
implementation("io.micronaut:micronaut-http-client")
implementation("io.micronaut:micronaut-jackson-databind")
implementation("io.micronaut:micronaut-validation")
implementation("io.micronaut.serde:micronaut-serde-jackson")
implementation("io.micronaut.security:micronaut-security")
implementation("io.micronaut.security:micronaut-security-jwt")
implementation("io.micronaut.security:micronaut-security-annotations")
Expand All @@ -61,12 +58,10 @@ dependencies {
implementation("net.coobird:thumbnailator:$thumbnailatorVersion")
implementation("org.apache.commons:commons-text:$commonsTextVersion")

runtimeOnly("org.yaml:snakeyaml")
runtimeOnly("ch.qos.logback:logback-classic")
runtimeOnly("com.fasterxml.jackson.module:jackson-module-kotlin")
runtimeOnly("com.h2database:h2:$h2Version")
runtimeOnly("org.postgresql:postgresql:$postgresqlJdbcVersion")

kaptTest("io.micronaut:micronaut-inject-java")
testImplementation("com.willowtreeapps.assertk:assertk:$assertKVersion")
testImplementation("org.mockito.kotlin:mockito-kotlin:$mockitoVersion")
}
Expand Down Expand Up @@ -100,14 +95,7 @@ tasks {
}
}

kapt {
arguments {
arg("micronaut.processing.incremental", true)
arg("micronaut.processing.annotations", "de.w3is.recipes.*")
}
}

graalvmNative.toolchainDetection.set(false)
graalvmNative.toolchainDetection.set(true)

micronaut {
version(micronautVersion)
Expand All @@ -117,6 +105,18 @@ micronaut {
incremental(true)
annotations("de.w3is.recipes.*")
}
aot {
optimizeServiceLoading.set(true)
convertYamlToJava.set(true)
replaceLogbackXml.set(true)
precomputeOperations.set(true)
cacheEnvironment.set(true)
optimizeClassLoading.set(true)
deduceEnvironment.set(true)
optimizeNetty.set(true)
possibleEnvironments.set(listOf("h2", "h2-local", "postgres"))
targetEnvironments.set(listOf("h2", "postgres"))
}
}

jooq {
Expand All @@ -138,6 +138,7 @@ jooq {
target.apply {
packageName = "de.w3is.recipes.infra.persistence.generated"
}
generate.withJpaAnnotations(true)
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/api/saltAndPepper.js
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ export const SaltAndPepper = {
},
}
);
if (result.status !== 202) {
if (result.status !== 204) {
throw Error(result.statusText);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import org.slf4j.LoggerFactory
import reactor.core.publisher.Mono

@Singleton
class DatabaseAuthenticationProvider(private val userRepository: UserRepository) : AuthenticationProvider {
class DatabaseAuthenticationProvider(private val userRepository: UserRepository) :
AuthenticationProvider<HttpRequest<*>> {

private val logger = LoggerFactory.getLogger(DatabaseAuthenticationProvider::class.java)

Expand Down
2 changes: 2 additions & 0 deletions src/main/kotlin/de/w3is/recipes/images/model/ImageId.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package de.w3is.recipes.images.model

import io.micronaut.serde.annotation.Serdeable
import java.util.*

@Serdeable
data class ImageId(val value: String) {
companion object {
fun new(): ImageId = ImageId(UUID.randomUUID().toString())
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/de/w3is/recipes/recipes/RecipeService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import de.w3is.recipes.recipes.model.Recipe
import de.w3is.recipes.recipes.model.RecipeId
import de.w3is.recipes.users.model.User
import jakarta.inject.Singleton
import jakarta.transaction.Transactional
import java.io.InputStream
import java.time.Clock
import java.time.OffsetDateTime
import javax.transaction.Transactional

@Singleton
open class RecipeService(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import de.w3is.recipes.recipes.model.AuthorId
import de.w3is.recipes.recipes.model.FilterKey
import de.w3is.recipes.recipes.model.Recipe
import de.w3is.recipes.recipes.model.SearchRequest
import io.micronaut.http.annotation.Body
import io.micronaut.http.annotation.Controller
import io.micronaut.http.annotation.Post
import io.micronaut.security.annotation.Secured
Expand All @@ -20,7 +21,7 @@ class RecipeSearchController(
) {

@Post
fun search(searchRequestViewModel: SearchRequestViewModel): SearchResponseViewModel {
fun search(@Body searchRequestViewModel: SearchRequestViewModel): SearchResponseViewModel {
val searchResponse = recipeRepository.search(searchRequestViewModel.toSearchRequest())
val possibleFilter = searchResponse.possibleFilter.toViewModel()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,24 @@ package de.w3is.recipes.recipes.infra.api

import de.w3is.recipes.recipes.model.FilterKey
import de.w3is.recipes.recipes.model.Order
import io.micronaut.serde.annotation.Serdeable

@Serdeable
data class SearchRequestViewModel(
val searchQuery: String,
val page: PageViewModel,
val filter: Map<FilterKey, List<String>>,
val order: Order,
)

@Serdeable
data class SearchResponseViewModel(
val data: List<SearchResponseData>,
val page: PageViewModel,
val possibleFilter: Map<FilterKey, List<FilterValueViewModel>>,
)

@Serdeable
data class SearchResponseData(
val id: String,
val imageUrl: String,
Expand All @@ -25,12 +29,14 @@ data class SearchResponseData(
val author: String,
)

@Serdeable
data class PageViewModel(
val size: Int,
val number: Int,
val maxNumber: Int?,
)

@Serdeable
data class FilterValueViewModel(
val value: String,
val label: String,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package de.w3is.recipes.recipes.infra.api

import io.micronaut.serde.annotation.Serdeable

@Serdeable
data class NewRecipeRequest(
val title: String,
val category: String,
Expand All @@ -10,10 +13,12 @@ data class NewRecipeRequest(
val modifications: String,
)

@Serdeable
data class NewRecipeResponse(
val id: String,
)

@Serdeable
data class RecipeViewModel(
val id: String,
val author: AuthorViewModel,
Expand All @@ -27,11 +32,13 @@ data class RecipeViewModel(
val images: List<ImageViewModel>,
)

@Serdeable
data class AuthorViewModel(
val id: String,
val name: String,
)

@Serdeable
data class ImageViewModel(
val id: String,
val url: String?,
Expand Down
7 changes: 7 additions & 0 deletions src/main/kotlin/de/w3is/recipes/recipes/model/Search.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package de.w3is.recipes.recipes.model

import io.micronaut.serde.annotation.Serdeable

data class SearchRequest(
val query: String,
val limit: Int,
Expand All @@ -14,28 +16,33 @@ data class SearchResponse(
val possibleFilter: Map<FilterKey, List<String>>,
)

@Serdeable
data class Page(
val current: Int,
val max: Int,
val size: Int,
)

@Serdeable
enum class FilterKey {
AUTHOR,
CATEGORY,
CUISINE,
}

@Serdeable
data class Order(
val field: OrderField,
val direction: SortDir,
)

@Serdeable
enum class OrderField {
TITLE,
CREATED_AT,
}

@Serdeable
enum class SortDir {
ASC,
DESC,
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/de/w3is/recipes/users/InvitationRepository.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package de.w3is.recipes.users

import de.w3is.recipes.users.model.Invite
import de.w3is.recipes.users.model.UserId
import java.time.Duration
import java.time.OffsetDateTime

interface InvitationRepository {
fun store(invite: Invite)
fun deleteAllOlderThan(duration: Duration)
fun deleteAllOlderThan(dateTime: OffsetDateTime)
fun findByCode(code: String): Invite?
fun invalidate(invite: Invite)
fun findByCreator(id: UserId): Invite?
Expand Down
12 changes: 7 additions & 5 deletions src/main/kotlin/de/w3is/recipes/users/InvitationService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,18 @@ import de.w3is.recipes.users.model.User
import io.micronaut.context.annotation.Property
import io.micronaut.scheduling.annotation.Scheduled
import jakarta.inject.Singleton
import jakarta.transaction.Transactional
import org.slf4j.LoggerFactory
import java.lang.RuntimeException
import java.time.Duration
import javax.transaction.Transactional
import java.time.Clock
import java.time.OffsetDateTime

@Singleton
open class InvitationService(
private val invitationRepository: InvitationRepository,
private val userService: UserService,
@Property(name = "application.allowInvitationFor")
private val allowInvitationForRole: List<String>,
private val clock: Clock,
) {

private val logger = LoggerFactory.getLogger(InvitationService::class.java)
Expand Down Expand Up @@ -48,14 +49,15 @@ open class InvitationService(
@Scheduled(fixedDelay = "1h")
fun deleteOldInvitations() {
logger.debug("Delete old invites")
invitationRepository.deleteAllOlderThan(Duration.ofDays(1))
invitationRepository.deleteAllOlderThan(OffsetDateTime.now(clock).minusDays(1))
}

fun isAllowedToInvite(user: User): Boolean {
return user.role.name in allowInvitationForRole
}

fun getInviteByCode(code: String): Invite = invitationRepository.findByCode(code) ?: throw InvitationNotFoundException()
fun getInviteByCode(code: String): Invite =
invitationRepository.findByCode(code) ?: throw InvitationNotFoundException()

@Transactional
open fun createUserByInvite(code: String, name: String, plainPassword: PlainPassword): User {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
package de.w3is.recipes.users.infra.api

import io.micronaut.serde.annotation.Serdeable

@Serdeable
data class InvitationCodeResponse(
val code: String,
)

@Serdeable
data class InvitationInfoResponse(
val invitingUser: String,
)

@Serdeable
data class InvitationRequest(
val username: String,
val password: String,
Expand Down
4 changes: 4 additions & 0 deletions src/main/kotlin/de/w3is/recipes/users/infra/api/Profile.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package de.w3is.recipes.users.infra.api

import io.micronaut.serde.annotation.Serdeable

@Serdeable
data class Profile(
val id: String,
val name: String,
val role: String,
val isAllowedToInvite: Boolean,
)

@Serdeable
data class ChangePasswordRequest(
val oldPassword: String,
val newPassword: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ import de.w3is.recipes.users.model.UserId
import jakarta.inject.Singleton
import org.jooq.DSLContext
import java.time.Clock
import java.time.Duration
import java.time.OffsetDateTime

@Singleton
class JooqInvitationRepository(
private val dslContext: DSLContext,
private val clock: Clock,
private val dslContext: DSLContext,
) : InvitationRepository {

override fun store(invite: Invite) {
Expand All @@ -25,9 +24,9 @@ class JooqInvitationRepository(
}.store()
}

override fun deleteAllOlderThan(duration: Duration) {
override fun deleteAllOlderThan(dateTime: OffsetDateTime) {
dslContext.deleteFrom(INVITATIONS)
.where(INVITATIONS.CREATED_ON.lessThan(OffsetDateTime.now(clock).minus(duration)))
.where(INVITATIONS.CREATED_ON.lessThan(dateTime))
.execute()
}

Expand Down
Loading

0 comments on commit 3de633b

Please sign in to comment.