Remove duplicated AddContactIn/add_contact/delete_all_contacts in vm_api.py
The contact create/delete endpoints and their Pydantic model were defined twice (identical blocks). Python kept the second definition, so the first was dead code. Drop the duplicate; module still compiles and each symbol is now defined exactly once.
This commit is contained in:
@ -582,53 +582,3 @@ def delete_all_contacts(vm_session: str = Cookie(default=None)):
|
|||||||
return {"ok": True}
|
return {"ok": True}
|
||||||
|
|
||||||
|
|
||||||
class AddContactIn(BaseModel):
|
|
||||||
number: str = ""
|
|
||||||
name: str
|
|
||||||
email: str | None = None
|
|
||||||
|
|
||||||
|
|
||||||
@app.post("/api/add_contact")
|
|
||||||
async def add_contact(body: AddContactIn, vm_session: str = Cookie(default=None)):
|
|
||||||
mb = _current_user(vm_session)[0]
|
|
||||||
num = (body.number or "").strip()
|
|
||||||
name = (body.name or "").strip()
|
|
||||||
email = (body.email or "").strip() or None
|
|
||||||
if not name:
|
|
||||||
raise HTTPException(400, "Name is required")
|
|
||||||
normalized = vm_contacts.normalize_uk(vm_contacts.digits_of(num)) if num else None
|
|
||||||
con = vm_store.connect()
|
|
||||||
if normalized:
|
|
||||||
row = con.execute(
|
|
||||||
"SELECT id FROM contacts WHERE number_e164 = ?", (normalized,)
|
|
||||||
).fetchone()
|
|
||||||
if row and row.get("id"):
|
|
||||||
con.execute(
|
|
||||||
"UPDATE contacts SET name=?, email=?, updated_at=NOW() WHERE id=?",
|
|
||||||
(name, email, row["id"]),
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
con.execute(
|
|
||||||
"INSERT INTO contacts (number_e164, name, email) VALUES (?, ?, ?)",
|
|
||||||
(normalized, name, email),
|
|
||||||
)
|
|
||||||
con.execute(
|
|
||||||
"UPDATE messages SET contact_name=?, contact_email=? "
|
|
||||||
"WHERE (REPLACE(REPLACE(callerid, ' ', ''), '\"', '') LIKE ? "
|
|
||||||
" OR REPLACE(REPLACE(callerid, ' ', ''), '\"', '') LIKE ?) "
|
|
||||||
"AND (contact_name IS NULL OR contact_name = '')",
|
|
||||||
(name, email, "%%%s%%" % normalized, "%%%s%%" % normalized.replace("+44", "0"),),
|
|
||||||
)
|
|
||||||
con.commit()
|
|
||||||
con.close()
|
|
||||||
return {"ok": True}
|
|
||||||
|
|
||||||
|
|
||||||
@app.post("/api/contacts/delete_all")
|
|
||||||
def delete_all_contacts(vm_session: str = Cookie(default=None)):
|
|
||||||
_current_user(vm_session)
|
|
||||||
con = vm_store.connect()
|
|
||||||
con.execute("DELETE FROM contacts")
|
|
||||||
con.commit()
|
|
||||||
con.close()
|
|
||||||
return {"ok": True}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user