diff --git a/build.gradle b/build.gradle index 3aab9a8b..309e884a 100644 --- a/build.gradle +++ b/build.gradle @@ -27,7 +27,6 @@ repositories { dependencies { implementation 'org.springframework.boot:spring-boot-starter-thymeleaf' - implementation 'org.springframework.boot:spring-boot-starter-amqp' implementation 'org.springframework.boot:spring-boot-starter-data-jpa' implementation 'org.springframework.boot:spring-boot-starter-data-redis' implementation 'org.springframework.boot:spring-boot-starter-security' @@ -77,6 +76,10 @@ dependencies { // https://mvnrepository.com/artifact/org.mockito/mockito-core testImplementation 'org.mockito:mockito-core:5.6.0' + // spring-batch + implementation 'org.springframework.boot:spring-boot-starter-batch' + testImplementation 'org.springframework.batch:spring-batch-test' + } tasks.named('test') { diff --git a/src/main/java/com/postgraduate/batch/cancel/CancelJobConfig.java b/src/main/java/com/postgraduate/batch/cancel/CancelJobConfig.java new file mode 100644 index 00000000..760226cb --- /dev/null +++ b/src/main/java/com/postgraduate/batch/cancel/CancelJobConfig.java @@ -0,0 +1,86 @@ +package com.postgraduate.batch.cancel; + +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.batch.core.Job; +import org.springframework.batch.core.Step; +import org.springframework.batch.core.job.builder.JobBuilder; +import org.springframework.batch.core.repository.JobRepository; +import org.springframework.batch.core.step.builder.StepBuilder; +import org.springframework.batch.item.database.JdbcPagingItemReader; +import org.springframework.batch.item.database.PagingQueryProvider; +import org.springframework.batch.item.database.builder.JdbcPagingItemReaderBuilder; +import org.springframework.batch.item.database.support.SqlPagingQueryProviderFactoryBean; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.transaction.PlatformTransactionManager; + +import javax.sql.DataSource; +import java.sql.Timestamp; +import java.time.LocalDateTime; +import java.util.HashMap; +import java.util.Map; + +import static java.time.LocalDateTime.now; + +@Configuration +@RequiredArgsConstructor +@Slf4j +public class CancelJobConfig { + private final JobRepository jobRepository; + private final PlatformTransactionManager transactionManager; + private final CancelMentoringWriter cancelMentoringWriter; + private final DataSource dataSource; + + private static final int CHUNK_SIZE = 50; + + @Bean(name = "cancelJob") + public Job cancelJob() throws Exception { + return new JobBuilder("cancelJob", jobRepository) + .start(cancelStep()) + .build(); + } + + @Bean(name = "cancelStep") + public Step cancelStep() throws Exception { + return new StepBuilder("cancelStep", jobRepository) + .chunk(CHUNK_SIZE, transactionManager) + .reader(itemReader()) + .writer(cancelMentoringWriter) + .faultTolerant() + .skip(Exception.class) + .skipLimit(Integer.MAX_VALUE) + .build(); + } + + @Bean(name = "cancelReader") + public JdbcPagingItemReader itemReader() throws Exception { + Map parameter = new HashMap<>(); + LocalDateTime now = now() + .toLocalDate() + .atStartOfDay(); + parameter.put("date", Timestamp.valueOf(now)); + + return new JdbcPagingItemReaderBuilder() + .pageSize(CHUNK_SIZE) + .fetchSize(CHUNK_SIZE) + .dataSource(dataSource) + .rowMapper(new CancelMentoringRowMapper()) + .queryProvider(cancelQueryProvider()) + .parameterValues(parameter) + .name("cancelReader") + .build(); + } + + @Bean(name = "cancelQuery") + public PagingQueryProvider cancelQueryProvider() throws Exception { + SqlPagingQueryProviderFactoryBean queryProvider = new SqlPagingQueryProviderFactoryBean(); + queryProvider.setDataSource(dataSource); + queryProvider.setSelectClause("select mentoring_id, user_user_id, senior_senior_id, payment_payment_id"); + queryProvider.setFromClause("from mentoring"); + queryProvider.setWhereClause("where status = 'WAITING' and created_at < :date"); + queryProvider.setSortKey("mentoring_id"); + return queryProvider.getObject(); + } +} + diff --git a/src/main/java/com/postgraduate/batch/cancel/CancelMentoring.java b/src/main/java/com/postgraduate/batch/cancel/CancelMentoring.java new file mode 100644 index 00000000..dcffb003 --- /dev/null +++ b/src/main/java/com/postgraduate/batch/cancel/CancelMentoring.java @@ -0,0 +1,9 @@ +package com.postgraduate.batch.cancel; + +public record CancelMentoring( + Long mentoringId, + Long userId, + Long seniorId, + Long paymentId +) { +} diff --git a/src/main/java/com/postgraduate/batch/cancel/CancelMentoringRepository.java b/src/main/java/com/postgraduate/batch/cancel/CancelMentoringRepository.java new file mode 100644 index 00000000..d3b7d5aa --- /dev/null +++ b/src/main/java/com/postgraduate/batch/cancel/CancelMentoringRepository.java @@ -0,0 +1,46 @@ +package com.postgraduate.batch.cancel; + +import lombok.RequiredArgsConstructor; +import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; +import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; +import org.springframework.jdbc.core.namedparam.SqlParameterSource; +import org.springframework.stereotype.Component; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Component +@RequiredArgsConstructor +public class CancelMentoringRepository{ + private final NamedParameterJdbcTemplate jdbcTemplate; + private static final String AUTO_CANCEL = "자동취소"; + private static final String UPDATE_MENTORING = "update mentoring set status = 'CANCEL' where mentoring_id = :mentoringId"; + private static final String INSERT_REFUSE = "insert into refuse(" + + "mentoring_mentoring_id, " + + "reason" + + ") values(" + + ":mentoringId, :reason" + + ")"; + + public void insertAllRefuse(List mentorings) { + jdbcTemplate.batchUpdate(INSERT_REFUSE, generateParameterSource(mentorings)); + } + + public void updateAllMentoring(List mentorings) { + jdbcTemplate.batchUpdate(UPDATE_MENTORING, generateParameterSource(mentorings)); + } + + private SqlParameterSource[] generateParameterSource(List mentorings) { + return mentorings.stream() + .map(mentoring -> new MapSqlParameterSource(generateEntityParams(mentoring))) + .toArray(SqlParameterSource[]::new); + } + + private Map generateEntityParams(CancelMentoring cancelMentoring) { + HashMap parameter = new HashMap<>(); + parameter.put("mentoringId", cancelMentoring.mentoringId()); + parameter.put("reason", AUTO_CANCEL); + return parameter; + } +} diff --git a/src/main/java/com/postgraduate/batch/cancel/CancelMentoringRowMapper.java b/src/main/java/com/postgraduate/batch/cancel/CancelMentoringRowMapper.java new file mode 100644 index 00000000..fdcd9d7f --- /dev/null +++ b/src/main/java/com/postgraduate/batch/cancel/CancelMentoringRowMapper.java @@ -0,0 +1,18 @@ +package com.postgraduate.batch.cancel; + +import org.springframework.jdbc.core.RowMapper; + +import java.sql.ResultSet; +import java.sql.SQLException; + +public class CancelMentoringRowMapper implements RowMapper { + @Override + public CancelMentoring mapRow(ResultSet rs, int rowNum) throws SQLException { + return new CancelMentoring( + rs.getLong("mentoring_id"), + rs.getLong("user_user_id"), + rs.getLong("senior_senior_id"), + rs.getLong("payment_payment_id") + ); + } +} diff --git a/src/main/java/com/postgraduate/batch/cancel/CancelMentoringWriter.java b/src/main/java/com/postgraduate/batch/cancel/CancelMentoringWriter.java new file mode 100644 index 00000000..4a81521a --- /dev/null +++ b/src/main/java/com/postgraduate/batch/cancel/CancelMentoringWriter.java @@ -0,0 +1,46 @@ +package com.postgraduate.batch.cancel; + +import com.postgraduate.domain.payment.application.usecase.PaymentManageUseCase; +import com.postgraduate.domain.user.domain.entity.User; +import com.postgraduate.domain.user.domain.service.UserGetService; +import com.postgraduate.global.bizppurio.application.usecase.BizppurioJuniorMessage; +import com.postgraduate.global.slack.SlackErrorMessage; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.batch.item.Chunk; +import org.springframework.batch.item.ItemWriter; +import org.springframework.stereotype.Component; + +import java.util.List; + +@Component +@RequiredArgsConstructor +@Slf4j +public class CancelMentoringWriter implements ItemWriter { + private final UserGetService userGetService; + private final PaymentManageUseCase paymentManageUseCase; + private final SlackErrorMessage slackErrorMessage; + private final CancelMentoringRepository cancelMentoringRepository; + private final BizppurioJuniorMessage bizppurioJuniorMessage; + @Override + public void write(Chunk chunk) { + log.info("ChunkSize : {}", chunk.size()); + chunk.forEach(this::updateCancelWithAuto); + } + + public void updateCancelWithAuto(CancelMentoring mentoring) { + try { + User user = userGetService.byUserId(mentoring.userId()); + cancelMentoringRepository.updateAllMentoring(List.of(mentoring)); + cancelMentoringRepository.insertAllRefuse(List.of(mentoring)); + paymentManageUseCase.refundPayByUser(mentoring.userId(), mentoring.paymentId()); + log.info("mentoringId : {} 자동 취소", mentoring.mentoringId()); + bizppurioJuniorMessage.mentoringRefuse(user); + } catch (Exception ex) { + log.error("mentoringId : {} 자동 취소 실패", mentoring.mentoringId()); + log.error(ex.getMessage()); + slackErrorMessage.sendSlackMentoringError(mentoring.mentoringId(), ex); + throw ex; + } + } +} diff --git a/src/main/java/com/postgraduate/batch/done/DoneJobConfig.java b/src/main/java/com/postgraduate/batch/done/DoneJobConfig.java new file mode 100644 index 00000000..f0966f78 --- /dev/null +++ b/src/main/java/com/postgraduate/batch/done/DoneJobConfig.java @@ -0,0 +1,74 @@ +package com.postgraduate.batch.done; + +import lombok.RequiredArgsConstructor; +import org.springframework.batch.core.Job; +import org.springframework.batch.core.Step; +import org.springframework.batch.core.job.builder.JobBuilder; +import org.springframework.batch.core.repository.JobRepository; +import org.springframework.batch.core.step.builder.StepBuilder; +import org.springframework.batch.item.database.JdbcPagingItemReader; +import org.springframework.batch.item.database.PagingQueryProvider; +import org.springframework.batch.item.database.builder.JdbcPagingItemReaderBuilder; +import org.springframework.batch.item.database.support.SqlPagingQueryProviderFactoryBean; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.transaction.PlatformTransactionManager; + +import javax.sql.DataSource; + +@Configuration +@RequiredArgsConstructor +public class DoneJobConfig { + private final JobRepository jobRepository; + private final PlatformTransactionManager transactionManager; + private final DataSource dataSource; + private final DoneMentoringProcessor doneMentoringProcessor; + private final DoneMentoringWriter doneMentoringWriter; + private final DoneMentoringSkipListener doneMentoringSkipListener; + + private static final int CHUNK_SIZE = 50; + + @Bean(name = "doneJob") + public Job doneJob() throws Exception { + return new JobBuilder("doneJob", jobRepository) + .start(doneStep()) + .build(); + } + + @Bean(name = "doneStep") + public Step doneStep() throws Exception { + return new StepBuilder("doneStep", jobRepository) + .chunk(CHUNK_SIZE, transactionManager) + .reader(doneReader()) + .processor(doneMentoringProcessor) + .writer(doneMentoringWriter) + .faultTolerant() + .skip(Exception.class) + .skipLimit(Integer.MAX_VALUE) + .listener(doneMentoringSkipListener) + .build(); + } + + @Bean(name = "doneReader") + public JdbcPagingItemReader doneReader() throws Exception { + return new JdbcPagingItemReaderBuilder() + .pageSize(CHUNK_SIZE) + .fetchSize(CHUNK_SIZE) + .dataSource(dataSource) + .rowMapper(new DoneMentoringRowMapper()) + .queryProvider(doneQueryProvider()) + .name("doneReader") + .build(); + } + + @Bean(name = "doneQuery") + public PagingQueryProvider doneQueryProvider() throws Exception { + SqlPagingQueryProviderFactoryBean queryProvider = new SqlPagingQueryProviderFactoryBean(); + queryProvider.setDataSource(dataSource); + queryProvider.setSelectClause("select m.mentoring_id, m.senior_senior_id, m.salary_salary_id, m.date, p.pay"); + queryProvider.setFromClause("from mentoring m join payment p on m.payment_payment_id = p.payment_id"); + queryProvider.setWhereClause("where m.status = 'EXPECTED'"); + queryProvider.setSortKey("mentoring_id"); + return queryProvider.getObject(); + } +} diff --git a/src/main/java/com/postgraduate/batch/done/DoneMentoring.java b/src/main/java/com/postgraduate/batch/done/DoneMentoring.java new file mode 100644 index 00000000..301ad211 --- /dev/null +++ b/src/main/java/com/postgraduate/batch/done/DoneMentoring.java @@ -0,0 +1,10 @@ +package com.postgraduate.batch.done; + +public record DoneMentoring( + Long mentoringId, + Long seniorId, + Long salaryId, + String date, + int pay +) { +} diff --git a/src/main/java/com/postgraduate/batch/done/DoneMentoringProcessor.java b/src/main/java/com/postgraduate/batch/done/DoneMentoringProcessor.java new file mode 100644 index 00000000..e1535553 --- /dev/null +++ b/src/main/java/com/postgraduate/batch/done/DoneMentoringProcessor.java @@ -0,0 +1,24 @@ +package com.postgraduate.batch.done; + +import org.springframework.batch.item.ItemProcessor; +import org.springframework.stereotype.Component; + +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; + +import static java.time.LocalDateTime.now; +import static java.time.LocalDateTime.parse; +import static java.time.format.DateTimeFormatter.ofPattern; + +@Component +public class DoneMentoringProcessor implements ItemProcessor { + @Override + public DoneMentoring process(DoneMentoring doneMentoring) { + DateTimeFormatter formatter = ofPattern("yyyy-MM-dd-HH-mm"); + LocalDateTime doneDate = parse(doneMentoring.date(), formatter); + if (now().minusDays(3) + .isAfter(doneDate)) + return doneMentoring; + return null; + } +} diff --git a/src/main/java/com/postgraduate/batch/done/DoneMentoringRepository.java b/src/main/java/com/postgraduate/batch/done/DoneMentoringRepository.java new file mode 100644 index 00000000..15db419f --- /dev/null +++ b/src/main/java/com/postgraduate/batch/done/DoneMentoringRepository.java @@ -0,0 +1,43 @@ +package com.postgraduate.batch.done; + +import com.postgraduate.domain.mentoring.domain.entity.constant.TermUnit; +import lombok.RequiredArgsConstructor; +import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; +import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; +import org.springframework.jdbc.core.namedparam.SqlParameterSource; +import org.springframework.stereotype.Component; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +@Component +@RequiredArgsConstructor +public class DoneMentoringRepository { + private final NamedParameterJdbcTemplate jdbcTemplate; + private static final int CHARGE = TermUnit.SHORT.getCharge(); + private static final String UPDATE_MENTORING = "update mentoring set status = 'DONE' where mentoring_id = :mentoringId"; + private static final String UPDATE_SALARY = "update salary set total_amount = total_amount + :amount where salary_id = :salaryId"; + + public void updateAllSalary(List mentorings) { + jdbcTemplate.batchUpdate(UPDATE_SALARY, generateParameterSource(mentorings)); + } + + public void updateAllMentoring(List mentorings) { + jdbcTemplate.batchUpdate(UPDATE_MENTORING, generateParameterSource(mentorings)); + } + + private SqlParameterSource[] generateParameterSource(List mentorings) { + return mentorings.stream() + .map(mentoring -> new MapSqlParameterSource(generateEntityParams(mentoring))) + .toArray(SqlParameterSource[]::new); + } + + private Map generateEntityParams(DoneMentoring doneMentoring) { + HashMap parameter = new HashMap<>(); + parameter.put("mentoringId", doneMentoring.mentoringId()); + parameter.put("amount", doneMentoring.pay() - CHARGE); + parameter.put("salaryId", doneMentoring.salaryId()); + return parameter; + } +} diff --git a/src/main/java/com/postgraduate/batch/done/DoneMentoringRowMapper.java b/src/main/java/com/postgraduate/batch/done/DoneMentoringRowMapper.java new file mode 100644 index 00000000..a7ee0d71 --- /dev/null +++ b/src/main/java/com/postgraduate/batch/done/DoneMentoringRowMapper.java @@ -0,0 +1,19 @@ +package com.postgraduate.batch.done; + +import org.springframework.jdbc.core.RowMapper; + +import java.sql.ResultSet; +import java.sql.SQLException; + +public class DoneMentoringRowMapper implements RowMapper { + @Override + public DoneMentoring mapRow(ResultSet rs, int rowNum) throws SQLException { + return new DoneMentoring( + rs.getLong("mentoring_id"), + rs.getLong("senior_senior_id"), + rs.getLong("salary_salary_id"), + rs.getString("date"), + rs.getInt("pay") + ); + } +} diff --git a/src/main/java/com/postgraduate/batch/done/DoneMentoringSkipListener.java b/src/main/java/com/postgraduate/batch/done/DoneMentoringSkipListener.java new file mode 100644 index 00000000..6f75a1df --- /dev/null +++ b/src/main/java/com/postgraduate/batch/done/DoneMentoringSkipListener.java @@ -0,0 +1,31 @@ +package com.postgraduate.batch.done; + +import com.postgraduate.global.slack.SlackErrorMessage; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.batch.core.SkipListener; +import org.springframework.stereotype.Component; + +@Component +@RequiredArgsConstructor +@Slf4j +public class DoneMentoringSkipListener implements SkipListener { + private final SlackErrorMessage slackErrorMessage; + + @Override + public void onSkipInRead(Throwable t) { + log.info("멘토링 자동 완료 ItemReader Skip message : {}", t.getMessage()); + } + + @Override + public void onSkipInProcess(DoneMentoring doneMentoring, Throwable t) { + log.info("mentoringId : {} 자동 완료 실패, message : {}", doneMentoring.mentoringId(), t.getMessage()); + slackErrorMessage.sendSlackMentoringError(doneMentoring.mentoringId(), t); + } + + @Override + public void onSkipInWrite(DoneMentoring doneMentoring, Throwable t) { + log.info("mentoringId : {} 자동 완료 실패, message : {}", doneMentoring.mentoringId(), t.getMessage()); + slackErrorMessage.sendSlackMentoringError(doneMentoring.mentoringId(), t); + } +} diff --git a/src/main/java/com/postgraduate/batch/done/DoneMentoringWriter.java b/src/main/java/com/postgraduate/batch/done/DoneMentoringWriter.java new file mode 100644 index 00000000..22b1403f --- /dev/null +++ b/src/main/java/com/postgraduate/batch/done/DoneMentoringWriter.java @@ -0,0 +1,26 @@ +package com.postgraduate.batch.done; + +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.batch.item.Chunk; +import org.springframework.batch.item.ItemWriter; +import org.springframework.stereotype.Component; + +import java.util.ArrayList; +import java.util.List; + +@Component +@RequiredArgsConstructor +@Slf4j +public class DoneMentoringWriter implements ItemWriter { + private final DoneMentoringRepository doneMentoringRepository; + + @Override + public void write(Chunk chunk) { + List doneMentorings = new ArrayList<>(); + chunk.forEach(doneMentorings::add); + doneMentoringRepository.updateAllMentoring(doneMentorings); + doneMentoringRepository.updateAllSalary(doneMentorings); + log.info("멘토링 자동 완료 size : {}", chunk.size()); + } +} diff --git a/src/main/java/com/postgraduate/batch/salary/CreateSalary.java b/src/main/java/com/postgraduate/batch/salary/CreateSalary.java new file mode 100644 index 00000000..e143f0e2 --- /dev/null +++ b/src/main/java/com/postgraduate/batch/salary/CreateSalary.java @@ -0,0 +1,10 @@ +package com.postgraduate.batch.salary; + +public record CreateSalary( + Long seniorId, + Long accountId, + String bank, + String accountNumber, + String accountHolder +) { +} diff --git a/src/main/java/com/postgraduate/batch/salary/CreateSalaryItemWriter.java b/src/main/java/com/postgraduate/batch/salary/CreateSalaryItemWriter.java new file mode 100644 index 00000000..d8bd95d8 --- /dev/null +++ b/src/main/java/com/postgraduate/batch/salary/CreateSalaryItemWriter.java @@ -0,0 +1,25 @@ +package com.postgraduate.batch.salary; + +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.batch.item.Chunk; +import org.springframework.batch.item.ItemWriter; +import org.springframework.stereotype.Component; + +import java.util.ArrayList; +import java.util.List; + +@Component +@RequiredArgsConstructor +@Slf4j +public class CreateSalaryItemWriter implements ItemWriter { + private final CreateSalaryRepository createSalaryRepository; + + @Override + public void write(Chunk chunk) throws Exception { + List createSalaries = new ArrayList<>(); + chunk.forEach(createSalaries::add); + createSalaryRepository.insertAllSalary(createSalaries); + log.info("salary 자동 생성 ChunkSize : {}", chunk.size()); + } +} diff --git a/src/main/java/com/postgraduate/batch/salary/CreateSalaryJobConfig.java b/src/main/java/com/postgraduate/batch/salary/CreateSalaryJobConfig.java new file mode 100644 index 00000000..bfcdb05c --- /dev/null +++ b/src/main/java/com/postgraduate/batch/salary/CreateSalaryJobConfig.java @@ -0,0 +1,105 @@ +package com.postgraduate.batch.salary; + +import com.postgraduate.domain.salary.domain.entity.Salary; +import com.postgraduate.domain.salary.domain.service.SalaryGetService; +import com.postgraduate.global.slack.SlackSalaryMessage; +import lombok.RequiredArgsConstructor; +import org.springframework.batch.core.Job; +import org.springframework.batch.core.Step; +import org.springframework.batch.core.job.builder.JobBuilder; +import org.springframework.batch.core.repository.JobRepository; +import org.springframework.batch.core.step.builder.StepBuilder; +import org.springframework.batch.item.database.JdbcPagingItemReader; +import org.springframework.batch.item.database.PagingQueryProvider; +import org.springframework.batch.item.database.builder.JdbcPagingItemReaderBuilder; +import org.springframework.batch.item.database.support.SqlPagingQueryProviderFactoryBean; +import org.springframework.batch.repeat.RepeatStatus; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.transaction.PlatformTransactionManager; + +import javax.sql.DataSource; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static com.postgraduate.domain.salary.util.SalaryUtil.getSalaryDate; + +@Configuration +@RequiredArgsConstructor +public class CreateSalaryJobConfig { + private final JobRepository jobRepository; + private final PlatformTransactionManager transactionManager; + private final SlackSalaryMessage slackSalaryMessage; + private final SalaryGetService salaryGetService; + private final CreateSalaryItemWriter createSalaryItemWriter; + private final CreateSalarySkipListener createSalarySkipListener; + private final DataSource dataSource; + + private static final int CHUNK_SIZE = 50; + + @Bean(name = "salaryJob") + public Job salaryJob() throws Exception { + return new JobBuilder("salaryJob", jobRepository) + .start(sendSlackStep()) + .next(createSalaryStep()) + .build(); + } + + @Bean(name = "sendSlackStep") + public Step sendSlackStep() { + return new StepBuilder("sendSlackStep", jobRepository) + .tasklet((contribution, chunkContext) -> { + List salaries = salaryGetService.findAllLast(); + slackSalaryMessage.sendSlackSalary(salaries); + return RepeatStatus.FINISHED; + }, transactionManager) + .build(); + } + + @Bean(name = "createSalaryStep") + public Step createSalaryStep() throws Exception { + return new StepBuilder("createSalaryStep", jobRepository) + .chunk(CHUNK_SIZE, transactionManager) + .reader(salaryReader()) + .writer(createSalaryItemWriter) + .faultTolerant() + .skip(Exception.class) + .skipLimit(Integer.MAX_VALUE) + .listener(createSalarySkipListener) + .build(); + } + + @Bean(name = "salaryReader") + public JdbcPagingItemReader salaryReader() throws Exception { + Map parameters = new HashMap<>(); + parameters.put("salaryDate", getSalaryDate().plusDays(7)); + return new JdbcPagingItemReaderBuilder() + .pageSize(CHUNK_SIZE) + .fetchSize(CHUNK_SIZE) + .dataSource(dataSource) + .rowMapper(new CreateSalaryRowMapper()) + .queryProvider(salaryQueryProvider()) + .parameterValues(parameters) + .name("salaryReader") + .build(); + } + + @Bean(name = "salaryQuery") + public PagingQueryProvider salaryQueryProvider() throws Exception { + SqlPagingQueryProviderFactoryBean queryProvider = new SqlPagingQueryProviderFactoryBean(); + queryProvider.setDataSource(dataSource); + queryProvider.setSelectClause("SELECT s.senior_id, a.bank, a.account_id, a.account_holder, a.account_number"); + queryProvider.setFromClause("FROM senior s\n" + + "JOIN user u ON s.user_user_id = u.user_id\n" + + "LEFT JOIN account a ON s.senior_id = a.senior_senior_id"); + queryProvider.setWhereClause("WHERE u.is_delete = false\n" + + "AND s.senior_id NOT IN (\n" + + "SELECT senior_senior_id\n" + + "FROM salary\n" + + "WHERE salary_date = :salaryDate\n" + + ")"); + queryProvider.setSortKey("senior_id"); + return queryProvider.getObject(); + } +} diff --git a/src/main/java/com/postgraduate/batch/salary/CreateSalaryRepository.java b/src/main/java/com/postgraduate/batch/salary/CreateSalaryRepository.java new file mode 100644 index 00000000..2a50b27d --- /dev/null +++ b/src/main/java/com/postgraduate/batch/salary/CreateSalaryRepository.java @@ -0,0 +1,43 @@ +package com.postgraduate.batch.salary; + +import lombok.RequiredArgsConstructor; +import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; +import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; +import org.springframework.jdbc.core.namedparam.SqlParameterSource; +import org.springframework.stereotype.Component; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import static com.postgraduate.domain.salary.util.SalaryUtil.getSalaryDate; + +@Component +@RequiredArgsConstructor +public class CreateSalaryRepository { + private final NamedParameterJdbcTemplate jdbcTemplate; + private static final String INSERT_SALARY = "insert into salary " + + "(salary_date, status, total_amount, senior_senior_id, account_holder, account_number, bank) " + + "values (:salaryDate, false, 0, :seniorId, :accountHolder, :accountNumber, :bank)"; + + + public void insertAllSalary(List createSalaries) { + jdbcTemplate.batchUpdate(INSERT_SALARY, generateParameterSource(createSalaries)); + } + + private SqlParameterSource[] generateParameterSource(List createSalaries) { + return createSalaries.stream() + .map(createSalary -> new MapSqlParameterSource(generateEntityParams(createSalary))) + .toArray(SqlParameterSource[]::new); + } + + private Map generateEntityParams(CreateSalary createSalary) { + HashMap parameter = new HashMap<>(); + parameter.put("salaryDate", getSalaryDate().plusDays(7)); + parameter.put("seniorId", createSalary.seniorId()); + parameter.put("accountHolder", createSalary.accountHolder()); + parameter.put("accountNumber", createSalary.accountNumber()); + parameter.put("bank", createSalary.bank()); + return parameter; + } +} diff --git a/src/main/java/com/postgraduate/batch/salary/CreateSalaryRowMapper.java b/src/main/java/com/postgraduate/batch/salary/CreateSalaryRowMapper.java new file mode 100644 index 00000000..dccd6887 --- /dev/null +++ b/src/main/java/com/postgraduate/batch/salary/CreateSalaryRowMapper.java @@ -0,0 +1,19 @@ +package com.postgraduate.batch.salary; + +import org.springframework.jdbc.core.RowMapper; + +import java.sql.ResultSet; +import java.sql.SQLException; + +public class CreateSalaryRowMapper implements RowMapper { + @Override + public CreateSalary mapRow(ResultSet rs, int rowNum) throws SQLException { + return new CreateSalary( + rs.getLong("senior_id"), + rs.getLong("account_id"), + rs.getString("bank"), + rs.getString("account_number"), + rs.getString("account_holder") + ); + } +} diff --git a/src/main/java/com/postgraduate/batch/salary/CreateSalarySkipListener.java b/src/main/java/com/postgraduate/batch/salary/CreateSalarySkipListener.java new file mode 100644 index 00000000..b3396e5c --- /dev/null +++ b/src/main/java/com/postgraduate/batch/salary/CreateSalarySkipListener.java @@ -0,0 +1,31 @@ +package com.postgraduate.batch.salary; + +import com.postgraduate.global.slack.SlackErrorMessage; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.batch.core.SkipListener; +import org.springframework.stereotype.Component; + +@Component +@RequiredArgsConstructor +@Slf4j +public class CreateSalarySkipListener implements SkipListener { + private final SlackErrorMessage slackErrorMessage; + + @Override + public void onSkipInRead(Throwable t) { + log.info("정산 자동 생성 ItemReader Skip message : {}", t.getMessage()); + } + + @Override + public void onSkipInProcess(CreateSalary createSalary, Throwable t) { + log.info("seniorId : {} 정산 자동 생성, message : {}", createSalary.seniorId(), t.getMessage()); + slackErrorMessage.sendSlackSalaryError(createSalary.seniorId(), t); + } + + @Override + public void onSkipInWrite(CreateSalary createSalary, Throwable t) { + log.info("seniorId : {} 정산 자동 생성, message : {}", createSalary.seniorId(), t.getMessage()); + slackErrorMessage.sendSlackSalaryError(createSalary.seniorId(), t); + } +} diff --git a/src/main/java/com/postgraduate/batch/scheduler/JobSchedulerConfig.java b/src/main/java/com/postgraduate/batch/scheduler/JobSchedulerConfig.java new file mode 100644 index 00000000..a2c675ac --- /dev/null +++ b/src/main/java/com/postgraduate/batch/scheduler/JobSchedulerConfig.java @@ -0,0 +1,54 @@ +package com.postgraduate.batch.scheduler; + +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.batch.core.Job; +import org.springframework.batch.core.JobParameters; +import org.springframework.batch.core.JobParametersBuilder; +import org.springframework.batch.core.JobParametersInvalidException; +import org.springframework.batch.core.launch.JobLauncher; +import org.springframework.batch.core.repository.JobExecutionAlreadyRunningException; +import org.springframework.batch.core.repository.JobInstanceAlreadyCompleteException; +import org.springframework.batch.core.repository.JobRestartException; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.context.annotation.Configuration; +import org.springframework.scheduling.annotation.Scheduled; + +import java.time.LocalDateTime; + +@Configuration +@Slf4j +@RequiredArgsConstructor +public class JobSchedulerConfig { + private final JobLauncher jobLauncher; + @Qualifier("cancelJob") + private final Job cancelJob; + @Qualifier("doneJob") + private final Job doneJob; + @Qualifier("salaryJob") + private final Job salaryJob; + + @Scheduled(cron = "0 59 23 * * *", zone = "Asia/Seoul") + public void launchCancelJob() throws JobInstanceAlreadyCompleteException, JobExecutionAlreadyRunningException, JobParametersInvalidException, JobRestartException { + JobParameters jobParameters = new JobParametersBuilder() + .addLocalDateTime("date", LocalDateTime.now()) + .toJobParameters(); + jobLauncher.run(cancelJob, jobParameters); + } + + @Scheduled(cron = "0 59 23 * * *", zone = "Asia/Seoul") + public void launchDoneJob() throws JobInstanceAlreadyCompleteException, JobExecutionAlreadyRunningException, JobParametersInvalidException, JobRestartException { + JobParameters jobParameters = new JobParametersBuilder() + .addLocalDateTime("date", LocalDateTime.now()) + .toJobParameters(); + jobLauncher.run(doneJob, jobParameters); + } + + @Scheduled(cron = "0 0 0 * * 4", zone = "Asia/Seoul") + public void launchSalaryJob() throws JobInstanceAlreadyCompleteException, JobExecutionAlreadyRunningException, JobParametersInvalidException, JobRestartException { + JobParameters jobParameters = new JobParametersBuilder() + .addLocalDateTime("date", LocalDateTime.now()) + .toJobParameters(); + jobLauncher.run(salaryJob, jobParameters); + } +} diff --git a/src/main/java/com/postgraduate/domain/adminssr/application/usecase/AdminSeniorUseCase.java b/src/main/java/com/postgraduate/domain/adminssr/application/usecase/AdminSeniorUseCase.java index 3c97d577..7ccdb127 100644 --- a/src/main/java/com/postgraduate/domain/adminssr/application/usecase/AdminSeniorUseCase.java +++ b/src/main/java/com/postgraduate/domain/adminssr/application/usecase/AdminSeniorUseCase.java @@ -10,7 +10,7 @@ import com.postgraduate.domain.senior.exception.SeniorCertificationException; import com.postgraduate.domain.wish.domain.entity.Wish; import com.postgraduate.domain.wish.domain.service.WishGetService; -import com.postgraduate.global.bizppurio.usecase.BizppurioSeniorMessage; +import com.postgraduate.global.bizppurio.application.usecase.BizppurioSeniorMessage; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; diff --git a/src/main/java/com/postgraduate/domain/auth/application/usecase/oauth/SignUpUseCase.java b/src/main/java/com/postgraduate/domain/auth/application/usecase/oauth/SignUpUseCase.java index 548ec6c6..ac291da4 100644 --- a/src/main/java/com/postgraduate/domain/auth/application/usecase/oauth/SignUpUseCase.java +++ b/src/main/java/com/postgraduate/domain/auth/application/usecase/oauth/SignUpUseCase.java @@ -15,7 +15,7 @@ import com.postgraduate.domain.wish.application.mapper.WishMapper; import com.postgraduate.domain.wish.domain.entity.Wish; import com.postgraduate.domain.wish.domain.service.WishSaveService; -import com.postgraduate.global.bizppurio.usecase.BizppurioSeniorMessage; +import com.postgraduate.global.bizppurio.application.usecase.BizppurioSeniorMessage; import com.postgraduate.global.slack.SlackSignUpMessage; import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Value; diff --git a/src/main/java/com/postgraduate/domain/mentoring/application/usecase/MentoringApplyingUseCase.java b/src/main/java/com/postgraduate/domain/mentoring/application/usecase/MentoringApplyingUseCase.java index 459100f3..5334dd70 100644 --- a/src/main/java/com/postgraduate/domain/mentoring/application/usecase/MentoringApplyingUseCase.java +++ b/src/main/java/com/postgraduate/domain/mentoring/application/usecase/MentoringApplyingUseCase.java @@ -13,8 +13,8 @@ import com.postgraduate.domain.payment.domain.service.PaymentGetService; import com.postgraduate.domain.senior.domain.entity.Senior; import com.postgraduate.domain.user.domain.entity.User; -import com.postgraduate.global.bizppurio.usecase.BizppurioJuniorMessage; -import com.postgraduate.global.bizppurio.usecase.BizppurioSeniorMessage; +import com.postgraduate.global.bizppurio.application.usecase.BizppurioJuniorMessage; +import com.postgraduate.global.bizppurio.application.usecase.BizppurioSeniorMessage; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; diff --git a/src/main/java/com/postgraduate/domain/mentoring/application/usecase/MentoringManageUseCase.java b/src/main/java/com/postgraduate/domain/mentoring/application/usecase/MentoringManageUseCase.java index b3a123a0..c187e2b2 100644 --- a/src/main/java/com/postgraduate/domain/mentoring/application/usecase/MentoringManageUseCase.java +++ b/src/main/java/com/postgraduate/domain/mentoring/application/usecase/MentoringManageUseCase.java @@ -21,9 +21,8 @@ import com.postgraduate.domain.senior.domain.entity.Senior; import com.postgraduate.domain.senior.domain.service.SeniorGetService; import com.postgraduate.domain.user.domain.entity.User; -import com.postgraduate.global.bizppurio.usecase.BizppurioJuniorMessage; -import com.postgraduate.global.bizppurio.usecase.BizppurioSeniorMessage; -import com.postgraduate.global.slack.SlackErrorMessage; +import com.postgraduate.global.bizppurio.application.usecase.BizppurioJuniorMessage; +import com.postgraduate.global.bizppurio.application.usecase.BizppurioSeniorMessage; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.scheduling.annotation.Scheduled; @@ -34,8 +33,8 @@ import java.util.List; import java.util.Optional; -import static com.postgraduate.domain.mentoring.util.DateUtils.*; import static com.postgraduate.domain.mentoring.util.DateUtils.mentoringDateToTime; +import static com.postgraduate.domain.mentoring.util.DateUtils.stringToLocalDateTime; import static com.postgraduate.domain.refuse.application.mapper.RefuseMapper.mapToRefuse; import static java.time.LocalDateTime.now; @@ -43,7 +42,6 @@ @Slf4j @RequiredArgsConstructor public class MentoringManageUseCase { - private final MentoringRenewalUseCase mentoringRenewalUseCase; private final MentoringUpdateService mentoringUpdateService; private final MentoringGetService mentoringGetService; private final RefuseSaveService refuseSaveService; @@ -52,7 +50,6 @@ public class MentoringManageUseCase { private final SalaryGetService salaryGetService; private final SalaryUpdateService salaryUpdateService; private final PaymentManageUseCase paymentManageUseCase; - private final SlackErrorMessage slackErrorMessage; private final MentoringApplyingUseCase mentoringApplyingUseCase; private final BizppurioJuniorMessage bizppurioJuniorMessage; private final BizppurioSeniorMessage bizppurioSeniorMessage; @@ -115,30 +112,6 @@ public Boolean updateExpected(User user, Long mentoringId, MentoringDateRequest return account.isPresent(); } - @Scheduled(cron = "0 59 23 * * *", zone = "Asia/Seoul") - public void updateAutoCancel() { - LocalDateTime now = now() - .toLocalDate() - .atStartOfDay(); - List waitingMentorings = mentoringGetService.byWaitingAndCreatedAt(now); - waitingMentorings.forEach(mentoringRenewalUseCase::updateCancelWithAuto); - } - - @Scheduled(cron = "0 59 23 * * *", zone = "Asia/Seoul") - public void updateAutoDone() { - List expectedMentorings = mentoringGetService.byExpected(); - expectedMentorings.stream() - .filter(mentoring -> { - try { - return mentoring.checkAutoDone(); - } catch (Exception ex) { - slackErrorMessage.sendSlackError(mentoring, ex); - return false; - } - }) - .forEach(mentoringRenewalUseCase::updateDoneWithAuto); - } - @Scheduled(fixedDelay = 1000*60*10) @Transactional public void sendFinishMessage() { diff --git a/src/main/java/com/postgraduate/domain/mentoring/application/usecase/MentoringRenewalUseCase.java b/src/main/java/com/postgraduate/domain/mentoring/application/usecase/MentoringRenewalUseCase.java deleted file mode 100644 index a7ac361f..00000000 --- a/src/main/java/com/postgraduate/domain/mentoring/application/usecase/MentoringRenewalUseCase.java +++ /dev/null @@ -1,69 +0,0 @@ -package com.postgraduate.domain.mentoring.application.usecase; - -import com.postgraduate.domain.mentoring.domain.entity.Mentoring; -import com.postgraduate.domain.mentoring.domain.service.MentoringGetService; -import com.postgraduate.domain.mentoring.domain.service.MentoringUpdateService; -import com.postgraduate.domain.payment.application.usecase.PaymentManageUseCase; -import com.postgraduate.domain.refuse.domain.entity.Refuse; -import com.postgraduate.domain.refuse.domain.service.RefuseSaveService; -import com.postgraduate.domain.salary.domain.entity.Salary; -import com.postgraduate.domain.salary.domain.service.SalaryGetService; -import com.postgraduate.domain.salary.domain.service.SalaryUpdateService; -import com.postgraduate.domain.senior.domain.entity.Senior; -import com.postgraduate.global.bizppurio.usecase.BizppurioJuniorMessage; -import com.postgraduate.global.slack.SlackErrorMessage; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import static com.postgraduate.domain.refuse.application.mapper.RefuseMapper.mapToRefuse; -import static org.springframework.transaction.interceptor.TransactionAspectSupport.currentTransactionStatus; - -@RequiredArgsConstructor -@Service -@Transactional -@Slf4j -public class MentoringRenewalUseCase { - private final MentoringGetService mentoringGetService; - private final MentoringUpdateService mentoringUpdateService; - private final PaymentManageUseCase paymentManageUseCase; - private final RefuseSaveService refuseSaveService; - private final SalaryUpdateService salaryUpdateService; - private final SalaryGetService salaryGetService; - private final SlackErrorMessage slackErrorMessage; - private final BizppurioJuniorMessage bizppurioJuniorMessage; - - public void updateCancelWithAuto(Mentoring mentoring) { - try { - paymentManageUseCase.refundPayByUser(mentoring.getUser(), mentoring.getPayment().getOrderId()); - Mentoring cancelMentoring = mentoringGetService.byMentoringIdWithLazy(mentoring.getMentoringId()); - mentoringUpdateService.updateCancel(cancelMentoring); - Refuse refuse = mapToRefuse(mentoring); - refuseSaveService.save(refuse); - log.info("mentoringId : {} 자동 취소", mentoring.getMentoringId()); - bizppurioJuniorMessage.mentoringRefuse(mentoring.getUser()); - } catch (Exception ex) { - log.error("mentoringId : {} 자동 취소 실패", mentoring.getMentoringId()); - log.error(ex.getMessage()); - slackErrorMessage.sendSlackError(mentoring, ex); - currentTransactionStatus().setRollbackOnly(); - } - } - - public void updateDoneWithAuto(Mentoring mentoring) { - try { - Mentoring doneMentoring = mentoringGetService.byMentoringIdWithLazy(mentoring.getMentoringId()); - Senior senior = mentoring.getSenior(); - Salary salary = salaryGetService.bySenior(senior); - salaryUpdateService.plusTotalAmount(salary, doneMentoring.calculateForSenior()); - mentoringUpdateService.updateDone(doneMentoring, salary); - log.info("mentoringId : {} 자동 완료", mentoring.getMentoringId()); - } catch (Exception ex) { - slackErrorMessage.sendSlackError(mentoring, ex); - log.error("mentoringId : {} 자동 완료 실패", mentoring.getMentoringId()); - log.error(ex.getMessage()); - currentTransactionStatus().setRollbackOnly(); - } - } -} diff --git a/src/main/java/com/postgraduate/domain/mentoring/domain/repository/MentoringRepository.java b/src/main/java/com/postgraduate/domain/mentoring/domain/repository/MentoringRepository.java index f7ef0545..8aa65c21 100644 --- a/src/main/java/com/postgraduate/domain/mentoring/domain/repository/MentoringRepository.java +++ b/src/main/java/com/postgraduate/domain/mentoring/domain/repository/MentoringRepository.java @@ -5,12 +5,17 @@ import com.postgraduate.domain.payment.domain.entity.Payment; import com.postgraduate.domain.senior.domain.entity.Senior; import com.postgraduate.domain.user.domain.entity.User; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; +import java.time.LocalDateTime; +import java.util.List; import java.util.Optional; public interface MentoringRepository extends JpaRepository, MentoringDslRepository { Optional findByPayment(Payment payment); Optional findByMentoringIdAndUserAndStatus(Long mentoringId, User user, Status status); Optional findByMentoringIdAndSeniorAndStatus(Long mentoringId, Senior senior, Status status); + Page findAllByStatusAndCreatedAtBefore(Status status, LocalDateTime createdAt, Pageable pageable); } diff --git a/src/main/java/com/postgraduate/domain/payment/application/usecase/PaymentManageUseCase.java b/src/main/java/com/postgraduate/domain/payment/application/usecase/PaymentManageUseCase.java index d6a88772..14364869 100644 --- a/src/main/java/com/postgraduate/domain/payment/application/usecase/PaymentManageUseCase.java +++ b/src/main/java/com/postgraduate/domain/payment/application/usecase/PaymentManageUseCase.java @@ -89,6 +89,12 @@ public void refundPayByUser(User user, String orderId) { refundPay(payment); } + public void refundPayByUser(Long userId, Long paymentId) { + log.info("환불 진행"); + Payment payment = paymentGetService.byUserIdAndOrderId(userId, paymentId); + refundPay(payment); + } + public void refundPayBySenior(Senior senior, String orderId) { Payment payment = paymentGetService.bySeniorAndOrderId(senior, orderId); refundPay(payment); diff --git a/src/main/java/com/postgraduate/domain/payment/domain/repository/PaymentRepository.java b/src/main/java/com/postgraduate/domain/payment/domain/repository/PaymentRepository.java index 544150a5..153061aa 100644 --- a/src/main/java/com/postgraduate/domain/payment/domain/repository/PaymentRepository.java +++ b/src/main/java/com/postgraduate/domain/payment/domain/repository/PaymentRepository.java @@ -10,5 +10,6 @@ public interface PaymentRepository extends JpaRepository, PaymentDslRepository { Optional findByUserAndOrderIdAndStatus(User user, String orderId, Status status); + Optional findByUser_UserIdAndPaymentIdAndStatus(Long userId, Long paymentId, Status status); Optional findBySeniorAndOrderIdAndStatus(Senior senior, String orderId, Status status); } diff --git a/src/main/java/com/postgraduate/domain/payment/domain/service/PaymentGetService.java b/src/main/java/com/postgraduate/domain/payment/domain/service/PaymentGetService.java index 4bbafb3e..6ebd2190 100644 --- a/src/main/java/com/postgraduate/domain/payment/domain/service/PaymentGetService.java +++ b/src/main/java/com/postgraduate/domain/payment/domain/service/PaymentGetService.java @@ -27,6 +27,11 @@ public Payment byUserAndOrderId(User user, String orderId) { .orElseThrow(PaymentNotFoundException::new); } + public Payment byUserIdAndOrderId(Long userId, Long paymentId) { + return paymentRepository.findByUser_UserIdAndPaymentIdAndStatus(userId, paymentId, DONE) + .orElseThrow(PaymentNotFoundException::new); + } + public Payment bySeniorAndOrderId(Senior senior, String orderId) { return paymentRepository.findBySeniorAndOrderIdAndStatus(senior, orderId, DONE).orElseThrow(PaymentNotFoundException::new); } diff --git a/src/main/java/com/postgraduate/domain/salary/application/usecase/SalaryManageUseCase.java b/src/main/java/com/postgraduate/domain/salary/application/usecase/SalaryManageUseCase.java deleted file mode 100644 index af2077c6..00000000 --- a/src/main/java/com/postgraduate/domain/salary/application/usecase/SalaryManageUseCase.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.postgraduate.domain.salary.application.usecase; - -import com.postgraduate.domain.salary.application.dto.SeniorAndAccount; -import com.postgraduate.domain.salary.domain.entity.Salary; -import com.postgraduate.domain.salary.domain.service.SalaryGetService; -import com.postgraduate.domain.senior.domain.service.SeniorGetService; -import com.postgraduate.global.slack.SlackSalaryMessage; -import lombok.RequiredArgsConstructor; -import org.springframework.scheduling.annotation.Scheduled; -import org.springframework.stereotype.Service; - -import java.time.LocalDate; -import java.util.List; - -import static com.postgraduate.domain.salary.util.SalaryUtil.getSalaryDate; - -@Service -@RequiredArgsConstructor -public class SalaryManageUseCase { - private final SalaryGetService salaryGetService; - private final SeniorGetService seniorGetService; - private final SlackSalaryMessage slackSalaryMessage; - private final SalaryRenewalUseCase salaryRenewalUseCase; - - @Scheduled(cron = "0 0 0 * * 4", zone = "Asia/Seoul") - public void createSalary() { - List salaries = salaryGetService.findAllLast(); - slackSalaryMessage.sendSlackSalary(salaries); - - List seniorAndAccounts = seniorGetService.findAllSeniorAndAccount(); - LocalDate salaryDate = getSalaryDate().plusDays(7); - seniorAndAccounts.stream() - .filter(seniorAndAccount -> salaryGetService.bySeniorOptional(seniorAndAccount.senior(), salaryDate).isEmpty()) - .forEach(seniorAndAccount -> salaryRenewalUseCase.createSalaryWithAuto(seniorAndAccount, salaryDate)); - } -} diff --git a/src/main/java/com/postgraduate/domain/salary/application/usecase/SalaryRenewalUseCase.java b/src/main/java/com/postgraduate/domain/salary/application/usecase/SalaryRenewalUseCase.java deleted file mode 100644 index 84414486..00000000 --- a/src/main/java/com/postgraduate/domain/salary/application/usecase/SalaryRenewalUseCase.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.postgraduate.domain.salary.application.usecase; - -import com.postgraduate.domain.salary.application.dto.SeniorAndAccount; -import com.postgraduate.domain.salary.application.mapper.SalaryMapper; -import com.postgraduate.domain.salary.domain.entity.Salary; -import com.postgraduate.domain.salary.domain.service.SalarySaveService; -import lombok.RequiredArgsConstructor; -import lombok.extern.slf4j.Slf4j; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -import java.time.LocalDate; - -@RequiredArgsConstructor -@Service -@Transactional -@Slf4j -public class SalaryRenewalUseCase { - private final SalarySaveService salarySaveService; - - public void createSalaryWithAuto(SeniorAndAccount seniorAndAccount, LocalDate salaryDate) { - Salary salary = SalaryMapper.mapToSalary(seniorAndAccount.senior(), salaryDate, seniorAndAccount.account()); - salarySaveService.save(salary); - } -} diff --git a/src/main/java/com/postgraduate/domain/salary/domain/service/SalaryGetService.java b/src/main/java/com/postgraduate/domain/salary/domain/service/SalaryGetService.java index 3f359748..4727b3bb 100644 --- a/src/main/java/com/postgraduate/domain/salary/domain/service/SalaryGetService.java +++ b/src/main/java/com/postgraduate/domain/salary/domain/service/SalaryGetService.java @@ -15,7 +15,6 @@ import java.time.LocalDate; import java.util.List; -import java.util.Optional; @Service @RequiredArgsConstructor @@ -42,10 +41,6 @@ public Salary bySenior(Senior senior) { .orElseThrow(SalaryNotFoundException::new); } - public Optional bySeniorOptional(Senior senior, LocalDate salaryDate) { - return salaryRepository.findBySeniorAndSalaryDate(senior, salaryDate); - } - public List allBySeniorAndAccountIsNull(Senior senior) { LocalDate salaryDate = SalaryUtil.getSalaryDate(); return salaryRepository.findAllBySalaryNoneAccount(salaryDate, senior); diff --git a/src/main/java/com/postgraduate/global/bizppurio/dto/req/CommonRequest.java b/src/main/java/com/postgraduate/global/bizppurio/application/dto/req/CommonRequest.java similarity index 73% rename from src/main/java/com/postgraduate/global/bizppurio/dto/req/CommonRequest.java rename to src/main/java/com/postgraduate/global/bizppurio/application/dto/req/CommonRequest.java index 72e2775f..bf77c3cd 100644 --- a/src/main/java/com/postgraduate/global/bizppurio/dto/req/CommonRequest.java +++ b/src/main/java/com/postgraduate/global/bizppurio/application/dto/req/CommonRequest.java @@ -1,4 +1,4 @@ -package com.postgraduate.global.bizppurio.dto.req; +package com.postgraduate.global.bizppurio.application.dto.req; public record CommonRequest( String account, diff --git a/src/main/java/com/postgraduate/global/bizppurio/application/dto/req/ContentRequest.java b/src/main/java/com/postgraduate/global/bizppurio/application/dto/req/ContentRequest.java new file mode 100644 index 00000000..efff5477 --- /dev/null +++ b/src/main/java/com/postgraduate/global/bizppurio/application/dto/req/ContentRequest.java @@ -0,0 +1,5 @@ +package com.postgraduate.global.bizppurio.application.dto.req; + +import com.postgraduate.global.bizppurio.application.dto.req.content.Message; + +public record ContentRequest(Message at) {} diff --git a/src/main/java/com/postgraduate/global/bizppurio/application/dto/req/JuniorMatchingFailRequest.java b/src/main/java/com/postgraduate/global/bizppurio/application/dto/req/JuniorMatchingFailRequest.java new file mode 100644 index 00000000..eb9c38be --- /dev/null +++ b/src/main/java/com/postgraduate/global/bizppurio/application/dto/req/JuniorMatchingFailRequest.java @@ -0,0 +1,6 @@ +package com.postgraduate.global.bizppurio.application.dto.req; + +public record JuniorMatchingFailRequest( + String phoneNumber, String name, String originPostgraduate, String originMajor, String alterPostgraduate, String alterMajor +) { +} diff --git a/src/main/java/com/postgraduate/global/bizppurio/application/dto/req/JuniorMatchingSuccessRequest.java b/src/main/java/com/postgraduate/global/bizppurio/application/dto/req/JuniorMatchingSuccessRequest.java new file mode 100644 index 00000000..8721fe1d --- /dev/null +++ b/src/main/java/com/postgraduate/global/bizppurio/application/dto/req/JuniorMatchingSuccessRequest.java @@ -0,0 +1,6 @@ +package com.postgraduate.global.bizppurio.application.dto.req; + +public record JuniorMatchingSuccessRequest( + String phoneNumber, String name, String postgraduate, String major +) { +} diff --git a/src/main/java/com/postgraduate/global/bizppurio/application/dto/req/JuniorMatchingWaitingRequest.java b/src/main/java/com/postgraduate/global/bizppurio/application/dto/req/JuniorMatchingWaitingRequest.java new file mode 100644 index 00000000..08e4d93a --- /dev/null +++ b/src/main/java/com/postgraduate/global/bizppurio/application/dto/req/JuniorMatchingWaitingRequest.java @@ -0,0 +1,7 @@ +package com.postgraduate.global.bizppurio.application.dto.req; + +public record JuniorMatchingWaitingRequest( + String name, + String phoneNumber +) { +} diff --git a/src/main/java/com/postgraduate/global/bizppurio/dto/req/content/CertificationApproveMessage.java b/src/main/java/com/postgraduate/global/bizppurio/application/dto/req/content/CertificationApproveMessage.java similarity index 52% rename from src/main/java/com/postgraduate/global/bizppurio/dto/req/content/CertificationApproveMessage.java rename to src/main/java/com/postgraduate/global/bizppurio/application/dto/req/content/CertificationApproveMessage.java index 475ebd73..e0ebb6f5 100644 --- a/src/main/java/com/postgraduate/global/bizppurio/dto/req/content/CertificationApproveMessage.java +++ b/src/main/java/com/postgraduate/global/bizppurio/application/dto/req/content/CertificationApproveMessage.java @@ -1,6 +1,6 @@ -package com.postgraduate.global.bizppurio.dto.req.content; +package com.postgraduate.global.bizppurio.application.dto.req.content; -import com.postgraduate.global.bizppurio.dto.req.content.button.WebLinkButton; +import com.postgraduate.global.bizppurio.application.dto.req.content.button.WebLinkButton; public record CertificationApproveMessage( String message, diff --git a/src/main/java/com/postgraduate/global/bizppurio/dto/req/content/CertificationDeniedMessage.java b/src/main/java/com/postgraduate/global/bizppurio/application/dto/req/content/CertificationDeniedMessage.java similarity index 52% rename from src/main/java/com/postgraduate/global/bizppurio/dto/req/content/CertificationDeniedMessage.java rename to src/main/java/com/postgraduate/global/bizppurio/application/dto/req/content/CertificationDeniedMessage.java index 9ed44777..51f9c569 100644 --- a/src/main/java/com/postgraduate/global/bizppurio/dto/req/content/CertificationDeniedMessage.java +++ b/src/main/java/com/postgraduate/global/bizppurio/application/dto/req/content/CertificationDeniedMessage.java @@ -1,6 +1,6 @@ -package com.postgraduate.global.bizppurio.dto.req.content; +package com.postgraduate.global.bizppurio.application.dto.req.content; -import com.postgraduate.global.bizppurio.dto.req.content.button.WebLinkButton; +import com.postgraduate.global.bizppurio.application.dto.req.content.button.WebLinkButton; public record CertificationDeniedMessage( String message, diff --git a/src/main/java/com/postgraduate/global/bizppurio/dto/req/content/JuniorAcceptMessage.java b/src/main/java/com/postgraduate/global/bizppurio/application/dto/req/content/JuniorAcceptMessage.java similarity index 66% rename from src/main/java/com/postgraduate/global/bizppurio/dto/req/content/JuniorAcceptMessage.java rename to src/main/java/com/postgraduate/global/bizppurio/application/dto/req/content/JuniorAcceptMessage.java index 50f78b34..8d29dc64 100644 --- a/src/main/java/com/postgraduate/global/bizppurio/dto/req/content/JuniorAcceptMessage.java +++ b/src/main/java/com/postgraduate/global/bizppurio/application/dto/req/content/JuniorAcceptMessage.java @@ -1,4 +1,4 @@ -package com.postgraduate.global.bizppurio.dto.req.content; +package com.postgraduate.global.bizppurio.application.dto.req.content; public record JuniorAcceptMessage( String message, diff --git a/src/main/java/com/postgraduate/global/bizppurio/dto/req/content/JuniorApplyMessage.java b/src/main/java/com/postgraduate/global/bizppurio/application/dto/req/content/JuniorApplyMessage.java similarity index 65% rename from src/main/java/com/postgraduate/global/bizppurio/dto/req/content/JuniorApplyMessage.java rename to src/main/java/com/postgraduate/global/bizppurio/application/dto/req/content/JuniorApplyMessage.java index 1ff06375..0cfbc462 100644 --- a/src/main/java/com/postgraduate/global/bizppurio/dto/req/content/JuniorApplyMessage.java +++ b/src/main/java/com/postgraduate/global/bizppurio/application/dto/req/content/JuniorApplyMessage.java @@ -1,4 +1,4 @@ -package com.postgraduate.global.bizppurio.dto.req.content; +package com.postgraduate.global.bizppurio.application.dto.req.content; public record JuniorApplyMessage( String message, diff --git a/src/main/java/com/postgraduate/global/bizppurio/dto/req/content/JuniorFinishMessage.java b/src/main/java/com/postgraduate/global/bizppurio/application/dto/req/content/JuniorFinishMessage.java similarity index 51% rename from src/main/java/com/postgraduate/global/bizppurio/dto/req/content/JuniorFinishMessage.java rename to src/main/java/com/postgraduate/global/bizppurio/application/dto/req/content/JuniorFinishMessage.java index af44bce0..6e16ac5d 100644 --- a/src/main/java/com/postgraduate/global/bizppurio/dto/req/content/JuniorFinishMessage.java +++ b/src/main/java/com/postgraduate/global/bizppurio/application/dto/req/content/JuniorFinishMessage.java @@ -1,6 +1,6 @@ -package com.postgraduate.global.bizppurio.dto.req.content; +package com.postgraduate.global.bizppurio.application.dto.req.content; -import com.postgraduate.global.bizppurio.dto.req.content.button.WebLinkButton; +import com.postgraduate.global.bizppurio.application.dto.req.content.button.WebLinkButton; public record JuniorFinishMessage( String message, diff --git a/src/main/java/com/postgraduate/global/bizppurio/application/dto/req/content/JuniorMatchingFailMessage.java b/src/main/java/com/postgraduate/global/bizppurio/application/dto/req/content/JuniorMatchingFailMessage.java new file mode 100644 index 00000000..15a79d2f --- /dev/null +++ b/src/main/java/com/postgraduate/global/bizppurio/application/dto/req/content/JuniorMatchingFailMessage.java @@ -0,0 +1,11 @@ +package com.postgraduate.global.bizppurio.application.dto.req.content; + +import com.postgraduate.global.bizppurio.application.dto.req.content.button.WebLinkButton; + +public record JuniorMatchingFailMessage ( + String message, + String senderkey, + String templatecode, + WebLinkButton[] button +) implements Message +{} diff --git a/src/main/java/com/postgraduate/global/bizppurio/application/dto/req/content/JuniorMatchingSuccessMessage.java b/src/main/java/com/postgraduate/global/bizppurio/application/dto/req/content/JuniorMatchingSuccessMessage.java new file mode 100644 index 00000000..a4557bdd --- /dev/null +++ b/src/main/java/com/postgraduate/global/bizppurio/application/dto/req/content/JuniorMatchingSuccessMessage.java @@ -0,0 +1,11 @@ +package com.postgraduate.global.bizppurio.application.dto.req.content; + +import com.postgraduate.global.bizppurio.application.dto.req.content.button.WebLinkButton; + +public record JuniorMatchingSuccessMessage( + String message, + String senderkey, + String templatecode, + WebLinkButton[] button +) implements Message { +} diff --git a/src/main/java/com/postgraduate/global/bizppurio/application/dto/req/content/JuniorMatchingWaitingMessage.java b/src/main/java/com/postgraduate/global/bizppurio/application/dto/req/content/JuniorMatchingWaitingMessage.java new file mode 100644 index 00000000..63d1451d --- /dev/null +++ b/src/main/java/com/postgraduate/global/bizppurio/application/dto/req/content/JuniorMatchingWaitingMessage.java @@ -0,0 +1,8 @@ +package com.postgraduate.global.bizppurio.application.dto.req.content; + +public record JuniorMatchingWaitingMessage( + String message, + String senderkey, + String templatecode +) implements Message { +} diff --git a/src/main/java/com/postgraduate/global/bizppurio/dto/req/content/JuniorRefuseMessage.java b/src/main/java/com/postgraduate/global/bizppurio/application/dto/req/content/JuniorRefuseMessage.java similarity index 51% rename from src/main/java/com/postgraduate/global/bizppurio/dto/req/content/JuniorRefuseMessage.java rename to src/main/java/com/postgraduate/global/bizppurio/application/dto/req/content/JuniorRefuseMessage.java index cb6a9aa6..651af74a 100644 --- a/src/main/java/com/postgraduate/global/bizppurio/dto/req/content/JuniorRefuseMessage.java +++ b/src/main/java/com/postgraduate/global/bizppurio/application/dto/req/content/JuniorRefuseMessage.java @@ -1,6 +1,6 @@ -package com.postgraduate.global.bizppurio.dto.req.content; +package com.postgraduate.global.bizppurio.application.dto.req.content; -import com.postgraduate.global.bizppurio.dto.req.content.button.WebLinkButton; +import com.postgraduate.global.bizppurio.application.dto.req.content.button.WebLinkButton; public record JuniorRefuseMessage( String message, diff --git a/src/main/java/com/postgraduate/global/bizppurio/application/dto/req/content/Message.java b/src/main/java/com/postgraduate/global/bizppurio/application/dto/req/content/Message.java new file mode 100644 index 00000000..b9ce39cd --- /dev/null +++ b/src/main/java/com/postgraduate/global/bizppurio/application/dto/req/content/Message.java @@ -0,0 +1,4 @@ +package com.postgraduate.global.bizppurio.application.dto.req.content; + +public interface Message { +} diff --git a/src/main/java/com/postgraduate/global/bizppurio/dto/req/content/SeniorAcceptMessage.java b/src/main/java/com/postgraduate/global/bizppurio/application/dto/req/content/SeniorAcceptMessage.java similarity index 66% rename from src/main/java/com/postgraduate/global/bizppurio/dto/req/content/SeniorAcceptMessage.java rename to src/main/java/com/postgraduate/global/bizppurio/application/dto/req/content/SeniorAcceptMessage.java index e109c6ac..9497de60 100644 --- a/src/main/java/com/postgraduate/global/bizppurio/dto/req/content/SeniorAcceptMessage.java +++ b/src/main/java/com/postgraduate/global/bizppurio/application/dto/req/content/SeniorAcceptMessage.java @@ -1,4 +1,4 @@ -package com.postgraduate.global.bizppurio.dto.req.content; +package com.postgraduate.global.bizppurio.application.dto.req.content; public record SeniorAcceptMessage( String message, diff --git a/src/main/java/com/postgraduate/global/bizppurio/dto/req/content/SeniorApplyMessage.java b/src/main/java/com/postgraduate/global/bizppurio/application/dto/req/content/SeniorApplyMessage.java similarity index 51% rename from src/main/java/com/postgraduate/global/bizppurio/dto/req/content/SeniorApplyMessage.java rename to src/main/java/com/postgraduate/global/bizppurio/application/dto/req/content/SeniorApplyMessage.java index 0536bfa4..0d3d7698 100644 --- a/src/main/java/com/postgraduate/global/bizppurio/dto/req/content/SeniorApplyMessage.java +++ b/src/main/java/com/postgraduate/global/bizppurio/application/dto/req/content/SeniorApplyMessage.java @@ -1,6 +1,6 @@ -package com.postgraduate.global.bizppurio.dto.req.content; +package com.postgraduate.global.bizppurio.application.dto.req.content; -import com.postgraduate.global.bizppurio.dto.req.content.button.WebLinkButton; +import com.postgraduate.global.bizppurio.application.dto.req.content.button.WebLinkButton; public record SeniorApplyMessage( String message, diff --git a/src/main/java/com/postgraduate/global/bizppurio/dto/req/content/SeniorFinishMessage.java b/src/main/java/com/postgraduate/global/bizppurio/application/dto/req/content/SeniorFinishMessage.java similarity index 66% rename from src/main/java/com/postgraduate/global/bizppurio/dto/req/content/SeniorFinishMessage.java rename to src/main/java/com/postgraduate/global/bizppurio/application/dto/req/content/SeniorFinishMessage.java index f2521eb3..ce81d0f2 100644 --- a/src/main/java/com/postgraduate/global/bizppurio/dto/req/content/SeniorFinishMessage.java +++ b/src/main/java/com/postgraduate/global/bizppurio/application/dto/req/content/SeniorFinishMessage.java @@ -1,4 +1,4 @@ -package com.postgraduate.global.bizppurio.dto.req.content; +package com.postgraduate.global.bizppurio.application.dto.req.content; public record SeniorFinishMessage( String message, diff --git a/src/main/java/com/postgraduate/global/bizppurio/dto/req/content/SeniorSingUpMessage.java b/src/main/java/com/postgraduate/global/bizppurio/application/dto/req/content/SeniorSingUpMessage.java similarity index 51% rename from src/main/java/com/postgraduate/global/bizppurio/dto/req/content/SeniorSingUpMessage.java rename to src/main/java/com/postgraduate/global/bizppurio/application/dto/req/content/SeniorSingUpMessage.java index b23840e8..9287918b 100644 --- a/src/main/java/com/postgraduate/global/bizppurio/dto/req/content/SeniorSingUpMessage.java +++ b/src/main/java/com/postgraduate/global/bizppurio/application/dto/req/content/SeniorSingUpMessage.java @@ -1,6 +1,6 @@ -package com.postgraduate.global.bizppurio.dto.req.content; +package com.postgraduate.global.bizppurio.application.dto.req.content; -import com.postgraduate.global.bizppurio.dto.req.content.button.WebLinkButton; +import com.postgraduate.global.bizppurio.application.dto.req.content.button.WebLinkButton; public record SeniorSingUpMessage( String message, diff --git a/src/main/java/com/postgraduate/global/bizppurio/dto/req/content/button/WebLinkButton.java b/src/main/java/com/postgraduate/global/bizppurio/application/dto/req/content/button/WebLinkButton.java similarity index 61% rename from src/main/java/com/postgraduate/global/bizppurio/dto/req/content/button/WebLinkButton.java rename to src/main/java/com/postgraduate/global/bizppurio/application/dto/req/content/button/WebLinkButton.java index 614d0c76..d0634528 100644 --- a/src/main/java/com/postgraduate/global/bizppurio/dto/req/content/button/WebLinkButton.java +++ b/src/main/java/com/postgraduate/global/bizppurio/application/dto/req/content/button/WebLinkButton.java @@ -1,4 +1,4 @@ -package com.postgraduate.global.bizppurio.dto.req.content.button; +package com.postgraduate.global.bizppurio.application.dto.req.content.button; public record WebLinkButton( String name, diff --git a/src/main/java/com/postgraduate/global/bizppurio/dto/res/BizppurioTokenResponse.java b/src/main/java/com/postgraduate/global/bizppurio/application/dto/res/BizppurioTokenResponse.java similarity index 58% rename from src/main/java/com/postgraduate/global/bizppurio/dto/res/BizppurioTokenResponse.java rename to src/main/java/com/postgraduate/global/bizppurio/application/dto/res/BizppurioTokenResponse.java index b390575f..4aaeedc3 100644 --- a/src/main/java/com/postgraduate/global/bizppurio/dto/res/BizppurioTokenResponse.java +++ b/src/main/java/com/postgraduate/global/bizppurio/application/dto/res/BizppurioTokenResponse.java @@ -1,3 +1,3 @@ -package com.postgraduate.global.bizppurio.dto.res; +package com.postgraduate.global.bizppurio.application.dto.res; public record BizppurioTokenResponse(String accesstoken, String type, String expired) {} diff --git a/src/main/java/com/postgraduate/global/bizppurio/dto/res/MessageResponse.java b/src/main/java/com/postgraduate/global/bizppurio/application/dto/res/MessageResponse.java similarity index 61% rename from src/main/java/com/postgraduate/global/bizppurio/dto/res/MessageResponse.java rename to src/main/java/com/postgraduate/global/bizppurio/application/dto/res/MessageResponse.java index 4ae6e6cc..3459a8e4 100644 --- a/src/main/java/com/postgraduate/global/bizppurio/dto/res/MessageResponse.java +++ b/src/main/java/com/postgraduate/global/bizppurio/application/dto/res/MessageResponse.java @@ -1,4 +1,4 @@ -package com.postgraduate.global.bizppurio.dto.res; +package com.postgraduate.global.bizppurio.application.dto.res; public record MessageResponse(int code, String description, String messagekey, String refkey) { } diff --git a/src/main/java/com/postgraduate/global/bizppurio/mapper/BizppurioMapper.java b/src/main/java/com/postgraduate/global/bizppurio/application/mapper/BizppurioMapper.java similarity index 69% rename from src/main/java/com/postgraduate/global/bizppurio/mapper/BizppurioMapper.java rename to src/main/java/com/postgraduate/global/bizppurio/application/mapper/BizppurioMapper.java index e55e2897..f8182d9b 100644 --- a/src/main/java/com/postgraduate/global/bizppurio/mapper/BizppurioMapper.java +++ b/src/main/java/com/postgraduate/global/bizppurio/application/mapper/BizppurioMapper.java @@ -1,10 +1,13 @@ -package com.postgraduate.global.bizppurio.mapper; +package com.postgraduate.global.bizppurio.application.mapper; +import com.postgraduate.global.bizppurio.application.dto.req.JuniorMatchingFailRequest; +import com.postgraduate.global.bizppurio.application.dto.req.JuniorMatchingSuccessRequest; +import com.postgraduate.global.bizppurio.application.dto.req.JuniorMatchingWaitingRequest; import com.postgraduate.domain.user.domain.entity.User; -import com.postgraduate.global.bizppurio.dto.req.CommonRequest; -import com.postgraduate.global.bizppurio.dto.req.ContentRequest; -import com.postgraduate.global.bizppurio.dto.req.content.*; -import com.postgraduate.global.bizppurio.dto.req.content.button.WebLinkButton; +import com.postgraduate.global.bizppurio.application.dto.req.CommonRequest; +import com.postgraduate.global.bizppurio.application.dto.req.ContentRequest; +import com.postgraduate.global.bizppurio.application.dto.req.content.*; +import com.postgraduate.global.bizppurio.application.dto.req.content.button.WebLinkButton; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; @@ -38,6 +41,12 @@ public class BizppurioMapper { private String juniorMentoringApply; @Value("${bizppurio.template.senior_signUp}") private String seniorSignUp; + @Value("${bizppurio.template.junior_matching_fail}") + private String juniorMatchingFail; + @Value("${bizppurio.template.junior_matching_success}") + private String juniorMatchingSucess; + @Value("${bizppurio.template.junior_matching_waiting}") + private String juniorMatchingWaiting; @Value("${bizppurio.url.certification}") private String certificationPage; @Value("${bizppurio.url.profile}") @@ -66,7 +75,7 @@ public CommonRequest mapToSeniorSignUpMessage(User user) { WebLinkButton profile = new WebLinkButton("프로필 작성하기", "WL", profilePage, profilePage); WebLinkButton[] buttons = {certification, profile}; Message messageBody = new SeniorSingUpMessage(message, senderKey, seniorSignUp, buttons); - return createCommonRequest(messageBody, user); + return createCommonRequest(messageBody, user.getPhoneNumber()); } public CommonRequest mapToSeniorApplyMessage(User user) { @@ -79,7 +88,7 @@ public CommonRequest mapToSeniorApplyMessage(User user) { WebLinkButton mentoringCheck = new WebLinkButton("멘토링 신청 확인하기", type, seniorMentoringPage, seniorMentoringPage); WebLinkButton[] buttons = {mentoringCheck}; Message messageBody = new SeniorApplyMessage(message, senderKey, seniorMentoringApply, buttons); - return createCommonRequest(messageBody, user); + return createCommonRequest(messageBody, user.getPhoneNumber()); } public CommonRequest mapToSeniorAcceptMessage(User user, String link, String time) { @@ -92,7 +101,7 @@ public CommonRequest mapToSeniorAcceptMessage(User user, String link, String tim "멘토링 진행 일시에 선배님께서 줌 또는 구글미트를 활용하여 비대면 대화 링크를 열어주시면 됩니다!" ); Message messageBody = new SeniorAcceptMessage(message, senderKey, seniorMentoringAccept); - return createCommonRequest(messageBody, user); + return createCommonRequest(messageBody, user.getPhoneNumber()); } public CommonRequest mapToCertificationApprove(User user) { @@ -104,7 +113,7 @@ public CommonRequest mapToCertificationApprove(User user) { WebLinkButton profile = new WebLinkButton("프로필 완성하기", type, profilePage, profilePage); WebLinkButton[] buttons = {profile}; CertificationApproveMessage messageBody = new CertificationApproveMessage(message, senderKey, certificationApprove, buttons); - return createCommonRequest(messageBody, user); + return createCommonRequest(messageBody, user.getPhoneNumber()); } public CommonRequest mapToCertificationDenied(User user) { @@ -118,7 +127,7 @@ public CommonRequest mapToCertificationDenied(User user) { WebLinkButton certification = new WebLinkButton("대학원 재인증하기", type, certificationPage, certificationPage); WebLinkButton[] buttons = {certification}; CertificationDeniedMessage messageBody = new CertificationDeniedMessage(message, senderKey, certificationDenied, buttons); - return createCommonRequest(messageBody, user); + return createCommonRequest(messageBody, user.getPhoneNumber()); } public CommonRequest mapToSeniorFinish(User user) { @@ -132,7 +141,7 @@ public CommonRequest mapToSeniorFinish(User user) { "멘토링 확정은 멘토링이 정상적으로 진행되었는지 확인하기 위함이며, 멘토링 완료 확정이 진행되지 않을시 정산이 지연될 수 있는점 양해 부탁드려요!\uD83D\uDE03" ); SeniorFinishMessage messageBody = new SeniorFinishMessage(message, senderKey, seniorMentoringFinish); - return createCommonRequest(messageBody, user); + return createCommonRequest(messageBody, user.getPhoneNumber()); } public CommonRequest mapToJuniorApplyMessage(User user) { @@ -144,7 +153,7 @@ public CommonRequest mapToJuniorApplyMessage(User user) { "선배님이 다음날 오후 11시 59분까지 멘토링을 수락해주시지 않으면 멘토링이 자동 취소 및 환불되니 유의해주세요! \uD83D\uDE42" ); JuniorApplyMessage messageBody = new JuniorApplyMessage(message, senderKey, juniorMentoringApply); - return createCommonRequest(messageBody, user); + return createCommonRequest(messageBody, user.getPhoneNumber()); } public CommonRequest mapToJuniorAcceptMessage(User user, String link, String time) { @@ -159,7 +168,7 @@ public CommonRequest mapToJuniorAcceptMessage(User user, String link, String tim "멘토링 시간은 꼭 지켜주세요! \uD83D\uDD05" ); JuniorAcceptMessage messageBody = new JuniorAcceptMessage(message, senderKey, juniorMentoringAccept); - return createCommonRequest(messageBody, user); + return createCommonRequest(messageBody, user.getPhoneNumber()); } public CommonRequest mapToJuniorRefuseMessage(User user) { @@ -173,7 +182,7 @@ public CommonRequest mapToJuniorRefuseMessage(User user) { WebLinkButton otherSenior = new WebLinkButton("다른 선배 보러가기", type, mainPage, mainPage); WebLinkButton[] buttons = {otherSenior}; JuniorRefuseMessage messageBody = new JuniorRefuseMessage(message, senderKey, juniorMentoringRefuse, buttons); - return createCommonRequest(messageBody, user); + return createCommonRequest(messageBody, user.getPhoneNumber()); } public CommonRequest mapToJuniorFinish(User user) { @@ -191,12 +200,63 @@ public CommonRequest mapToJuniorFinish(User user) { WebLinkButton[] buttons = {mentoringFinish}; JuniorFinishMessage messageBody = new JuniorFinishMessage(message, senderKey, juniorMentoringFinish, buttons); - return createCommonRequest(messageBody, user); + return createCommonRequest(messageBody, user.getPhoneNumber()); } - private CommonRequest createCommonRequest(Message messageBody, User user) { + public CommonRequest mapToJuniorMatchingFail(JuniorMatchingFailRequest request) { + String message = ( + "안녕하세요, " + request.name() + "님.\n" + + "\n" + + "오래 기다려주셔서 감사드립니다!\n" + + "\n" + + request.name() + "님께서 신청해주신, " + request.originPostgraduate() + "대학원 " + request.originMajor() + "학과 선배 대신\n" + + "\n" + + request.alterPostgraduate() + "대학원 " + request.alterMajor() + "학과의 선배를 매칭 드리고 싶어요!\n" + + "\n" + + "신청해주신 선배는 찾지 못했지만, 유사학과의 다른 선배와 멘토링을 해보는 건 어때요 ?" + ); + WebLinkButton goMainPage = new WebLinkButton("대학원 김선배 바로가기", type, mainPage, mainPage); + WebLinkButton[] buttons = {goMainPage}; + + JuniorMatchingFailMessage messageBody = new JuniorMatchingFailMessage(message, senderKey, juniorMatchingFail, buttons); + return createCommonRequest(messageBody, request.phoneNumber()); + } + + public CommonRequest mapToJuniorMatchingSuccess(JuniorMatchingSuccessRequest request) { + String message = ( + "안녕하세요, " + request.name() + "님.\n" + + "\n" + + "오래 기다려주셔서 감사드립니다!\n" + + "\n" + + request.name() + "님께서 신청해주신, " + request.postgraduate() + "대학원 " + request.major() + "학과 선배와 매칭되었어요 \uD83D\uDE42\n" + + "\n" + + "아래 링크를 눌러 멘토링을 진행해보세요 !" + ); + WebLinkButton goMainPage = new WebLinkButton("대학원 김선배 바로가기", type, mainPage, mainPage); + WebLinkButton[] buttons = {goMainPage}; + + JuniorMatchingSuccessMessage messageBody = new JuniorMatchingSuccessMessage(message, senderKey, juniorMatchingSucess, buttons); + return createCommonRequest(messageBody, request.phoneNumber()); + } + + public CommonRequest mapToJuniorMatchingWaiting(JuniorMatchingWaitingRequest request) { + String message = ( + "안녕하세요, " + request.name() + "님.\n" + + "\n" + + "김선배와 함께 해주셔서 감사드립니다.\n" + + "\n" + + request.name() + "님이 신청한 선배를 저희 김선배에서 찾고 있어요 !\n" + + "\n" + + "신청해주신 선배를 찾는데에는 3~7일 정도 소요되어요 \uD83D\uDE0A" + ); + + JuniorMatchingWaitingMessage messageBody = new JuniorMatchingWaitingMessage(message, senderKey, juniorMatchingWaiting); + return createCommonRequest(messageBody, request.phoneNumber()); + } + + private CommonRequest createCommonRequest(Message messageBody, String phoneNumber) { String refKey = UUID.randomUUID().toString().replace("-", ""); ContentRequest contentRequest = new ContentRequest(messageBody); - return new CommonRequest(id, "at", number , user.getPhoneNumber(), contentRequest, refKey); + return new CommonRequest(id, "at", number , phoneNumber, contentRequest, refKey); } } diff --git a/src/main/java/com/postgraduate/global/bizppurio/usecase/BizppurioAuth.java b/src/main/java/com/postgraduate/global/bizppurio/application/usecase/BizppurioAuth.java similarity index 94% rename from src/main/java/com/postgraduate/global/bizppurio/usecase/BizppurioAuth.java rename to src/main/java/com/postgraduate/global/bizppurio/application/usecase/BizppurioAuth.java index 34da9681..1b85579a 100644 --- a/src/main/java/com/postgraduate/global/bizppurio/usecase/BizppurioAuth.java +++ b/src/main/java/com/postgraduate/global/bizppurio/application/usecase/BizppurioAuth.java @@ -1,6 +1,6 @@ -package com.postgraduate.global.bizppurio.usecase; +package com.postgraduate.global.bizppurio.application.usecase; -import com.postgraduate.global.bizppurio.dto.res.BizppurioTokenResponse; +import com.postgraduate.global.bizppurio.application.dto.res.BizppurioTokenResponse; import com.postgraduate.global.config.redis.RedisRepository; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; diff --git a/src/main/java/com/postgraduate/global/bizppurio/usecase/BizppurioJuniorMessage.java b/src/main/java/com/postgraduate/global/bizppurio/application/usecase/BizppurioJuniorMessage.java similarity index 54% rename from src/main/java/com/postgraduate/global/bizppurio/usecase/BizppurioJuniorMessage.java rename to src/main/java/com/postgraduate/global/bizppurio/application/usecase/BizppurioJuniorMessage.java index 24bb5287..658e40f2 100644 --- a/src/main/java/com/postgraduate/global/bizppurio/usecase/BizppurioJuniorMessage.java +++ b/src/main/java/com/postgraduate/global/bizppurio/application/usecase/BizppurioJuniorMessage.java @@ -1,8 +1,11 @@ -package com.postgraduate.global.bizppurio.usecase; +package com.postgraduate.global.bizppurio.application.usecase; import com.postgraduate.domain.senior.domain.entity.Senior; import com.postgraduate.domain.user.domain.entity.User; -import com.postgraduate.global.bizppurio.mapper.BizppurioMapper; +import com.postgraduate.global.bizppurio.application.dto.req.JuniorMatchingFailRequest; +import com.postgraduate.global.bizppurio.application.dto.req.JuniorMatchingSuccessRequest; +import com.postgraduate.global.bizppurio.application.dto.req.JuniorMatchingWaitingRequest; +import com.postgraduate.global.bizppurio.application.mapper.BizppurioMapper; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; @@ -32,4 +35,16 @@ public void mentoringRefuse(User user) { public void mentoringFinish(User user) { bizppurioSend.sendMessageWithExceptionHandling(() -> mapper.mapToJuniorFinish(user)); } + + public void matchingWaiting(JuniorMatchingWaitingRequest request) { + bizppurioSend.sendMessageWithExceptionHandling(() -> mapper.mapToJuniorMatchingWaiting(request)); + } + + public void matchingFail(JuniorMatchingFailRequest request) { + bizppurioSend.sendMessageWithExceptionHandling(() -> mapper.mapToJuniorMatchingFail(request)); + } + + public void matchingSuccess(JuniorMatchingSuccessRequest request) { + bizppurioSend.sendMessageWithExceptionHandling(() -> mapper.mapToJuniorMatchingSuccess(request)); + } } diff --git a/src/main/java/com/postgraduate/global/bizppurio/usecase/BizppurioSend.java b/src/main/java/com/postgraduate/global/bizppurio/application/usecase/BizppurioSend.java similarity index 89% rename from src/main/java/com/postgraduate/global/bizppurio/usecase/BizppurioSend.java rename to src/main/java/com/postgraduate/global/bizppurio/application/usecase/BizppurioSend.java index 3c981791..e2f0fab0 100644 --- a/src/main/java/com/postgraduate/global/bizppurio/usecase/BizppurioSend.java +++ b/src/main/java/com/postgraduate/global/bizppurio/application/usecase/BizppurioSend.java @@ -1,8 +1,8 @@ -package com.postgraduate.global.bizppurio.usecase; +package com.postgraduate.global.bizppurio.application.usecase; import com.fasterxml.jackson.databind.ObjectMapper; -import com.postgraduate.global.bizppurio.dto.req.CommonRequest; -import com.postgraduate.global.bizppurio.dto.res.MessageResponse; +import com.postgraduate.global.bizppurio.application.dto.req.CommonRequest; +import com.postgraduate.global.bizppurio.application.dto.res.MessageResponse; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; diff --git a/src/main/java/com/postgraduate/global/bizppurio/usecase/BizppurioSeniorMessage.java b/src/main/java/com/postgraduate/global/bizppurio/application/usecase/BizppurioSeniorMessage.java similarity index 91% rename from src/main/java/com/postgraduate/global/bizppurio/usecase/BizppurioSeniorMessage.java rename to src/main/java/com/postgraduate/global/bizppurio/application/usecase/BizppurioSeniorMessage.java index caa45b47..cfaab53d 100644 --- a/src/main/java/com/postgraduate/global/bizppurio/usecase/BizppurioSeniorMessage.java +++ b/src/main/java/com/postgraduate/global/bizppurio/application/usecase/BizppurioSeniorMessage.java @@ -1,8 +1,8 @@ -package com.postgraduate.global.bizppurio.usecase; +package com.postgraduate.global.bizppurio.application.usecase; import com.postgraduate.domain.senior.domain.entity.Senior; import com.postgraduate.domain.user.domain.entity.User; -import com.postgraduate.global.bizppurio.mapper.BizppurioMapper; +import com.postgraduate.global.bizppurio.application.mapper.BizppurioMapper; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; diff --git a/src/main/java/com/postgraduate/global/bizppurio/dto/req/ContentRequest.java b/src/main/java/com/postgraduate/global/bizppurio/dto/req/ContentRequest.java deleted file mode 100644 index 1399c6d7..00000000 --- a/src/main/java/com/postgraduate/global/bizppurio/dto/req/ContentRequest.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.postgraduate.global.bizppurio.dto.req; - -import com.postgraduate.global.bizppurio.dto.req.content.Message; - -public record ContentRequest(Message at) {} diff --git a/src/main/java/com/postgraduate/global/bizppurio/dto/req/content/Message.java b/src/main/java/com/postgraduate/global/bizppurio/dto/req/content/Message.java deleted file mode 100644 index 1087ab3e..00000000 --- a/src/main/java/com/postgraduate/global/bizppurio/dto/req/content/Message.java +++ /dev/null @@ -1,4 +0,0 @@ -package com.postgraduate.global.bizppurio.dto.req.content; - -public interface Message { -} diff --git a/src/main/java/com/postgraduate/global/bizppurio/presantation/BizppurioController.java b/src/main/java/com/postgraduate/global/bizppurio/presantation/BizppurioController.java new file mode 100644 index 00000000..493bd2be --- /dev/null +++ b/src/main/java/com/postgraduate/global/bizppurio/presantation/BizppurioController.java @@ -0,0 +1,39 @@ +package com.postgraduate.global.bizppurio.presantation; + +import com.postgraduate.global.bizppurio.application.dto.req.JuniorMatchingFailRequest; +import com.postgraduate.global.bizppurio.application.dto.req.JuniorMatchingSuccessRequest; +import com.postgraduate.global.bizppurio.application.dto.req.JuniorMatchingWaitingRequest; +import com.postgraduate.global.bizppurio.application.usecase.BizppurioJuniorMessage; +import com.postgraduate.global.dto.ResponseDto; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequiredArgsConstructor +@RequestMapping("/bizppurio") +@Tag(name = "BIZPPURIO Controller", description = "알림톡 수동 전송용 API (관리자 권한 필요)") +public class BizppurioController { + private final BizppurioJuniorMessage bizppurioJuniorMessage; + + @PostMapping("/matching/waiting") + public ResponseDto matchingWaiting(@RequestBody JuniorMatchingWaitingRequest request) { + bizppurioJuniorMessage.matchingWaiting(request); + return ResponseDto.create("200", request.phoneNumber() + " 번호로 " + request.name() + " 님께 알림톡 전송 완료"); + } + + @PostMapping("/matching/fail") + public ResponseDto matchingFail(@RequestBody JuniorMatchingFailRequest request) { + bizppurioJuniorMessage.matchingFail(request); + return ResponseDto.create("200", request.phoneNumber() + " 번호로 " + request.name() + " 님께 알림톡 전송 완료"); + } + + @PostMapping("/matching/success") + public ResponseDto matchingSuccess(@RequestBody JuniorMatchingSuccessRequest request) { + bizppurioJuniorMessage.matchingSuccess(request); + return ResponseDto.create("200", request.phoneNumber() + " 번호로 " + request.name() + " 님께 알림톡 전송 완료"); + } +} diff --git a/src/main/java/com/postgraduate/global/config/security/SecurityConfig.java b/src/main/java/com/postgraduate/global/config/security/SecurityConfig.java index 54e52475..b0ea38a9 100644 --- a/src/main/java/com/postgraduate/global/config/security/SecurityConfig.java +++ b/src/main/java/com/postgraduate/global/config/security/SecurityConfig.java @@ -58,7 +58,8 @@ protected SecurityFilterChain config(HttpSecurity http) throws Exception { .requestMatchers("/admin/**").hasAuthority(Role.ADMIN.name()) .requestMatchers("/adminServer/loginForm").permitAll() .requestMatchers("/adminServer/login").permitAll() - .requestMatchers("adminServer/**").hasAuthority(Role.ADMIN.name()) + .requestMatchers("/adminServer/**").hasAuthority(Role.ADMIN.name()) + .requestMatchers("/bizppurio/**").hasAuthority(Role.ADMIN.name()) .requestMatchers(HttpMethod.PATCH, "/senior/**").hasAuthority(Role.SENIOR.name()) .requestMatchers(HttpMethod.POST, "/senior/**").hasAuthority(Role.SENIOR.name()) .requestMatchers("/senior/me/**").hasAuthority(Role.SENIOR.name()) diff --git a/src/main/java/com/postgraduate/global/slack/SlackErrorMessage.java b/src/main/java/com/postgraduate/global/slack/SlackErrorMessage.java index 2becea32..b50e130e 100644 --- a/src/main/java/com/postgraduate/global/slack/SlackErrorMessage.java +++ b/src/main/java/com/postgraduate/global/slack/SlackErrorMessage.java @@ -38,6 +38,44 @@ public void sendSlackError(Mentoring mentoring, Exception ex) { } } + public void sendSlackMentoringError(Long mentoringId, Throwable ex) { + try { + slackClient.send(logWebHookUrl, Payload.builder() + .text("멘토링 자동 갱신 에러 발생!! 백엔드팀 확인 요망!!") + .attachments( + List.of(generateMentoringErrorSlackAttachment(mentoringId, ex)) + ) + .build()); + } catch (IOException e) { + log.error("slack 전송 오류"); + } + } + + public void sendSlackSalaryError(Long seniorId, Throwable ex) { + try { + slackClient.send(logWebHookUrl, Payload.builder() + .text("정산 자동 생성 에러 발생!! 백엔드팀 확인 요망!!") + .attachments( + List.of(generateSalaryErrorSlackAttachment(seniorId, ex)) + ) + .build()); + } catch (IOException e) { + log.error("slack 전송 오류"); + } + } + + private Attachment generateMentoringErrorSlackAttachment(Long mentoringId, Throwable ex) { + String requestTime = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:SS").format(LocalDateTime.now()); + return Attachment.builder() + .color("ff0000") + .title(requestTime + "에 발생한 에러 로그") + .fields(List.of( + generateSlackField("Error Message", ex.getMessage()), + generateSlackField("Mentoring 번호", String.valueOf(mentoringId)) + )) + .build(); + } + private Attachment generateErrorSlackAttachment(Mentoring mentoring, Exception ex) { String requestTime = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:SS").format(LocalDateTime.now()); return Attachment.builder() @@ -49,4 +87,16 @@ private Attachment generateErrorSlackAttachment(Mentoring mentoring, Exception e )) .build(); } + + private Attachment generateSalaryErrorSlackAttachment(Long seniorId, Throwable ex) { + String requestTime = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:SS").format(LocalDateTime.now()); + return Attachment.builder() + .color("ff0000") + .title(requestTime + "에 발생한 에러 로그") + .fields(List.of( + generateSlackField("Error Message", ex.getMessage()), + generateSlackField("정산 자동 생성 실패, 선배 번호", String.valueOf(seniorId)) + )) + .build(); + } } diff --git a/src/test/java/com/postgraduate/Integration/AuthControllerTest.java b/src/test/java/com/postgraduate/Integration/AuthControllerTest.java index 5de6f65e..eb4bc06e 100644 --- a/src/test/java/com/postgraduate/Integration/AuthControllerTest.java +++ b/src/test/java/com/postgraduate/Integration/AuthControllerTest.java @@ -2,10 +2,11 @@ import com.postgraduate.domain.auth.application.dto.req.*; import com.postgraduate.domain.auth.application.dto.res.KakaoUserInfoResponse; +import com.postgraduate.domain.senior.domain.entity.Senior; import com.postgraduate.domain.user.domain.entity.User; import com.postgraduate.domain.wish.domain.entity.Wish; -import com.postgraduate.domain.wish.domain.entity.constant.Status; import com.postgraduate.support.IntegrationTest; +import com.postgraduate.support.Resource; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -27,7 +28,6 @@ import static com.postgraduate.domain.user.presentation.constant.UserResponseMessage.NOT_FOUND_USER; import static com.postgraduate.global.constant.ErrorCode.VALID_BLANK; import static java.lang.Boolean.FALSE; -import static java.time.LocalDateTime.now; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.when; @@ -36,15 +36,25 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; class AuthControllerTest extends IntegrationTest { + private Resource resource = new Resource(); private static final String AUTHORIZATION = "Authorization"; private static final String BEARER = "Bearer "; private User user; - private final Long anonymousUserSocialId = 2L; + private Wish wish; + private User seniorUser; + private Senior senior; + private final Long anonymousUserSocialId = -5L; @BeforeEach void setUp() { - user = new User(0L, 1L, "mail", "후배", "011", "profile", 0, USER, true, now(), now(), false); + user = resource.getUser(); userRepository.save(user); + wish = resource.getWish(); + wishRepository.save(wish); + seniorUser = resource.getSeniorUser(); + userRepository.save(seniorUser); + senior = resource.getSenior(); + seniorRepository.save(senior); doNothing().when(slackLogErrorMessage).sendSlackLog(any()); doNothing().when(slackSignUpMessage).sendSeniorSignUp(any()); doNothing().when(slackSignUpMessage).sendJuniorSignUp(any(), any()); @@ -53,14 +63,11 @@ void setUp() { @Test @DisplayName("회원이 로그인한다.") void authLoginByUser() throws Exception { - Wish wish = new Wish(0L, "major", "field", true, user, Status.MATCHED); - wishRepository.save(wish); - CodeRequest codeRequest = new CodeRequest("code"); String request = objectMapper.writeValueAsString(codeRequest); when(kakaoAccessTokenUseCase.getAccessToken(codeRequest)) - .thenReturn(new KakaoUserInfoResponse(1L, any())); + .thenReturn(new KakaoUserInfoResponse(user.getSocialId(), any())); mvc.perform(post("/auth/login/KAKAO") .content(request) @@ -151,9 +158,6 @@ void signUpUserWithoutWish(String empty) throws Exception { @Test @DisplayName("대학원생이 대학생으로 변경한다.") void changeUserToken() throws Exception { - Wish wish = new Wish(0L, "major", "field", true, user, Status.MATCHED); - wishRepository.save(wish); - String token = jwtUtil.generateAccessToken(user.getUserId(), SENIOR); mvc.perform(post("/auth/user/token") @@ -168,7 +172,7 @@ void changeUserToken() throws Exception { @Test @DisplayName("대학생으로 가입하지 않은 경우 대학생으로 변경할 수 없다.") void changeUserTokenWithoutWish() throws Exception { - String token = jwtUtil.generateAccessToken(user.getUserId(), SENIOR); + String token = jwtUtil.generateAccessToken(seniorUser.getUserId(), SENIOR); mvc.perform(post("/auth/user/token") .header(AUTHORIZATION, BEARER + token)) @@ -180,7 +184,7 @@ void changeUserTokenWithoutWish() throws Exception { @Test @DisplayName("선배가 후배로 추가 가입합니다.") void changeUser() throws Exception { - String seniorAccessToken = jwtUtil.generateAccessToken(user.getUserId(), SENIOR); + String seniorAccessToken = jwtUtil.generateAccessToken(seniorUser.getUserId(), SENIOR); String request = objectMapper.writeValueAsString( new UserChangeRequest("major", "field", true) @@ -202,7 +206,7 @@ void changeUser() throws Exception { @NullAndEmptySource @DisplayName("전공과 분야가 없어도 후배로 추가 가입할 수 있다") void changeUser(String empty) throws Exception { - String seniorAccessToken = jwtUtil.generateAccessToken(user.getUserId(), SENIOR); + String seniorAccessToken = jwtUtil.generateAccessToken(seniorUser.getUserId(), SENIOR); String request = objectMapper.writeValueAsString( new UserChangeRequest(empty, empty, FALSE) @@ -299,10 +303,7 @@ void changeSenior(String empty) throws Exception { @Test @DisplayName("대학생이 대학원생으로 변경한다.") void changeSeniorToken() throws Exception { - User senior = new User(0L, 2L, "mail", "선배", "011", "profile", 0, SENIOR, true, now(), now(), false); - userRepository.save(senior); - - String token = jwtUtil.generateAccessToken(senior.getUserId(), USER); + String token = jwtUtil.generateAccessToken(seniorUser.getUserId(), USER); mvc.perform(post("/auth/senior/token") .header(AUTHORIZATION, BEARER + token)) @@ -328,9 +329,6 @@ void changeSeniorTokenWithoutWish() throws Exception { @Test @DisplayName("토큰을 재발급한다.") void refresh() throws Exception { - Wish wish = new Wish(0L, "major", "field", true, user, Status.MATCHED); - wishRepository.save(wish); - String refreshToken = jwtUtil.generateRefreshToken(user.getUserId(), USER); when(redisRepository.getValues(any())).thenReturn(Optional.of(refreshToken)); diff --git a/src/test/java/com/postgraduate/Integration/MentoringControllerTest.java b/src/test/java/com/postgraduate/Integration/MentoringControllerTest.java index 0ecf6e89..826af822 100644 --- a/src/test/java/com/postgraduate/Integration/MentoringControllerTest.java +++ b/src/test/java/com/postgraduate/Integration/MentoringControllerTest.java @@ -6,14 +6,13 @@ import com.postgraduate.domain.payment.domain.entity.Payment; import com.postgraduate.domain.refuse.application.dto.req.MentoringRefuseRequest; import com.postgraduate.domain.salary.domain.entity.Salary; -import com.postgraduate.domain.salary.domain.entity.SalaryAccount; import com.postgraduate.domain.senior.domain.entity.Info; -import com.postgraduate.domain.senior.domain.entity.Profile; import com.postgraduate.domain.senior.domain.entity.Senior; import com.postgraduate.domain.user.domain.entity.User; import com.postgraduate.domain.user.domain.entity.constant.Role; import com.postgraduate.global.constant.ErrorCode; import com.postgraduate.support.IntegrationTest; +import com.postgraduate.support.Resource; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -23,14 +22,11 @@ import org.springframework.http.MediaType; import java.io.IOException; -import java.time.LocalDateTime; import static com.postgraduate.domain.auth.presentation.constant.AuthResponseCode.AUTH_DENIED; import static com.postgraduate.domain.auth.presentation.constant.AuthResponseMessage.PERMISSION_DENIED; import static com.postgraduate.domain.mentoring.presentation.constant.MentoringResponseCode.*; import static com.postgraduate.domain.mentoring.presentation.constant.MentoringResponseMessage.*; -import static com.postgraduate.domain.payment.domain.entity.constant.Status.DONE; -import static com.postgraduate.domain.salary.util.SalaryUtil.getSalaryDate; import static com.postgraduate.domain.senior.domain.entity.constant.Status.WAITING; import static java.time.LocalDateTime.now; import static org.mockito.ArgumentMatchers.any; @@ -41,10 +37,14 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; class MentoringControllerTest extends IntegrationTest { + private Resource resource = new Resource(); private static final String AUTHORIZATION = "Authorization"; private static final String BEARER = "Bearer "; private User user; + private User seniorUser; + private User otherUser; private Senior senior; + private Senior otherSenior; private Payment payment; private Salary salary; private String userAccessToken; @@ -52,26 +52,29 @@ class MentoringControllerTest extends IntegrationTest { @BeforeEach void setUp() throws IOException { - user = new User(0L, 1L, "mail", "후배", "011", "profile", 0, Role.USER, true, now(), now(), false); + user = resource.getUser(); userRepository.save(user); - User userOfSenior = new User(0L, 2L, "mail", "선배", "012", "profile", 0, Role.SENIOR, true, now(), now(), false); - userRepository.save(userOfSenior); + seniorUser = resource.getSeniorUser(); + userRepository.save(seniorUser); - Info info = new Info("major", "서울대학교", "교수님", "키워드1,키워드2", "랩실", "인공지능", false, false, "인공지능,키워드1,키워드2", "chatLink", 30); - Profile profile = new Profile("저는요", "한줄소개", "대상"); - senior = new Senior(0L, userOfSenior, "certification", WAITING, 0, info, profile, now(), now()); + otherUser = resource.getOtherUser(); + userRepository.save(otherUser); + + senior = resource.getSenior(); seniorRepository.save(senior); - SalaryAccount salaryAccount = new SalaryAccount("bank", "1234", "holder"); - salary = new Salary(0L, false, senior, 20000, getSalaryDate(), LocalDateTime.now(), salaryAccount); + otherSenior = resource.getOtherSenior(); + seniorRepository.save(otherSenior); + + salary = resource.getSalary(); salaryRepository.save(salary); - payment = new Payment(0L, user, senior, 20000, "1", "123", "123", LocalDateTime.now(), LocalDateTime.now(), DONE); + payment = resource.getPayment(); paymentRepository.save(payment); userAccessToken = jwtUtil.generateAccessToken(user.getUserId(), Role.USER); - seniorAccessToken = jwtUtil.generateAccessToken(userOfSenior.getUserId(), Role.SENIOR); + seniorAccessToken = jwtUtil.generateAccessToken(seniorUser.getUserId(), Role.SENIOR); doNothing().when(slackLogErrorMessage).sendSlackLog(any()); } @@ -80,7 +83,7 @@ void setUp() throws IOException { @EnumSource(value = Status.class, names = {"WAITING", "DONE"}) @DisplayName("대학생이 확정대기 및 완료 상태의 멘토링 목록을 조회한다") void getWaitingMentorings(Status status) throws Exception { - Mentoring mentoring = new Mentoring(0L, user, senior, payment, salary, "topic", "question", "date", 40, status, now(), now()); + Mentoring mentoring = new Mentoring(-1L, user, senior, payment, salary, "topic", "question", "date", 40, status, now(), now()); mentoringRepository.save(mentoring); mvc.perform(get("/mentoring/me/{status}", status.name().toLowerCase()) @@ -95,7 +98,7 @@ void getWaitingMentorings(Status status) throws Exception { @Test @DisplayName("대학생이 예정된 멘토링 목록을 조회한다") void getExpectedMentorings() throws Exception { - Mentoring mentoring = new Mentoring(0L, user, senior, payment, null, "topic", "question", "date", 40, Status.EXPECTED, now(), now()); + Mentoring mentoring = new Mentoring(-1L, user, senior, payment, null, "topic", "question", "date", 40, Status.EXPECTED, now(), now()); mentoringRepository.save(mentoring); mvc.perform(get("/mentoring/me/expected") @@ -110,7 +113,7 @@ void getExpectedMentorings() throws Exception { @EnumSource(value = Status.class, names = {"WAITING", "EXPECTED"}) @DisplayName("대학생이 멘토링을 상세조회한다.") void getMentoringDetail(Status status) throws Exception { - Mentoring mentoring = new Mentoring(0L, user, senior, payment, null, "topic", "question", "date", 40, status, now(), now()); + Mentoring mentoring = new Mentoring(-1L, user, senior, payment, null, "topic", "question", "date", 40, status, now(), now()); mentoringRepository.save(mentoring); mvc.perform(get("/mentoring/me/{mentoringId}", mentoring.getMentoringId()) @@ -124,9 +127,7 @@ void getMentoringDetail(Status status) throws Exception { @Test @DisplayName("자신이 신청한 멘토링이 아니라면 상세조회되지 않는다") void getOtherMentoringDetail() throws Exception { - User otherUser = new User(-1L, 0L, "mail", "다른 후배", "011", "profile", 0, Role.USER, true, now(), now(), false); - userRepository.save(otherUser); - Mentoring mentoring = new Mentoring(0L, otherUser, senior, payment, null, "topic", "question", "date", 40, Status.EXPECTED, now(), now()); + Mentoring mentoring = new Mentoring(-1L, otherUser, senior, payment, null, "topic", "question", "date", 40, Status.EXPECTED, now(), now()); mentoringRepository.save(mentoring); mvc.perform(get("/mentoring/me/{mentoringId}", mentoring.getMentoringId()) @@ -141,7 +142,7 @@ void getOtherMentoringDetail() throws Exception { @EnumSource(value = Status.class, names = {"DONE", "CANCEL", "REFUSE"}) @DisplayName("대학생의 완료, 취소, 거절 상태의 멘토링은 상세조회되지 않는다.") void getDoneMentoringDetail(Status status) throws Exception { - Mentoring mentoring = new Mentoring(0L, user, senior, payment, null, "topic", "question", "date", 40, status, now(), now()); + Mentoring mentoring = new Mentoring(-1L, user, senior, payment, null, "topic", "question", "date", 40, status, now(), now()); mentoringRepository.save(mentoring); mvc.perform(get("/mentoring/me/{mentoringId}", mentoring.getMentoringId()) @@ -203,7 +204,7 @@ void getDoneMentoringDetail(Status status) throws Exception { @Test @DisplayName("대학생이 멘토링을 완료한다.") void updateMentoringDone() throws Exception { - Mentoring mentoring = new Mentoring(0L, user, senior, payment, null, "topic", "question", "date", 40, Status.EXPECTED, now(), now()); + Mentoring mentoring = new Mentoring(-1L, user, senior, payment, null, "topic", "question", "date", 40, Status.EXPECTED, now(), now()); mentoringRepository.save(mentoring); mvc.perform(patch("/mentoring/me/{mentoringId}/done", mentoring.getMentoringId()) @@ -217,13 +218,9 @@ void updateMentoringDone() throws Exception { @EnumSource(value = Status.class, names = {"WAITING", "DONE", "CANCEL", "REFUSE"}) @DisplayName("진행예정이 아닌 멘토링의 경우 완료할 수 없다.") void updateMentoringDoneWithoutExpected(Status status) throws Exception { - Mentoring mentoring = new Mentoring(0L, user, senior, payment, null, "topic", "question", "date", 40, status, now(), now()); + Mentoring mentoring = new Mentoring(-1L, user, senior, payment, null, "topic", "question", "date", 40, status, now(), now()); mentoringRepository.save(mentoring); - SalaryAccount salaryAccount = new SalaryAccount("bank", "1234", "holder"); - Salary salary = new Salary(0L, false, senior, 10000, getSalaryDate(), now(), salaryAccount); - salaryRepository.save(salary); - mvc.perform(patch("/mentoring/me/{mentoringId}/done", mentoring.getMentoringId()) .header(AUTHORIZATION, BEARER + userAccessToken)) .andExpect(status().isOk()) @@ -249,7 +246,7 @@ void updateMentoringDoneWithoutExpected(Status status) throws Exception { @EnumSource(value = Status.class, names = {"EXPECTED", "DONE", "CANCEL", "REFUSE"}) @DisplayName("멘토링이 확정대기 상태가 아니라면 취소할 수 없다.") void updateMentoringCancelWithoutWaiting(Status status) throws Exception { - Mentoring mentoring = new Mentoring(0L, user, senior, payment, null, "topic", "question", "date", 40, status, now(), now()); + Mentoring mentoring = new Mentoring(-1L, user, senior, payment, null, "topic", "question", "date", 40, status, now(), now()); mentoringRepository.save(mentoring); mvc.perform(patch("/mentoring/me/{mentoringId}/cancel", mentoring.getMentoringId()) @@ -263,7 +260,7 @@ void updateMentoringCancelWithoutWaiting(Status status) throws Exception { @EnumSource(value = Status.class, names = {"WAITING", "EXPECTED", "DONE"}) @DisplayName("대학원생이 멘토링 목록을 조회한다.") void getSeniorMentorings(Status status) throws Exception { - Mentoring mentoring = new Mentoring(0L, user, senior, payment, salary, "topic", "question", "2024-01-20-18-00", 40, status, now(), now()); + Mentoring mentoring = new Mentoring(-1L, user, senior, payment, salary, "topic", "question", "2024-01-20-18-00", 40, status, now(), now()); mentoringRepository.save(mentoring); mvc.perform(get("/mentoring/senior/me/{status}", status.name().toLowerCase()) @@ -278,7 +275,7 @@ void getSeniorMentorings(Status status) throws Exception { @EnumSource(value = Status.class, names = {"WAITING", "EXPECTED"}) @DisplayName("대학원생이 멘토링을 상세조회합니다.") void getSeniorMentoringDetails(Status status) throws Exception { - Mentoring mentoring = new Mentoring(0L, user, senior, payment, null, "topic", "question", "date", 40, status, now(), now()); + Mentoring mentoring = new Mentoring(-1L, user, senior, payment, null, "topic", "question", "date", 40, status, now(), now()); mentoringRepository.save(mentoring); mvc.perform(get("/mentoring/senior/me/{mentoringId}", mentoring.getMentoringId()) @@ -293,14 +290,7 @@ void getSeniorMentoringDetails(Status status) throws Exception { @Test @DisplayName("자신이 신청받은 멘토링이 아니라면 상세조회되지 않는다") void getOtherSeniorMentoringDetail() throws Exception { - User otherUser = new User(-1L, 0L, "mail", "다른 후배", "011", "profile", 0, Role.USER, true, now(), now(), false); - userRepository.save(otherUser); - - Info info = new Info("major", "서울대학교", "교수님", "키워드1,키워드2", "랩실", "인공지능", false, false, "인공지능,키워드1,키워드2", "chatLink", 30); - Senior otherSenior = new Senior(-1L, otherUser, "certification", WAITING, 0, info, null, now(), now()); - seniorRepository.save(otherSenior); - - Mentoring mentoring = new Mentoring(0L, otherUser, otherSenior, payment, null, "topic", "question", "date", 40, Status.EXPECTED, now(), now()); + Mentoring mentoring = new Mentoring(-1L, otherUser, otherSenior, payment, null, "topic", "question", "date", 40, Status.EXPECTED, now(), now()); mentoringRepository.save(mentoring); mvc.perform(get("/mentoring/senior/me/{mentoringId}", mentoring.getMentoringId()) @@ -314,7 +304,7 @@ void getOtherSeniorMentoringDetail() throws Exception { @EnumSource(value = Status.class, names = {"DONE", "CANCEL", "REFUSE"}) @DisplayName("대학원생의 완료, 취소, 거절 상태의 멘토링은 상세조회되지 않는다.") void doNotGetMentoringDetails(Status status) throws Exception { - Mentoring mentoring = new Mentoring(0L, user, senior, payment, null, "topic", "question", "date", 40, status, now(), now()); + Mentoring mentoring = new Mentoring(-1L, user, senior, payment, null, "topic", "question", "date", 40, status, now(), now()); mentoringRepository.save(mentoring); mvc.perform(get("/mentoring/senior/me/{mentoringId}", mentoring.getMentoringId()) @@ -327,7 +317,7 @@ void doNotGetMentoringDetails(Status status) throws Exception { @Test @DisplayName("대학원생이 멘토링을 수락한다.") void updateSeniorMentoringExpected() throws Exception { - Mentoring mentoring = new Mentoring(0L, user, senior, payment, null, "topic", "question", "2024-04-18-18-00,2024-04-18-18-00,2024-04-18-18-00", 40, Status.WAITING, now(), now()); + Mentoring mentoring = new Mentoring(-1L, user, senior, payment, null, "topic", "question", "2024-04-18-18-00,2024-04-18-18-00,2024-04-18-18-00", 40, Status.WAITING, now(), now()); mentoringRepository.save(mentoring); String request = objectMapper.writeValueAsString(new MentoringDateRequest("2024-04-18-18-00")); @@ -345,7 +335,7 @@ void updateSeniorMentoringExpected() throws Exception { @EnumSource(value = Status.class, names = {"EXPECTED", "DONE", "CANCEL", "REFUSE"}) @DisplayName("멘토링이 확정대기 상태가 아니라면 수락할 수 없다.") void updateSeniorMentoringExpectedWithoutWaiting(Status status) throws Exception { - Mentoring mentoring = new Mentoring(0L, user, senior, payment, null, "topic", "question", "date1,date2,date3", 40, status, now(), now()); + Mentoring mentoring = new Mentoring(-1L, user, senior, payment, null, "topic", "question", "date1,date2,date3", 40, status, now(), now()); mentoringRepository.save(mentoring); String request = objectMapper.writeValueAsString(new MentoringDateRequest("date1")); @@ -363,7 +353,7 @@ void updateSeniorMentoringExpectedWithoutWaiting(Status status) throws Exception @NullAndEmptySource @DisplayName("확정날짜가 비어있다면 멘토링을 수락할 수 없다") void updateSeniorMentoringExpectedWithoutDate(String empty) throws Exception { - Mentoring mentoring = new Mentoring(0L, user, senior, payment, null, "topic", "question", "date1,date2,date3", 40, Status.WAITING, now(), now()); + Mentoring mentoring = new Mentoring(-1L, user, senior, payment, null, "topic", "question", "date1,date2,date3", 40, Status.WAITING, now(), now()); mentoringRepository.save(mentoring); String request = objectMapper.writeValueAsString(new MentoringDateRequest(empty)); @@ -398,7 +388,7 @@ void updateSeniorMentoringExpectedWithoutDate(String empty) throws Exception { @EnumSource(value = Status.class, names = {"EXPECTED", "DONE", "CANCEL", "REFUSE"}) @DisplayName("멘토링이 확정대기 상태가 아니라면 거절할 수 없다.") void updateSeniorMentoringRefuseWithoutWaiting(Status status) throws Exception { - Mentoring mentoring = new Mentoring(0L, user, senior, payment, null, "topic", "question", "date", 40, status, now(), now()); + Mentoring mentoring = new Mentoring(-1L, user, senior, payment, null, "topic", "question", "date", 40, status, now(), now()); mentoringRepository.save(mentoring); String request = objectMapper.writeValueAsString(new MentoringRefuseRequest("reason")); @@ -416,7 +406,7 @@ void updateSeniorMentoringRefuseWithoutWaiting(Status status) throws Exception { @NullAndEmptySource @DisplayName("사유가 비어있다면 멘토링을 거절할 수 없다") void updateSeniorMentoringExpectedWithoutRefuse(String empty) throws Exception { - Mentoring mentoring = new Mentoring(0L, user, senior, payment, null, "topic", "question", "date1,date2,date3", 40, Status.WAITING, now(), now()); + Mentoring mentoring = new Mentoring(-1L, user, senior, payment, null, "topic", "question", "date1,date2,date3", 40, Status.WAITING, now(), now()); mentoringRepository.save(mentoring); String request = objectMapper.writeValueAsString(new MentoringRefuseRequest(empty)); diff --git a/src/test/java/com/postgraduate/Integration/SalaryControllerTest.java b/src/test/java/com/postgraduate/Integration/SalaryControllerTest.java index 6011c3a1..3cbb058a 100644 --- a/src/test/java/com/postgraduate/Integration/SalaryControllerTest.java +++ b/src/test/java/com/postgraduate/Integration/SalaryControllerTest.java @@ -1,15 +1,11 @@ package com.postgraduate.Integration; import com.postgraduate.domain.salary.domain.entity.Salary; -import com.postgraduate.domain.salary.domain.entity.SalaryAccount; -import com.postgraduate.domain.salary.util.SalaryUtil; -import com.postgraduate.domain.senior.domain.entity.Info; -import com.postgraduate.domain.senior.domain.entity.Profile; import com.postgraduate.domain.senior.domain.entity.Senior; -import com.postgraduate.domain.senior.domain.entity.constant.Status; import com.postgraduate.domain.user.domain.entity.User; import com.postgraduate.domain.user.domain.entity.constant.Role; import com.postgraduate.support.IntegrationTest; +import com.postgraduate.support.Resource; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -19,7 +15,6 @@ import static com.postgraduate.domain.salary.presentation.constant.SalaryResponseCode.SALARY_FIND; import static com.postgraduate.domain.salary.presentation.constant.SalaryResponseCode.SALARY_NOT_FOUND; import static com.postgraduate.domain.salary.presentation.constant.SalaryResponseMessage.*; -import static java.time.LocalDateTime.now; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doNothing; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; @@ -27,24 +22,27 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; class SalaryControllerTest extends IntegrationTest { + private Resource resource = new Resource(); private static final String AUTHORIZATION = "Authorization"; private static final String BEARER = "Bearer "; private String token; private Salary salary; + private User user; + private User otherUser; + private User seniorUser; + private Senior senior; + private Senior otherSenior; @BeforeEach void setUp() throws IOException { - User user = new User(0L, 1L, "mail", "후배", "011", "profile", 0, Role.SENIOR, true, now(), now(), false); + user = resource.getSeniorUser(); userRepository.save(user); - Info info = new Info("major", "postgradu", "교수님", "keyword1,keyword2", "랩실", "field", false, false, "field,keyword1,keyword2", "chatLink", 30); - Profile profile = new Profile("저는요", "한줄소개", "대상"); - Senior senior = new Senior(0L, user, "certification", Status.APPROVE, 0, info, profile, now(), now()); + senior = resource.getSenior(); seniorRepository.save(senior); - SalaryAccount salaryAccount = new SalaryAccount("bank", "1234", "holder"); - salary = new Salary(0L, false, senior, 0, SalaryUtil.getSalaryDate(), null, salaryAccount); + salary = resource.getSalary(); salaryRepository.save(salary); token = jwtUtil.generateAccessToken(user.getUserId(), Role.SENIOR); diff --git a/src/test/java/com/postgraduate/Integration/SeniorControllerTest.java b/src/test/java/com/postgraduate/Integration/SeniorControllerTest.java index 27288a5b..720d2e97 100644 --- a/src/test/java/com/postgraduate/Integration/SeniorControllerTest.java +++ b/src/test/java/com/postgraduate/Integration/SeniorControllerTest.java @@ -4,24 +4,20 @@ import com.postgraduate.domain.available.application.dto.req.AvailableCreateRequest; import com.postgraduate.domain.available.domain.entity.Available; import com.postgraduate.domain.salary.domain.entity.Salary; -import com.postgraduate.domain.salary.domain.entity.SalaryAccount; import com.postgraduate.domain.senior.application.dto.req.*; -import com.postgraduate.domain.senior.domain.entity.Info; -import com.postgraduate.domain.senior.domain.entity.Profile; import com.postgraduate.domain.senior.domain.entity.Senior; -import com.postgraduate.domain.senior.domain.entity.constant.Status; import com.postgraduate.domain.senior.presentation.constant.SeniorResponseCode; import com.postgraduate.domain.senior.presentation.constant.SeniorResponseMessage; import com.postgraduate.domain.user.domain.entity.User; import com.postgraduate.domain.user.domain.entity.constant.Role; import com.postgraduate.global.constant.ErrorCode; import com.postgraduate.support.IntegrationTest; +import com.postgraduate.support.Resource; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.EmptySource; -import org.junit.jupiter.params.provider.EnumSource; import org.junit.jupiter.params.provider.NullAndEmptySource; import org.springframework.http.MediaType; import org.springframework.security.test.context.support.WithMockUser; @@ -30,12 +26,10 @@ import java.util.ArrayList; import java.util.List; -import static com.postgraduate.domain.salary.util.SalaryUtil.getSalaryDate; import static com.postgraduate.domain.senior.presentation.constant.SeniorResponseCode.*; import static com.postgraduate.domain.senior.presentation.constant.SeniorResponseMessage.*; import static java.lang.Boolean.FALSE; import static java.lang.Boolean.TRUE; -import static java.time.LocalDateTime.now; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doNothing; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; @@ -43,55 +37,45 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; class SeniorControllerTest extends IntegrationTest { + private Resource resource = new Resource(); private static final String AUTHORIZATION = "Authorization"; private static final String BEARER = "Bearer "; private Senior senior; private Senior otherSenior; private String token; - private String seniorToken; + private String otherSeniorToken; private String userToken; private User user; private User otherUser; - private SalaryAccount salaryAccount; @BeforeEach void setUp() throws IOException { - user = new User(-2L, 1L, "mail", "후배1", "011", "profile", 0, Role.SENIOR, true, now(), now(), false); - otherUser = new User(-1L, 1234L, "mail", "후배2", "011", "profile", 0, Role.SENIOR, true, now(), now(), false); + user = resource.getUser(); userRepository.save(user); + + User seniorUser = resource.getSeniorUser(); + userRepository.save(seniorUser); + + otherUser = resource.getOtherUser(); userRepository.save(otherUser); - Info info1 = new Info("major", "postgradu", "교수님", "keyword1,keyword2", "랩실", "field", false, false, "field,keyword1,keyword2", "chatLink", 30); - Profile profile1 = new Profile("info", "one", "u"); - senior = new Senior(-2L, user, "certification", Status.APPROVE, 0, info1, profile1, now(), now()); + senior = resource.getSenior(); seniorRepository.save(senior); - Info info2 = new Info("major", "postgradu", "교수님", "keyword1,keyword2", "랩실", "field", false, false, "field,keyword1,keyword2", "chatLink", 30); - otherSenior = new Senior(-1L, otherUser, "certification", Status.APPROVE, 0, info2, null, now(), now()); + otherSenior = resource.getOtherSenior(); seniorRepository.save(otherSenior); - token = jwtUtil.generateAccessToken(user.getUserId(), Role.SENIOR); - seniorToken = jwtUtil.generateAccessToken(otherUser.getUserId(), Role.SENIOR); - userToken = jwtUtil.generateAccessToken(otherUser.getUserId(), Role.USER); - - salaryAccount = new SalaryAccount("신한은행", "1234", "김모씨"); - doNothing().when(slackLogErrorMessage).sendSlackLog(any()); - } + Salary salary = resource.getSalary(); + salaryRepository.save(salary); + List availables = resource.getAvailables(); + availableRepository.saveAll(availables); - private void updateProfile() { - Profile profile = new Profile("저는요", "한줄소개", "대상"); - senior.updateProfile(profile); - seniorRepository.save(senior); - } + token = jwtUtil.generateAccessToken(senior.getUser().getUserId(), Role.SENIOR); + otherSeniorToken = jwtUtil.generateAccessToken(otherSenior.getUser().getUserId(), Role.SENIOR); + userToken = jwtUtil.generateAccessToken(user.getUserId(), Role.USER); - private void updateAvailable() { - List availables = List.of( - new Available(0L, "월", "17:00", "23:00", senior), - new Available(0L, "금", "10:00", "20:00", senior), - new Available(0L, "토", "10:00", "20:00", senior) - ); - availableRepository.saveAll(availables); + doNothing().when(slackLogErrorMessage).sendSlackLog(any()); } @Test @@ -192,11 +176,8 @@ void InvalidDay() throws Exception { @Test @DisplayName("대학원생 정산 계좌를 생성한다") void updateAccount() throws Exception { - Salary salary = new Salary(0L, false, senior, 10000, getSalaryDate(), now(), null); - salaryRepository.save(salary); - String request = objectMapper.writeValueAsString( - new SeniorAccountRequest("농협", "주인", "123123123456") + new SeniorAccountRequest("123123123456", "농협", "주인") ); mvc.perform(post("/senior/account") @@ -214,9 +195,6 @@ void updateAccount() throws Exception { @WithMockUser(authorities = {"SENIOR"}) @DisplayName("빈 정산 계좌를 입력으면 예외가 발생한다") void updateInvalidAccount(String empty) throws Exception { - Salary salary = new Salary(0L, false, senior, 10000, getSalaryDate(), now(), null); - salaryRepository.save(salary); - String request = objectMapper.writeValueAsString( new SeniorAccountRequest(empty, empty, empty) ); @@ -249,9 +227,6 @@ void getSeniorInfo() throws Exception { @Test @DisplayName("대학원생 마이페이지 프로필 수정시 기존 정보를 조회한다") void getSeniorProfile() throws Exception { - updateProfile(); - updateAvailable(); - mvc.perform(get("/senior/me/profile") .header(AUTHORIZATION, BEARER + token)) .andExpect(status().isOk()) @@ -271,7 +246,7 @@ void getSeniorProfile() throws Exception { @DisplayName("등록된 프로필이 없다면 [내 프로필 수정] 기본 정보를 조회할 수 없다") void getEmptySeniorProfile() throws Exception { mvc.perform(get("/senior/me/profile") - .header(AUTHORIZATION, BEARER + seniorToken)) + .header(AUTHORIZATION, BEARER + otherSeniorToken)) .andExpect(status().isOk()) .andExpect(jsonPath("$.code").value(SENIOR_FIND.getCode())) .andExpect(jsonPath("$.message").value(GET_SENIOR_MYPAGE_PROFILE.getMessage())) @@ -397,7 +372,6 @@ void getSeniorUserEmptyAccount() throws Exception { @DisplayName("대학원생 마이페이지 계정 설정시 기존 정보를 조회한다") void getSeniorUserAccount() throws Exception { updateAccount(); - mvc.perform(get("/senior/me/account") .header(AUTHORIZATION, BEARER + token)) .andExpect(status().isOk()) @@ -414,9 +388,6 @@ void getSeniorUserAccount() throws Exception { @Test @DisplayName("대학원생 마이페이지 계정을 설정한다") void updateSeniorUserAccount() throws Exception { - Salary salary = new Salary(0L, false, senior, 10000, getSalaryDate(), now(), null); - salaryRepository.save(salary); - String request = objectMapper.writeValueAsString( new SeniorMyPageUserAccountRequest("뉴닉", "01098765432", "profile", "98765", "국민", "예금주") ); @@ -436,9 +407,6 @@ void updateSeniorUserAccount() throws Exception { @WithMockUser(authorities = {"SENIOR"}) @DisplayName("대학원생 마이페이지 계정을 수정 요청에 닉네임, 전화번호, 프로필사진이 없다면 예외가 발생한다") void updateEmptySeniorUserAccount(String empty) throws Exception { - Salary salary = new Salary(0L, false, senior, 10000, getSalaryDate(), now(), null); - salaryRepository.save(salary); - String request = objectMapper.writeValueAsString( new SeniorMyPageUserAccountRequest(empty, empty, empty, "98765", "국민", "예금주") ); @@ -456,16 +424,13 @@ void updateEmptySeniorUserAccount(String empty) throws Exception { @EmptySource @DisplayName("계좌등록을 한 선배가 수정할 때 계좌를 입력하지 않으면 예외가 발생한다") void updateSeniorUserWithoutAccount(String empty) throws Exception { - Account account = new Account(0L, "accountNumber", "bank", "accountHolder", senior); - accountRepository.save(account); - - Salary salary = new Salary(0L, false, senior, 10000, getSalaryDate(), now(), null); - salaryRepository.save(salary); - String request = objectMapper.writeValueAsString( new SeniorMyPageUserAccountRequest("뉴닉", "01098765432", "profile", empty, empty, empty) ); + Account account = resource.getAccount(); + accountRepository.save(account); + mvc.perform(patch("/senior/me/account") .header(AUTHORIZATION, BEARER + token) .content(request) @@ -479,9 +444,6 @@ void updateSeniorUserWithoutAccount(String empty) throws Exception { @Test @DisplayName("대학원생을 상세 조회한다 - 본인 조회") void getSeniorDetails() throws Exception { - updateProfile(); - updateAvailable(); - mvc.perform(get("/senior/{seniorId}", senior.getSeniorId()) .header(AUTHORIZATION, BEARER + token)) .andExpect(status().isOk()) @@ -506,9 +468,6 @@ void getSeniorDetails() throws Exception { @WithMockUser(authorities = {"USER", "SENIOR", "ADMIN"}) @DisplayName("대학원생을 상세 조회한다 - 타인 조회") void getSeniorDetailsOthers() throws Exception { - updateProfile(); - updateAvailable(); - mvc.perform(get("/senior/{seniorId}", senior.getSeniorId()) .header(AUTHORIZATION, BEARER + userToken)) .andExpect(status().isOk()) @@ -533,9 +492,6 @@ void getSeniorDetailsOthers() throws Exception { @WithMockUser(authorities = {"USER"}) @DisplayName("결제 시 대학원생의 기본 정보를 확인한다") void testGetSeniorProfile() throws Exception { - updateProfile(); - updateAvailable(); - mvc.perform(get("/senior/{seniorId}/profile", senior.getSeniorId()) .header(AUTHORIZATION, BEARER + userToken)) .andExpect(status().isOk()) @@ -554,9 +510,6 @@ void testGetSeniorProfile() throws Exception { @WithMockUser(authorities = {"USER"}) @DisplayName("신청서 작성 시 대학원생의 가능 시간 정보를 조회한다") void getSeniorTimes() throws Exception { - updateProfile(); - updateAvailable(); - mvc.perform(get("/senior/{seniorId}/times", senior.getSeniorId())) .andExpect(status().isOk()) .andExpect(jsonPath("$.code").value(SENIOR_FIND.getCode())) @@ -569,11 +522,11 @@ void getSeniorTimes() throws Exception { @DisplayName("대학원생을 검색한다") void getSearchSenior() throws Exception { mvc.perform(get("/senior/search", senior.getSeniorId()) - .param("find", "keyword")) + .param("find", senior.getInfo().getKeyword())) .andExpect(status().isOk()) .andExpect(jsonPath("$.code").value(SENIOR_FIND.getCode())) .andExpect(jsonPath("$.message").value(GET_SENIOR_LIST_INFO.getMessage())) - .andExpect(jsonPath("$.data.seniorSearchResponses[0].seniorId").value(senior.getSeniorId())) + .andExpect(jsonPath("$.data.seniorSearchResponses[0].seniorId").isNotEmpty()) .andExpect(jsonPath("$.data.seniorSearchResponses[0].profile").isNotEmpty()) .andExpect(jsonPath("$.data.seniorSearchResponses[0].nickName").isNotEmpty()) .andExpect(jsonPath("$.data.seniorSearchResponses[0].postgradu").isNotEmpty()) @@ -586,12 +539,12 @@ void getSearchSenior() throws Exception { @DisplayName("대학원생을 분야와 대학교로 검색한다") void getFieldSenior() throws Exception { mvc.perform(get("/senior/field", senior.getSeniorId()) - .param("field", "field") - .param("postgradu", "postgradu")) + .param("field", senior.getInfo().getField()) + .param("postgradu", senior.getInfo().getPostgradu())) .andExpect(status().isOk()) .andExpect(jsonPath("$.code").value(SENIOR_FIND.getCode())) .andExpect(jsonPath("$.message").value(GET_SENIOR_LIST_INFO.getMessage())) - .andExpect(jsonPath("$.data.seniorSearchResponses[0].seniorId").value(senior.getSeniorId())) + .andExpect(jsonPath("$.data.seniorSearchResponses[0].seniorId").isNotEmpty()) .andExpect(jsonPath("$.data.seniorSearchResponses[0].profile").isNotEmpty()) .andExpect(jsonPath("$.data.seniorSearchResponses[0].nickName").isNotEmpty()) .andExpect(jsonPath("$.data.seniorSearchResponses[0].postgradu").isNotEmpty()) diff --git a/src/test/java/com/postgraduate/Integration/UserControllerTest.java b/src/test/java/com/postgraduate/Integration/UserControllerTest.java index aa1b6db0..1e716b95 100644 --- a/src/test/java/com/postgraduate/Integration/UserControllerTest.java +++ b/src/test/java/com/postgraduate/Integration/UserControllerTest.java @@ -5,6 +5,7 @@ import com.postgraduate.domain.user.domain.entity.constant.Role; import com.postgraduate.domain.user.presentation.constant.UserResponseCode; import com.postgraduate.support.IntegrationTest; +import com.postgraduate.support.Resource; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -17,7 +18,6 @@ import static com.postgraduate.domain.user.presentation.constant.UserResponseCode.USER_FIND; import static com.postgraduate.domain.user.presentation.constant.UserResponseCode.USER_UPDATE; import static com.postgraduate.domain.user.presentation.constant.UserResponseMessage.*; -import static java.time.LocalDateTime.now; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doNothing; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; @@ -28,11 +28,12 @@ class UserControllerTest extends IntegrationTest { private static final String AUTHORIZATION = "Authorization"; private static final String BEARER = "Bearer "; + private Resource resource = new Resource(); private String token; @BeforeEach void setUp() throws IOException { - User user = new User(0L, 1L, "mail", "후배", "011", "profile", 0, Role.USER, true, now(), now(), false); + User user = resource.getUser(); userRepository.save(user); token = jwtUtil.generateAccessToken(user.getUserId(), Role.USER); diff --git a/src/test/java/com/postgraduate/domain/auth/application/usecase/oauth/SignUpUseTypeTest.java b/src/test/java/com/postgraduate/domain/auth/application/usecase/oauth/SignUpUseTypeTest.java index 5b038a9d..79efe126 100644 --- a/src/test/java/com/postgraduate/domain/auth/application/usecase/oauth/SignUpUseTypeTest.java +++ b/src/test/java/com/postgraduate/domain/auth/application/usecase/oauth/SignUpUseTypeTest.java @@ -19,7 +19,7 @@ import com.postgraduate.domain.wish.domain.entity.Wish; import com.postgraduate.domain.wish.domain.entity.constant.Status; import com.postgraduate.domain.wish.domain.service.WishSaveService; -import com.postgraduate.global.bizppurio.usecase.BizppurioSeniorMessage; +import com.postgraduate.global.bizppurio.application.usecase.BizppurioSeniorMessage; import com.postgraduate.global.slack.SlackSignUpMessage; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; diff --git a/src/test/java/com/postgraduate/domain/auth/presentation/AuthControllerTest.java b/src/test/java/com/postgraduate/domain/auth/presentation/AuthControllerTest.java index b3033fc7..f7e51752 100644 --- a/src/test/java/com/postgraduate/domain/auth/presentation/AuthControllerTest.java +++ b/src/test/java/com/postgraduate/domain/auth/presentation/AuthControllerTest.java @@ -32,7 +32,7 @@ class AuthControllerTest extends ControllerTest { @Test @WithMockUser - @DisplayName("회원이 로그인한다.") + @DisplayName("대학생이 로그인한다.") void authLoginByUser() throws Exception { CodeRequest codeRequest = new CodeRequest("code"); String request = objectMapper.writeValueAsString(codeRequest); diff --git a/src/test/java/com/postgraduate/domain/mentoring/application/usecase/MentoringApplyingUseTypeTest.java b/src/test/java/com/postgraduate/domain/mentoring/application/usecase/MentoringApplyingUseTypeTest.java index 6b5bc4e6..624ceca0 100644 --- a/src/test/java/com/postgraduate/domain/mentoring/application/usecase/MentoringApplyingUseTypeTest.java +++ b/src/test/java/com/postgraduate/domain/mentoring/application/usecase/MentoringApplyingUseTypeTest.java @@ -17,8 +17,8 @@ import com.postgraduate.domain.senior.domain.entity.Profile; import com.postgraduate.domain.senior.domain.entity.Senior; import com.postgraduate.domain.user.domain.entity.User; -import com.postgraduate.global.bizppurio.usecase.BizppurioJuniorMessage; -import com.postgraduate.global.bizppurio.usecase.BizppurioSeniorMessage; +import com.postgraduate.global.bizppurio.application.usecase.BizppurioJuniorMessage; +import com.postgraduate.global.bizppurio.application.usecase.BizppurioSeniorMessage; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; diff --git a/src/test/java/com/postgraduate/domain/mentoring/application/usecase/MentoringManageUseTypeTest.java b/src/test/java/com/postgraduate/domain/mentoring/application/usecase/MentoringManageUseTypeTest.java index 7f2b1d45..d5770e87 100644 --- a/src/test/java/com/postgraduate/domain/mentoring/application/usecase/MentoringManageUseTypeTest.java +++ b/src/test/java/com/postgraduate/domain/mentoring/application/usecase/MentoringManageUseTypeTest.java @@ -25,8 +25,8 @@ import com.postgraduate.domain.senior.domain.entity.Senior; import com.postgraduate.domain.senior.domain.service.SeniorGetService; import com.postgraduate.domain.user.domain.entity.User; -import com.postgraduate.global.bizppurio.usecase.BizppurioJuniorMessage; -import com.postgraduate.global.bizppurio.usecase.BizppurioSeniorMessage; +import com.postgraduate.global.bizppurio.application.usecase.BizppurioJuniorMessage; +import com.postgraduate.global.bizppurio.application.usecase.BizppurioSeniorMessage; import com.postgraduate.global.slack.SlackErrorMessage; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; @@ -38,7 +38,6 @@ import java.time.LocalDate; import java.time.LocalDateTime; -import java.util.List; import java.util.Optional; import static com.postgraduate.domain.mentoring.domain.entity.constant.Status.WAITING; @@ -51,12 +50,10 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.verify; @ExtendWith(MockitoExtension.class) class MentoringManageUseTypeTest { - @Mock - private MentoringRenewalUseCase mentoringRenewalUseCase; @Mock private MentoringUpdateService mentoringUpdateService; @Mock @@ -304,40 +301,4 @@ void updateExpectedFail() { assertThatThrownBy(() -> mentoringManageUseCase.updateExpected(user, mentoringId, dateRequest)) .isInstanceOf(MentoringNotFoundException.class); } - - @Test - @DisplayName("자동 취소 테스트") - void updateAutoCancel() { - List mentorings = List.of(mock(Mentoring.class), mock(Mentoring.class)); - LocalDateTime now = LocalDateTime.now() - .toLocalDate() - .atStartOfDay(); - given(mentoringGetService.byWaitingAndCreatedAt(now)) - .willReturn(mentorings); - mentoringManageUseCase.updateAutoCancel(); - - verify(mentoringRenewalUseCase, times(mentorings.size())) - .updateCancelWithAuto(any()); - } - - @Test - @DisplayName("자동 완료 테스트") - void updateAutoDone() { - Mentoring mentoring1 = mock(Mentoring.class); - Mentoring mentoring2 = mock(Mentoring.class); - Mentoring mentoring3 = mock(Mentoring.class); - List mentorings = List.of(mentoring1, mentoring2, mentoring3); - given(mentoringGetService.byExpected()) - .willReturn(mentorings); - given(mentoring1.checkAutoDone()) - .willReturn(true); - given(mentoring2.checkAutoDone()) - .willReturn(true); - given(mentoring3.checkAutoDone()) - .willReturn(false); - mentoringManageUseCase.updateAutoDone(); - - verify(mentoringRenewalUseCase, times(mentorings.size()-1)) - .updateDoneWithAuto(any()); - } } diff --git a/src/test/java/com/postgraduate/domain/salary/application/usecase/SalaryInfoUseTypeTest.java b/src/test/java/com/postgraduate/domain/salary/application/usecase/CreateSalaryUseTypeTest.java similarity index 99% rename from src/test/java/com/postgraduate/domain/salary/application/usecase/SalaryInfoUseTypeTest.java rename to src/test/java/com/postgraduate/domain/salary/application/usecase/CreateSalaryUseTypeTest.java index 5770d8ec..f8fb2c0a 100644 --- a/src/test/java/com/postgraduate/domain/salary/application/usecase/SalaryInfoUseTypeTest.java +++ b/src/test/java/com/postgraduate/domain/salary/application/usecase/CreateSalaryUseTypeTest.java @@ -33,7 +33,7 @@ import static org.mockito.BDDMockito.mock; @ExtendWith(MockitoExtension.class) -class SalaryInfoUseTypeTest { +class CreateSalaryUseTypeTest { @Mock private SeniorGetService seniorGetService; @Mock diff --git a/src/test/java/com/postgraduate/domain/salary/application/usecase/SalaryManageUseTypeTest.java b/src/test/java/com/postgraduate/domain/salary/application/usecase/SalaryManageUseTypeTest.java deleted file mode 100644 index 72e13125..00000000 --- a/src/test/java/com/postgraduate/domain/salary/application/usecase/SalaryManageUseTypeTest.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.postgraduate.domain.salary.application.usecase; - -import com.postgraduate.domain.salary.application.dto.SeniorAndAccount; -import com.postgraduate.domain.salary.domain.service.SalaryGetService; -import com.postgraduate.domain.senior.domain.service.SeniorGetService; -import com.postgraduate.global.slack.SlackSalaryMessage; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; - -import java.util.List; - -import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.*; - -@ExtendWith(MockitoExtension.class) -class SalaryManageUseTypeTest { - @Mock - private SalaryGetService salaryGetService; - @Mock - private SeniorGetService seniorGetService; - @Mock - private SlackSalaryMessage slackSalaryMessage; - @Mock - private SalaryRenewalUseCase salaryRenewalUseCase; - @InjectMocks - private SalaryManageUseCase salaryManageUseCase; - - @Test - @DisplayName("정산 자동 생성 테스트") - void createSalary() { - List seniorAndAccounts = List.of(mock(SeniorAndAccount.class), mock(SeniorAndAccount.class), mock(SeniorAndAccount.class)); - given(seniorGetService.findAllSeniorAndAccount()) - .willReturn(seniorAndAccounts); - salaryManageUseCase.createSalary(); - - verify(salaryRenewalUseCase, times(seniorAndAccounts.size())) - .createSalaryWithAuto(any(), any()); - } -} diff --git a/src/test/java/com/postgraduate/domain/salary/application/usecase/SalaryRenewalUseTypeTest.java b/src/test/java/com/postgraduate/domain/salary/application/usecase/SalaryRenewalUseTypeTest.java deleted file mode 100644 index 92d52cb3..00000000 --- a/src/test/java/com/postgraduate/domain/salary/application/usecase/SalaryRenewalUseTypeTest.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.postgraduate.domain.salary.application.usecase; - -import com.postgraduate.domain.salary.application.dto.SeniorAndAccount; -import com.postgraduate.domain.salary.domain.service.SalarySaveService; -import com.postgraduate.domain.salary.util.SalaryUtil; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; - -import java.time.LocalDate; - -import static org.mockito.Mockito.*; - -@ExtendWith(MockitoExtension.class) -class SalaryRenewalUseTypeTest { - @Mock - private SalarySaveService salarySaveService; - @InjectMocks - private SalaryRenewalUseCase salaryRenewalUseCase; - - @Test - @DisplayName("정산 생성 테스트") - void createSalary() { - LocalDate salaryDate = SalaryUtil.getSalaryDate(); - SeniorAndAccount seniorAndAccount = mock(SeniorAndAccount.class); - salaryRenewalUseCase.createSalaryWithAuto(seniorAndAccount, salaryDate); - verify(salarySaveService) - .save(any()); - } -} diff --git a/src/test/java/com/postgraduate/support/Resource.java b/src/test/java/com/postgraduate/support/Resource.java index d531faaf..049d88c8 100644 --- a/src/test/java/com/postgraduate/support/Resource.java +++ b/src/test/java/com/postgraduate/support/Resource.java @@ -1,5 +1,6 @@ package com.postgraduate.support; +import com.postgraduate.domain.account.domain.entity.Account; import com.postgraduate.domain.available.domain.entity.Available; import com.postgraduate.domain.mentoring.domain.entity.Mentoring; import com.postgraduate.domain.mentoring.domain.entity.constant.Status; @@ -10,6 +11,7 @@ import com.postgraduate.domain.senior.domain.entity.Profile; import com.postgraduate.domain.senior.domain.entity.Senior; import com.postgraduate.domain.user.domain.entity.User; +import com.postgraduate.domain.wish.domain.entity.Wish; import org.springframework.stereotype.Component; import java.time.LocalDateTime; @@ -24,25 +26,32 @@ import static java.time.LocalDateTime.now; public class Resource { - private User user = new User(0L, 1L, "mail", "후배", "011", "profile", 0, USER, true, now(), now(), false); - private User userOfSenior = new User(0L, 2L, "mail", "선배", "012", "profile", 0, SENIOR, true, now(), now(), false); + private User user = new User(-1L, -1L, "mail", "후배", "011", "profile", 0, USER, true, now(), now(), false); + private Wish wish = new Wish(-1L, "major", "field", true, user, com.postgraduate.domain.wish.domain.entity.constant.Status.WAITING); + private User otherUser = new User(-3L, -3L, "mail", "다른후배", "011", "profile", 0, USER, true, now(), now(), false); + private User userOfSenior = new User(-2L, -2L, "mail", "선배", "012", "profile", 0, SENIOR, true, now(), now(), false); private Info info = new Info("major", "서울대학교", "교수님", "키워드1,키워드2", "랩실", "인공지능", false, false, "인공지능,키워드1,키워드2", "chatLink", 30); private Profile profile = new Profile("저는요", "한줄소개", "대상"); - private Senior senior = new Senior(0L, userOfSenior, "certification", com.postgraduate.domain.senior.domain.entity.constant.Status.WAITING, 0, info, profile, now(), now()); + private Senior senior = new Senior(-1L, userOfSenior, "certification", com.postgraduate.domain.senior.domain.entity.constant.Status.WAITING, 0, info, profile, now(), now()); + private Senior otherSenior = new Senior(-3L, otherUser, "certification", com.postgraduate.domain.senior.domain.entity.constant.Status.WAITING, 0, info, null, now(), now()); private SalaryAccount salaryAccount = new SalaryAccount("bank", "1234", "holder"); - private Salary salary = new Salary(0L, false, senior, 20000, getSalaryDate(), LocalDateTime.now(), salaryAccount); - private Payment payment = new Payment(0L, user, senior, 20000, "1", "123", "123", LocalDateTime.now(), LocalDateTime.now(), DONE); - private Mentoring waitingMentoring = new Mentoring(0L, user, senior, payment, salary, "topic", "question", "date1,date2,date3", 30, WAITING, now(), now()); - private Mentoring expectedMentoring = new Mentoring(0L, user, senior, payment, salary, "topic", "question", "date", 30, EXPECTED, now(), now()); - private Mentoring doneMentoring = new Mentoring(0L, user, senior, payment, salary, "topic", "question", "2024-02-03-18-12", 30, Status.DONE, now(), now()); + private Salary salary = new Salary(-1L, false, senior, 20000, getSalaryDate(), LocalDateTime.now(), salaryAccount); + private Payment payment = new Payment(-1L, user, senior, 20000, "1", "123", "123", LocalDateTime.now(), LocalDateTime.now(), DONE); + private Mentoring waitingMentoring = new Mentoring(-1L, user, senior, payment, salary, "topic", "question", "date1,date2,date3", 30, WAITING, now(), now()); + private Mentoring expectedMentoring = new Mentoring(-2L, user, senior, payment, salary, "topic", "question", "date", 30, EXPECTED, now(), now()); + private Mentoring doneMentoring = new Mentoring(-3L, user, senior, payment, salary, "topic", "question", "2024-02-03-18-12", 30, Status.DONE, now(), now()); + private Account account = new Account(-1L, "010", "신한", "김씨", senior); private List availables = List.of( - new Available(0L, "월", "17:00", "23:00", senior), - new Available(0L, "금", "10:00", "20:00", senior), - new Available(0L, "토", "10:00", "20:00", senior)); + new Available(-1L, "월", "17:00", "23:00", senior), + new Available(-2L, "금", "10:00", "20:00", senior), + new Available(-3L, "토", "10:00", "20:00", senior)); public User getUser(){return user;} + public User getOtherUser(){return otherUser;} public User getSeniorUser(){return userOfSenior;} + public Wish getWish(){return wish;} public Senior getSenior() {return senior;} - public SalaryAccount getSalaryAccount() {return salaryAccount;} + public Senior getOtherSenior() {return otherSenior;} + public Account getAccount(){return account;} public Salary getSalary() {return salary;} public Payment getPayment() {return payment;} public Mentoring getWaitingMentoring() {return waitingMentoring;}