Skip to content

Commit

Permalink
Other stuff, let's rebase this branch
Browse files Browse the repository at this point in the history
  • Loading branch information
Willdotwhite committed Apr 17, 2024
1 parent 3ed1c30 commit 75900ee
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
5 changes: 3 additions & 2 deletions api/src/main/kotlin/com/gmtkgamejam/routing/PostRoutes.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import io.ktor.server.auth.*
import io.ktor.server.request.*
import io.ktor.server.response.*
import io.ktor.server.routing.*
import org.litote.kmongo.eq
import java.time.LocalDateTime
import java.time.format.DateTimeFormatter
import kotlin.math.min
Expand All @@ -34,7 +35,7 @@ fun Application.configurePostRouting() {
get {
OpenSearch.initCluster()
// TODO: Bulk!
service.getPosts().map { OpenSearch.index(SearchItem(it)) }
service.getPosts(PostItem::deletedAt eq null).map { OpenSearch.index(SearchItem(it)) }
call.respondJSON("We here now", HttpStatusCode.OK)
}
}
Expand All @@ -53,7 +54,6 @@ fun Application.configurePostRouting() {
posts.map { it.isFavourite = favouritesList.postIds.contains(it.id) }
}

posts.map { OpenSearch.index(SearchItem(it)) }
call.respond(posts)
}

Expand Down Expand Up @@ -165,6 +165,7 @@ fun Application.configurePostRouting() {
?.let { service.getPostByAuthorId(it.discordId) }
?.let {
service.deletePost(it)
OpenSearch.delete(it.id)
return@delete call.respondJSON("Post deleted", status = HttpStatusCode.OK)
}

Expand Down
15 changes: 13 additions & 2 deletions api/src/main/kotlin/com/gmtkgamejam/search/Opensearch.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ import org.opensearch.client.opensearch.OpenSearchClient
import org.opensearch.client.opensearch._types.SortOptions
import org.opensearch.client.opensearch._types.mapping.SearchAsYouTypeProperty
import org.opensearch.client.opensearch._types.query_dsl.Query
import org.opensearch.client.opensearch.core.DeleteRequest
import org.opensearch.client.opensearch.core.IndexRequest
import org.opensearch.client.opensearch.core.SearchRequest
import org.opensearch.client.opensearch.core.UpdateRequest
import org.opensearch.client.opensearch.indices.CreateIndexRequest
import org.opensearch.client.opensearch.indices.DeleteIndexRequest
import org.opensearch.client.transport.OpenSearchTransport
import org.opensearch.client.transport.httpclient5.ApacheHttpClient5TransportBuilder

Expand All @@ -31,6 +33,8 @@ object OpenSearch {
// Manually called when needed
// TODO: Add to a superadmin dashboard somewhere
fun initCluster() {
client.indices().delete(DeleteIndexRequest.Builder().index("posts").build())

val createPostsIndex = CreateIndexRequest.Builder()
.index("posts")
.mappings { it.properties(mapOf("description_shingle" to SearchAsYouTypeProperty.Builder().build()._toProperty())) }
Expand All @@ -45,7 +49,7 @@ object OpenSearch {
val searchRequest = SearchRequest.Builder()
.index("posts")
.query(query)
.size(24)
.size(32)
.sort(sortOptions)
.build()

Expand Down Expand Up @@ -76,5 +80,12 @@ object OpenSearch {
client.update(upsertRequest, SearchItem::class.java)
}

fun delete(item: SearchItem): Nothing = TODO()
fun delete(id: String) {
val deleteRequest = DeleteRequest.Builder()
.index("posts")
.id(id)
.build()

client.delete(deleteRequest)
}
}
2 changes: 1 addition & 1 deletion api/src/main/kotlin/com/gmtkgamejam/search/SearchItem.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ data class SearchItem(
) {
constructor(postItem: PostItem): this(
id = postItem.id,
description_shingle = postItem.description, // TODO: what work needs doing?
description_shingle = postItem.description.lowercase().replace("\n", " "), // TODO: what work needs doing?
size = postItem.size,
skillsPossessed = postItem.skillsPossessed,
skillsSought = postItem.skillsSought,
Expand Down
4 changes: 2 additions & 2 deletions api/src/main/kotlin/com/gmtkgamejam/services/PostService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ class PostService : KoinComponent {
col.insertOne(postItem)
}

fun getPosts(): List<PostItem> {
return col.find().toList()
fun getPosts(filter: Bson): List<PostItem> {
return col.find(filter).toList()
}

// Un-paginated version should be used for Admin endpoints
Expand Down

0 comments on commit 75900ee

Please sign in to comment.