-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: make fields case-insensitive #502
- Loading branch information
1 parent
7ad9746
commit 3c92efb
Showing
16 changed files
with
407 additions
and
167 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
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
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
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
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
13 changes: 13 additions & 0 deletions
13
lapis2/src/main/kotlin/org/genspectrum/lapis/request/CaseInsensitiveFieldsCleaner.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,13 @@ | ||
package org.genspectrum.lapis.request | ||
|
||
import org.genspectrum.lapis.config.DatabaseConfig | ||
import org.springframework.stereotype.Component | ||
|
||
@Component | ||
class CaseInsensitiveFieldsCleaner(databaseConfig: DatabaseConfig) { | ||
private val fieldsMap = databaseConfig.schema.metadata.map { it.name }.associateBy { it.lowercase() } | ||
|
||
fun clean(fieldName: String) = fieldsMap[fieldName.lowercase()] | ||
|
||
fun getKnownFields() = fieldsMap.values | ||
} |
20 changes: 20 additions & 0 deletions
20
lapis2/src/main/kotlin/org/genspectrum/lapis/request/Field.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,20 @@ | ||
package org.genspectrum.lapis.request | ||
|
||
import org.genspectrum.lapis.controller.BadRequestException | ||
import org.springframework.core.convert.converter.Converter | ||
import org.springframework.stereotype.Component | ||
|
||
data class Field(val fieldName: String) | ||
|
||
@Component | ||
class FieldConverter(private val caseInsensitiveFieldsCleaner: CaseInsensitiveFieldsCleaner) : | ||
Converter<String, Field> { | ||
override fun convert(source: String): Field { | ||
val cleaned = caseInsensitiveFieldsCleaner.clean(source) | ||
?: throw BadRequestException( | ||
"Unknown field: $source, known values are ${caseInsensitiveFieldsCleaner.getKnownFields()}", | ||
) | ||
|
||
return Field(cleaned) | ||
} | ||
} |
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
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
Oops, something went wrong.