Ajit Panday commited on
Commit
7714b76
·
1 Parent(s): 30d5632

Fix timestamp handling in customer endpoints

Browse files
Files changed (2) hide show
  1. app/auth.py +9 -4
  2. app/schemas.py +5 -5
app/auth.py CHANGED
@@ -117,11 +117,14 @@ async def create_customer(
117
  )
118
 
119
  # Create new customer
 
120
  customer = CustomerModel(
121
  name=customer_data["name"],
122
  company_name=customer_data["company_name"],
123
  email=customer_data["email"],
124
- api_key=str(secrets.token_urlsafe(32))
 
 
125
  )
126
 
127
  db.add(customer)
@@ -134,7 +137,9 @@ async def create_customer(
134
  "company_name": customer.company_name,
135
  "email": customer.email,
136
  "api_key": customer.api_key,
137
- "is_active": customer.is_active
 
 
138
  }
139
  except HTTPException as he:
140
  raise he
@@ -161,8 +166,8 @@ async def list_customers(
161
  email=customer.email,
162
  api_key=customer.api_key,
163
  is_active=customer.is_active,
164
- created_at=customer.created_at,
165
- updated_at=customer.updated_at
166
  ) for customer in customers
167
  ]
168
  except Exception as e:
 
117
  )
118
 
119
  # Create new customer
120
+ now = datetime.utcnow()
121
  customer = CustomerModel(
122
  name=customer_data["name"],
123
  company_name=customer_data["company_name"],
124
  email=customer_data["email"],
125
+ api_key=str(secrets.token_urlsafe(32)),
126
+ created_at=now,
127
+ updated_at=now
128
  )
129
 
130
  db.add(customer)
 
137
  "company_name": customer.company_name,
138
  "email": customer.email,
139
  "api_key": customer.api_key,
140
+ "is_active": customer.is_active,
141
+ "created_at": customer.created_at,
142
+ "updated_at": customer.updated_at
143
  }
144
  except HTTPException as he:
145
  raise he
 
166
  email=customer.email,
167
  api_key=customer.api_key,
168
  is_active=customer.is_active,
169
+ created_at=customer.created_at or datetime.utcnow(),
170
+ updated_at=customer.updated_at or datetime.utcnow()
171
  ) for customer in customers
172
  ]
173
  except Exception as e:
app/schemas.py CHANGED
@@ -1,4 +1,4 @@
1
- from pydantic import BaseModel
2
  from typing import Optional
3
  from datetime import datetime
4
 
@@ -14,8 +14,8 @@ class Customer(CustomerBase):
14
  id: int
15
  api_key: str
16
  is_active: bool
17
- created_at: datetime
18
- updated_at: datetime
19
 
20
  class Config:
21
  from_attributes = True
@@ -34,8 +34,8 @@ class CallRecordCreate(CallRecordBase):
34
  class CallRecord(CallRecordBase):
35
  id: str
36
  customer_id: int
37
- created_at: datetime
38
- updated_at: datetime
39
 
40
  class Config:
41
  from_attributes = True
 
1
+ from pydantic import BaseModel, Field
2
  from typing import Optional
3
  from datetime import datetime
4
 
 
14
  id: int
15
  api_key: str
16
  is_active: bool
17
+ created_at: Optional[datetime] = Field(default_factory=datetime.utcnow)
18
+ updated_at: Optional[datetime] = Field(default_factory=datetime.utcnow)
19
 
20
  class Config:
21
  from_attributes = True
 
34
  class CallRecord(CallRecordBase):
35
  id: str
36
  customer_id: int
37
+ created_at: Optional[datetime] = Field(default_factory=datetime.utcnow)
38
+ updated_at: Optional[datetime] = Field(default_factory=datetime.utcnow)
39
 
40
  class Config:
41
  from_attributes = True