-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Martim Francisco
committed
Apr 4, 2022
1 parent
3dd1707
commit e0400b4
Showing
13 changed files
with
113 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
code/jvm/src/main/kotlin/pt/isel/ion/teams/ConfigProperties.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package pt.isel.ion.teams | ||
|
||
import org.springframework.boot.context.properties.ConfigurationProperties | ||
import org.springframework.boot.context.properties.ConstructorBinding | ||
|
||
@ConstructorBinding | ||
@ConfigurationProperties("app") | ||
data class ConfigProperties( | ||
val dbConnString: String | ||
) |
27 changes: 25 additions & 2 deletions
27
code/jvm/src/main/kotlin/pt/isel/ion/teams/IOnteamsServiceApplication.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,34 @@ | ||
package pt.isel.ion.teams | ||
|
||
import org.jdbi.v3.core.Jdbi | ||
import org.jdbi.v3.core.kotlin.KotlinPlugin | ||
import org.jdbi.v3.postgres.PostgresPlugin | ||
import org.jdbi.v3.sqlobject.SqlObjectPlugin | ||
import org.springframework.boot.autoconfigure.SpringBootApplication | ||
import org.springframework.boot.context.properties.ConfigurationPropertiesScan | ||
import org.springframework.boot.runApplication | ||
import org.springframework.context.annotation.Bean | ||
import org.postgresql.ds.PGSimpleDataSource | ||
import javax.sql.DataSource | ||
|
||
@SpringBootApplication | ||
class IOnteamsServiceApplication | ||
@ConfigurationPropertiesScan | ||
class IOnteamsServiceApplication( | ||
private val configProperties: ConfigProperties | ||
) { | ||
@Bean | ||
fun dataSource() = PGSimpleDataSource().apply { | ||
setURL(configProperties.dbConnString) | ||
} | ||
|
||
@Bean | ||
fun jdbi(dataSource: DataSource) = Jdbi.create(dataSource).apply { | ||
installPlugin(KotlinPlugin()) | ||
installPlugin(PostgresPlugin()) | ||
installPlugin(SqlObjectPlugin()) | ||
} | ||
} | ||
|
||
fun main(args: Array<String>) { | ||
runApplication<IOnteamsServiceApplication>(*args) | ||
runApplication<IOnteamsServiceApplication>(*args) | ||
} |
15 changes: 15 additions & 0 deletions
15
code/jvm/src/main/kotlin/pt/isel/ion/teams/organizations/OrganitazionController.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package pt.isel.ion.teams.organizations | ||
|
||
import org.jdbi.v3.core.Jdbi | ||
import org.springframework.web.bind.annotation.GetMapping | ||
import org.springframework.web.bind.annotation.RequestMapping | ||
import org.springframework.web.bind.annotation.RestController | ||
|
||
@RestController | ||
@RequestMapping("api/orgs") | ||
class OrganizationController(val jdbi: Jdbi) { | ||
|
||
@GetMapping | ||
fun getAllOrganizations() = jdbi.onDemand(OrganizationDAO::class.java).getAllOrganizations() | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
code/jvm/src/main/kotlin/pt/isel/ion/teams/organizations/Organization.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package pt.isel.ion.teams.organizations | ||
|
||
data class Organization ( | ||
val id: Int, | ||
val name: String, | ||
val description: String | ||
) |
8 changes: 8 additions & 0 deletions
8
code/jvm/src/main/kotlin/pt/isel/ion/teams/organizations/OrganizationDAO.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package pt.isel.ion.teams.organizations | ||
|
||
import org.jdbi.v3.sqlobject.statement.SqlQuery | ||
|
||
interface OrganizationDAO { | ||
@SqlQuery("SELECT * FROM organization") | ||
fun getAllOrganizations(): List<Organization> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
|
||
app.dbConnString=jdbc:postgresql://localhost:5432/postgres?user=postgres&password=${POSTGRES_PASSWORD} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
CREATE TABLE ORGANIZATION ( | ||
id serial, | ||
name varchar(50), | ||
description varchar(256), | ||
PRIMARY KEY (id) | ||
); | ||
|
||
|