コード例 #1
0
ファイル: UserComments.py プロジェクト: theoarmengou/MoviePi
 def patch(self, film_id):
     if not film_id:
         return fill_return_packet(0, "Il manque un paramètre", None)
     uuid = check_auth_token(request)
     if not uuid:
         return fill_return_packet(0, "Token invalide", None)
     packet = request.json
     if not packet["comment"] or packet["id_comment"]:
         return fill_return_packet(0, "Ce commentaire n'est pas bon", None)
     uuid_binary = userH.getUUIDBinaryFromStr(uuid)
     userInfos = userH.getUserInformations(user_uuid=uuid_binary)
     if not userInfos:
         return fill_return_packet(0, "Cet utilisateur n'existe pas", None)
     original_comment = db.request(
         "SELECT * FROM comments WHERE id = %s AND fk_users = %s AND fk_films = %s",
         packet["id_comment"], userInfos["id"], film_id)
     if not original_comment:
         return fill_return_packet(0, "Ce commentaire n'existe pas", None)
     db.request("UPDATE comments SET comment = %s WHERE id = %s",
                packet["comment"], packet["id_comment"])
     result = db.request("SELECT * FROM comments WHERE fk_films = %s",
                         film_id)
     for comment in result:
         userInfos = db.request("SELECT username FROM users WHERE id = %s",
                                comment["fk_users"])
         if not userInfos:
             pass
         else:
             comment["username"] = userInfos['username']
     return fill_return_packet(1, "OK", result)
コード例 #2
0
ファイル: UserComments.py プロジェクト: theoarmengou/MoviePi
 def post(self, film_id):
     if not film_id:
         return fill_return_packet(0, "Il manque un paramètre", None)
     uuid = check_auth_token(request)
     if not uuid:
         return fill_return_packet(0, "Token invalide", None)
     packet = request.json
     if not packet["comment"]:
         return fill_return_packet(0, "Ce commentaire n'est pas bon", None)
     uuid_binary = userH.getUUIDBinaryFromStr(uuid)
     userInfos = userH.getUserInformations(user_uuid=uuid_binary)
     if not userInfos:
         return fill_return_packet(0, "Cet utilisateur n'existe pas", None)
     result = db.insert(
         "INSERT INTO comments (fk_users, fk_films, comment) VALUES (%s, %s, %s)",
         userInfos["id"], film_id, packet["comment"])
     if not result:
         return fill_return_packet(0, "Une erreur est survenue", None)
     result = db.request("SELECT * FROM comments WHERE fk_films = %s",
                         film_id)
     for comment in result:
         userInfos = db.request("SELECT username FROM users WHERE id = %s",
                                comment["fk_users"])
         if not userInfos:
             pass
         else:
             comment["username"] = userInfos[0]['username']
     return fill_return_packet(1, "OK", result)
コード例 #3
0
ファイル: UserNote.py プロジェクト: theoarmengou/MoviePi
 def patch(self, film_id, note):
     if not film_id or not note:
         return fill_return_packet(
             0, "Un des parametres est manquant ou invalide", None)
     user_uuid = check_auth_token(request)
     if not user_uuid:
         return fill_return_packet(0, "Invalid Token", None)
     uuid_binary = userH.getUUIDBinaryFromStr(user_uuid)
     user = userH.getUserInformations(user_uuid=uuid_binary)
     if not user:
         return fill_return_packet(0, "Compte inexistant", None)
     checker = db.request(
         "SELECT * FROM users_ratings WHERE fk_users=%s AND fk_films=%s",
         user['id'], film_id)
     if checker:
         db.request("UPDATE users_ratings SET rating=%s WHERE id=%s", note,
                    checker[0]["id"])
     else:
         db.insert(
             "INSERT INTO users_ratings (fk_users, fk_films, rating) VALUES (%s, %s, %s)",
             user['id'], film_id, note)
     if not checker:
         return fill_return_packet(0,
                                   "L'ajout des données a la DB a échoué",
                                   None)
     if (adjust_weight_user(film_id, note, int(user['id'])) == False):
         return fill_return_packet(0, "L'ajustement des poids a échoué",
                                   None)
     return fill_return_packet(1, "OK", None)
コード例 #4
0
ファイル: UserComments.py プロジェクト: theoarmengou/MoviePi
 def get(self, film_id):
     if not film_id:
         return fill_return_packet(0, "Il manque un paramètre", None)
     result = db.request("SELECT * FROM comments WHERE fk_films = %s",
                         film_id)
     if not result:
         return fill_return_packet(0, "Aucun commentaire sur ce film", None)
     for comment in result:
         userInfos = db.request("SELECT username FROM users WHERE id = %s",
                                comment["fk_users"])
         if not userInfos:
             pass
         else:
             comment["username"] = userInfos[0]['username']
     return fill_return_packet(1, "OK", result)
コード例 #5
0
ファイル: Films.py プロジェクト: theoarmengou/MoviePi
 def get(self, film_id):
     if not film_id:
         return fill_return_packet(0, "Un ID de film est nécessaire", None)
     uuid = check_auth_token(request)
     if not uuid:
         return fill_return_packet(0, "Token Invalide", None)
     uuid_binary = userH.getUUIDBinaryFromStr(uuid)
     user = userH.getUserInformations(user_uuid=uuid_binary)
     if not user:
         return fill_return_packet(0, "Ce compte n'existe pas", None)
     result = db.request("SELECT * from films where id=%s", film_id)
     if not result:
         return fill_return_packet(0, "Pas de film trouvé a l'id demandé",
                                   None)
     if result[0]["adult"] and user["age"] < 18:
         return fill_return_packet(0, "Film adulte", None)
     return fill_return_packet(1, "OK", result)
コード例 #6
0
ファイル: UserNote.py プロジェクト: theoarmengou/MoviePi
 def get(self, film_id, note=None):
     if not film_id:
         return fill_return_packet(
             0, "Un des parametres est manquant ou invalide", None)
     user_uuid = check_auth_token(request)
     if not user_uuid:
         return fill_return_packet(0, "Invalid Token", None)
     uuid_binary = userH.getUUIDBinaryFromStr(user_uuid)
     user = userH.getUserInformations(user_uuid=uuid_binary)
     if not user:
         return fill_return_packet(0, "Compte inexistant", None)
     result = db.request(
         "SELECT * FROM users_ratings WHERE fk_users=%s AND fk_films=%s",
         user['id'], film_id)
     if not result:
         return fill_return_packet(
             0, "L'utilisateur n'a aucune note sur le film", None)
     return fill_return_packet(1, "OK", result)