Beispiel #1
0
class Job:
    api = Namespace('Job', description='User operations')
    model = api.model(
        'job', {
            'job_id':
            fields.Integer(description='Job id'),
            'job_name':
            fields.String(description='Job name, if None = job.id'),
            'job_file':
            fields.String(
                description='File name that contains a job, example: "job.py"'
            ),
            'seconds':
            fields.Integer(description='Interval in seconds'),
            'minutes':
            fields.Integer(description='Interval in minutes'),
            'hours':
            fields.Integer(description='Interval in hours'),
            'days':
            fields.Integer(description='Interval in days'),
            'weeks':
            fields.Integer(description='Interval in weeks'),
            'start_date':
            fields.Date(description='Start date'),
            'end_date':
            fields.Date(description='End date')
        })
Beispiel #2
0
class UserDto:
    """User DTO"""
    api = Namespace('user', description='user related operations')
    signup = api.model('signup', {
        'email': fields.String(required=True, description='user email address'),
        'username': fields.String(required=True, description='user username'),
        'password': fields.String(required=True, description='user password'),
        'hire_date': fields.Date(required=True, description='user hire date')
    })

    lookup = api.model('lookup', {
        'id': fields.Integer(description='user identifier', readonly=True),
        'email': fields.String(required=True, description='user email address'),
        'username': fields.String(required=True, description='user username'),
        'hire_date': fields.Date(required=True, description='user hire date'),
        'admin': fields.Boolean(required=True, description='is user admin')
    })

    profile = api.model('profile', {
        'email': fields.String(description='user email address'),
        'username': fields.String(description='user username'),
        'hire_date': fields.Date(description='user hire date'),
        'admin': fields.Boolean(description='is user admin'),
        'department_id': fields.Integer(description='department id'),
    })

    manager = api.model('user_manager_relationship', {
        'manager_id': fields.Integer(description='manger id', required=True)
    })
Beispiel #3
0
class FundingProjectDTO:
    funding_project_api = Namespace(
        "Funding Project", description="Funding project related operations"
    )
    funding_project = funding_project_api.model(
        "funding_project",
        {
            "number": fields.String(required=True, description="Project number"),
            "title": fields.String(required=True, description="Project title"),
            "description": fields.String(
                required=True, description="Project description"
            ),
            "relevance": fields.String(required=True, description="Project relevance"),
            "objectives": fields.String(
                required=True, description="Project objectives"
            ),
            "justification": fields.String(
                required=True, description="Project justification"
            ),
            "work_plan": fields.String(required=True, description="Project work plan"),
            "status": fields.String(required=True, description="Project status"),
            "fund_amount": fields.Float(
                required=True, description="Project fund amount"
            ),
            "start_date": fields.Date(description="Project starting date"),
            "end_date": fields.Date(description="Project ending date"),
            "investor_email": fields.String(
                required=True, description="Investor email"
            ),
            "funding_application_number": fields.String(
                required=True, description="Funding application number"
            ),
        },
    )
class UserDto:
    api = Namespace('user', description='user related operations')

    interest = api.model('interest', {
        'id': fields.Integer(description="Id field", attribute='id'),
        'value': fields.String(required=True, description='The interest', attribute='value')
    })

    user = api.model('user', {
        'email': fields.String(required=True, description='user email address'),
        'username': fields.String(required=True, description='user username'),
        'password': fields.String(required=True, description='user password'),
        'first_name': fields.String(required=False, description='First Name'),
        'last_name': fields.String(required=False, description='Last Name'),
        'dob': fields.Date(required=False, description='Date Of Birth dd-mm-yyyy', attribute="date_of_birth"),
        'city': fields.String(description='City'),
        'gender_id': fields.Integer(description='Gender'),
        'public_id': fields.String(description='user Identifier'),
    })

    user_details = api.model('user', {
        'email': fields.String(required=True, description='user email address', attribute='email'),
        'username': fields.String(required=True, description='user username', attribute='username'),
        'first_name': fields.String(required=False, description='First Name', attribute='first_name'),
        'last_name': fields.String(required=False, description='Last Name', attribute='last_name'),
        'dob': fields.Date(required=False, description='Date Of Birth dd-mm-yyyy', attribute=lambda x: x.date_of_birth),
        'city': fields.String(description='City', attribute='city'),
        'gender_id': fields.Integer(description='Gender', attribute='gender_id'),
        'public_id': fields.String(description='user Identifier', attribute='public_id'),
        'interests': fields.List(fields.Nested(interest), required=False, description='interests', attribute='interests')
    })
