This commit is contained in:
ITQ
2025-11-22 11:57:10 +03:00
parent 2dd6e53bf8
commit 579f784fbd
10 changed files with 158 additions and 42 deletions
@@ -24,6 +24,14 @@ class ResumeDataGateway(Protocol):
async def list_by_user_id(self, user_id: UserId, limit: int, offset: int) -> Sequence[Resume]:
raise NotImplementedError
@abstractmethod
async def list_latest_by_user_id(self, user_id: UserId, limit: int, offset: int) -> Sequence[Resume]:
raise NotImplementedError
@abstractmethod
async def get_history(self, resume_id: ResumeId) -> Sequence[Resume]:
raise NotImplementedError
class ResumePredictionDataGateway(Protocol):
@abstractmethod
@@ -26,6 +26,7 @@ class AddResumeInteractor:
key_skills=key_skills,
experience_type=experience_type,
down_resume_id=None,
up_resume_id=None,
)
# TODO: тут надо сделать запуск фоновой таски для вычитывания подходящей вакансии
@@ -4,7 +4,7 @@ from template_project.application.common.identity_provider import IdentityProvid
from template_project.application.common.interactor import to_interactor
from template_project.application.common.unit_of_work import UnitOfWork
from template_project.application.resume.data_gateway import ResumeDataGateway
from template_project.application.resume.entity import ResumeId
from template_project.application.resume.entity import Resume, ResumeId
from template_project.application.resume.errors import ResumeDoesBelongUserError
@@ -32,25 +32,36 @@ class EditResumeInteractor:
experience_type: ExperienceType | None,
) -> _Response:
user = await self.identity_provider.get_current_user()
resume = await self.resume_data_gateway.load(resume_id)
if resume.user_id != user.id:
old_resume = await self.resume_data_gateway.load(resume_id)
if old_resume.user_id != user.id:
raise ResumeDoesBelongUserError
if position is not None:
resume.position = position
if about_me is not None:
resume.about_me = about_me
if key_skills is not None:
resume.key_skills = key_skills
if experience_type is not None:
resume.experience_type = experience_type
new_position = position if position is not None else old_resume.position
new_about_me = about_me if about_me is not None else old_resume.about_me
new_key_skills = key_skills if key_skills is not None else old_resume.key_skills
new_experience_type = experience_type if experience_type is not None else old_resume.experience_type
new_resume = Resume.factory(
user_id=user.id,
position=new_position,
about_me=new_about_me,
key_skills=new_key_skills,
experience_type=new_experience_type,
down_resume_id=old_resume.id,
up_resume_id=None,
)
await self.unit_of_work.add(new_resume)
if old_resume.up_resume_id is None:
old_resume.up_resume_id = new_resume.id
await self.unit_of_work.commit()
return _Response(
id=resume.id,
position=resume.position,
about_me=resume.about_me,
key_skills=resume.key_skills,
experience_type=resume.experience_type,
id=new_resume.id,
position=new_resume.position,
about_me=new_resume.about_me,
key_skills=new_resume.key_skills,
experience_type=new_resume.experience_type,
)
@@ -65,6 +65,7 @@ class GetResumeInteractor:
@to_data_structure
class ResumeListItemResponse:
id: ResumeId
position: str
about_me: str
key_skills: list[str]
@@ -79,10 +80,11 @@ class GetResumeListInteractor:
async def execute(self, limit: int, offset: int) -> list[ResumeListItemResponse]:
user = await self.identity_provider.get_current_user()
resumes = await self.resume_data_gateway.list_by_user_id(user.id, limit=limit, offset=offset)
resumes = await self.resume_data_gateway.list_latest_by_user_id(user.id, limit=limit, offset=offset)
return [
ResumeListItemResponse(
id=r.id,
position=r.position,
about_me=r.about_me,
key_skills=r.key_skills,
@@ -90,3 +92,29 @@ class GetResumeListInteractor:
)
for r in resumes
]
@to_interactor
class GetResumeHistoryInteractor:
identity_provider: IdentityProvider
resume_data_gateway: ResumeDataGateway
async def execute(self, resume_id: ResumeId) -> list[ResumeListItemResponse]:
user = await self.identity_provider.get_current_user()
resume = await self.resume_data_gateway.load(resume_id)
if resume.user_id != user.id:
raise ResumeDoesBelongUserError
history = await self.resume_data_gateway.get_history(resume_id)
return [
ResumeListItemResponse(
id=r.id,
position=r.position,
about_me=r.about_me,
key_skills=r.key_skills,
experience_type=r.experience_type,
)
for r in history
]