Skip to content

Conversation

@Angeluz-07
Copy link
Contributor

This PR includes :

  • Implementation for the Activity Model
  • Suite of test for the Activity Model

I reused most of the implementation of projects. Thanks @EliuX for your help on it.


response = client.get("/activities/%s" % invalid_id, follow_redirects=True)

assert 422 == response.status_code
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of Status codes use constants if you don't mind :D

class Activities(Resource):
@ns.doc('list_activities')
@ns.marshal_list_with(activity, code=200)
@ns.marshal_list_with(activity, code=HTTPStatus.OK)
Copy link
Contributor

Choose a reason for hiding this comment

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

by default it is OK. So this is redundant.

return activity_dao.get_all(), HTTPStatus.OK

@ns.doc('create_activity')
@ns.response(HTTPStatus.BAD_REQUEST, 'Bad request')
Copy link
Contributor

Choose a reason for hiding this comment

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

If we are going to put a message, lets better put one customized, like:

Invalid format or structure of the attributes of the activity

Also, it would be nice to specify that a CONFLICT may occur if there is already an activity with the same name

    @ns.response(HTTPStatus.CONFLICT, 'This activity already exists')

class Activity(Resource):
@ns.doc('get_activity')
@ns.marshal_with(activity)
@ns.response(HTTPStatus.UNPROCESSABLE_ENTITY, 'The id has an invalid format')
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of here, or you will have to repeat it every time.

def delete(self, id):
return None, 204
"""Get an activity"""
return activity_dao.get(id), HTTPStatus.OK
Copy link
Contributor

Choose a reason for hiding this comment

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

Not necessary to specify OK as a result. By default it returns 200.

@ns.doc('put_activity')
@ns.response(400, 'Invalid format of the attributes of the activity.')
@ns.doc('update_activity')
@ns.response(HTTPStatus.UNPROCESSABLE_ENTITY, 'The data has an invalid format.')
Copy link
Contributor

Choose a reason for hiding this comment

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

I would suggest to remove UNPROCESSABLE_ENTITY (it would be in the class) and add:

    @ns.response(HTTPStatus.BAD_REQUEST, 'Invalid format or structure of the activity')
    @ns.response(HTTPStatus.CONFLICT, 'An activity already exists with this new data')

return activity_dao.update(id, ns.payload)

@ns.doc('delete_activity')
@ns.response(HTTPStatus.UNPROCESSABLE_ENTITY, 'The id has an invalid format')
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove the UNPROCESSABLE_ENTITY. It will be in the class.

Copy link
Contributor

@EliuX EliuX left a comment

Choose a reason for hiding this comment

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

KUDOS

@Angeluz-07 Angeluz-07 merged commit 377214b into master Mar 26, 2020
@EliuX EliuX deleted the feature/implement-activity-model#14 branch March 26, 2020 15:07
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.

3 participants