Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename EakApplications to Applications #598

Merged
merged 1 commit into from
Oct 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ import org.jetbrains.exposed.dao.id.IntIdTable
import org.jetbrains.exposed.sql.javatime.CurrentDateTime
import org.jetbrains.exposed.sql.javatime.datetime

object EakApplications : IntIdTable() {
object Applications : IntIdTable() {
val regionId = reference("regionId", Regions)
val jsonValue = text("jsonValue")
val createdDate = datetime("createdDate").defaultExpression(CurrentDateTime)
}

class EakApplicationEntity(id: EntityID<Int>) : IntEntity(id) {
companion object : IntEntityClass<EakApplicationEntity>(
EakApplications
class ApplicationEntity(id: EntityID<Int>) : IntEntity(id) {
companion object : IntEntityClass<ApplicationEntity>(
Applications
)

var regionId by EakApplications.regionId
var jsonValue by EakApplications.jsonValue
var createdDate by EakApplications.createdDate
var regionId by Applications.regionId
var jsonValue by Applications.jsonValue
var createdDate by Applications.createdDate
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ import org.jetbrains.exposed.sql.SchemaUtils

fun setupDatabase() {
SchemaUtils.create(
EakApplications
Applications
)
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package app.ehrenamtskarte.backend.application.database.repos

import app.ehrenamtskarte.backend.application.database.EakApplicationEntity
import app.ehrenamtskarte.backend.application.database.EakApplications
import app.ehrenamtskarte.backend.application.database.ApplicationEntity
import app.ehrenamtskarte.backend.application.database.Applications
import app.ehrenamtskarte.backend.application.webservice.schema.create.BlueCardApplication
import app.ehrenamtskarte.backend.application.webservice.schema.create.GoldenCardApplication
import app.ehrenamtskarte.backend.application.webservice.schema.view.ApplicationView
Expand All @@ -15,9 +15,9 @@ import org.jetbrains.exposed.dao.id.EntityID
import org.jetbrains.exposed.sql.transactions.transaction
import java.io.File

object EakApplicationRepository {
object ApplicationRepository {

fun <T> addEakApplication(
fun <T> addApplication(
regionId: Int,
application: T,
graphQLContext: GraphQLContext,
Expand All @@ -44,7 +44,7 @@ object EakApplicationRepository {
graphQLContext: GraphQLContext
) {
val newApplication = transaction {
EakApplicationEntity.new {
ApplicationEntity.new {
this.regionId = EntityID(regionId, Regions)
this.jsonValue = applicationJson
}
Expand Down Expand Up @@ -76,14 +76,14 @@ object EakApplicationRepository {

fun getApplications(regionId: Int): List<ApplicationView> {
return transaction {
EakApplicationEntity.find { EakApplications.regionId eq regionId }
ApplicationEntity.find { Applications.regionId eq regionId }
.map { ApplicationView(it.id.value, it.regionId.value, it.createdDate.toString(), it.jsonValue) }
}
}

fun delete(applicationId: Int, graphQLContext: GraphQLContext): Boolean {
return transaction {
val application = EakApplicationEntity.findById(applicationId)
val application = ApplicationEntity.findById(applicationId)
if (application != null) {
val applicationDirectory = File(graphQLContext.applicationData, application.id.toString())
application.delete()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package app.ehrenamtskarte.backend.application.webservice

import app.ehrenamtskarte.backend.application.database.EakApplicationEntity
import app.ehrenamtskarte.backend.application.database.repos.EakApplicationRepository
import app.ehrenamtskarte.backend.application.database.ApplicationEntity
import app.ehrenamtskarte.backend.application.database.repos.ApplicationRepository
import app.ehrenamtskarte.backend.application.webservice.schema.create.BlueCardApplication
import app.ehrenamtskarte.backend.application.webservice.schema.create.GoldenCardApplication
import app.ehrenamtskarte.backend.auth.database.AdministratorEntity
Expand All @@ -21,11 +21,11 @@ class EakApplicationMutationService {
dfe: DataFetchingEnvironment
): Boolean {
val context = dfe.getLocalContext<GraphQLContext>()
EakApplicationRepository.addEakApplication(
ApplicationRepository.addApplication(
regionId,
application,
context,
EakApplicationRepository::validateBlueApplication
ApplicationRepository::validateBlueApplication
)
return true
}
Expand All @@ -37,11 +37,11 @@ class EakApplicationMutationService {
dfe: DataFetchingEnvironment
): Boolean {
val context = dfe.getLocalContext<GraphQLContext>()
EakApplicationRepository.addEakApplication(
ApplicationRepository.addApplication(
regionId,
application,
context,
EakApplicationRepository::validateGoldenApplication
ApplicationRepository::validateGoldenApplication
)
return true
}
Expand All @@ -54,7 +54,7 @@ class EakApplicationMutationService {
val context = dfe.getLocalContext<GraphQLContext>()
val jwtPayload = context.enforceSignedIn()

val application = EakApplicationEntity.findById(applicationId) ?: throw UnauthorizedException()
val application = ApplicationEntity.findById(applicationId) ?: throw UnauthorizedException()
// We throw an UnauthorizedException here, as we do not know whether there was an application with id
// `applicationId` and whether this application was contained in the user's project & region.

Expand All @@ -63,6 +63,6 @@ class EakApplicationMutationService {
throw UnauthorizedException()
}

return EakApplicationRepository.delete(applicationId, context)
return ApplicationRepository.delete(applicationId, context)
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package app.ehrenamtskarte.backend.application.webservice

import app.ehrenamtskarte.backend.application.database.repos.EakApplicationRepository
import app.ehrenamtskarte.backend.application.database.repos.ApplicationRepository
import app.ehrenamtskarte.backend.application.webservice.schema.view.ApplicationView
import app.ehrenamtskarte.backend.auth.database.repos.AdministratorsRepository
import app.ehrenamtskarte.backend.auth.service.Authorizer
Expand All @@ -24,6 +24,6 @@ class EakApplicationQueryService {
throw UnauthorizedException()
}

return EakApplicationRepository.getApplications(regionId)
return ApplicationRepository.getApplications(regionId)
}
}