Skip to content

Commit 6c4996e

Browse files
committed
feat(api): add v2.0 session-based “_s” endpoints (token routes kept for CLI)
Update supported_versions so: - legacy token routes are valid Upto v2.0 - new session routes are valid Since v2.0 Clients ≥ 2.0 negotiate the new API; CLI clients continue to work. Front-end now uses only the “_s” routes.
1 parent 2bcc8c7 commit 6c4996e

11 files changed

+520
-115
lines changed

src/app/learnocaml_common.ml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ let get_state_as_save_file ?(include_reports = false) () =
472472
}
473473

474474
let rec sync_save session save_file on_sync =
475-
Server_caller.request (Learnocaml_api.Update_save (session, save_file))
475+
Server_caller.request (Learnocaml_api.Update_save_s (session, save_file))
476476
>>= function
477477
| Ok save ->
478478
set_state_from_save_file ~session save;
@@ -937,7 +937,7 @@ module Editor_button (E : Editor_info) = struct
937937
let rec fetch_draft_solution sess () =
938938
match sess with
939939
| session ->
940-
Server_caller.request (Learnocaml_api.Fetch_save session) >>= function
940+
Server_caller.request (Learnocaml_api.Fetch_save_s session) >>= function
941941
| Ok save ->
942942
set_state_from_save_file ~session save;
943943
Lwt.return_some (save.Save.nickname)
@@ -1174,7 +1174,7 @@ let get_session ?(has_server = true) () =
11741174
let token = Token.parse (input_tok) in
11751175
Server_caller.request (Learnocaml_api.Login token) >>= function
11761176
| Ok session ->
1177-
(Server_caller.request (Learnocaml_api.Fetch_save session)
1177+
(Server_caller.request (Learnocaml_api.Fetch_save_s session)
11781178
>>= function
11791179
| Ok save ->
11801180
set_state_from_save_file ~session save;
@@ -1263,7 +1263,7 @@ module Display_exercise =
12631263
12641264
let get_skill_index session =
12651265
let index = lazy (
1266-
retrieve (Learnocaml_api.Exercise_index (Some session))
1266+
retrieve (Learnocaml_api.Exercise_index_s (Some session))
12671267
>|= fun (index, _) ->
12681268
Exercise.Index.fold_exercises (fun (req, focus) id meta ->
12691269
let add sk id map =
@@ -1381,7 +1381,7 @@ module Display_exercise =
13811381
| [] -> None
13821382
| [author] -> Some (display_authors [%i "Author:"] [author])
13831383
| authors -> Some (display_authors [%i "Authors:"] authors) in
1384-
retrieve (Learnocaml_api.Exercise_index session)
1384+
retrieve (Learnocaml_api.Exercise_index_s session)
13851385
>|= fun (index, _) ->
13861386
let req_map, focus_map = extract_maps_exo_index index in
13871387
let focus =

src/app/learnocaml_description_main.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ let () =
6363
match get_encoded_session () with
6464
| Some { arg_name = _; raw_arg = _; session } -> begin
6565
let exercise_fetch =
66-
retrieve (Learnocaml_api.Exercise (Some session, id, true))
66+
retrieve (Learnocaml_api.Exercise_s (Some session, id, true))
6767
in
6868
init_tabs ();
6969
exercise_fetch >>= fun (ex_meta, exo, _deadline) ->

src/app/learnocaml_exercise_main.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ let () =
119119
Js.string (id ^ " - " ^ "Learn OCaml" ^" v."^ Learnocaml_api.version);
120120
let exercise_fetch =
121121
session >>= fun session ->
122-
retrieve (Learnocaml_api.Exercise (session, id, true))
122+
retrieve (Learnocaml_api.Exercise_s (session, id, true))
123123
in
124124
let after_init top =
125125
exercise_fetch >>= fun (_meta, exo, _deadline) ->

src/app/learnocaml_index_main.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ let exercises_tab session: tab_handler =
175175
let open Tyxml_js.Html5 in
176176
show_loading [%i"Loading exercises"] @@ fun () ->
177177
Lwt_js.sleep 0.5 >>= fun () ->
178-
retrieve (Learnocaml_api.Exercise_index session)
178+
retrieve (Learnocaml_api.Exercise_index_s session)
179179
>>= fun (index, deadlines) ->
180180
let exercises_to_display_signal =
181181
make_exercises_to_display_signal index
@@ -741,7 +741,7 @@ let init_token_dialog () =
741741
| Ok session ->
742742
Learnocaml_local_storage.(store sync_session) session;
743743
Learnocaml_local_storage.(store is_teacher) (Token.is_teacher token);
744-
Server_caller.request (Learnocaml_api.Fetch_save session)
744+
Server_caller.request (Learnocaml_api.Fetch_save_s session)
745745
>>= (function
746746
| Ok save ->
747747
set_state_from_save_file ~session:session save;
@@ -981,7 +981,7 @@ let () =
981981
let logout_dialog () =
982982
fetch_token () >>= fun token ->
983983
Server_caller.request
984-
(Learnocaml_api.Update_save
984+
(Learnocaml_api.Update_save_s
985985
(get_stored_session (), get_state_as_save_file ()))
986986
>|= (function
987987
| Ok _ ->

src/app/learnocaml_partition_view.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ let main () =
235235
| None -> true
236236
| Some (tok,_) ->
237237
Lwt.async (fun () ->
238-
retrieve (Learnocaml_api.Fetch_save session)
238+
retrieve (Learnocaml_api.Fetch_save_s session)
239239
>|= fun save ->
240240
match SMap.find_opt exercise_id save.Save.all_exercise_states with
241241
| None -> ()
@@ -251,15 +251,15 @@ let main () =
251251
else true in
252252

253253
let fetch_students =
254-
retrieve (Learnocaml_api.Students_list session)
254+
retrieve (Learnocaml_api.Students_list_s session)
255255
>|= fun students ->
256256
let map =
257257
List.fold_left (fun res st -> Token.Map.add st.Student.token st res)
258258
Token.Map.empty students in
259259
students_map := map in
260260

261261
let fetch_part =
262-
retrieve (Learnocaml_api.Partition (session, exercise_id, fun_id, prof))
262+
retrieve (Learnocaml_api.Partition_s (session, exercise_id, fun_id, prof))
263263
>|= fun part ->
264264
partition := Some part in
265265

src/app/learnocaml_student_view.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -349,9 +349,9 @@ let stats_tab assignments answers =
349349
]
350350

351351
let init_exercises_and_stats_tabs student_token session answers =
352-
retrieve (Learnocaml_api.Exercise_index (Some session))
352+
retrieve (Learnocaml_api.Exercise_index_s (Some session))
353353
>>= fun (index, _) ->
354-
retrieve (Learnocaml_api.Exercise_status_index session)
354+
retrieve (Learnocaml_api.Exercise_status_index_s session)
355355
>>= fun status ->
356356
let assignments = gather_assignments student_token index status in
357357
Manip.replaceChildren El.Tabs.(stats.tab) (stats_tab assignments answers);
@@ -504,7 +504,7 @@ let () =
504504
init_draft_tab ();
505505
Manip.setInnerText El.token
506506
([%i"Status of student: "] ^ Token.to_string student_token);
507-
retrieve (Learnocaml_api.Fetch_save session)
507+
retrieve (Learnocaml_api.Fetch_save_s session)
508508
>>= fun save ->
509509
Manip.setInnerText El.nickname save.Save.nickname;
510510
init_exercises_and_stats_tabs
@@ -516,7 +516,7 @@ let () =
516516
| None -> ()
517517
| Some ex_id ->
518518
Lwt.async @@ fun () ->
519-
retrieve (Learnocaml_api.Exercise (Some session, ex_id, true))
519+
retrieve (Learnocaml_api.Exercise_s (Some session, ex_id, true))
520520
>>= fun (meta, exo, _) ->
521521
clear_tabs ();
522522
let ans = SMap.find_opt ex_id save.Save.all_exercise_states in

src/app/learnocaml_teacher_tab.ml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ let rec teacher_tab session _select _params () =
101101
| "" -> None
102102
| s -> Some s
103103
in
104-
retrieve (Learnocaml_api.Create_teacher_token (session, nick))
104+
retrieve (Learnocaml_api.Create_teacher_token_s (session, nick))
105105
>|= fun new_token ->
106106
alert ~title:[%i"TEACHER TOKEN"]
107107
(Printf.sprintf [%if"New teacher token created:\n%s\n\n\
@@ -217,7 +217,7 @@ let rec teacher_tab session _select _params () =
217217
Seq.filter_map (function `Token tk -> Some tk | `Any -> None) |>
218218
List.of_seq
219219
in
220-
retrieve (Learnocaml_api.Students_csv (session, exercises, students))
220+
retrieve (Learnocaml_api.Students_csv_s (session, exercises, students))
221221
>|= fun csv ->
222222
Learnocaml_common.fake_download
223223
~name:"learnocaml.csv"
@@ -946,11 +946,11 @@ let rec teacher_tab session _select _params () =
946946
in
947947
(if changes = [] then Lwt.return () else
948948
retrieve
949-
(Learnocaml_api.Set_exercise_status (session, changes)))
949+
(Learnocaml_api.Set_exercise_status_s (session, changes)))
950950
>>= fun () ->
951951
(if students_changes = [] then Lwt.return () else
952952
retrieve
953-
(Learnocaml_api.Set_students_list (session, students_changes)))
953+
(Learnocaml_api.Set_students_list_s (session, students_changes)))
954954
>>= fun () ->
955955
(* Reload the full tab: a bit more costly, but safer & simpler *)
956956
teacher_tab session _select _params () >|=
@@ -1333,12 +1333,12 @@ let rec teacher_tab session _select _params () =
13331333
]
13341334
in
13351335
let fetch_exercises =
1336-
retrieve (Learnocaml_api.Exercise_index (Some session))
1336+
retrieve (Learnocaml_api.Exercise_index_s (Some session))
13371337
>|= fun (index, _) ->
13381338
exercises_index := index
13391339
in
13401340
let fetch_stats =
1341-
retrieve (Learnocaml_api.Exercise_status_index session)
1341+
retrieve (Learnocaml_api.Exercise_status_index_s session)
13421342
>|= fun statuses ->
13431343
let map =
13441344
List.fold_left (fun m ex -> SMap.add ex.ES.id ex m)
@@ -1347,7 +1347,7 @@ let rec teacher_tab session _select _params () =
13471347
status_map := map
13481348
in
13491349
let fetch_students =
1350-
retrieve (Learnocaml_api.Students_list session)
1350+
retrieve (Learnocaml_api.Students_list_s session)
13511351
>|= fun students ->
13521352
students_map :=
13531353
List.fold_left (fun m st -> Token.Map.add st.Student.token st m)

src/app/server_caller.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ let fetch_lesson id =
115115
request_exn (Learnocaml_api.Lesson id)
116116

117117
let fetch_exercise session id js =
118-
request_exn (Learnocaml_api.Exercise (session,id,js))
118+
request_exn (Learnocaml_api.Exercise_s (session,id,js))
119119

120120
let fetch_tutorial_index () =
121121
request_exn (Learnocaml_api.Tutorial_index ())

0 commit comments

Comments
 (0)