Beispiel #1
0
    def post():
        """Post endpoint for registering users into the database.

        Takes params username and password to put into database. Usernames
        cannot be duplicated and will return json message and 400 error if tried.
        On successful user creation will return json message and 201 code"""
        parser = Parser()
        parser.required_fields('username', 'password')
        data = parser.parse_args()
        if UserModel.find_by_username(data['username']):
            return {'message': 'User already exists'}, 400
        UserModel(**data).save_to_db()
        return {'message': 'User created successfully'}, 201
Beispiel #2
0
    def post(self):
        """Post endpoint for adding requests into the database.

        Headers: {Authorization: JWT jwt_token, ContentType: application/json}
        Body must be json with priority, target_date, product_area, client_name,
        title, description fields. Database must have matching client_name or
        will return json message 400 error. If error occurs while inserting into
        database will return json message and 500 error. On successful insert
        into database returns json of request and 201 code."""
        parser = Parser()
        parser.required_fields(
            'priority',
            'target_date',
            'product_area',
            'client_name',
            'title',
            'description')
        data = parser.parse_args()
        if not ClientModel.select(data['client_name']):
            return {
                'message': 'Client does not exist'}, 400
        request = RequestModel(**data)
        client_name = data['client_name']
        priority = data['priority']
        update_list = []
        try:
            while RequestModel.select_same_priority(client_name, priority):
                update_list.append(
                    RequestModel.select_same_priority(
                        client_name, priority))
                priority += 1
            request.save_to_db()
            for req in update_list:
                req.priority += 1
                req.save_to_db()
        except BaseException:
            return {'message': 'Something went wrong'}, 500
        return request.json(), 201