Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Develop #1

Merged
merged 49 commits into from
Nov 17, 2016
Merged

Develop #1

merged 49 commits into from
Nov 17, 2016

Conversation

dmigwi
Copy link
Owner

@dmigwi dmigwi commented Nov 11, 2016

No description provided.

Migwi Ndung'u and others added 30 commits October 30, 2016 01:58
(Chore) Further code refactoring
(Chore) Further code refactoring
Copy link

@amwaleh amwaleh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Daniel nice work !! I have put some comment which seem to repeat themselves in most of the modules please pass through the other modules and try to rectify the similar logics that I have commented on
NB. have not finished going through all the modules especially the test. Will do so when I get Time cheers

time_now = datetime.now()
ret_value = request.json

bucklist_name = '' if not ret_value else ret_value.get('name', '')
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

avoid repetition
if not ret_value should have been validated at point of assignment ret_value = request.json
i think bucketlist_name should only recieve the value
bucketlist_name=ret_value.get('name', '')

bucketlist_names = [bucket.name for bucket in all_current_bucketlist]

# check if the name was passed or exists
if bucklist_name not in bucketlist_names:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • I don't think this logic is necessary the unique attribute in of Column in SQLALchemy can handle the e.g Column('col1', Integer, unique=True),

once applied you can handle the Integrity error that will be thrown

  • You may also try to query for the bucklist_name and check if the query returns an object

date_modified=time_now,
created_by=g.user_id)
b_list.save()
new_items = BucketList.query.filter_by(date_created=time_now).first()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is happening here?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to obtain all the details of the newly created bucketlist. Am querying the database so to obtain new items id which is generated by the database.

time_now = datetime.now()
return_bucketlists = {}

limit = '20' if not request.args else request.args.get('limit', '20')
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The request object will always have an args attribute we can reduce the code to request.args.get('limit', '20')

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Am using request.args.get('limit', '20') because i believe there is a possibility that request.args may not be null but the key limit may be missing at a such an instance. So when such an occurence happens, i provide default value '20' and avoid KeyError exception being raised.


all_bucks = BucketList.query.filter_by(
created_by=g.user_id).limit(limit).all()
q = '' if not request.args else request.args.get('q', '')
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The request object will always have an args attribute we can reduce the code

return return_response(
dict(Error=('Get Failed: No Bucketlists Found.')), 500)

for bucket_l in all_bucks:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi have a look at this link you might need to serialize your data from within the models.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay

Error='Update Failed: Bucketlist Id %s '
'was not found' % id)), 400)

name = request.json.get('name', '')
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use None instead of empty string ""
name = request.json.get('name', None)

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay that will also work, i will do that.

return return_response(new_query.get(), 201)

if request.method == 'DELETE':
if not query:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this to line 150

query_items = Item.query.all()
item_names = [item.name for item in query_items]

# Helps not to save a name already saved or not found
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use Unique constraint attribute on this field.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason why a unique constraint may not be that relevant is that a user logged in the system cannot be able to view other people's bucketlist and other information. The Secret behind this that a single user cannot have several items with the same name but multiple users can have each a single entry of the item with the same name.

if query_new:
query_new = query_new.get()
else:
query_new = dict(Message="Resource already exists")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this logic right??

@dmigwi dmigwi temporarily deployed to aa-bucketlist November 13, 2016 17:50 Inactive
@coveralls
Copy link

Coverage Status

Changes Unknown when pulling a3a41cf on develop into * on master*.

@dmigwi dmigwi temporarily deployed to aa-bucketlist November 14, 2016 10:11 Inactive
@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 00a1a9d on develop into * on master*.

@dmigwi
Copy link
Owner Author

dmigwi commented Nov 14, 2016

Pull request Review Notes

  • Get empty bucket list should return 400 status code with empty data/results.
  • Preferably, get bucketlist should return a list of bucket list
  • Post request to /bucketlists/ and bucketlist/id/items should allow form data
  • Search of bucket lists that has no results should return empty data/result
  • The status code should be 404 for non existing resource.
  • All 500 states code errors of invalid or bad requests should return 400 as status code
  • Consider using this to check for done status done = True if str(done).lower() == 'true' else False.
  • Consider paginating your result set when getting bucket lists result

@dmigwi
Copy link
Owner Author

dmigwi commented Nov 14, 2016

  • After creating a new item (POST /bucketlist/id/items/, the detail of the item should be returned as opposed to the success message (it shuld be like the way POST /bucketlist response appears).
  • Consider refactoring the bucketlist_id function (that allows you to manage a single bucket list - with GET, PUT or DELETE ) in order to remove duplicated code(line 155- 158, 167 - 171, 184-188 in app.py file).

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 3bc81fb on develop into * on master*.

@dmigwi dmigwi temporarily deployed to aa-bucketlist November 15, 2016 14:21 Inactive
@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 1145d3a on develop into * on master*.

@dmigwi dmigwi temporarily deployed to aa-bucketlist November 15, 2016 18:44 Inactive
@dmigwi dmigwi temporarily deployed to aa-bucketlist November 15, 2016 18:44 Inactive
@dmigwi dmigwi temporarily deployed to aa-bucketlist November 15, 2016 18:44 Inactive
(Chore) adding more comments
(BugFix) fix a bug with the items
@coveralls
Copy link

Coverage Status

Changes Unknown when pulling 140fff1 on develop into * on master*.

@dmigwi dmigwi temporarily deployed to aa-bucketlist November 16, 2016 11:24 Inactive
@dmigwi dmigwi merged commit f0e13d7 into master Nov 17, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants