Use get method to retrieve account.

This commit is contained in:
Alexis Lahouze 2015-08-16 00:35:20 +02:00
parent fe53de1633
commit 51763e0ddf

View File

@ -74,7 +74,15 @@ class AccountListResource(Resource):
session.add(account)
return account, 201
# Flush session to have id in account.
session.flush()
# Return account with solds.
return Account.query(
session
).filter(
Account.id == account.id
).one(), 201
def delete(self):
"""
@ -104,22 +112,16 @@ class AccountResource(Resource):
@session_aware
@marshal_with_field(Object(resource_fields))
def delete(self, account_id, session):
try:
account = Account.query(
session
).filter(
Account.id == account_id
).one()
except NoResultFound:
# Need to get the object to update it.
account = session.query(Account).get(account_id)
if not account:
return None, 404
session.delete(account)
return account
def patch(self, id):
pass
@session_aware
@marshal_with_field(Object(resource_fields))
def post(self, account_id, session):
@ -128,13 +130,10 @@ class AccountResource(Resource):
assert (id not in kwargs or kwargs.id is None
or kwargs.id == account_id)
try:
account = Account.query(
session
).filter(
Account.id == account_id
).one()
except NoResultFound:
# Need to get the object to update it.
account = session.query(Account).get(account_id)
if not account:
return None, 404
# SQLAlchemy objects ignore __dict__.update() with merge.
@ -143,7 +142,12 @@ class AccountResource(Resource):
session.merge(account)
return account
# Return account with solds.
return Account.query(
session
).filter(
Account.id == account_id
).one()
api_api.add_resource(AccountListResource, '/accounts')