-
Notifications
You must be signed in to change notification settings - Fork 0
/
account_client.py
39 lines (30 loc) · 1.07 KB
/
account_client.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
31
32
33
34
35
36
37
38
39
from models import Account, session
from http import HTTPStatus
from sqlalchemy.exc import IntegrityError
import jwt_token_utils
import logging
def create_or_update_account(updated_account):
existing_account = session \
.query(Account) \
.filter_by(google_id=updated_account.google_id) \
.first()
if not existing_account:
try:
logging.info("Account does not exist in the system!")
session.add(updated_account)
session.flush()
session.commit()
existing_account = updated_account
except IntegrityError:
session.rollback()
logging.info('User already exists in the system!')
existing_account = session \
.query(Account) \
.filter_by(google_id=updated_account.google_id) \
.first()
return {'token': jwt_token_utils.create_jwt_token(existing_account)}, HTTPStatus.OK
def get_account(account_id):
return session\
.query(Account)\
.filter_by(id=account_id)\
.first()