Skip to content

Commit

Permalink
Merge branch 'main' into #62-MakeBackendRunViaDockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-markl committed Dec 10, 2020
2 parents f8ea7ec + f8c9970 commit 43df282
Show file tree
Hide file tree
Showing 56 changed files with 1,269 additions and 678 deletions.
4 changes: 3 additions & 1 deletion .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

124 changes: 124 additions & 0 deletions .idea/uiDesigner.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ class Database {
SchemaUtils.create(
Categories,
Contacts,
AcceptingStores
AcceptingStores,
PhysicalStores,
Addresses
)

executeScript("sql/create_tilebbox.sql")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,48 @@ class ContactEntity(id: EntityID<Int>) : IntEntity(id) {
object AcceptingStores : IntIdTable() {
val name = varchar("name", 150)
val description = varchar("description", 2500)
val location = point("location")
val address = varchar("address", 200)
val contactId = reference("contactId", Contacts)
val categoryId = reference("categoryId", Categories)
}

class AcceptingStoreEntity(id: EntityID<Int>) : IntEntity(id) {
companion object : IntEntityClass<AcceptingStoreEntity>(AcceptingStores)
var name by AcceptingStores.name
var description by AcceptingStores.description
var contactId by AcceptingStores.contactId
var categoryId by AcceptingStores.categoryId
}

object PhysicalStores : IntIdTable() {
val coordinates = point("coordinates")
val addressId = reference("addressId", Addresses)
val storeId = reference("storeId", AcceptingStores)
}

class PhysicalStoreEntity(id: EntityID<Int>) : IntEntity(id) {
companion object : IntEntityClass<PhysicalStoreEntity>(PhysicalStores)
var storeId by PhysicalStores.storeId
var addressId by PhysicalStores.addressId
var coordinates by PhysicalStores.coordinates
}

object Addresses : IntIdTable() {
val street = varchar("street", 200)
val houseNumber = varchar("houseNumber", 10)
val postalCode = varchar("postalCode", 10)
val location = varchar("location", 200)
val state = varchar("state", 200)
}

class AddressEntity(id: EntityID<Int>) : IntEntity(id) {
companion object : IntEntityClass<AddressEntity>(Addresses)
var street by Addresses.street
var houseNumber by Addresses.houseNumber
var postalCode by Addresses.postalCode
var locaction by Addresses.location
var state by Addresses.state
}

fun Table.point(name: String, srid: Int = 4326) : Column<Point>
= registerColumn(name, PointColumnType(srid))

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package xyz.elitese.ehrenamtskarte.database.repos

import xyz.elitese.ehrenamtskarte.database.AddressEntity
import xyz.elitese.ehrenamtskarte.database.Addresses

object AddressRepository {
fun findByIds(ids: List<Int>) = AddressEntity.find {
Addresses.id inList ids
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package xyz.elitese.ehrenamtskarte.database.repos

import xyz.elitese.ehrenamtskarte.database.PhysicalStoreEntity
import xyz.elitese.ehrenamtskarte.database.PhysicalStores

object PhysicalStoresRepository {

fun findAll() = PhysicalStoreEntity.all()

fun findByIds(ids: List<Int>) = PhysicalStoreEntity.find {
PhysicalStores.id inList ids
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ fun initializeDataLoaderRegistry(dataLoaderRegistry: DataLoaderRegistry) {
dataLoaderRegistry.register(CATEGORY_LOADER_NAME, batchCategoryLoader)
dataLoaderRegistry.register(ACCEPTING_STORE_LOADER_NAME, acceptingStoreLoader)
dataLoaderRegistry.register(PHYSICAL_STORE_LOADER_NAME, physicalStoreLoader)
dataLoaderRegistry.register(ADDRESS_LOADER_NAME, batchAddressLoader)
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ val acceptingStoreLoader = DataLoader<Int, AcceptingStore?> { ids ->
runBlocking {
transaction {
AcceptingStoresRepository.findByIds(ids).map {
AcceptingStore(it.id.value, it.name, it.contactId.value, it.categoryId.value)
AcceptingStore(it.id.value, it.name, it.description, it.contactId.value, it.categoryId.value)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package xyz.elitese.ehrenamtskarte.webservice.dataloader

import kotlinx.coroutines.runBlocking
import org.dataloader.DataLoader
import org.jetbrains.exposed.sql.transactions.transaction
import xyz.elitese.ehrenamtskarte.database.repos.AddressRepository
import xyz.elitese.ehrenamtskarte.webservice.schema.types.Address
import java.util.concurrent.CompletableFuture

const val ADDRESS_LOADER_NAME = "ADDRESS_LOADER"

val batchAddressLoader = DataLoader<Int, Address?> { ids ->
CompletableFuture.supplyAsync {
runBlocking {
transaction {
AddressRepository.findByIds(ids).map {
Address(it.street, it.houseNumber, it.postalCode, it.locaction, it.state)
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,22 @@ package xyz.elitese.ehrenamtskarte.webservice.dataloader

import kotlinx.coroutines.runBlocking
import org.dataloader.DataLoader
import xyz.elitese.ehrenamtskarte.webservice.schema.types.Address
import xyz.elitese.ehrenamtskarte.webservice.schema.types.Coordinates
import org.jetbrains.exposed.sql.transactions.transaction
import xyz.elitese.ehrenamtskarte.database.repos.AcceptingStoresRepository
import xyz.elitese.ehrenamtskarte.database.repos.PhysicalStoresRepository
import xyz.elitese.ehrenamtskarte.webservice.schema.types.PhysicalStore
import java.util.concurrent.CompletableFuture

const val PHYSICAL_STORE_LOADER_NAME = "PHYSICAL_STORE_LOADER"

val allPhysicalStores = listOf(
PhysicalStore(1, Address(
"Washington street",
"120a",
"123354",
"Washington",
"WAshington State",
Coordinates(23.23, 23.23)
))
)

val physicalStoreLoader = DataLoader<Long, PhysicalStore?> { ids ->
val physicalStoreLoader = DataLoader<Int, PhysicalStore?> { ids ->
CompletableFuture.supplyAsync {
runBlocking {
ids.map { id -> allPhysicalStores.find { store -> store.id == id } }
transaction {
PhysicalStoresRepository.findByIds(ids).map {
PhysicalStore(it.id.value, it.storeId.value, it.addressId.value)
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,24 @@ package xyz.elitese.ehrenamtskarte.webservice.schema
import com.expediagroup.graphql.annotations.GraphQLDescription
import graphql.schema.DataFetchingEnvironment
import org.jetbrains.exposed.sql.transactions.transaction
import xyz.elitese.ehrenamtskarte.database.repos.AcceptingStoresRepository
import xyz.elitese.ehrenamtskarte.webservice.dataloader.ACCEPTING_STORE_LOADER_NAME
import xyz.elitese.ehrenamtskarte.webservice.schema.types.AcceptingStore
import xyz.elitese.ehrenamtskarte.database.repos.PhysicalStoresRepository
import xyz.elitese.ehrenamtskarte.webservice.dataloader.PHYSICAL_STORE_LOADER_NAME
import xyz.elitese.ehrenamtskarte.webservice.schema.types.PhysicalStore

class AcceptingStoreQueryService {

@GraphQLDescription("Return list of all accepting stores.")
@Suppress("unused")
suspend fun acceptingStores() = transaction {
AcceptingStoresRepository.findAll().map {
AcceptingStore(it.id.value, it.name, it.contactId.value, it.categoryId.value)
suspend fun physicalStores() = transaction {
PhysicalStoresRepository.findAll().map {
PhysicalStore(it.id.value, it.storeId.value, it.addressId.value)
}
}

@Suppress("unused")
suspend fun acceptingStoreById(params: Params, dataFetchingEnvironment: DataFetchingEnvironment) =
dataFetchingEnvironment.getDataLoader<Long, AcceptingStore>(ACCEPTING_STORE_LOADER_NAME)
suspend fun physicalStoresById(params: Params, dataFetchingEnvironment: DataFetchingEnvironment) =
dataFetchingEnvironment.getDataLoader<Int, PhysicalStore>(PHYSICAL_STORE_LOADER_NAME)
.loadMany(params.ids).join()
}

data class Params(val ids: List<Long>)
data class Params(val ids: List<Int>)
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,11 @@ import xyz.elitese.ehrenamtskarte.webservice.dataloader.PHYSICAL_STORE_LOADER_NA
data class AcceptingStore(
val id: Int,
val name: String,
val description: String,
val contactId: Int,
val categoryId: Int
) {

suspend fun physicalStore(dataFetchingEnvironment: DataFetchingEnvironment): PhysicalStore? {
return dataFetchingEnvironment.getDataLoader<Int, PhysicalStore?>(PHYSICAL_STORE_LOADER_NAME)
.load(id).join()
}

suspend fun contact(dataFetchingEnvironment: DataFetchingEnvironment): Contact {
return dataFetchingEnvironment.getDataLoader<Int, Contact>(CONTACT_LOADER_NAME)
.load(contactId).join()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package xyz.elitese.ehrenamtskarte.webservice.schema.types

data class Address(
val street: String,
val houseNumber: String,
val postalCode: String,
val location: String,
val state: String
)
Loading

0 comments on commit 43df282

Please sign in to comment.