Beispiel #5
0
class EmployeeDTO:
    api = Namespace('employee', description='Endpoint to manage Employee')
    new_employee = api.model('new_employee',
                             {
                                 'firstName': fields.String(required=True, description='First Name of employee'),
                                 'lastName': fields.String(required=False, description='Last Name of employee'),
                                 'email': fields.String(required=True, description='Email ID of employee'),
                                 'designation': fields.String(required=False, description='Designation of employee'),
                                 'DOB': fields.Date(required=True, description='Date of Birth of employee'),
                                 'active': fields.Boolean(required=True, description='Active state of employee'),
                                 'company': fields.Integer(required=True, description='Company ID where an employee is working'),

                             })

    employees = api.model('employees',
                          {
                              'eId': fields.Integer(required=True, description='Id of employee'),
                              'firstName': fields.String(required=True, description='First Name of employee'),
                              'lastName': fields.String(required=False, description='Last Name of employee'),
                              'email': fields.String(required=True, description='Email ID of employee'),
                              'designation': fields.String(required=False, description='Designation of employee'),
                              'DOB': fields.Date(required=True, description='Date of Birth of employee'),
                              'active': fields.Boolean(required=True, description='Active state of employee'),
                              'company': fields.List(fields.Nested(api.model('employee',
                                                                             {
                                                                                 'cId': fields.Integer(required=True, description='Id of the company'),
                                                                                 'name': fields.String(required=True, description='Name of the Company'),
                                                                                 'address': fields.List(fields.Nested(api.model('address',
                                                                                                                                {'aId': fields.Integer(required=False, description='Id of Address'),
                                                                                                                                 'doorNo': fields.String(required=False),
                                                                                                                                 'streetName': fields.String(required=False),
                                                                                                                                 'city': fields.String(required=True),
                                                                                                                                 'state': fields.String(required=True),
                                                                                                                                 'country': fields.String(required=True),
                                                                                                                                 'pincode': fields.String(required=True),
                                                                                                                                 }), required=True)),
                                                                                 'latitude': fields.String(required=False, description='Latitude of company location'),
                                                                                 'longitude': fields.String(required=False, description='Longitude of company location')
                                                                             })))
                              #   'company': fields.String()
                          })

    update_employee = api.model('update_employee',
                                {
                                    'eId': fields.Integer(required=True, description='Id of employee'),
                                    'firstName': fields.String(required=True, description='First Name of employee'),
                                    'lastName': fields.String(required=False, description='Last Name of employee'),
                                    'email': fields.String(required=True, description='Email ID of employee'),
                                    'designation': fields.String(required=False, description='Designation of employee'),
                                    'DOB': fields.Date(required=True, description='Date of Birth of employee'),
                                    'active': fields.Boolean(required=True, description='Active state of employee'),
                                    'company': fields.Integer(required=True, description='Company ID where an employee is working'),

                                })
Beispiel #6
0
class ApplicationFormDto:
    api = Namespace('application_form',
                    description='application_form related operations')

    application_form = api.model(
        'application_form', {
            'date': fields.Date(required=True, description='partial form'),
            'time': fields.DateTime(required=True, description='partial form'),
            'plot': fields.Integer(required=True, description='partial form'),
            'product': fields.String(required=True,
                                     description='partial form'),
            'quantity': fields.Integer(required=True,
                                       description='partial form'),
            'dose': fields.Float(required=True, description='partial form'),
            'machine': fields.String(required=True,
                                     description='partial form'),
            'note': fields.String(required=True, description='partial form'),
        })

    application_form_field_based = api.model(
        'application_form_field_based', {
            'application_form':
            fields.Nested(application_form, required=True),
            'field_required':
            fields.String(default=None,
                          required=True,
                          description="fields to make predictions on"),
        })
