Skip to content

Commit

Permalink
new endpoint to show a bulk
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar committed Jan 23, 2024
1 parent a09775d commit 843ad5b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
6 changes: 6 additions & 0 deletions app/controllers/BulkPairing.scala
Expand Up @@ -12,6 +12,12 @@ final class BulkPairing(env: Env) extends LilaController(env):
JsonOk(Json.obj("bulks" -> list.map(SetupBulk.toJson)))
}

def show(id: String) = ScopedBody(_.Challenge.Bulk) { _ ?=> me ?=>
env.challenge.bulk.findBy(id, me) map:
_.fold(notFoundJson()): bulk =>
JsonOk(SetupBulk.toJson(bulk))
}

def delete(id: String) = ScopedBody(_.Challenge.Bulk) { _ ?=> me ?=>
env.challenge.bulk.deleteBy(id, me) flatMap:
if _ then jsonOkResult else notFoundJson()
Expand Down
1 change: 1 addition & 0 deletions conf/routes
Expand Up @@ -702,6 +702,7 @@ GET /api/cloud-eval controllers.Api.cloudEval
POST /api/import controllers.Importer.apiSendGame
GET /api/bulk-pairing controllers.BulkPairing.list
POST /api/bulk-pairing controllers.BulkPairing.create
GET /api/bulk-pairing/:id controllers.BulkPairing.show(id)
DELETE /api/bulk-pairing/:id controllers.BulkPairing.delete(id)
POST /api/bulk-pairing/:id/start-clocks controllers.BulkPairing.startClocks(id)

Expand Down
5 changes: 4 additions & 1 deletion modules/challenge/src/main/ChallengeBulk.scala
Expand Up @@ -42,7 +42,10 @@ final class ChallengeBulkApi(
)

def scheduledBy(me: User): Fu[List[ScheduledBulk]] =
coll.list[ScheduledBulk]($doc("by" -> me.id))
coll.find($doc("by" -> me.id)).sort($sort desc "pairAt").cursor[ScheduledBulk]().list(100)

def findBy(id: String, me: User): Fu[Option[ScheduledBulk]] =
coll.one[ScheduledBulk]($doc("_id" -> id, "by" -> me.id))

def deleteBy(id: String, me: User): Fu[Boolean] =
coll.delete.one($doc("_id" -> id, "by" -> me.id)).map(_.n == 1)
Expand Down

0 comments on commit 843ad5b

Please sign in to comment.