Skip to content

Commit 7531753

Browse files
committed
response statuses change
1 parent a4ef44a commit 7531753

7 files changed

Lines changed: 118 additions & 112 deletions

File tree

surftimer/ck_bonus.py

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,17 @@ def insertBonus(
6363
# time.sleep(3)
6464

6565
if xquery < 1:
66-
return JSONResponse(
67-
status_code=status.HTTP_400_BAD_REQUEST,
68-
content={"inserted": xquery, "xtime": time.perf_counter() - tic},
69-
)
66+
response.body = {"inserted": xquery, "xtime": time.perf_counter() - tic}
67+
response.status_code = status.HTTP_304_NOT_MODIFIED
68+
return response
7069

7170
# Prepare the response
7271
toc = time.perf_counter()
7372
print(f"Execution time {toc - tic:0.4f}")
7473

75-
return {"inserted": xquery, "xtime": time.perf_counter() - tic}
76-
74+
response.body = {"inserted": xquery, "xtime": time.perf_counter() - tic}
75+
response.status_code = status.HTTP_201_CREATED
76+
return response
7777

7878
@router.put(
7979
"/surftimer/updateBonus",
@@ -101,17 +101,17 @@ def updateBonus(
101101
xquery = insertQuery(sql)
102102

103103
if xquery < 1:
104-
return JSONResponse(
105-
status_code=status.HTTP_400_BAD_REQUEST,
106-
content={"inserted": xquery, "xtime": time.perf_counter() - tic},
107-
)
104+
response.body = {"updated": xquery, "xtime": time.perf_counter() - tic}
105+
response.status_code = status.HTTP_304_NOT_MODIFIED
106+
return response
108107

109108
# Prepare the response
110109
toc = time.perf_counter()
111110
print(f"Execution time {toc - tic:0.4f}")
112111

113-
return {"inserted": xquery, "xtime": time.perf_counter() - tic}
114-
112+
response.body = {"updated": xquery, "xtime": time.perf_counter() - tic}
113+
response.status_code = status.HTTP_200_OK
114+
return response
115115

116116
@router.get(
117117
"/surftimer/selectBonusCount",
@@ -384,13 +384,14 @@ def deleteBonus(
384384

385385
xquery = insertQuery(surftimer.queries.sql_deleteBonus.format(mapname))
386386

387-
if xquery <= 0:
388-
return JSONResponse(
389-
status_code=status.HTTP_404_NOT_FOUND,
390-
content={"xtime": time.perf_counter() - tic},
391-
)
387+
if xquery < 1:
388+
response.body = {"deleted": xquery, "xtime": time.perf_counter() - tic}
389+
response.status_code = status.HTTP_304_NOT_MODIFIED
390+
return response
392391

393392
toc = time.perf_counter()
394393
print(f"Execution time {toc - tic:0.4f}")
395394

396-
return {"deleted": xquery, "xtime": time.perf_counter() - tic}
395+
response.body = {"deleted": xquery, "xtime": time.perf_counter() - tic}
396+
response.status_code = status.HTTP_200_OK
397+
return response

surftimer/ck_checkpoints.py

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,17 @@ async def insertOrUpdateCheckpoints(
4949
xquery = insertQuery(sql)
5050

5151
if xquery < 1:
52-
return JSONResponse(
53-
status_code=status.HTTP_204_NO_CONTENT,
54-
content={"inserted": xquery, "xtime": time.perf_counter() - tic},
55-
)
52+
response.body = {"inserted": xquery, "xtime": time.perf_counter() - tic}
53+
response.status_code = status.HTTP_304_NOT_MODIFIED
54+
return response
5655

5756
# Prepare the response
5857
toc = time.perf_counter()
5958
print(f"Execution time {toc - tic:0.4f}")
60-
61-
return {"inserted": xquery, "xtime": time.perf_counter() - tic}
59+
60+
response.body = {"inserted": xquery, "xtime": time.perf_counter() - tic}
61+
response.status_code = status.HTTP_201_CREATED
62+
return response
6263

6364

6465
@router.get(
@@ -205,17 +206,17 @@ async def deleteCheckpoints(
205206

206207
xquery = insertQuery(surftimer.queries.sql_deleteCheckpoints.format(mapname))
207208

208-
if xquery <= 0:
209-
return JSONResponse(
210-
status_code=status.HTTP_404_NOT_FOUND,
211-
content={"xtime": time.perf_counter() - tic},
212-
)
209+
if xquery < 1:
210+
response.body = {"deleted": xquery, "xtime": time.perf_counter() - tic}
211+
response.status_code = status.HTTP_304_NOT_MODIFIED
212+
return response
213213

214214
toc = time.perf_counter()
215215
print(f"Execution time {toc - tic:0.4f}")
216216

217-
return {"deleted": xquery, "xtime": time.perf_counter() - tic}
218-
217+
response.body = {"deleted": xquery, "xtime": time.perf_counter() - tic}
218+
response.status_code = status.HTTP_200_OK
219+
return response
219220

220221
@router.get(
221222
"/surftimer/selectStageTimes",

surftimer/ck_latestrecords.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,14 @@ async def insertLatestRecord(
7878
# time.sleep(3)
7979

8080
if xquery < 1:
81-
JSONResponse(
82-
status_code=status.HTTP_204_NO_CONTENT,
83-
content={"inserted": xquery, "xtime": time.perf_counter() - tic},
84-
)
81+
response.body = {"inserted": xquery, "xtime": time.perf_counter() - tic}
82+
response.status_code = status.HTTP_304_NOT_MODIFIED
83+
return response
8584

8685
# Prepare the response
8786
toc = time.perf_counter()
8887
print(f"Execution time {toc - tic:0.4f}")
8988

90-
return {"inserted": xquery, "xtime": time.perf_counter() - tic}
89+
response.body = {"inserted": xquery, "xtime": time.perf_counter() - tic}
90+
response.status_code = status.HTTP_201_CREATED
91+
return response

surftimer/ck_maptier.py

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,17 @@ async def insertMapTier(
7575
xquery = insertQuery(surftimer.queries.sql_insertmaptier.format(data.mapname, data.tier))
7676

7777
if xquery < 1:
78-
return JSONResponse(
79-
status_code=status.HTTP_204_NO_CONTENT,
80-
content={"inserted": xquery, "xtime": time.perf_counter() - tic},
81-
)
78+
response.body = {"inserted": xquery, "xtime": time.perf_counter() - tic}
79+
response.status_code = status.HTTP_304_NOT_MODIFIED
80+
return response
8281

8382
# Prepare the response
8483
toc = time.perf_counter()
8584
print(f"Execution time {toc - tic:0.4f}")
86-
87-
return {"inserted": xquery, "xtime": time.perf_counter() - tic}
85+
86+
response.body = {"inserted": xquery, "xtime": time.perf_counter() - tic}
87+
response.status_code = status.HTTP_201_CREATED
88+
return response
8889

8990

9091
@router.put(
@@ -105,17 +106,17 @@ async def updateMapTier(
105106
xquery = insertQuery(surftimer.queries.sql_updatemaptier.format(data.tier, data.mapname))
106107

107108
if xquery < 1:
108-
return JSONResponse(
109-
status_code=status.HTTP_204_NO_CONTENT,
110-
content={"updated": xquery, "xtime": time.perf_counter() - tic},
111-
)
109+
response.body = {"updated": xquery, "xtime": time.perf_counter() - tic}
110+
response.status_code = status.HTTP_304_NOT_MODIFIED
111+
return response
112112

113113
# Prepare the response
114114
toc = time.perf_counter()
115115
print(f"Execution time {toc - tic:0.4f}")
116116

117-
return {"updated": xquery, "xtime": time.perf_counter() - tic}
118-
117+
response.body = {"updated": xquery, "xtime": time.perf_counter() - tic}
118+
response.status_code = status.HTTP_200_OK
119+
return response
119120

120121
@router.put(
121122
"/surftimer/updateMapperName",
@@ -135,13 +136,14 @@ async def updateMapperName(
135136
xquery = insertQuery(surftimer.queries.sql_updateMapperName.format(data.mappername, data.mapname))
136137

137138
if xquery < 1:
138-
return JSONResponse(
139-
status_code=status.HTTP_204_NO_CONTENT,
140-
content={"updated": xquery, "xtime": time.perf_counter() - tic},
141-
)
139+
response.body = {"updated": xquery, "xtime": time.perf_counter() - tic}
140+
response.status_code = status.HTTP_304_NOT_MODIFIED
141+
return response
142142

143143
# Prepare the response
144144
toc = time.perf_counter()
145145
print(f"Execution time {toc - tic:0.4f}")
146146

147-
return {"updated": xquery, "xtime": time.perf_counter() - tic}
147+
response.body = {"updated": xquery, "xtime": time.perf_counter() - tic}
148+
response.status_code = status.HTTP_200_OK
149+
return response

surftimer/ck_playeroptions2.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,17 @@ async def insertPlayerOptions(request: Request, response: Response, steamid32: s
6464
xquery = insertQuery(surftimer.queries.sql_insertPlayerOptions.format(steamid32))
6565

6666
if xquery < 1:
67-
return JSONResponse(
68-
status_code=status.HTTP_204_NO_CONTENT,
69-
content={"inserted": xquery, "xtime": time.perf_counter() - tic},
70-
)
67+
response.body = {"inserted": xquery, "xtime": time.perf_counter() - tic}
68+
response.status_code = status.HTTP_304_NOT_MODIFIED
69+
return response
7170

7271
# Prepare the response
7372
toc = time.perf_counter()
7473
print(f"Execution time {toc - tic:0.4f}")
7574

76-
return {"inserted": xquery, "xtime": time.perf_counter() - tic}
77-
75+
response.body = {"inserted": xquery, "xtime": time.perf_counter() - tic}
76+
response.status_code = status.HTTP_201_CREATED
77+
return response
7878

7979
@router.get(
8080
"/surftimer/selectPlayerOptions",
@@ -165,13 +165,14 @@ async def updatePlayerOptions(
165165
)
166166

167167
if xquery < 1:
168-
return JSONResponse(
169-
status_code=status.HTTP_204_NO_CONTENT,
170-
content={"updated": xquery, "xtime": time.perf_counter() - tic},
171-
)
168+
response.body = {"updated": xquery, "xtime": time.perf_counter() - tic}
169+
response.status_code = status.HTTP_304_NOT_MODIFIED
170+
return response
172171

173172
# Prepare the response
174173
toc = time.perf_counter()
175174
print(f"Execution time {toc - tic:0.4f}")
176175

177-
return {"updated": xquery, "xtime": time.perf_counter() - tic}
176+
response.body = {"updated": xquery, "xtime": time.perf_counter() - tic}
177+
response.status_code = status.HTTP_200_OK
178+
return response

surftimer/ck_playerrank.py

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -68,17 +68,17 @@ async def insertPlayerRank(
6868
xquery = insertQuery(sql)
6969

7070
if xquery < 1:
71-
return JSONResponse(
72-
status_code=status.HTTP_204_NO_CONTENT,
73-
content={"inserted": xquery, "xtime": time.perf_counter() - tic},
74-
)
71+
response.body = {"inserted": xquery, "xtime": time.perf_counter() - tic}
72+
response.status_code = status.HTTP_304_NOT_MODIFIED
73+
return response
7574

7675
# Prepare the response
7776
toc = time.perf_counter()
7877
print(f"Execution time {toc - tic:0.4f}")
7978

80-
return {"inserted": xquery, "xtime": time.perf_counter() - tic}
81-
79+
response.body = {"inserted": xquery, "xtime": time.perf_counter() - tic}
80+
response.status_code = status.HTTP_201_CREATED
81+
return response
8282

8383
@router.put(
8484
"surftimer/updatePlayerRankPoints",
@@ -116,17 +116,17 @@ async def updatePlayerRankPoints(
116116
xquery = insertQuery(sql)
117117

118118
if xquery < 1:
119-
return JSONResponse(
120-
status_code=status.HTTP_204_NO_CONTENT,
121-
content={"updated": xquery, "xtime": time.perf_counter() - tic},
122-
)
119+
response.body = {"updated": xquery, "xtime": time.perf_counter() - tic}
120+
response.status_code = status.HTTP_304_NOT_MODIFIED
121+
return response
123122

124123
# Prepare the response
125124
toc = time.perf_counter()
126125
print(f"Execution time {toc - tic:0.4f}")
127126

128-
return {"updated": xquery, "xtime": time.perf_counter() - tic}
129-
127+
response.body = {"updated": xquery, "xtime": time.perf_counter() - tic}
128+
response.status_code = status.HTTP_200_OK
129+
return response
130130

131131
@router.put(
132132
"surftimer/updatePlayerRankPoints2",
@@ -167,17 +167,17 @@ async def updatePlayerRankPoints2(
167167
xquery = insertQuery(sql)
168168

169169
if xquery < 1:
170-
return JSONResponse(
171-
status_code=status.HTTP_204_NO_CONTENT,
172-
content={"updated": xquery, "xtime": time.perf_counter() - tic},
173-
)
170+
response.body = {"updated": xquery, "xtime": time.perf_counter() - tic}
171+
response.status_code = status.HTTP_304_NOT_MODIFIED
172+
return response
174173

175174
# Prepare the response
176175
toc = time.perf_counter()
177176
print(f"Execution time {toc - tic:0.4f}")
178177

179-
return {"updated": xquery, "xtime": time.perf_counter() - tic}
180-
178+
response.body = {"updated": xquery, "xtime": time.perf_counter() - tic}
179+
response.status_code = status.HTTP_200_OK
180+
return response
181181

182182
@router.put(
183183
"surftimer/updatePlayerRank",
@@ -203,17 +203,17 @@ async def updatePlayerRank(
203203
xquery = insertQuery(sql)
204204

205205
if xquery < 1:
206-
return JSONResponse(
207-
status_code=status.HTTP_204_NO_CONTENT,
208-
content={"updated": xquery, "xtime": time.perf_counter() - tic},
209-
)
206+
response.body = {"updated": xquery, "xtime": time.perf_counter() - tic}
207+
response.status_code = status.HTTP_304_NOT_MODIFIED
208+
return response
210209

211210
# Prepare the response
212211
toc = time.perf_counter()
213212
print(f"Execution time {toc - tic:0.4f}")
214213

215-
return {"updated": xquery, "xtime": time.perf_counter() - tic}
216-
214+
response.body = {"updated": xquery, "xtime": time.perf_counter() - tic}
215+
response.status_code = status.HTTP_200_OK
216+
return response
217217

218218
@router.get(
219219
"/surftimer/selectPlayerName",
@@ -272,17 +272,17 @@ async def updateLastSeen(
272272
xquery = insertQuery(sql)
273273

274274
if xquery < 1:
275-
return JSONResponse(
276-
status_code=status.HTTP_204_NO_CONTENT,
277-
content={"updated": xquery, "xtime": time.perf_counter() - tic},
278-
)
275+
response.body = {"updated": xquery, "xtime": time.perf_counter() - tic}
276+
response.status_code = status.HTTP_304_NOT_MODIFIED
277+
return response
279278

280279
# Prepare the response
281280
toc = time.perf_counter()
282281
print(f"Execution time {toc - tic:0.4f}")
283282

284-
return {"updated": xquery, "xtime": time.perf_counter() - tic}
285-
283+
response.body = {"updated": xquery, "xtime": time.perf_counter() - tic}
284+
response.status_code = status.HTTP_200_OK
285+
return response
286286

287287
@router.get(
288288
"/surftimer/selectTopPlayers",

0 commit comments

Comments
 (0)