Beispiel #7
0
class HarvestingFormDto:
    api = Namespace('harvesting_form',
                    description='harvesting_form related operations')
    harvesting_form = api.model(
        'harvesting_form', {
            'date':
            fields.Date(required=True, description='partial form'),
            'time':
            fields.DateTime(required=True, description='partial form'),
            'plot':
            fields.Integer(required=True, description='partial form'),
            'quantity':
            fields.Integer(required=True, description='partial form'),
            'harvest_quantity':
            fields.String(required=True, description='partial form'),
            'note':
            fields.String(required=True, description='partial form'),
        })

    harvesting_form_field_based = api.model(
        'harvesting_form_field_based', {
            'harvesting_form':
            fields.Nested(harvesting_form, required=True),
            'field_required':
            fields.String(default=None,
                          required=True,
                          description="fields to make predictions on"),
        })
Beispiel #8
0
class TaskDto():

    api = Namespace('tasks', description='Task api information')

    model_content = api.model(
        'content', {
            'text': fields.String(required=True, description='text value'),
            'created_on': fields.Date(description='YYYY-MM-DD'),
            'updated_on': fields.Date(description='YYYY-MM-DD'),
        })

    model_nest = fields.Nested(model_content)

    model_wild = fields.Wildcard(model_nest)

    task = api.model('task', {'*': model_wild})
Beispiel #9
0
 def test_with_default_as_datetime(self):
     field = fields.Date(default=datetime(2014, 8, 25))
     assert field.__schema__ == {
         "type": "string",
         "format": "date",
         "default": "2014-08-25",
     }
Beispiel #10
0
class SowingFormDto:
    api = Namespace('sowing_form',
                    description='sowing_form related operations')
    sowing_form = api.model(
        'sowing_form', {
            'date':
            fields.Date(required=True, description='partial form'),
            'plot':
            fields.Integer(required=True, description='partial form'),
            'crop':
            fields.String(required=True, description='partial form'),
            'quantity':
            fields.Integer(required=True, description='partial form'),
            'time_to_harvest':
            fields.String(required=True, description='partial form'),
            'harvest_duration':
            fields.String(required=True, description='partial form'),
            'expected_yield':
            fields.String(required=True, description='partial form'),
            'unit':
            fields.String(required=True, description='partial form'),
        })

    sowing_form_field_based = api.model(
        'sowing_form_field_based', {
            'sowing_form':
            fields.Nested(sowing_form, required=True),
            'field_required':
            fields.String(default=None,
                          required=True,
                          description="fields to make predictions on"),
        })
Beispiel #11
0
class AuthorDto:
    """
    Author data transfer object definitions
    """

    api = Namespace('authors', description='Author related operations')

    author_basic = api.model(
        'Author Basic', {
            'label':
            fields.String(
                readOnly=True, description='Author name', attribute='name'),
            'value':
            fields.Integer(readOnly=True,
                           description='Author identifier',
                           attribute='id'),
        })

    author = api.model(
        'Author', {
            'id':
            fields.Integer(description='Author identifier'),
            'first_name':
            fields.String(description='Author first name', required=True),
            'last_name':
            fields.String(description='Author last name', required=True),
            'avatar':
            fields.String(description='Author avatar', required=True),
            'birthday':
            fields.Date(description='Author birthday', required=True),
            'user_id':
            fields.Integer(description='Author internal user identifier.',
                           required=False)
        })
Beispiel #12
0
 def test_with_default(self):
     field = fields.Date(default="2014-08-25")
     assert field.__schema__ == {
         "type": "string",
         "format": "date",
         "default": "2014-08-25",
     }
     self.assert_field(field, None, "2014-08-25")
Beispiel #13
0
class GetUserExpenses(Resource):
    filtered_expense_fields = api.model(
        'UserExpenses',
        {
            'email': fields.String(description="User email ID", required=True),
            'from_date': fields.Date(description="For filtering"),
            'to_date': fields.Date(description="For filtering"),
        },
    )

    @api.expect(filtered_expense_fields, validate=True)
    def post(self):
        """
        Get all expenses of a particular user
        """
        data = request.get_json(force=True)

        email_id = data['email']
        from_date = data.get('from_date')
        to_date = data.get('to_date')

        if from_date is not None and to_date is not None:
            from_date = time.strptime(from_date, "%Y-%m-%d")
            to_date = time.strptime(to_date, "%Y-%m-%d")

        if from_date is None:
            from_date = datetime(1970, 1, 1)
        if to_date is None:
            to_date = datetime.utcnow()

        result = []
        try:
            usr: User = repository.get_user(email_id)
            for exp in usr.expense_ids:
                exp_obj: Expense = repository.get_expense(exp)
                # Filter date
                if from_date < dateutil.parser.isoparse(
                        exp_obj.date) < to_date:
                    result.append(exp_obj.to_dict())
            return ReturnDocument(result, "success").asdict()

        except RepositoryException as err:
            return ReturnDocument(err.__doc__, "error").asdict()
        except ClientError as err:
            return ReturnDocument(err.__str__(), "error").asdict()
