I have a python flask restful app that I would like to improve by checking if an appointment exists with a specific doctor at a specifique time before inserting it into the database
I added an if statement at the post method but nothing happens even if I add a new entry. Help me please what did I do wrong
def post(self):
    """creation de rendez-vous avec pat_id et doc_id"""
    appointment = request.get_json(force=True)
    pat_id = appointment['pat_id']
    doc_id = appointment['doc_id']
    appointment_date = appointment['appointment_date']
    a = conn.execute("SELECT count(*) From appointment WHERE doc_id =? AND appointment_date=?",(doc_id,appointment_date,)).fetchone()
    if a == 0:
        appointment['app_id'] = conn.execute('''INSERT INTO appointment(pat_id,doc_id,appointment_date)
            VALUES(?,?,?)''', (pat_id, doc_id,appointment_date)).lastrowid
        conn.commit()
        return appointment
the POST command is succesful yet nothing adds to the database
I am using a sqlite3 database and I'm connecting to it with this:
import sqlite3
import json
with open('config.json') as data_file:
config = json.load(data_file)
conn=sqlite3.connect(config['database'], check_same_thread=False)
conn.execute('pragma foreign_keys=ON')
def dict_factory(cursor, row):
    """rend la base de donn en json"""
    d = {}
    for idx, col in enumerate(cursor.description):
        d[col[0]] = row[idx]
    return d
conn.row_factory = dict_factory
 
    