Skip to content

Commit

Permalink
feat(api): basic missions retrieving ways
Browse files Browse the repository at this point in the history
  • Loading branch information
Inerska committed Mar 8, 2024
1 parent 81a4d8d commit c8669e6
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 2 deletions.
2 changes: 1 addition & 1 deletion talent-hub_api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ dependencies {
implementation("io.quarkus:quarkus-resteasy-reactive")
implementation("io.quarkus:quarkus-kotlin")
implementation("io.quarkus:quarkus-hibernate-reactive-panache-kotlin")
implementation("io.quarkus:quarkus-reactive-pg-client")
implementation("io.quarkus:quarkus-mongodb-panache")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
implementation("io.quarkus:quarkus-arc")
testImplementation("io.quarkus:quarkus-junit5")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.talenthub.infrastructure.persistence.entity

import io.quarkus.mongodb.panache.reactive.ReactivePanacheMongoEntity
import java.time.LocalDate

data class Mission(
var name: String,
var description: String,
var budget: Int,
var deadline: String,
var status: String,
var employerSnowflake: String,
var createdAt: LocalDate,
var updatedAt: LocalDate
) : ReactivePanacheMongoEntity()
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.talenthub.infrastructure.persistence.repository

import io.quarkus.mongodb.panache.reactive.ReactivePanacheMongoRepository
import jakarta.enterprise.context.ApplicationScoped
import org.talenthub.infrastructure.persistence.entity.Mission

@ApplicationScoped
class MissionRepository
: ReactivePanacheMongoRepository<Mission>
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package org.talenthub.presentation.resources

import io.smallrye.mutiny.Uni
import jakarta.inject.Inject
import jakarta.ws.rs.GET
import jakarta.ws.rs.Path
import jakarta.ws.rs.PathParam
import jakarta.ws.rs.Produces
import jakarta.ws.rs.core.MediaType
import jakarta.ws.rs.core.Response
import org.bson.types.ObjectId
import org.talenthub.infrastructure.persistence.repository.MissionRepository

@Path("/missions")
class MissionResource @Inject constructor(
private val _missionRepository: MissionRepository,
) {

@GET
@Produces(MediaType.APPLICATION_JSON)
fun getAllMissions(): Uni<Response> {
return _missionRepository.listAll()
.map { missions ->
Response.ok(missions).build()
}
.onFailure().recoverWithItem(Response.status(Response.Status.INTERNAL_SERVER_ERROR).build())
}


@GET
@Path("/{id}")
@Produces(MediaType.APPLICATION_JSON)
fun getMissionById(id: String): Uni<Response> {
return try {
val objectId = ObjectId(id)

_missionRepository.findById(objectId)
.map { mission ->
if (mission != null) {
Response.ok(mission).build()
} else {
Response.status(Response.Status.NOT_FOUND).build()
}
}
.onFailure().recoverWithItem(Response.status(Response.Status.INTERNAL_SERVER_ERROR).build())

} catch (e: IllegalArgumentException) {
Uni.createFrom().item(Response.status(Response.Status.BAD_REQUEST).build())
}
}
}
3 changes: 2 additions & 1 deletion talent-hub_api/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
quarkus.live-reload.instrumentation=true
quarkus.live-reload.instrumentation=true
quarkus.mongodb.database=talenthub

0 comments on commit c8669e6

Please sign in to comment.