From 23d9f570e02e4a6986c018269c5bc4aca80db18e Mon Sep 17 00:00:00 2001
From: sanj <67624670+iodrift@users.noreply.github.com>
Date: Mon, 28 Oct 2024 12:34:34 -0700
Subject: [PATCH] Auto-update: Mon Oct 28 12:34:34 PDT 2024

---
 sijapi/routers/timing.py | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/sijapi/routers/timing.py b/sijapi/routers/timing.py
index e635f03..043fce2 100644
--- a/sijapi/routers/timing.py
+++ b/sijapi/routers/timing.py
@@ -55,8 +55,34 @@ class TimingRequest(BaseModel):
 ####################
 #### TIMING API ####
 ####################
+
 @timing.post("/time/post")
 async def post_time_entry_to_timing(entry: Dict):
+    """Post a single time entry to Timing API."""
+    url = 'https://web.timingapp.com/api/v1/time-entries'
+    headers = {
+        'Authorization': f'Bearer {TIMING_API_KEY}',
+        'Content-Type': 'application/json',
+        'Accept': 'application/json',
+        'X-Time-Zone': 'America/Los_Angeles'
+    }
+    l.debug(f"Posting entry: {entry}")
+    
+    try:
+        async with httpx.AsyncClient() as client:
+            response = await client.post(url, headers=headers, json=entry)
+            response.raise_for_status()  # Raises exception for 4xx/5xx responses
+            return response.json()
+    except httpx.HTTPStatusError as exc:
+        l.debug(f"HTTPStatusError caught: Status code: {exc.response.status_code}, Detail: {exc.response.text}")
+        raise HTTPException(status_code=exc.response.status_code, detail=str(exc.response.text))
+    except Exception as exc:
+        l.debug(f"General exception caught: {exc}")
+        raise HTTPException(status_code=500, detail="An unexpected error occurred")
+
+
+@timing.post("/time/post_old")
+async def old_post_time_entry_to_timing(entry: Dict):
     url = 'https://web.timingapp.com/api/v1/time-entries'
     headers = {
         'Authorization': f'Bearer {TIMING_API_KEY}',