-
Notifications
You must be signed in to change notification settings - Fork 0
/
crud.py
30 lines (24 loc) · 1.09 KB
/
crud.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from sqlalchemy.orm import Session
from datetime import datetime, timedelta
import models
def write_access_data(access_id: str, user_id: str, channel_id: str, db: Session):
query_result = db.query(models.Access_Table).filter(models.Access_Table.access_id == access_id).first()
if query_result is None:
# Homework: write access data to database fill all column
access_time = datetime.now()
korea_time_difference = timedelta(hours=9)
access_time = access_time + korea_time_difference
# Create a new Access_Table object and fill its attributes
access_data = models.Access_Table(
access_id=access_id,
user_id=user_id,
channel_id = channel_id,
access_time=access_time
)
# Add the new_access object to the session and commit the changes
db.add(access_data)
db.commit()
message = f"Access Data.. user id : {user_id}, access time : {access_time}"
return {"message": message, 'result': True}
else:
return {"message": "already access id", 'result': False}