Skip to content

Commit

Permalink
#5 - Added move API
Browse files Browse the repository at this point in the history
  • Loading branch information
hohonuuli committed Sep 7, 2022
1 parent 74c7923 commit 4f74fb1
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/main/scala/org/mbari/vars/vam/api/MediaV1Api.scala
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,25 @@ class MediaV1Api(controller: MediaController)(

}

put("/move/:video_reference_uuid") {
validateRequest()
val videoReferenceUuid = params
.getAs[UUID]("video_reference_uuid")
.getOrElse(halt(BadRequest("""{"error":"A 'video_reference_uuid' is required"}""")))
val videoName = params.get("video_name")
.getOrElse(halt(BadRequest("""{"error":"A 'video_name' is required"}""")))
val start = params.getAs[Instant]("start_timestamp")
.getOrElse(halt(BadRequest("""{"error":"A 'start_timestamp' is required"}""")))
val duration = params.getAs[Duration]("duration_millis")
.getOrElse(halt(BadRequest("""{"error":"A 'duration_millis' is required"}""")))
controller.moveVideoReference(videoReferenceUuid, videoName, start, duration)
.map({
case Some(media) => controller.toJson(media)
case None => halt(NotFound(s"""{not_found: "A videoReference with uuid=$videoReferenceUuid was not found"}"""))
})

}

get("/sha512/:sha512") {
val shaString = params
.get("sha512")
Expand Down Expand Up @@ -336,4 +355,6 @@ class MediaV1Api(controller: MediaController)(

}



}
33 changes: 33 additions & 0 deletions src/test/scala/org/mbari/vars/vam/api/MediaV1ApiSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ package org.mbari.vars.vam.api
import org.mbari.vars.vam.controllers.MediaController
import org.mbari.vars.vam.dao.jpa.ByteArrayConverter
import org.mbari.vars.vam.model.Media

import java.net.URLEncoder
import java.net.URI
import scala.concurrent.Await
import scala.concurrent.duration._
import java.time.Instant
import java.util.UUID

/**
* @author Brian Schlining
Expand Down Expand Up @@ -191,4 +193,35 @@ class MediaV1ApiSpec extends WebApiStack {
}

}

it should "move with uuid and form body" in {
val now = Instant.now()
val media = exec(mediaController.findByVideoName("V20160922T030001Z"))
media should not be (null)
media should not be empty
val m = media.head
put(
s"/v1/media/move/${m.videoReferenceUuid}",
"duration_millis" -> "2000",
"start_timestamp" -> now.toString,
"video_name" -> "XXX"
) {
status should be(200)
val m2 = gson.fromJson(body, classOf[Media])
m2.startTimestamp should be (now)
m2.duration should be(java.time.Duration.ofMillis(2000))
m2.videoName should be ("XXX")
}
}

it should "move fails with 404" in {
put(
s"/v1/media/move/${UUID.randomUUID()}",
"duration_millis" -> "2000",
"start_timestamp" -> Instant.now().toString,
"video_name" -> "XXX"
) {
status should be(404)
}
}
}

0 comments on commit 4f74fb1

Please sign in to comment.