Skip to content
This repository was archived by the owner on Sep 15, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,11 @@ Your answer to this test should be a repository. Please refrain from forking thi

Feel free to implement this project in whatever way you feel like, we do not impose any limitations/requirements.
You can choose any framework (or no framework), any design pattern (or none), any database (or none) for this.

``
## Getting Started

* First start by creating a environment with the requirements from requirements.txt file.
* Then run the create-db script to create a initialize the database and populate it with some fake data.
* Set the FLASK_APP environment variable with the name of the app
* Run the flask app with the command `flask run`
18 changes: 18 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from flask import redirect
import os
import config

connexion_app = config.connexion_app

connexion_app.add_api('api.yml')

app = config.app


@app.route('/')
def doc_root():
return redirect("/api/ui")


if __name__ == "__main__":
connexion_app.run(debug=True)
29 changes: 29 additions & 0 deletions config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import connexion
import os
from flask_sqlalchemy import SQLAlchemy
from flask_marshmallow import Marshmallow
from sqlalchemy.orm import sessionmaker
from sqlalchemy import create_engine

Session = sessionmaker()

basedir = os.path.abspath(os.path.dirname(__file__))
connexion_app = connexion.App(__name__, specification_dir='specification')

app = connexion_app.app

db_url = "sqlite:////" + os.path.join(basedir, 'vms.db')

engine = create_engine(db_url)
Session.configure(bind=engine)
session = Session()

# Configure the SQLAlchemy
app.config["SQLALCHEMY_ECHO"] = False
app.config["SQLALCHEMY_DATABASE_URI"] = db_url
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False

db = SQLAlchemy(app)

ma = Marshmallow(app)

81 changes: 81 additions & 0 deletions create-db.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import datetime
import os
import random

from config import db
from vms.model.employee import Employee
from vms.model.team import Team, team_employee
from vms.model.vacation import Vacation
from faker import Faker


fake = Faker()

if os.path.exists('vms.db'):
os.remove('vms.db')

db.create_all()


def add_team():
for _ in range(3):
team = Team(
name=fake.color_name()
)
db.session.add(team)


def add_employees():
for _ in range(10):
customer = Employee(
first_name=fake.first_name(),
last_name=fake.last_name(),
address=fake.street_address(),
postcode=fake.postcode(),
email=fake.email(),
phone=fake.phone_number()
)
db.session.add(customer)


def add_team_employee():
teams = Team.query.all()
employees = Employee.query.all()

for team in teams:
k = random.randint(1, 3)
employee = random.sample(employees, k)
team.employees.extend(employee)

db.session.commit()


def add_vacations():
employees = Employee.query.all()
for _ in range(5):
employee = random.choice(employees)
start_dates = []
for i in range(1,10):
if len(start_dates) > 0:
start = start_dates.pop()
start_date = fake.date_between_dates(date_start=start+datetime.timedelta(days=1), date_end=start+datetime.timedelta(days=15))
else:
start_date = fake.date_between(start_date='-1y', end_date='today')
end_date = fake.date_between_dates(date_start=start_date, date_end=start_date+datetime.timedelta(days=10))
start_dates.append(end_date)
vacation_type = random.choices(['NORMALE', 'UNPAID', 'RTT'], [60, 5, 25])[0]

vacation = Vacation(
employee_id=employee.id,
start_date=start_date,
end_date=end_date,
type=vacation_type
)
db.session.add(vacation)


add_team()
add_employees()
add_team_employee()
add_vacations()
db.session.commit()
30 changes: 30 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
attrs==20.3.0
certifi==2020.12.5
chardet==3.0.4
click==7.1.2
clickclick==20.10.2
connexion==2.7.0
Faker==5.0.0
Flask==1.1.2
flask-marshmallow==0.14.0
Flask-SQLAlchemy==2.4.4
idna==2.10
inflection==0.5.1
install==1.3.4
itsdangerous==1.1.0
Jinja2==2.11.2
jsonschema==3.2.0
MarkupSafe==1.1.1
marshmallow==3.9.1
marshmallow-sqlalchemy==0.24.1
openapi-spec-validator==0.2.9
pyrsistent==0.17.3
python-dateutil==2.8.1
PyYAML==5.3.1
requests==2.25.0
six==1.15.0
SQLAlchemy==1.3.20
swagger-ui-bundle==0.0.8
text-unidecode==1.3
urllib3==1.26.2
Werkzeug==1.0.1
Loading