11import fastapi
22import db_models
33import api_models
4- import uuid
54import typing
65import base64
76import pymongo
7+ from bson import ObjectId
88import pydantic
99
1010
@@ -97,15 +97,14 @@ def route_submit(params: RunSubmitSimpleParams, db: pymongo.database.Database =
9797 fields of request body; `id` will be real id of this run.
9898 """
9999
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 ,
103102 problem_name = params .problem , user_id = user_id , contest_name = params .contest , phase = str (db_models .RunPhase .QUEUED ))
104103 doc_source = db_models .RunSourceProj (
105104 source = base64 .b64decode (params .code ))
106105 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 )
109108
110109 @app .get ('/runs' , response_model = typing .List [api_models .Run ],
111110 operation_id = 'listRuns' )
@@ -122,13 +121,13 @@ def route_list_runs(db: pymongo.database.Database = fastapi.Depends(db_connect))
122121 return runs
123122
124123 @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 )):
126125 """
127126 Loads run by id
128127 """
129128
130129 run = db .runs .find_one (projection = db_models .RunMainProj .FIELDS , filter = {
131- 'id ' : run_id
130+ '_id ' : run_id
132131 })
133132 if run is None :
134133 raise fastapi .HTTPException (404 , detail = 'RunNotFound' )
@@ -139,13 +138,13 @@ def route_get_run(run_id: uuid.UUID, db: pymongo.database.Database = fastapi.Dep
139138 'description' : "Run source is not available"
140139 }
141140 })
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 )):
143142 """
144143 Returns run source as base64-encoded JSON string
145144 """
146145
147146 doc = db .runs .find_one (projection = ['source' ], filter = {
148- 'id ' : run_id
147+ '_id ' : run_id
149148 })
150149 if doc is None :
151150 raise fastapi .HTTPException (404 , detail = 'RunNotFound' )
@@ -154,7 +153,7 @@ def route_get_run_source(run_id: uuid.UUID, db: pymongo.database.Database = fast
154153 return base64 .b64encode (doc ['source' ])
155154
156155 @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 )):
158157 """
159158 Modifies existing run
160159
0 commit comments