move tournament API endpoints to /api/tournament

pull/2184/head
Thibault Duplessis 2016-08-15 13:10:53 +02:00
parent 36113ff03e
commit aabd656191
3 changed files with 25 additions and 5 deletions

View File

@ -378,12 +378,12 @@ This returns the raw PGN for a game.
1. e4 e5 2. Nf3 Nc6 3. Bc4 { Italian Game, General } Qf6?! { (0.13 → 0.98) Inaccuracy. Best move was Nf6. } (3... Nf6 4. d3 Bc5 5. O-O O-O 6. Bg5 Be7 7. a3 d6 8. h3 a6) 4. d3 h6 5. Be3 d6 6. h3?! { (0.84 → 0.31) Inaccuracy. The best move was Nc3. } (6. Nc3 Be6 7. Nd5 Qd8 8. d4 exd4 9. Nxd4 Nxd4 10. Qxd4 c6 11. Nc3 Bxc4 12. Qxc4 Nf6 13. O-O Be7) 6... a6 7. Nbd2 Be6 8. Qe2 Bxc4 9. Nxc4 Nge7 10. a3 Nd4?! { (0.29 → 0.79) Inaccuracy. The best move was O-O-O. } (10... O-O-O 11. O-O g5 12. a4 Bg7 13. Bd2 Kb8 14. Rae1 Qe6 15. b4 f5 16. b5 fxe4) 11. Bxd4 exd4 12. O-O-O Nc6 13. Rhe1 O-O-O 14. e5 dxe5 15. Nfxe5 Nxe5 16. Qxe5 Qxe5? { (0.35 → 1.78) Mistake. The best move was Qxf2. } (16... Qxf2 17. Re2 Qf6 18. Qxf6 gxf6 19. Rf1 Bg7 20. Nd2 h5 21. Ne4 Rhe8 22. Ref2 Re5 23. b3 Rdd5 24. Kb2) 17. Nxe5 Rg8?! { (1.76 → 2.32) Inaccuracy. The best move was Rd7. } (17... Rd7 18. Nxd7 Kxd7 19. Re4 c5 20. c3 dxc3 21. bxc3 Bd6 22. Kc2 b5 23. a4 Ra8 24. d4 Kc6 25. dxc5) 18. Nxf7 Rd7? { (2.35 → Mate in 2) Checkmate is now unavoidable. The best move was Rd5. } (18... Rd5 19. Re8+ Kd7 20. Rde1 Bb4 21. Rxg8 Bxe1 22. Rxg7 Bxf2 23. Nxh6+ Kc6 24. Kd1 Rb5 25. b3 Rh5 26. Nf7) 19. Re8+ { Black resigns } 1-0
```
### `GET /tournament` fetch current tournaments
### `GET /api/tournament` fetch current tournaments
Returns tournaments displayed on the schedule: https://en.lichess.org/tournament
Returns tournaments displayed on the schedule: https://lichess.org/tournament
```
> curl -H "Accept:application/vnd.lichess.v2+json" https://en.lichess.org/tournament
> curl https://en.lichess.org/api/tournament
```
```javascript
@ -431,7 +431,9 @@ Returns tournaments displayed on the schedule: https://en.lichess.org/tournament
}
```
### `GET /tournament/<tournamentId>` fetch one tournament
JSONP is available.
### `GET /api/tournament/<tournamentId>` fetch one tournament
Returns tournament info, and a page of the tournament standing
@ -440,7 +442,7 @@ name | type | default | description
**page** | int | 1 | for standing pagination
```
curl -H 'Accept:application/vnd.lichess.v2+json' 'https://en.lichess.org/tournament/x5WNIngd?page=1'
curl 'https://en.lichess.org/api/tournament/x5WNIngd?page=1'
```
```javascript
@ -540,6 +542,8 @@ curl -H 'Accept:application/vnd.lichess.v2+json' 'https://en.lichess.org/tournam
}
```
JSONP is available.
Credits
-------

View File

@ -121,6 +121,20 @@ object Api extends LilaController {
token = get("token")) map toApiResult
}
def currentTournaments = ApiRequest { implicit ctx =>
Env.tournament.api.fetchVisibleTournaments map
Env.tournament.scheduleJsonView.apply map Data.apply
}
def tournament(id: String) = ApiRequest { implicit ctx =>
val page = (getInt("page") | 1) max 1 min 200
lila.tournament.TournamentRepo byId id flatMap {
_ ?? { tour =>
Env.tournament.jsonView(tour, page.some, none, none, none) map some
}
} map toApiResult
}
sealed trait ApiResult
case class Data(json: JsValue) extends ApiResult
case object NoData extends ApiResult

View File

@ -414,6 +414,8 @@ GET /api/user controllers.Api.users
GET /api/user/:name controllers.Api.user(name: String)
GET /api/user/:name/games controllers.Api.userGames(name: String)
GET /api/game/:id controllers.Api.game(id: String)
GET /api/tournament controllers.Api.currentTournaments
GET /api/tournament/:id controllers.Api.tournament(id: String)
GET /api/status controllers.Api.status
# Misc