Skip to content

Commit

Permalink
Merge pull request #15 from Maxcutex/modify-employment-data
Browse files Browse the repository at this point in the history
modify employment data with migration
  • Loading branch information
Maxcutex authored Jan 16, 2021
2 parents 949f970 + 1a396f5 commit 3d1566d
Show file tree
Hide file tree
Showing 8 changed files with 233 additions and 2 deletions.
43 changes: 43 additions & 0 deletions app/controllers/user_employment_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ def create_user_employment(self):
user_id,
institution_name,
job_title,
employment_type,
institution_url,
institution_city,
institution_country,
institution_size,
work_summary,
accomplishments,
start_date,
end_date,
is_current,
Expand All @@ -74,6 +81,13 @@ def create_user_employment(self):
"user_id",
"institution_name",
"job_title",
"employment_type",
"institution_url",
"institution_city",
"institution_country",
"institution_size",
"work_summary",
"accomplishments",
"start_date",
"end_date",
"is_current",
Expand All @@ -97,6 +111,13 @@ def create_user_employment(self):
user_id=user_id,
institution_name=institution_name,
job_title=job_title,
employment_type=employment_type,
institution_url=institution_url,
institution_city=institution_city,
institution_country=institution_country,
institution_size=institution_size,
work_summary=work_summary,
accomplishments=accomplishments,
start_date=start_date,
end_date=end_date,
is_current=is_current,
Expand Down Expand Up @@ -145,6 +166,13 @@ def update_user_employment(self, update_id):
user_employment_id,
institution_name,
job_title,
employment_type,
institution_url,
institution_city,
institution_country,
institution_size,
work_summary,
accomplishments,
start_date,
end_date,
is_current,
Expand All @@ -154,6 +182,13 @@ def update_user_employment(self, update_id):
"user_employment_id",
"institution_name",
"job_title",
"employment_type",
"institution_url",
"institution_city",
"institution_country",
"institution_size",
"work_summary",
"accomplishments",
"start_date",
"end_date",
"is_current",
Expand All @@ -163,6 +198,7 @@ def update_user_employment(self, update_id):
return self.handle_response(
"Invalid or incorrect user_employment_id provided", status_code=400
)

if skills is not None:
self._validate_skills(skills)

