1
1
import fastapi
2
2
import db_models
3
3
import api_models
4
- import uuid
5
4
import typing
6
5
import base64
7
6
import pymongo
7
+ from bson import ObjectId
8
8
import pydantic
9
9
10
10
@@ -97,15 +97,14 @@ def route_submit(params: RunSubmitSimpleParams, db: pymongo.database.Database =
97
97
fields of request body; `id` will be real id of this run.
98
98
"""
99
99
100
- run_uuid = uuid .uuid4 ()
101
- user_id = uuid .UUID ('12345678123456781234567812345678' )
102
- doc_main = db_models .RunMainProj (id = run_uuid , toolchain_name = params .toolchain ,
100
+ user_id = ObjectId ('507f1f77bcf86cd799439011' )
101
+ doc_main = db_models .RunMainProj (toolchain_name = params .toolchain ,
103
102
problem_name = params .problem , user_id = user_id , contest_name = params .contest , phase = str (db_models .RunPhase .QUEUED ))
104
103
doc_source = db_models .RunSourceProj (
105
104
source = base64 .b64decode (params .code ))
106
105
doc = {** dict (doc_main ), ** dict (doc_source )}
107
- db .runs .insert_one (doc )
108
- return api_models .Run (id = run_uuid , toolchain_name = params .toolchain , problem_name = params .problem , user_id = user_id , contest_name = params .contest )
106
+ result = db .runs .insert_one (doc )
107
+ return api_models .Run (id = str ( result . inserted_id ) , toolchain_name = params .toolchain , problem_name = params .problem , user_id = str ( user_id ) , contest_name = params .contest )
109
108
110
109
@app .get ('/runs' , response_model = typing .List [api_models .Run ],
111
110
operation_id = 'listRuns' )
@@ -122,13 +121,13 @@ def route_list_runs(db: pymongo.database.Database = fastapi.Depends(db_connect))
122
121
return runs
123
122
124
123
@app .get ('/runs/{run_id}' , response_model = api_models .Run , operation_id = 'getRun' )
125
- def route_get_run (run_id : uuid . UUID , db : pymongo .database .Database = fastapi .Depends (db_connect )):
124
+ def route_get_run (run_id : str , db : pymongo .database .Database = fastapi .Depends (db_connect )):
126
125
"""
127
126
Loads run by id
128
127
"""
129
128
130
129
run = db .runs .find_one (projection = db_models .RunMainProj .FIELDS , filter = {
131
- 'id ' : run_id
130
+ '_id ' : run_id
132
131
})
133
132
if run is None :
134
133
raise fastapi .HTTPException (404 , detail = 'RunNotFound' )
@@ -139,13 +138,13 @@ def route_get_run(run_id: uuid.UUID, db: pymongo.database.Database = fastapi.Dep
139
138
'description' : "Run source is not available"
140
139
}
141
140
})
142
- def route_get_run_source (run_id : uuid . UUID , db : pymongo .database .Database = fastapi .Depends (db_connect )):
141
+ def route_get_run_source (run_id : db_models . Id , db : pymongo .database .Database = fastapi .Depends (db_connect )):
143
142
"""
144
143
Returns run source as base64-encoded JSON string
145
144
"""
146
145
147
146
doc = db .runs .find_one (projection = ['source' ], filter = {
148
- 'id ' : run_id
147
+ '_id ' : run_id
149
148
})
150
149
if doc is None :
151
150
raise fastapi .HTTPException (404 , detail = 'RunNotFound' )
@@ -154,7 +153,7 @@ def route_get_run_source(run_id: uuid.UUID, db: pymongo.database.Database = fast
154
153
return base64 .b64encode (doc ['source' ])
155
154
156
155
@app .patch ('/runs/{run_id}' , response_model = api_models .Run , operation_id = 'patchRun' )
157
- def route_run_patch (run_id : uuid . UUID , patch : RunPatch , db : pymongo .database .Database = fastapi .Depends (db_connect )):
156
+ def route_run_patch (run_id : db_models . Id , patch : RunPatch , db : pymongo .database .Database = fastapi .Depends (db_connect )):
158
157
"""
159
158
Modifies existing run
160
159
0 commit comments