/
ZufarFaiz
/
SberProject
Обзор
Документация
Войти
/
ZufarFaiz
/
SberProject
Код
Запросы
1
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
develop
src/main/java/com/example/JobExchange_app/service/impl/JobResponseServiceImpl.java
61 строка
3 KB
Семейный
Добавил логи
06 июн 2025, 23:26
06 июн 2025, 23:26
145678e
Код
Авторство
О чём код?
package com.example.JobExchange_app.service.impl; import com.example.JobExchange_app.dto.ApplicantProfileDto; import com.example.JobExchange_app.exception.AlreadyResponseException; import com.example.JobExchange_app.model.Applicant; import com.example.JobExchange_app.model.Job; import com.example.JobExchange_app.model.JobResponse; import com.example.JobExchange_app.model.ResponseStatus; import com.example.JobExchange_app.repository.ApplicantRepository; import com.example.JobExchange_app.repository.JobRepository; import com.example.JobExchange_app.repository.JobResponseRepository; import com.example.JobExchange_app.service.JobResponseService; import jakarta.persistence.EntityNotFoundException; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import java.util.List; @Slf4j @Service @RequiredArgsConstructor public class JobResponseServiceImpl implements JobResponseService { private final ApplicantRepository applicantRepository; private final JobResponseRepository jobResponseRepository; private final JobRepository jobRepository; public void respondToVacancy(String username,Long jobId) { Applicant applicant = applicantRepository.findByUserName(username). orElseThrow(() -> new EntityNotFoundException("Applicant not found")); Job job = jobRepository.findById(jobId) .orElseThrow(() -> new EntityNotFoundException("Job not found")); JobResponse jobResponse = new JobResponse(); jobResponse.setStatus(ResponseStatus.NEW); jobResponse.setJob(job); jobResponse.setApplicant(applicant); if (jobResponseRepository.existsByJob_jobIdAndApplicant_applicantId(jobId,applicant.getApplicantId())){ throw new AlreadyResponseException("Вы уже откликались на эту вакансию"); } jobResponseRepository.save(jobResponse); log.info("Новый отклик на вакансию! ID вакансии:"+jobId +" ID соискателя: "+ applicant.getApplicantId()); } public List<ApplicantProfileDto> viewApplicants(Long jobId) { List<JobResponse> jobResponses = jobResponseRepository.findByJobId(jobId); List<ApplicantProfileDto> applicantProfileDtos=jobResponses.stream() .map(JobResponse::getApplicant) .distinct() .map(applicant -> new ApplicantProfileDto( applicant.getUser().getUserName(), applicant.getUser().getEmail(), applicant.getEducation(), applicant.getResume() )) .toList(); return applicantProfileDtos; } }