Beispiel #14
0
class ManagerDto:
    """Manager DTO"""
    api = Namespace('manager', description='manager related operations')
    staff = api.model('staff', {
        'id': fields.Integer(description='staff identifier', readonly=True),
        'manager_id': fields.Integer(description='manager identifier', readonly=True),
        'email': fields.String(required=True, description='staff email address'),
        'username': fields.String(required=True, description='staff username'),
        'hire_date': fields.Date(required=True, description='staff hire date')
    })
Beispiel #15
0
class ProyectoDTO:
    api = Namespace('proyecto', description='Operaciones del Proyecto')
    proyecto = api.model(
        'proyecto', {
            'id':
            fields.Integer(),
            'nombre_Obra':
            fields.String(required=True, description='nombre de obra'),
            'contratante':
            fields.String(required=True, description='nombre del contratante'),
            'proponente':
            fields.String(required=True, description='nombre del proponente'),
            'fecha_Presentacion':
            fields.Date(required=True, description='fecha de presentacion'),
            'fecha_Modificacion':
            fields.Date(required=True,
                        description='fecha de ultima modificacion'),
            'comentarios':
            fields.String(required=True,
                          description='comentarios del proyecto'),
        })
Beispiel #16
0
class IssueDto:
    api = Namespace('issue_form', description='issue_form related operations')
    issue = api.model(
        'issue_form', {
            'date':
            fields.Date(required=True, description='partial form'),
            'plot':
            fields.Integer(required=True, description='partial form'),
            'issue_type':
            fields.String(required=True, description='partial form'),
            'description':
            fields.String(required=True, description='partial form'),
        })
Beispiel #17
0
class MSPPReportAgeDto:
    api = Namespace('mspp_report_age', description='Report by age')
    mspp_report_age = api.model(
        'mspp_departement_report', {
            'date': fields.Date(required=True,
                                descripttion="Date of the report"),
            'ref': fields.String(required=True),
            'specimen': fields.Float(required=True),
            'tested': fields.Float(required=True),
            'positive': fields.Float(required=True),
            'negative': fields.Float(required=True),
            'comment': fields.String(required=False),
            'age_range': fields.Integer(required=True)
        })
Beispiel #18
0
class IssueFormDto:
    api = Namespace('issue_form',
                    description='issue_form related operations')
    issue_form = api.model('issue_form', {
        'date': fields.Date(required=True, description='partial form'),
        'time': fields.DateTime(required=True, description='partial form'),
        'plot': fields.Integer(required=True, description='partial form'),
        'issue_type': fields.Integer(required=True, description='partial form'),
        'description': fields.String(required=True, description='partial form'),
        'note': fields.String(required=True, description='partial form'),
    })

    issue_form_field_based = api.model('issue_form_field_based', {
        'issue_form': fields.Nested(issue_form, required=True),
        'field_required': fields.String(default=None, required=True, description="fields to make predictions on"), })
class TweetRetrievalDto:
    api = Namespace(
        'tweetRetrieval',
        description='Operations related to tweets retrieval from Twitter API')
    twitterQuery = api.model(
        'TwitterQuery', {
            'topic_title':
            fields.String(required=True, description="Tweet's topic"),
            'tags':
            fields.List(fields.String,
                        required=True,
                        description="Queries to look up on twitter"),
            'maxAmount':
            fields.Integer(
                required=True,
                description=
                "Maximum amount of tweets to be saved on the json file"),
            'since':
            fields.Date(description=""),
            'until':
            fields.Date(description=""),
            'language':
            fields.String(description="")
        })
