-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
100 additions
and
0 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
it-sqlserver/src/test/scala/org/mbari/oni/endpoints/SqlServerHistoryEndpointsSuite.scala
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,7 @@ | ||
package org.mbari.oni.endpoints | ||
|
||
import org.mbari.oni.SqlServerMixin | ||
|
||
class SqlServerHistoryEndpointsSuite extends HistoryEndpointsSuite with SqlServerMixin { | ||
|
||
} |
38 changes: 38 additions & 0 deletions
38
it/src/main/scala/org/mbari/oni/endpoints/HistoryEndpointsSuite.scala
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,38 @@ | ||
package org.mbari.oni.endpoints | ||
|
||
import org.mbari.oni.domain.ExtendedHistory | ||
import org.mbari.oni.jpa.DataInitializer | ||
import sttp.model.StatusCode | ||
import org.mbari.oni.etc.circe.CirceCodecs.{*, given} | ||
|
||
trait HistoryEndpointsSuite extends EndpointsSuite with DataInitializer: | ||
|
||
lazy val endpoints: HistoryEndpoints = HistoryEndpoints(entityManagerFactory) | ||
|
||
test("pending") { | ||
init(3, 5) | ||
runGet( | ||
endpoints.pendingEndpointImpl, | ||
"http://test.com/v1/history/pending", | ||
response => { | ||
assertEquals(response.code, StatusCode.Ok) | ||
val histories = checkResponse[Seq[ExtendedHistory]](response.body) | ||
assert(histories.nonEmpty) | ||
} | ||
) | ||
} | ||
|
||
test("approved") { | ||
init(3, 5) | ||
runGet( | ||
endpoints.approvedEndpointsImpl, | ||
"http://test.com/v1/history/approved", | ||
response => { | ||
assertEquals(response.code, StatusCode.Ok) | ||
val histories = checkResponse[Seq[ExtendedHistory]](response.body) | ||
assert(histories.nonEmpty) | ||
} | ||
) | ||
} | ||
|
||
|
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
51 changes: 51 additions & 0 deletions
51
oni/src/main/scala/org/mbari/oni/endpoints/HistoryEndpoints.scala
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,51 @@ | ||
package org.mbari.oni.endpoints | ||
|
||
import jakarta.persistence.EntityManagerFactory | ||
import org.mbari.oni.domain.{ErrorMsg, ExtendedHistory} | ||
import org.mbari.oni.etc.circe.CirceCodecs.given | ||
import org.mbari.oni.services.HistoryService | ||
import sttp.tapir.* | ||
import sttp.tapir.Endpoint | ||
import sttp.tapir.json.circe.* | ||
import sttp.tapir.server.ServerEndpoint | ||
import sttp.tapir.server.nima.Id | ||
|
||
class HistoryEndpoints(entityManagerFactory: EntityManagerFactory) extends Endpoints: | ||
|
||
private val service = HistoryService(entityManagerFactory) | ||
private val base = "history" | ||
private val tag = "History" | ||
|
||
val pendingEndpoint: Endpoint[Unit, Unit, ErrorMsg, Seq[ExtendedHistory], Any] = openEndpoint | ||
.get | ||
.in(base / "pending") | ||
.out(jsonBody[Seq[ExtendedHistory]]) | ||
.name("pending") | ||
.description("Get all pending change requests") | ||
.tag(tag) | ||
|
||
val pendingEndpointImpl: ServerEndpoint[Any, Id] = pendingEndpoint.serverLogic { | ||
_ => handleErrors(service.findAllPending()) | ||
} | ||
|
||
val approvedEndpoints: Endpoint[Unit, Unit, ErrorMsg, Seq[ExtendedHistory], Any] = openEndpoint | ||
.get | ||
.in(base / "approved") | ||
.out(jsonBody[Seq[ExtendedHistory]]) | ||
.name("approved") | ||
.description("Get all approved change requests") | ||
.tag(tag) | ||
|
||
val approvedEndpointsImpl: ServerEndpoint[Any, Id] = approvedEndpoints.serverLogic { | ||
_ => handleErrors(service.findAllApproved()) | ||
} | ||
|
||
override def all: List[Endpoint[_, _, _, _, _]] = List( | ||
approvedEndpoints, | ||
pendingEndpoint | ||
) | ||
|
||
override def allImpl: List[ServerEndpoint[Any, Id]] = List( | ||
approvedEndpointsImpl, | ||
pendingEndpointImpl | ||
) |
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