Board
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

progrss

+32 -17
+32 -17
app.py
··· 286 286 mycursor.execute(f"SELECT parentid FROM board WHERE id={myresult[0]}") 287 287 288 288 postparentid = mycursor.fetchone(); 289 + 290 + mycursor.execute(f"SELECT COUNT(*) FROM ratings WHERE postid=\"{postid_}\" AND rating=1;") 291 + 292 + positiveratings = mycursor.fetchone(); 293 + 294 + mycursor.execute(f"SELECT COUNT(*) FROM ratings WHERE postid=\"{postid_}\" AND rating=0;") 295 + 296 + negativeratings = mycursor.fetchone(); 297 + 298 + print(f"{positiveratings} {negativeratings}") 289 299 290 300 mycursor.execute(f"SELECT username FROM users WHERE id=\"{myresult[1]}\"") 291 301 myresult = { ··· 296 306 "message": myresult[3], 297 307 "timestamp": myresult[4], 298 308 "replycount": replycount[0], 299 - "parentid": postparentid[0] 309 + "parentid": postparentid[0], 310 + "positiveratings": positiveratings, 311 + "negativeratings": negativeratings 300 312 } 301 313 302 314 return Response(json.dumps(myresult), status=200, mimetype="application/json") ··· 347 359 348 360 if user == None: 349 361 return Response(json.dumps("Invalid sessionid provided 2"), status=400, mimetype="application/json") 362 + 363 + mycursor.execute(f"SELECT * FROM ratings WHERE postid=\"{postid_}\" AND userid=\"{user[0]}\"") 364 + 365 + rating = mycursor.fetchone() 350 366 351 - print(user) 367 + mycursor.execute(f"SELECT * FROM board WHERE postid=\"{postid_}\"") 352 368 353 - # curtime = int( time.time() ) 354 - # sql = "" 355 - # if(parentid_ == None): 356 - # if(senderid_ != None): 357 - # sql = f"INSERT INTO board (userid, senderip, message, timestamp) VALUES (\"{senderid_}\", \"{ip_}\", \"{message_}\", \"{curtime}\")" 358 - # else: 359 - # sql = f"INSERT INTO board (senderip, message, timestamp) VALUES (\"{ip_}\", \"{message_}\", \"{curtime}\")" 360 - # else: 361 - # if(senderid_ != None): 362 - # sql = f"INSERT INTO board (userid, senderip, message, timestamp, parentid) VALUES (\"{senderid_}\", \"{ip_}\", \"{message_}\", \"{curtime}\", \"{parentid_}\")" 363 - # else: 364 - # sql = f"INSERT INTO board (senderip, message, timestamp, parentid) VALUES (\"{ip_}\", \"{message_}\", \"{curtime}\", \"{parentid_}\")" 365 - # mycursor.execute(sql) 369 + post = mycursor.fetchone() 370 + 371 + if post == None: 372 + return Response(json.dumps("Post was not found"), status=500, mimetype="application/json") 373 + 374 + sql = "" 375 + curtime = int( time.time() ) 376 + if rating != None: 377 + sql = f"UPDATE ratings SET rating=\"{0 if rating_ == False else 1}\" WHERE postid=\"{postid_}\" AND userid=\"{user[0]}\"" 378 + else: 379 + sql = f"INSERT INTO ratings (postid, userid, senderid, rating, timestamp) VALUES (\"{postid_}\", \"{user[0]}\", \"{post[1]}\", \"{0 if rating_ == False else 1}\", \"{curtime}\")" 366 380 367 - # mydb.commit() 381 + mycursor.execute(sql) 382 + mydb.commit() 368 383 369 - return Response("Created", status=201) 384 + return Response("Rated post", status=200) 370 385 371 386 372 387 @app.route("/api/v1/user/create", methods=["POST"])