Beispiel #20
0
class PeopleDto:
    api = Namespace('people', description='People related operations')
    people = api.model(
        'people', {
            'phone':
            fields.String(required=True, description='People phone number'),
            'first_name':
            fields.String(required=True, description='Firstname'),
            'last_name':
            fields.String(required=True, description='Lastname'),
            'dob':
            fields.Date(required=False, description='Dob'),
            'symptoms':
            fields.String(required=True, description='Symptoms'),
            'lat':
            fields.Float(description='GPS location'),
            'lon':
            fields.Float(description='GPS location')
        })
Beispiel #21
0
 def get_restx_model() -> Model:
     return Model(
         "User Model",
         {
             "id": restxFields.Integer(),
             "time_created": restxFields.DateTime(),
             "time_updated": restxFields.DateTime(),
             "username": restxFields.String(),
             "email": restxFields.String(),
             "active": restxFields.Boolean(),
             "first_name": restxFields.String(),
             "last_name": restxFields.String(),
             "birthday": restxFields.Date(),
             "height_inches": restxFields.Float(),
             "weight_lbs": restxFields.Float(),
             "gender": restxFields.String(),
             "household": restxFields.Raw(),
             "household_id": restxFields.Integer(),
             "roles": restxFields.List(restxFields.Raw()),
         },
     )
Beispiel #22
0
 def map_marshmallow_field_to_api_field(cls, marshmallow_field: mf.Field):
     if isinstance(marshmallow_field, mf.String):
         return frf.String()
     if isinstance(marshmallow_field, (mf.Raw, mf.Mapping, mf.Dict)):
         return frf.Raw()
     if isinstance(marshmallow_field, (mf.List, mf.Tuple)):
         return frf.List(
             cls.map_marshmallow_field_to_api_field(
                 marshmallow_field.inner))
     if isinstance(marshmallow_field,
                   (mf.Number, mf.Integer, mf.Decimal, mf.Int)):
         return frf.Integer()
     if isinstance(marshmallow_field, (mf.Boolean, mf.Bool)):
         return frf.Boolean()
     if isinstance(marshmallow_field, mf.Float):
         return frf.Float()
     if isinstance(marshmallow_field, mf.Date):
         return frf.Date()
     if isinstance(marshmallow_field, mf.DateTime):
         return frf.DateTime()
     if isinstance(marshmallow_field, (mf.Url, mf.URL)):
         return frf.Url()
     raise Exception(f"Cannot map {marshmallow_field} to API model field")
Beispiel #23
0
 def test_min_as_date(self):
     field = fields.Date(min=date(1984, 6, 7))
     assert "minimum" in field.__schema__
     assert field.__schema__["minimum"] == "1984-06-07"
     assert "exclusiveMinimum" not in field.__schema__
Beispiel #24
0
 def test_unsupported_value_format(self):
     self.assert_field_raises(fields.Date(), "xxx")
Beispiel #25
0
 def test_value(self, value, expected):
     self.assert_field(fields.Date(), value, expected)
Beispiel #26
0
 def test_max_exclusive(self):
     field = fields.Date(max="1984-06-07", exclusiveMax=True)
     assert "maximum" in field.__schema__
     assert field.__schema__["maximum"] == "1984-06-07"
     assert "exclusiveMaximum" in field.__schema__
     assert field.__schema__["exclusiveMaximum"] is True
Beispiel #27
0
 def test_max_as_datetime(self):
     field = fields.Date(max=datetime(1984, 6, 7, 1, 2, 0))
     assert "maximum" in field.__schema__
     assert field.__schema__["maximum"] == "1984-06-07"
     assert "exclusiveMaximum" not in field.__schema__
Beispiel #28
0
 def test_max(self):
     field = fields.Date(max="1984-06-07")
     assert "maximum" in field.__schema__
     assert field.__schema__["maximum"] == "1984-06-07"
     assert "exclusiveMaximum" not in field.__schema__
Beispiel #29
0
 def test_min_exlusive(self):
     field = fields.Date(min="1984-06-07", exclusiveMin=True)
     assert "minimum" in field.__schema__
     assert field.__schema__["minimum"] == "1984-06-07"
     assert "exclusiveMinimum" in field.__schema__
     assert field.__schema__["exclusiveMinimum"] is True
Beispiel #30
0
 def test_defaults(self):
     field = fields.Date()
     assert not field.required
     assert field.__schema__ == {"type": "string", "format": "date"}