Skip to content

Commit

Permalink
add /api/study/by/:user endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar committed May 9, 2023
1 parent e1bdee7 commit b801d0b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
11 changes: 11 additions & 0 deletions app/controllers/Study.scala
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,17 @@ final class Study(
.toFuccess
}

def apiListByOwner(username: UserStr) = OpenOrScoped(_.Study.Read) { me =>
val isMe = me.exists(_ is username)
apiC
.jsonDownload:
env.study.studyRepo
.sourceByOwner(username.id, isMe)
.throttle(if isMe then 50 else 20, 1.second)
.map(lila.study.JsonView.metadata)
.toFuccess
}

private def requestPgnFlags(req: RequestHeader) =
lila.study.PgnDump.WithFlags(
comments = getBoolOpt("comments", req) | true,
Expand Down
1 change: 1 addition & 0 deletions conf/routes
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ GET /study/glyphs/:lang.json controllers.Study.glyphs(lang)
GET /$lang<\w\w\w?>/study controllers.Study.homeLang(lang)
GET /api/study/$id<\w{8}>.pgn controllers.Study.apiPgn(id)
GET /api/study/$id<\w{8}>/$chapterId<\w{8}>.pgn controllers.Study.apiChapterPgn(id, chapterId)
GET /api/study/by/:user controllers.Study.apiListByOwner(user)

# Relay
GET /broadcast controllers.RelayTour.index(page: Int ?= 1, q ?= "")
Expand Down
7 changes: 7 additions & 0 deletions modules/study/src/main/JsonView.scala
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,13 @@ object JsonView:
Json.obj("id" -> s._id, "name" -> s.name)
}

def metadata(study: Study) = Json.obj(
"id" -> study.id,
"name" -> study.name,
"createdAt" -> study.createdAt,
"updatedAt" -> study.updatedAt
)

def glyphs(lang: play.api.i18n.Lang): JsObject =
import lila.tree.Node.given
import lila.i18n.I18nKeys.{ study as trans }
Expand Down

0 comments on commit b801d0b

Please sign in to comment.