Skip to content
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
16 changes: 11 additions & 5 deletions api/src/main/kotlin/edu/wgu/osmt/api/model/ApiSortEnum.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package edu.wgu.osmt.api.model

import edu.wgu.osmt.config.CATEGORY_ASC
import edu.wgu.osmt.config.CATEGORY_DESC
import edu.wgu.osmt.config.NAME_ASC
import edu.wgu.osmt.config.NAME_DESC
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.springframework.data.domain.Sort
Expand Down Expand Up @@ -32,24 +36,26 @@ interface SortOrderCompanion<T> where T: SortOrder{
fun forApiValue(apiValue: String): T
}



/**
* Provides an enum for Rich skills that defines elasticsearch sorting
*/
enum class SkillSortEnum(override val apiValue: String) : SortOrder {
CategoryAsc("name.asc") {
CategoryAsc(CATEGORY_ASC) {
override val sort = Sort.by(
Sort.Order.asc("category.sort_insensitive"),
Sort.Order.asc("name.sort_insensitive"))
},
CategoryDesc("name.desc") {
CategoryDesc(CATEGORY_DESC) {
override val sort = Sort.by(
Sort.Order.desc("category.sort_insensitive"),
Sort.Order.asc("name.sort_insensitive"))
},
NameAsc("skill.asc") {
NameAsc(NAME_ASC) {
override val sort = Sort.by(nameKeyword).ascending()
},
NameDesc("skill.desc") {
NameDesc(NAME_DESC) {
override val sort = Sort.by(nameKeyword).descending()
};

Expand All @@ -76,7 +82,7 @@ enum class CollectionSortEnum(override val apiValue: String) : SortOrder {
SkillCountDesc("skill.desc") {
override val sort = Sort.by("skillCount").descending()
},
CollectionNameAsc("name.asc") {
CollectionNameAsc(NAME_ASC) {
override val sort = Sort.by(nameKeyword).ascending()
},
CollectionNameDesc("name.desc") {
Expand Down
9 changes: 8 additions & 1 deletion api/src/main/kotlin/edu/wgu/osmt/config/Constants.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
package edu.wgu.osmt.config

const val UNAUTHENTICATED_USERNAME = "unauthenticated"
const val QUOTED_SEARCH_REGEX_PATTERN = "([\"\'])(?:(?=(\\\\?))\\2.)*?\\1"

// API parameter constants
const val CATEGORY_ASC = "name.asc"
const val CATEGORY_DESC = "name.desc"
const val NAME_ASC = "skill.asc"
const val NAME_DESC = "skill.desc"



Expand All @@ -9,4 +16,4 @@ const val INDEX_RICHSKILL_DOC = "richskill_v1"
const val INDEX_COLLECTION_DOC = "collection_v1"
const val INDEX_JOBCODE_DOC = "jobcode_v1"
const val INDEX_KEYWORD_DOC = "keyword"
const val QUOTED_SEARCH_REGEX_PATTERN = "([\"\'])(?:(?=(\\\\?))\\2.)*?\\1"