Expand All @@ -176,6 +212,13 @@ def update_user_employment(self, update_id):
updates = {
"institution_name": institution_name,
"job_title": job_title,
"employment_type": employment_type,
"institution_url": institution_url,
"institution_city": institution_city,
"institution_country": institution_country,
"institution_size": institution_size,
"work_summary": work_summary,
"accomplishments": accomplishments,
"start_date": start_date,
"end_date": end_date,
"is_current": is_current,
Expand Down
11 changes: 11 additions & 0 deletions app/models/user_employment.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from .base_model import BaseModel, db
from ..utils.enums import EmploymentType


class UserEmployment(BaseModel):
Expand All @@ -7,6 +8,16 @@ class UserEmployment(BaseModel):

institution_name = db.Column(db.String, nullable=False)
job_title = db.Column(db.String, nullable=False)
employment_type = db.Column(
db.Enum(EmploymentType, values_callable=lambda obj: [e.value for e in obj]),
nullable=True,
)
institution_url = db.Column(db.String, nullable=False)
institution_city = db.Column(db.String, nullable=False)
institution_country = db.Column(db.String, nullable=False)
institution_size = db.Column(db.String, nullable=False)
work_summary = db.Column(db.Text, nullable=False)
accomplishments = db.Column(db.Text, nullable=False)
start_date = db.Column(db.Date(), nullable=False)
end_date = db.Column(db.Date(), nullable=False)
user_id = db.Column(db.Integer(), db.ForeignKey("users.id"))
Expand Down
22 changes: 21 additions & 1 deletion app/repositories/user_employment_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,31 @@ def __init__(self):
BaseRepo.__init__(self, UserEmployment)

def new_user_employment(
self, user_id, institution_name, job_title, start_date, end_date, is_current
self,
user_id,
institution_name,
job_title,
employment_type,
institution_url,
institution_city,
institution_country,
institution_size,
work_summary,
accomplishments,
start_date,
end_date,
is_current,
):
user_employment = UserEmployment(
institution_name=institution_name,
job_title=job_title,
employment_type=employment_type,
institution_url=institution_url,
institution_city=institution_city,
institution_country=institution_country,
institution_size=institution_size,
work_summary=work_summary,
accomplishments=accomplishments,
start_date=start_date,
end_date=end_date,
user_id=user_id,
Expand Down
6 changes: 6 additions & 0 deletions app/utils/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ class Gender(BaseEnum):
female = "female"


class EmploymentType(BaseEnum):
full = "full"
part = "part"
contract = "contract"


class WeekDays(BaseEnum):
monday = "monday"
tuesday = "tuesday"
Expand Down
18 changes: 17 additions & 1 deletion factories/user_employment_factory.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import factory
from faker import Faker
from faker.providers import internet, company, job, date_time
from faker.providers import internet, company, job, date_time, lorem, address

from app.models import UserEmployment, UserEmploymentSkill
from app.utils import db
Expand All @@ -12,6 +12,8 @@
fake.add_provider(company)
fake.add_provider(job)
fake.add_provider(date_time)
fake.add_provider(lorem)
fake.add_provider(address)


class UserEmploymentFactory(factory.alchemy.SQLAlchemyModelFactory):
Expand All @@ -22,6 +24,13 @@ class Meta:
user = factory.SubFactory(UserFactory)
user_id = factory.SelfAttribute("user.id")
institution_name = fake.company()
employment_type = "full"
institution_url = fake.uri()
institution_city = fake.city()
institution_country = fake.country()
institution_size = "11-50 employees"
work_summary = fake.paragraph(nb_sentences=5)
accomplishments = fake.paragraph(nb_sentences=5)
job_title = fake.job()
start_date = fake.date_between()
end_date = fake.date_between()
Expand All @@ -35,6 +44,13 @@ class Meta:
user_id = factory.SelfAttribute("user.id")
institution_name = fake.company()
job_title = fake.job()
employment_type = "full"
institution_url = fake.uri()
institution_city = fake.city()
institution_country = fake.country()
institution_size = "11-50 employees"
work_summary = fake.paragraph(nb_sentences=5)
accomplishments = fake.paragraph(nb_sentences=5)
start_date = fake.date_between()
end_date = fake.date_between()
is_current = False
Expand Down
72 changes: 72 additions & 0 deletions migrations/versions/d893d7e95bd5_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
"""empty message
Revision ID: d893d7e95bd5
Revises: 4e41bd179702
Create Date: 2021-01-16 15:55:18.974323
"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
from sqlalchemy.dialects import postgresql

revision = "d893d7e95bd5"
down_revision = "4e41bd179702"
branch_labels = None
depends_on = None


def upgrade():
employment_type_enum = postgresql.ENUM(
"full", "part", "contract", name="employment_type_enum"
)
employment_type_enum.create(op.get_bind())

# ### commands auto generated by Alembic - please adjust! ###
op.add_column(
"user_employments", sa.Column("accomplishments", sa.Text(), nullable=False)
)
op.add_column(
"user_employments",
sa.Column(
"employment_type",
sa.Enum("full", "part", "contract", name="employment_type_enum"),
nullable=True,
),
)
op.add_column(
"user_employments", sa.Column("institution_city", sa.String(), nullable=False)
)
op.add_column(
"user_employments",
sa.Column("institution_country", sa.String(), nullable=False),
)
op.add_column(
"user_employments", sa.Column("institution_size", sa.String(), nullable=False)
)
op.add_column(
"user_employments", sa.Column("institution_url", sa.String(), nullable=False)
)
op.add_column(
"user_employments", sa.Column("work_summary", sa.Text(), nullable=False)
)
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_column("user_employments", "work_summary")
op.drop_column("user_employments", "institution_url")
op.drop_column("user_employments", "institution_size")
op.drop_column("user_employments", "institution_country")
op.drop_column("user_employments", "institution_city")
op.drop_column("user_employments", "employment_type")
op.drop_column("user_employments", "accomplishments")

employment_type_enum = postgresql.ENUM(
"full", "part", "contract", name="employment_type_enum"
)
employment_type_enum.drop(op.get_bind())
# ### end Alembic commands ###
21 changes: 21 additions & 0 deletions tests/integration/endpoints/test_user_employment_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ def test_create_user_employment_endpoint(self):
"user_id": user_id,
"institution_name": user_emp_data.institution_name,
"job_title": user_emp_data.job_title,
"employment_type": user_emp_data.employment_type,
"institution_url": user_emp_data.institution_url,
"institution_city": user_emp_data.institution_city,
"institution_country": user_emp_data.institution_country,
"institution_size": user_emp_data.institution_size,
"work_summary": user_emp_data.work_summary,
"accomplishments": user_emp_data.accomplishments,
"start_date": str(user_emp_data.start_date),
"end_date": str(user_emp_data.end_date),
"is_current": user_emp_data.is_current,
Expand Down Expand Up @@ -126,6 +133,13 @@ def test_update_user_employment_endpoint(self):
"user_employment_id": user_emp_data.id,
"institution_name": user_emp_data.institution_name,
"job_title": user_emp_data.job_title,
"employment_type": user_emp_data.employment_type,
"institution_url": user_emp_data.institution_url,
"institution_city": user_emp_data.institution_city,
"institution_country": user_emp_data.institution_country,
"institution_size": user_emp_data.institution_size,
"work_summary": user_emp_data.work_summary,
"accomplishments": user_emp_data.accomplishments,
"start_date": str(user_emp_data.start_date),
"end_date": str(user_emp_data.end_date),
"is_current": user_emp_data.is_current,
Expand Down Expand Up @@ -158,6 +172,13 @@ def test_invalid_update(self):
"user_employment_id": user_emp_data.id,
"institution_name": user_emp_data.institution_name,
"job_title": user_emp_data.job_title,
"employment_type": user_emp_data.employment_type,
"institution_url": user_emp_data.institution_url,
"institution_city": user_emp_data.institution_city,
"institution_country": user_emp_data.institution_country,
"institution_size": user_emp_data.institution_size,
"work_summary": user_emp_data.work_summary,
"accomplishments": user_emp_data.accomplishments,
"start_date": str(user_emp_data.start_date),
"end_date": str(user_emp_data.end_date),
"is_current": user_emp_data.is_current,
Expand Down
Loading

0 comments on commit 3d1566d

Please sign in to comment.