Merge pull request #1 from sdeleuze/master

Refactor to idiomatic Spring + Kotlin code
This commit is contained in:
Reinhard Prechtl 2017-12-28 23:38:41 +01:00 committed by GitHub
commit 7ccc36c412
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 28 deletions

View file

@ -5,15 +5,9 @@ import javax.persistence.AttributeConverter
class DoubleAttributeConverter : AttributeConverter<Double, BigDecimal?> { class DoubleAttributeConverter : AttributeConverter<Double, BigDecimal?> {
override fun convertToDatabaseColumn(attribute: Double?): BigDecimal? { override fun convertToDatabaseColumn(attribute: Double?) =
return if (attribute != null) { if (attribute != null) { BigDecimal(attribute) } else { null }
BigDecimal(attribute)
} else {
null
}
}
override fun convertToEntityAttribute(dbData: BigDecimal?): Double? { override fun convertToEntityAttribute(dbData: BigDecimal?) =
return dbData?.toDouble() dbData?.toDouble()
}
} }

View file

@ -21,13 +21,6 @@ internal data class CityEntity(
val updatedAt: LocalDateTime = LocalDateTime.now(), val updatedAt: LocalDateTime = LocalDateTime.now(),
val createdAt: LocalDateTime = LocalDateTime.now()) { val createdAt: LocalDateTime = LocalDateTime.now()) {
// Default constructor for JPA
@Suppress("unused")
private constructor() : this(
name = "",
location = Coordinate.origin(),
updatedAt = LocalDateTime.MIN)
fun toDto(): CityDto = CityDto( fun toDto(): CityDto = CityDto(
id = this.id!!, id = this.id!!,
name = this.name, name = this.name,

View file

@ -23,7 +23,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version> <java.version>1.8</java.version>
<kotlin.version>1.1.2-2</kotlin.version> <kotlin.version>1.1.2-5</kotlin.version>
<mockito.version>2.8.9</mockito.version> <mockito.version>2.8.9</mockito.version>
<assertj.version>3.8.0</assertj.version> <assertj.version>3.8.0</assertj.version>
</properties> </properties>
@ -105,6 +105,7 @@
<configuration> <configuration>
<compilerPlugins> <compilerPlugins>
<plugin>spring</plugin> <plugin>spring</plugin>
<plugin>jpa</plugin>
</compilerPlugins> </compilerPlugins>
<jvmTarget>1.8</jvmTarget> <jvmTarget>1.8</jvmTarget>
</configuration> </configuration>
@ -130,6 +131,11 @@
<artifactId>kotlin-maven-allopen</artifactId> <artifactId>kotlin-maven-allopen</artifactId>
<version>${kotlin.version}</version> <version>${kotlin.version}</version>
</dependency> </dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-noarg</artifactId>
<version>${kotlin.version}</version>
</dependency>
</dependencies> </dependencies>
</plugin> </plugin>
</plugins> </plugins>

View file

@ -1,8 +1,5 @@
package de.rpr.mycity package de.rpr.mycity
import com.fasterxml.jackson.databind.DeserializationFeature
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.module.kotlin.KotlinModule
import org.slf4j.Logger import org.slf4j.Logger
import org.slf4j.LoggerFactory import org.slf4j.LoggerFactory
import org.springframework.beans.factory.InjectionPoint import org.springframework.beans.factory.InjectionPoint
@ -18,13 +15,6 @@ class Application {
@Scope("prototype") @Scope("prototype")
fun logger(injectionPoint: InjectionPoint): Logger = LoggerFactory.getLogger(injectionPoint.methodParameter.containingClass) fun logger(injectionPoint: InjectionPoint): Logger = LoggerFactory.getLogger(injectionPoint.methodParameter.containingClass)
@Bean
fun objectMapper(): ObjectMapper {
val mapper = ObjectMapper().registerModule(KotlinModule())
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false)
return mapper
}
} }
fun main(args: Array<String>) { fun main(args: Array<String>) {