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