Skip to content

Commit

Permalink
lint: fix lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
saku-koodari committed Sep 5, 2024
1 parent e2ba7f4 commit d21b765
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication

@SpringBootApplication
class KituKotlinApplication
class KituApplication

fun main(args: Array<String>) {
runApplication<KituKotlinApplication>(*args)
runApplication<KituApplication>(*args)
}
5 changes: 4 additions & 1 deletion src/main/kotlin/fi/oph/kitu/oppija/Oppija.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
package fi.oph.kitu.oppija

data class Oppija(val id: Long, val name: String)
data class Oppija(
val id: Long,
val name: String,
)
43 changes: 22 additions & 21 deletions src/main/kotlin/fi/oph/kitu/oppija/OppijaRepository.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,33 @@ import org.springframework.stereotype.Repository
import javax.sql.DataSource

@Repository
class OppijaRepository(dataSource: DataSource) : JdbcTemplate(dataSource) {
override fun afterPropertiesSet() {
super.afterPropertiesSet()
class OppijaRepository(
dataSource: DataSource,
) : JdbcTemplate(dataSource) {
override fun afterPropertiesSet() {
super.afterPropertiesSet()

execute("DROP TABLE IF EXISTS oppija")
execute(
"""
execute("DROP TABLE IF EXISTS oppija")
execute(
"""
|CREATE TABLE oppija (
| id SERIAL PRIMARY KEY,
| name TEXT
|)
""".trimMargin()
)
}
""".trimMargin(),
)
}

fun getAll(): Iterable<Oppija> {
return query(
"SELECT id, name FROM oppija ORDER BY name, id",
RowMapper { rs, _ -> Oppija(rs.getLong("id"), rs.getString("name")) })
}
fun getAll(): Iterable<Oppija> =
query(
"SELECT id, name FROM oppija ORDER BY name, id",
RowMapper { rs, _ -> Oppija(rs.getLong("id"), rs.getString("name")) },
)

fun insert(name: String): Oppija? {
return queryForObject(
"INSERT INTO oppija(name) VALUES (?) RETURNING id, name",
{ rs, _ -> Oppija(rs.getLong("id"), rs.getString("name")) },
name
)
}
fun insert(name: String): Oppija? =
queryForObject(
"INSERT INTO oppija(name) VALUES (?) RETURNING id, name",
{ rs, _ -> Oppija(rs.getLong("id"), rs.getString("name")) },
name,
)
}
12 changes: 5 additions & 7 deletions src/main/kotlin/fi/oph/kitu/oppija/OppijaService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ package fi.oph.kitu.oppija
import org.springframework.stereotype.Service

@Service
class OppijaService(private val oppijaRepository: OppijaRepository) {
fun getAll(): Iterable<Oppija> {
return oppijaRepository.getAll()
}
class OppijaService(
private val oppijaRepository: OppijaRepository,
) {
fun getAll(): Iterable<Oppija> = oppijaRepository.getAll()

fun insert(name: String): Oppija? {
return oppijaRepository.insert(name)
}
fun insert(name: String): Oppija? = oppijaRepository.insert(name)
}
39 changes: 20 additions & 19 deletions src/test/kotlin/fi/oph/kitu/KituApplicationTests.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,27 @@ import org.springframework.boot.test.context.SpringBootTest
import kotlin.test.assertContentEquals

@SpringBootTest
class KituKotlinApplicationTests {
@Autowired
private lateinit var oppijaService: OppijaService
class KituApplicationTests {
@Autowired
private lateinit var oppijaService: OppijaService

@Test
fun contextLoads() {
}
@Test
fun contextLoads() {
}

@Test
fun dbConnectionIsAvailable() {
oppijaService.insert("Firstname Lastname")
oppijaService.insert("Somebody Else")
oppijaService.insert("Another One")
@Test
fun dbConnectionIsAvailable() {
oppijaService.insert("Firstname Lastname")
oppijaService.insert("Somebody Else")
oppijaService.insert("Another One")

val actual = oppijaService.getAll()
val expected = listOf(
Oppija(3L, "Another One"),
Oppija(1L, "Firstname Lastname"),
Oppija(2L, "Somebody Else"),
)
assertContentEquals(expected, actual)
}
val actual = oppijaService.getAll()
val expected =
listOf(
Oppija(3L, "Another One"),
Oppija(1L, "Firstname Lastname"),
Oppija(2L, "Somebody Else"),
)
assertContentEquals(expected, actual)
}
}

0 comments on commit d21b765

Please sign in to comment.