From a0cad48b762f0b7fe643eaabbae0210ef69e849f Mon Sep 17 00:00:00 2001 From: yang Date: Wed, 8 May 2024 02:31:20 +0900 Subject: [PATCH 01/19] =?UTF-8?q?RAC-360=20feat=20:=20=EC=8A=A4=ED=94=84?= =?UTF-8?q?=EB=A7=81=20=EB=B0=B0=EC=B9=98=20=EA=B8=B0=EB=B3=B8=20=EC=9E=91?= =?UTF-8?q?=EC=97=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 4 + .../repository/MentoringRepository.java | 5 ++ .../global/batch/cancel/CancelJobConfig.java | 75 +++++++++++++++++++ .../global/batch/cancel/CancelMentoring.java | 9 +++ .../global/batch/cancel/CancelWriter.java | 57 ++++++++++++++ .../batch/cancel/MentoringRowMapper.java | 23 ++++++ .../batch/repository/BatchRepository.java | 35 +++++++++ .../batch/scheduler/JobSchedulerConfig.java | 30 ++++++++ 8 files changed, 238 insertions(+) create mode 100644 src/main/java/com/postgraduate/global/batch/cancel/CancelJobConfig.java create mode 100644 src/main/java/com/postgraduate/global/batch/cancel/CancelMentoring.java create mode 100644 src/main/java/com/postgraduate/global/batch/cancel/CancelWriter.java create mode 100644 src/main/java/com/postgraduate/global/batch/cancel/MentoringRowMapper.java create mode 100644 src/main/java/com/postgraduate/global/batch/repository/BatchRepository.java create mode 100644 src/main/java/com/postgraduate/global/batch/scheduler/JobSchedulerConfig.java diff --git a/build.gradle b/build.gradle index 3aab9a8b..a37e0eda 100644 --- a/build.gradle +++ b/build.gradle @@ -77,6 +77,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/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/global/batch/cancel/CancelJobConfig.java b/src/main/java/com/postgraduate/global/batch/cancel/CancelJobConfig.java new file mode 100644 index 00000000..26e2ea6a --- /dev/null +++ b/src/main/java/com/postgraduate/global/batch/cancel/CancelJobConfig.java @@ -0,0 +1,75 @@ +package com.postgraduate.global.batch.cancel; + +import com.postgraduate.domain.mentoring.domain.entity.Mentoring; +import com.postgraduate.domain.mentoring.domain.repository.MentoringRepository; +import jakarta.persistence.EntityManagerFactory; +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; + +@Configuration +@RequiredArgsConstructor +@Slf4j +public class CancelJobConfig { + private final JobRepository jobRepository; + private final PlatformTransactionManager transactionManager; + private final CancelWriter cancelWriter; + private final DataSource dataSource; + + private static final int CHUNK_SIZE = 10; + + @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(cancelWriter) + .faultTolerant() + .skip(Exception.class) + .skipLimit(Integer.MAX_VALUE) + .build(); + } + + @Bean + public JdbcPagingItemReader itemReader() throws Exception { + return new JdbcPagingItemReaderBuilder() + .pageSize(CHUNK_SIZE) + .fetchSize(CHUNK_SIZE) + .dataSource(dataSource) + .rowMapper(new MentoringRowMapper()) + .queryProvider(queryProvider()) + .name("reader") + .build(); + } + + @Bean + public PagingQueryProvider queryProvider() throws Exception { + SqlPagingQueryProviderFactoryBean queryProvider = new SqlPagingQueryProviderFactoryBean(); + queryProvider.setDataSource(dataSource); + queryProvider.setSelectClause("select mentoring_id"); + queryProvider.setFromClause("from mentoring"); + queryProvider.setWhereClause("where mentoring.status = 'WAITING'"); + queryProvider.setSortKey("mentoring_id"); + return queryProvider.getObject(); + } +} diff --git a/src/main/java/com/postgraduate/global/batch/cancel/CancelMentoring.java b/src/main/java/com/postgraduate/global/batch/cancel/CancelMentoring.java new file mode 100644 index 00000000..c583e3eb --- /dev/null +++ b/src/main/java/com/postgraduate/global/batch/cancel/CancelMentoring.java @@ -0,0 +1,9 @@ +package com.postgraduate.global.batch.cancel; + +public record CancelMentoring( + Long mentoringId, + Long userId, + Long seniorId, + Long paymentId +) { +} diff --git a/src/main/java/com/postgraduate/global/batch/cancel/CancelWriter.java b/src/main/java/com/postgraduate/global/batch/cancel/CancelWriter.java new file mode 100644 index 00000000..7b6065f2 --- /dev/null +++ b/src/main/java/com/postgraduate/global/batch/cancel/CancelWriter.java @@ -0,0 +1,57 @@ +package com.postgraduate.global.batch.cancel; + +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.global.bizppurio.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; + +import static com.postgraduate.domain.refuse.application.mapper.RefuseMapper.mapToRefuse; + +@Component +@RequiredArgsConstructor +@Slf4j +public class CancelWriter implements ItemWriter { + private final MentoringGetService mentoringGetService; + private final MentoringUpdateService mentoringUpdateService; + private final PaymentManageUseCase paymentManageUseCase; + private final RefuseSaveService refuseSaveService; + private final SlackErrorMessage slackErrorMessage; + private final BizppurioJuniorMessage bizppurioJuniorMessage; + @Override + public void write(Chunk chunk) { + log.info("ChunkSize : {}", chunk.size()); + chunk.forEach(this::updateCancelWithAuto); + } + + 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(cancelMentoring); + refuseSaveService.save(refuse); + log.info("mentoringId : {} 자동 취소", cancelMentoring.getMentoringId()); + bizppurioJuniorMessage.mentoringRefuse(cancelMentoring.getUser()); + + if (cancelMentoring.getSenior().getSeniorId() == 12604) + throw new IllegalArgumentException(); + + } catch (Exception ex) { + log.error("mentoringId : {} 자동 취소 실패", mentoring.getMentoringId()); + log.error(ex.getMessage()); +// slackErrorMessage.sendSlackError(mentoring, ex); + throw ex; + } + } +} diff --git a/src/main/java/com/postgraduate/global/batch/cancel/MentoringRowMapper.java b/src/main/java/com/postgraduate/global/batch/cancel/MentoringRowMapper.java new file mode 100644 index 00000000..b1cd2c4c --- /dev/null +++ b/src/main/java/com/postgraduate/global/batch/cancel/MentoringRowMapper.java @@ -0,0 +1,23 @@ +package com.postgraduate.global.batch.cancel; + +import com.postgraduate.domain.mentoring.domain.entity.Mentoring; +import org.springframework.jdbc.core.RowMapper; + +import java.sql.ResultSet; +import java.sql.SQLException; + +public class MentoringRowMapper implements RowMapper { + @Override + public Mentoring mapRow(ResultSet rs, int rowNum) throws SQLException { + return Mentoring.builder() + .mentoringId(rs.getLong("mentoring_id")) + .build(); + +// 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/global/batch/repository/BatchRepository.java b/src/main/java/com/postgraduate/global/batch/repository/BatchRepository.java new file mode 100644 index 00000000..d06c7304 --- /dev/null +++ b/src/main/java/com/postgraduate/global/batch/repository/BatchRepository.java @@ -0,0 +1,35 @@ +package com.postgraduate.global.batch.repository; + +import com.postgraduate.global.batch.cancel.CancelMentoring; +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 BatchRepository { + private final NamedParameterJdbcTemplate jdbcTemplate; + private static final String UPDATE = "update mentoring set status = 'CANCEL' where mentoring_id = :mentoringId"; + + public void updateAll(List cancelMentorings) { + jdbcTemplate.batchUpdate(UPDATE, generateParameterSource(cancelMentorings)); + } + + private SqlParameterSource[] generateParameterSource(List cancelMentorings) { + return cancelMentorings.stream() + .map(cancelMentoring -> new MapSqlParameterSource(generateEntityParams(cancelMentoring))) + .toArray(SqlParameterSource[]::new); + } + + private Map generateEntityParams(CancelMentoring cancelMentoring) { + Map parameter = new HashMap<>(); + parameter.put("mentoringId", cancelMentoring.mentoringId()); + return parameter; + } +} diff --git a/src/main/java/com/postgraduate/global/batch/scheduler/JobSchedulerConfig.java b/src/main/java/com/postgraduate/global/batch/scheduler/JobSchedulerConfig.java new file mode 100644 index 00000000..ba7267cd --- /dev/null +++ b/src/main/java/com/postgraduate/global/batch/scheduler/JobSchedulerConfig.java @@ -0,0 +1,30 @@ +package com.postgraduate.global.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.configuration.JobRegistry; +import org.springframework.batch.core.launch.JobLauncher; +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; + @Scheduled(fixedDelay = 60000) + public void launchCancelJob() throws Exception { + JobParameters jobParameters = new JobParametersBuilder() + .addLocalDateTime("date", LocalDateTime.now()) + .toJobParameters(); + jobLauncher.run(cancelJob, jobParameters); + } +} From 7e41c8b5d76e2dfef2fa93dc132186ccb5a1d5f8 Mon Sep 17 00:00:00 2001 From: yang Date: Wed, 8 May 2024 03:23:49 +0900 Subject: [PATCH 02/19] =?UTF-8?q?RAC-360=20feat=20:=20=EC=9E=90=EB=8F=99?= =?UTF-8?q?=20=EC=B7=A8=EC=86=8C=20=EB=B0=B0=EC=B9=98=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../usecase/PaymentManageUseCase.java | 6 +++ .../domain/repository/PaymentRepository.java | 1 + .../domain/service/PaymentGetService.java | 5 +++ .../global/batch/BatchRepository.java | 36 ++++++++++++++++ .../global/batch/cancel/CancelJobConfig.java | 39 +++++++++++------- .../cancel/CancelMentoringRepository.java | 31 ++++++++++++++ .../cancel/CancelMentoringRowMapper.java | 18 ++++++++ .../global/batch/cancel/CancelWriter.java | 41 +++++++------------ .../batch/cancel/MentoringRowMapper.java | 23 ----------- .../batch/repository/BatchRepository.java | 35 ---------------- .../batch/scheduler/JobSchedulerConfig.java | 9 ++-- .../global/slack/SlackErrorMessage.java | 25 +++++++++++ 12 files changed, 168 insertions(+), 101 deletions(-) create mode 100644 src/main/java/com/postgraduate/global/batch/BatchRepository.java create mode 100644 src/main/java/com/postgraduate/global/batch/cancel/CancelMentoringRepository.java create mode 100644 src/main/java/com/postgraduate/global/batch/cancel/CancelMentoringRowMapper.java delete mode 100644 src/main/java/com/postgraduate/global/batch/cancel/MentoringRowMapper.java delete mode 100644 src/main/java/com/postgraduate/global/batch/repository/BatchRepository.java 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/global/batch/BatchRepository.java b/src/main/java/com/postgraduate/global/batch/BatchRepository.java new file mode 100644 index 00000000..3de36096 --- /dev/null +++ b/src/main/java/com/postgraduate/global/batch/BatchRepository.java @@ -0,0 +1,36 @@ +package com.postgraduate.global.batch; + +import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; +import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; +import org.springframework.jdbc.core.namedparam.SqlParameterSource; + +import java.util.List; +import java.util.Map; + +public abstract class BatchRepository { + private final NamedParameterJdbcTemplate jdbcTemplate; + private final String insertSql; + private final String updateSql; + + protected BatchRepository(NamedParameterJdbcTemplate jdbcTemplate, String insertSql, String updateSql) { + this.jdbcTemplate = jdbcTemplate; + this.insertSql = insertSql; + this.updateSql = updateSql; + } + + public void insertAll(List entities) { + jdbcTemplate.batchUpdate(insertSql, generateParameterSource(entities)); + } + + public void updateAll(List entities) { + jdbcTemplate.batchUpdate(updateSql, generateParameterSource(entities)); + } + + private SqlParameterSource[] generateParameterSource(List entities) { + return entities.stream() + .map(entity -> new MapSqlParameterSource(generateEntityParams(entity))) + .toArray(SqlParameterSource[]::new); + } + + protected abstract Map generateEntityParams(T entity); +} diff --git a/src/main/java/com/postgraduate/global/batch/cancel/CancelJobConfig.java b/src/main/java/com/postgraduate/global/batch/cancel/CancelJobConfig.java index 26e2ea6a..b79f4e00 100644 --- a/src/main/java/com/postgraduate/global/batch/cancel/CancelJobConfig.java +++ b/src/main/java/com/postgraduate/global/batch/cancel/CancelJobConfig.java @@ -1,8 +1,5 @@ package com.postgraduate.global.batch.cancel; -import com.postgraduate.domain.mentoring.domain.entity.Mentoring; -import com.postgraduate.domain.mentoring.domain.repository.MentoringRepository; -import jakarta.persistence.EntityManagerFactory; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.batch.core.Job; @@ -19,6 +16,12 @@ 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 @@ -41,7 +44,7 @@ public Job cancelJob() throws Exception { @Bean(name = "cancelStep") public Step cancelStep() throws Exception { return new StepBuilder("cancelStep", jobRepository) - .chunk(CHUNK_SIZE, transactionManager) + .chunk(CHUNK_SIZE, transactionManager) .reader(itemReader()) .writer(cancelWriter) .faultTolerant() @@ -50,26 +53,34 @@ public Step cancelStep() throws Exception { .build(); } - @Bean - public JdbcPagingItemReader itemReader() throws Exception { - return new JdbcPagingItemReaderBuilder() + @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 MentoringRowMapper()) - .queryProvider(queryProvider()) - .name("reader") + .rowMapper(new CancelMentoringRowMapper()) + .queryProvider(cancelQueryProvider()) + .parameterValues(parameter) + .name("cancelReader") .build(); } - @Bean - public PagingQueryProvider queryProvider() throws Exception { + @Bean(name = "cancelQuery") + public PagingQueryProvider cancelQueryProvider() throws Exception { SqlPagingQueryProviderFactoryBean queryProvider = new SqlPagingQueryProviderFactoryBean(); queryProvider.setDataSource(dataSource); - queryProvider.setSelectClause("select mentoring_id"); + queryProvider.setSelectClause("select mentoring_id, user_user_id, senior_senior_id, payment_payment_id"); queryProvider.setFromClause("from mentoring"); - queryProvider.setWhereClause("where mentoring.status = 'WAITING'"); + queryProvider.setWhereClause("where status = 'WAITING' and created_at < :date"); queryProvider.setSortKey("mentoring_id"); return queryProvider.getObject(); } } + diff --git a/src/main/java/com/postgraduate/global/batch/cancel/CancelMentoringRepository.java b/src/main/java/com/postgraduate/global/batch/cancel/CancelMentoringRepository.java new file mode 100644 index 00000000..5554ed6f --- /dev/null +++ b/src/main/java/com/postgraduate/global/batch/cancel/CancelMentoringRepository.java @@ -0,0 +1,31 @@ +package com.postgraduate.global.batch.cancel; + +import com.postgraduate.global.batch.BatchRepository; +import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; +import org.springframework.stereotype.Component; + +import java.util.HashMap; +import java.util.Map; + +@Component +public class CancelMentoringRepository extends BatchRepository { + private static final String AUTO_CANCEL = "자동취소"; + private static final String UPDATE_SQL = "update mentoring set status = 'CANCEL' where mentoring_id = :mentoringId"; + private static final String INSERT_SQL = "insert into refuse(" + + "mentoring_mentoring_id, " + + "reason" + + ") values(" + + ":mentoringId, :reason" + + ")"; + public CancelMentoringRepository(NamedParameterJdbcTemplate jdbcTemplate) { + super(jdbcTemplate, INSERT_SQL, UPDATE_SQL); + } + + @Override + protected 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/global/batch/cancel/CancelMentoringRowMapper.java b/src/main/java/com/postgraduate/global/batch/cancel/CancelMentoringRowMapper.java new file mode 100644 index 00000000..25ff0a16 --- /dev/null +++ b/src/main/java/com/postgraduate/global/batch/cancel/CancelMentoringRowMapper.java @@ -0,0 +1,18 @@ +package com.postgraduate.global.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/global/batch/cancel/CancelWriter.java b/src/main/java/com/postgraduate/global/batch/cancel/CancelWriter.java index 7b6065f2..ca881a05 100644 --- a/src/main/java/com/postgraduate/global/batch/cancel/CancelWriter.java +++ b/src/main/java/com/postgraduate/global/batch/cancel/CancelWriter.java @@ -1,11 +1,8 @@ package com.postgraduate.global.batch.cancel; -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.user.domain.entity.User; +import com.postgraduate.domain.user.domain.service.UserGetService; import com.postgraduate.global.bizppurio.usecase.BizppurioJuniorMessage; import com.postgraduate.global.slack.SlackErrorMessage; import lombok.RequiredArgsConstructor; @@ -16,41 +13,33 @@ import java.util.List; -import static com.postgraduate.domain.refuse.application.mapper.RefuseMapper.mapToRefuse; - @Component @RequiredArgsConstructor @Slf4j -public class CancelWriter implements ItemWriter { - private final MentoringGetService mentoringGetService; - private final MentoringUpdateService mentoringUpdateService; +public class CancelWriter implements ItemWriter { + private final UserGetService userGetService; private final PaymentManageUseCase paymentManageUseCase; - private final RefuseSaveService refuseSaveService; private final SlackErrorMessage slackErrorMessage; + private final CancelMentoringRepository cancelMentoringRepository; private final BizppurioJuniorMessage bizppurioJuniorMessage; @Override - public void write(Chunk chunk) { + public void write(Chunk chunk) { log.info("ChunkSize : {}", chunk.size()); chunk.forEach(this::updateCancelWithAuto); } - public void updateCancelWithAuto(Mentoring mentoring) { + public void updateCancelWithAuto(CancelMentoring mentoring) { try { -// paymentManageUseCase.refundPayByUser(mentoring.getUser(), mentoring.getPayment().getOrderId()); - Mentoring cancelMentoring = mentoringGetService.byMentoringIdWithLazy(mentoring.getMentoringId()); - mentoringUpdateService.updateCancel(cancelMentoring); - Refuse refuse = mapToRefuse(cancelMentoring); - refuseSaveService.save(refuse); - log.info("mentoringId : {} 자동 취소", cancelMentoring.getMentoringId()); - bizppurioJuniorMessage.mentoringRefuse(cancelMentoring.getUser()); - - if (cancelMentoring.getSenior().getSeniorId() == 12604) - throw new IllegalArgumentException(); - + User user = userGetService.byUserId(mentoring.userId()); + paymentManageUseCase.refundPayByUser(mentoring.userId(), mentoring.paymentId()); + cancelMentoringRepository.updateAll(List.of(mentoring)); + cancelMentoringRepository.insertAll(List.of(mentoring)); + log.info("mentoringId : {} 자동 취소", mentoring.mentoringId()); + bizppurioJuniorMessage.mentoringRefuse(user); } catch (Exception ex) { - log.error("mentoringId : {} 자동 취소 실패", mentoring.getMentoringId()); + log.error("mentoringId : {} 자동 취소 실패", mentoring.mentoringId()); log.error(ex.getMessage()); -// slackErrorMessage.sendSlackError(mentoring, ex); + slackErrorMessage.sendSlackError(mentoring.mentoringId(), ex); throw ex; } } diff --git a/src/main/java/com/postgraduate/global/batch/cancel/MentoringRowMapper.java b/src/main/java/com/postgraduate/global/batch/cancel/MentoringRowMapper.java deleted file mode 100644 index b1cd2c4c..00000000 --- a/src/main/java/com/postgraduate/global/batch/cancel/MentoringRowMapper.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.postgraduate.global.batch.cancel; - -import com.postgraduate.domain.mentoring.domain.entity.Mentoring; -import org.springframework.jdbc.core.RowMapper; - -import java.sql.ResultSet; -import java.sql.SQLException; - -public class MentoringRowMapper implements RowMapper { - @Override - public Mentoring mapRow(ResultSet rs, int rowNum) throws SQLException { - return Mentoring.builder() - .mentoringId(rs.getLong("mentoring_id")) - .build(); - -// 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/global/batch/repository/BatchRepository.java b/src/main/java/com/postgraduate/global/batch/repository/BatchRepository.java deleted file mode 100644 index d06c7304..00000000 --- a/src/main/java/com/postgraduate/global/batch/repository/BatchRepository.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.postgraduate.global.batch.repository; - -import com.postgraduate.global.batch.cancel.CancelMentoring; -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 BatchRepository { - private final NamedParameterJdbcTemplate jdbcTemplate; - private static final String UPDATE = "update mentoring set status = 'CANCEL' where mentoring_id = :mentoringId"; - - public void updateAll(List cancelMentorings) { - jdbcTemplate.batchUpdate(UPDATE, generateParameterSource(cancelMentorings)); - } - - private SqlParameterSource[] generateParameterSource(List cancelMentorings) { - return cancelMentorings.stream() - .map(cancelMentoring -> new MapSqlParameterSource(generateEntityParams(cancelMentoring))) - .toArray(SqlParameterSource[]::new); - } - - private Map generateEntityParams(CancelMentoring cancelMentoring) { - Map parameter = new HashMap<>(); - parameter.put("mentoringId", cancelMentoring.mentoringId()); - return parameter; - } -} diff --git a/src/main/java/com/postgraduate/global/batch/scheduler/JobSchedulerConfig.java b/src/main/java/com/postgraduate/global/batch/scheduler/JobSchedulerConfig.java index ba7267cd..912249c3 100644 --- a/src/main/java/com/postgraduate/global/batch/scheduler/JobSchedulerConfig.java +++ b/src/main/java/com/postgraduate/global/batch/scheduler/JobSchedulerConfig.java @@ -5,8 +5,11 @@ import org.springframework.batch.core.Job; import org.springframework.batch.core.JobParameters; import org.springframework.batch.core.JobParametersBuilder; -import org.springframework.batch.core.configuration.JobRegistry; +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; @@ -20,8 +23,8 @@ public class JobSchedulerConfig { private final JobLauncher jobLauncher; @Qualifier("cancelJob") private final Job cancelJob; - @Scheduled(fixedDelay = 60000) - public void launchCancelJob() throws Exception { + @Scheduled(fixedDelay = 60000) //todo : 스케줄링 수정 + public void launchCancelJob() throws JobInstanceAlreadyCompleteException, JobExecutionAlreadyRunningException, JobParametersInvalidException, JobRestartException { JobParameters jobParameters = new JobParametersBuilder() .addLocalDateTime("date", LocalDateTime.now()) .toJobParameters(); diff --git a/src/main/java/com/postgraduate/global/slack/SlackErrorMessage.java b/src/main/java/com/postgraduate/global/slack/SlackErrorMessage.java index 2becea32..d91e8fca 100644 --- a/src/main/java/com/postgraduate/global/slack/SlackErrorMessage.java +++ b/src/main/java/com/postgraduate/global/slack/SlackErrorMessage.java @@ -38,6 +38,31 @@ public void sendSlackError(Mentoring mentoring, Exception ex) { } } + public void sendSlackError(Long mentoringId, Exception ex) { + try { + slackClient.send(logWebHookUrl, Payload.builder() + .text("자동 갱신 에러 발생!! 백엔드팀 확인 요망!!") + .attachments( + List.of(generateErrorSlackAttachment(mentoringId, ex)) + ) + .build()); + } catch (IOException e) { + log.error("slack 전송 오류"); + } + } + + private Attachment generateErrorSlackAttachment(Long mentoringId, Exception 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() From 831d7df6e91b7918cf64c469a6356f53d6fec199 Mon Sep 17 00:00:00 2001 From: yang Date: Wed, 8 May 2024 19:45:45 +0900 Subject: [PATCH 03/19] =?UTF-8?q?RAC-360=20feat=20:=20=EC=9E=90=EB=8F=99?= =?UTF-8?q?=20=EC=99=84=EB=A3=8C=20=EB=B0=B0=EC=B9=98=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../global/batch/BatchRepository.java | 36 ---------- .../global/batch/cancel/CancelJobConfig.java | 4 +- .../cancel/CancelMentoringRepository.java | 31 +++++--- ...Writer.java => CancelMentoringWriter.java} | 8 +-- .../global/batch/done/DoneJobConfig.java | 72 +++++++++++++++++++ .../global/batch/done/DoneMentoring.java | 10 +++ .../batch/done/DoneMentoringProcessor.java | 24 +++++++ .../batch/done/DoneMentoringRepository.java | 43 +++++++++++ .../batch/done/DoneMentoringRowMapper.java | 19 +++++ .../batch/done/DoneMentoringWriter.java | 26 +++++++ .../batch/scheduler/JobSchedulerConfig.java | 13 +++- 11 files changed, 235 insertions(+), 51 deletions(-) delete mode 100644 src/main/java/com/postgraduate/global/batch/BatchRepository.java rename src/main/java/com/postgraduate/global/batch/cancel/{CancelWriter.java => CancelMentoringWriter.java} (86%) create mode 100644 src/main/java/com/postgraduate/global/batch/done/DoneJobConfig.java create mode 100644 src/main/java/com/postgraduate/global/batch/done/DoneMentoring.java create mode 100644 src/main/java/com/postgraduate/global/batch/done/DoneMentoringProcessor.java create mode 100644 src/main/java/com/postgraduate/global/batch/done/DoneMentoringRepository.java create mode 100644 src/main/java/com/postgraduate/global/batch/done/DoneMentoringRowMapper.java create mode 100644 src/main/java/com/postgraduate/global/batch/done/DoneMentoringWriter.java diff --git a/src/main/java/com/postgraduate/global/batch/BatchRepository.java b/src/main/java/com/postgraduate/global/batch/BatchRepository.java deleted file mode 100644 index 3de36096..00000000 --- a/src/main/java/com/postgraduate/global/batch/BatchRepository.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.postgraduate.global.batch; - -import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; -import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; -import org.springframework.jdbc.core.namedparam.SqlParameterSource; - -import java.util.List; -import java.util.Map; - -public abstract class BatchRepository { - private final NamedParameterJdbcTemplate jdbcTemplate; - private final String insertSql; - private final String updateSql; - - protected BatchRepository(NamedParameterJdbcTemplate jdbcTemplate, String insertSql, String updateSql) { - this.jdbcTemplate = jdbcTemplate; - this.insertSql = insertSql; - this.updateSql = updateSql; - } - - public void insertAll(List entities) { - jdbcTemplate.batchUpdate(insertSql, generateParameterSource(entities)); - } - - public void updateAll(List entities) { - jdbcTemplate.batchUpdate(updateSql, generateParameterSource(entities)); - } - - private SqlParameterSource[] generateParameterSource(List entities) { - return entities.stream() - .map(entity -> new MapSqlParameterSource(generateEntityParams(entity))) - .toArray(SqlParameterSource[]::new); - } - - protected abstract Map generateEntityParams(T entity); -} diff --git a/src/main/java/com/postgraduate/global/batch/cancel/CancelJobConfig.java b/src/main/java/com/postgraduate/global/batch/cancel/CancelJobConfig.java index b79f4e00..1d875620 100644 --- a/src/main/java/com/postgraduate/global/batch/cancel/CancelJobConfig.java +++ b/src/main/java/com/postgraduate/global/batch/cancel/CancelJobConfig.java @@ -29,7 +29,7 @@ public class CancelJobConfig { private final JobRepository jobRepository; private final PlatformTransactionManager transactionManager; - private final CancelWriter cancelWriter; + private final CancelMentoringWriter cancelMentoringWriter; private final DataSource dataSource; private static final int CHUNK_SIZE = 10; @@ -46,7 +46,7 @@ public Step cancelStep() throws Exception { return new StepBuilder("cancelStep", jobRepository) .chunk(CHUNK_SIZE, transactionManager) .reader(itemReader()) - .writer(cancelWriter) + .writer(cancelMentoringWriter) .faultTolerant() .skip(Exception.class) .skipLimit(Integer.MAX_VALUE) diff --git a/src/main/java/com/postgraduate/global/batch/cancel/CancelMentoringRepository.java b/src/main/java/com/postgraduate/global/batch/cancel/CancelMentoringRepository.java index 5554ed6f..8ca80586 100644 --- a/src/main/java/com/postgraduate/global/batch/cancel/CancelMentoringRepository.java +++ b/src/main/java/com/postgraduate/global/batch/cancel/CancelMentoringRepository.java @@ -1,28 +1,43 @@ package com.postgraduate.global.batch.cancel; -import com.postgraduate.global.batch.BatchRepository; +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 -public class CancelMentoringRepository extends BatchRepository { +@RequiredArgsConstructor +public class CancelMentoringRepository{ + private final NamedParameterJdbcTemplate jdbcTemplate; private static final String AUTO_CANCEL = "자동취소"; - private static final String UPDATE_SQL = "update mentoring set status = 'CANCEL' where mentoring_id = :mentoringId"; - private static final String INSERT_SQL = "insert into refuse(" + + 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 CancelMentoringRepository(NamedParameterJdbcTemplate jdbcTemplate) { - super(jdbcTemplate, INSERT_SQL, UPDATE_SQL); + + 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); } - @Override - protected Map generateEntityParams(CancelMentoring cancelMentoring) { + private Map generateEntityParams(CancelMentoring cancelMentoring) { HashMap parameter = new HashMap<>(); parameter.put("mentoringId", cancelMentoring.mentoringId()); parameter.put("reason", AUTO_CANCEL); diff --git a/src/main/java/com/postgraduate/global/batch/cancel/CancelWriter.java b/src/main/java/com/postgraduate/global/batch/cancel/CancelMentoringWriter.java similarity index 86% rename from src/main/java/com/postgraduate/global/batch/cancel/CancelWriter.java rename to src/main/java/com/postgraduate/global/batch/cancel/CancelMentoringWriter.java index ca881a05..282e6846 100644 --- a/src/main/java/com/postgraduate/global/batch/cancel/CancelWriter.java +++ b/src/main/java/com/postgraduate/global/batch/cancel/CancelMentoringWriter.java @@ -16,7 +16,7 @@ @Component @RequiredArgsConstructor @Slf4j -public class CancelWriter implements ItemWriter { +public class CancelMentoringWriter implements ItemWriter { private final UserGetService userGetService; private final PaymentManageUseCase paymentManageUseCase; private final SlackErrorMessage slackErrorMessage; @@ -27,13 +27,13 @@ public void write(Chunk chunk) { log.info("ChunkSize : {}", chunk.size()); chunk.forEach(this::updateCancelWithAuto); } - + //todo : User 조회 수정 (비즈뿌리오와 함께) public void updateCancelWithAuto(CancelMentoring mentoring) { try { User user = userGetService.byUserId(mentoring.userId()); paymentManageUseCase.refundPayByUser(mentoring.userId(), mentoring.paymentId()); - cancelMentoringRepository.updateAll(List.of(mentoring)); - cancelMentoringRepository.insertAll(List.of(mentoring)); + cancelMentoringRepository.updateAllMentoring(List.of(mentoring)); + cancelMentoringRepository.insertAllRefuse(List.of(mentoring)); log.info("mentoringId : {} 자동 취소", mentoring.mentoringId()); bizppurioJuniorMessage.mentoringRefuse(user); } catch (Exception ex) { diff --git a/src/main/java/com/postgraduate/global/batch/done/DoneJobConfig.java b/src/main/java/com/postgraduate/global/batch/done/DoneJobConfig.java new file mode 100644 index 00000000..5632274a --- /dev/null +++ b/src/main/java/com/postgraduate/global/batch/done/DoneJobConfig.java @@ -0,0 +1,72 @@ +package com.postgraduate.global.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 static final int CHUNK_SIZE = 10; + + @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) + .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/global/batch/done/DoneMentoring.java b/src/main/java/com/postgraduate/global/batch/done/DoneMentoring.java new file mode 100644 index 00000000..cea75132 --- /dev/null +++ b/src/main/java/com/postgraduate/global/batch/done/DoneMentoring.java @@ -0,0 +1,10 @@ +package com.postgraduate.global.batch.done; + +public record DoneMentoring( + Long mentoringId, + Long seniorId, + Long salaryId, + String date, + int pay +) { +} diff --git a/src/main/java/com/postgraduate/global/batch/done/DoneMentoringProcessor.java b/src/main/java/com/postgraduate/global/batch/done/DoneMentoringProcessor.java new file mode 100644 index 00000000..6f16fc9d --- /dev/null +++ b/src/main/java/com/postgraduate/global/batch/done/DoneMentoringProcessor.java @@ -0,0 +1,24 @@ +package com.postgraduate.global.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/global/batch/done/DoneMentoringRepository.java b/src/main/java/com/postgraduate/global/batch/done/DoneMentoringRepository.java new file mode 100644 index 00000000..8b5ca74a --- /dev/null +++ b/src/main/java/com/postgraduate/global/batch/done/DoneMentoringRepository.java @@ -0,0 +1,43 @@ +package com.postgraduate.global.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/global/batch/done/DoneMentoringRowMapper.java b/src/main/java/com/postgraduate/global/batch/done/DoneMentoringRowMapper.java new file mode 100644 index 00000000..cfa0c426 --- /dev/null +++ b/src/main/java/com/postgraduate/global/batch/done/DoneMentoringRowMapper.java @@ -0,0 +1,19 @@ +package com.postgraduate.global.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/global/batch/done/DoneMentoringWriter.java b/src/main/java/com/postgraduate/global/batch/done/DoneMentoringWriter.java new file mode 100644 index 00000000..b165e9c5 --- /dev/null +++ b/src/main/java/com/postgraduate/global/batch/done/DoneMentoringWriter.java @@ -0,0 +1,26 @@ +package com.postgraduate.global.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/global/batch/scheduler/JobSchedulerConfig.java b/src/main/java/com/postgraduate/global/batch/scheduler/JobSchedulerConfig.java index 912249c3..65049c67 100644 --- a/src/main/java/com/postgraduate/global/batch/scheduler/JobSchedulerConfig.java +++ b/src/main/java/com/postgraduate/global/batch/scheduler/JobSchedulerConfig.java @@ -23,11 +23,22 @@ public class JobSchedulerConfig { private final JobLauncher jobLauncher; @Qualifier("cancelJob") private final Job cancelJob; - @Scheduled(fixedDelay = 60000) //todo : 스케줄링 수정 + @Qualifier("doneJob") + private final Job doneJob; + +// @Scheduled(fixedDelay = 60000) //todo : 스케줄링 수정 public void launchCancelJob() throws JobInstanceAlreadyCompleteException, JobExecutionAlreadyRunningException, JobParametersInvalidException, JobRestartException { JobParameters jobParameters = new JobParametersBuilder() .addLocalDateTime("date", LocalDateTime.now()) .toJobParameters(); jobLauncher.run(cancelJob, jobParameters); } + + @Scheduled(fixedDelay = 600000) + public void launchDoneJob() throws JobInstanceAlreadyCompleteException, JobExecutionAlreadyRunningException, JobParametersInvalidException, JobRestartException { + JobParameters jobParameters = new JobParametersBuilder() + .addLocalDateTime("date", LocalDateTime.now()) + .toJobParameters(); + jobLauncher.run(doneJob, jobParameters); + } } From 5a77d7392172adb2f33c0f695404ff55affcff15 Mon Sep 17 00:00:00 2001 From: yang Date: Wed, 8 May 2024 23:28:13 +0900 Subject: [PATCH 04/19] =?UTF-8?q?RAC-360=20feat=20:=20=EC=A0=95=EC=82=B0?= =?UTF-8?q?=20=EC=9E=90=EB=8F=99=20=EC=83=9D=EC=84=B1=20=EB=B0=B0=EC=B9=98?= =?UTF-8?q?=20=EC=84=B8=ED=8C=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../global/batch/salary/SalaryInfo.java | 12 +++ .../global/batch/salary/SalaryJobConfig.java | 94 +++++++++++++++++++ 2 files changed, 106 insertions(+) create mode 100644 src/main/java/com/postgraduate/global/batch/salary/SalaryInfo.java create mode 100644 src/main/java/com/postgraduate/global/batch/salary/SalaryJobConfig.java diff --git a/src/main/java/com/postgraduate/global/batch/salary/SalaryInfo.java b/src/main/java/com/postgraduate/global/batch/salary/SalaryInfo.java new file mode 100644 index 00000000..84fc3a2d --- /dev/null +++ b/src/main/java/com/postgraduate/global/batch/salary/SalaryInfo.java @@ -0,0 +1,12 @@ +package com.postgraduate.global.batch.salary; + +import java.time.LocalDate; + +public record SalaryInfo( + Long seniorId, + Long accountId, + String bank, + String accountNumber, + String accountHolder +) { +} diff --git a/src/main/java/com/postgraduate/global/batch/salary/SalaryJobConfig.java b/src/main/java/com/postgraduate/global/batch/salary/SalaryJobConfig.java new file mode 100644 index 00000000..b6170f32 --- /dev/null +++ b/src/main/java/com/postgraduate/global/batch/salary/SalaryJobConfig.java @@ -0,0 +1,94 @@ +package com.postgraduate.global.batch.salary; + +import com.postgraduate.domain.salary.domain.entity.Salary; +import com.postgraduate.domain.salary.domain.service.SalaryGetService; +import com.postgraduate.global.batch.done.DoneMentoring; +import com.postgraduate.global.batch.done.DoneMentoringRowMapper; +import com.postgraduate.global.slack.SlackSalaryMessage; +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.StepContribution; +import org.springframework.batch.core.job.builder.JobBuilder; +import org.springframework.batch.core.repository.JobRepository; +import org.springframework.batch.core.scope.context.ChunkContext; +import org.springframework.batch.core.step.builder.StepBuilder; +import org.springframework.batch.core.step.tasklet.Tasklet; +import org.springframework.batch.item.ItemReader; +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.List; + +@Configuration +@RequiredArgsConstructor +@Slf4j +public class SalaryJobConfig { + private final JobRepository jobRepository; + private final PlatformTransactionManager transactionManager; + private final SlackSalaryMessage slackSalaryMessage; + private final SalaryGetService salaryGetService; + private final DataSource dataSource; + + private static final int CHUNK_SIZE = 10; + + @Bean(name = "salaryJob") + public Job salaryJob() { + return new JobBuilder("salaryJob", jobRepository) + .start(sendSlackStep()) + .next(makeSalaryStep()) + } + + @Bean(name = "sendSlackStep") + public Step sendSlackStep() { + return new StepBuilder("sendSlackStep", jobRepository) + .tasklet(new Tasklet() { + @Override + public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception { + List salaries = salaryGetService.findAllLast(); + slackSalaryMessage.sendSlackSalary(salaries); + return RepeatStatus.FINISHED; + } + }, transactionManager) + .build(); + } + + @Bean(name = "makeSalaryStep") + public Step makeSalaryStep() throws Exception { + return new StepBuilder("makeSalaryStep", jobRepository) + .chunk(CHUNK_SIZE, transactionManager) + .reader(salaryReader()) + } + + @Bean(name = "salaryReader") + public JdbcPagingItemReader salaryReader() throws Exception { + return new JdbcPagingItemReaderBuilder() + .pageSize(CHUNK_SIZE) + .fetchSize(CHUNK_SIZE) + .dataSource(dataSource) + .rowMapper(new DoneMentoringRowMapper()) + .queryProvider(doneQueryProvider()) + .name("doneReader") + .build(); + } + + @Bean(name = "salaryQuery") + public PagingQueryProvider doneQueryProvider() 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 left join account a on s.senior_id = a.senior_senior_id\n" + + "join user u on s.user_user_id = u.user_id"); + queryProvider.setWhereClause("where u.is_delete = false"); + queryProvider.setSortKey("senior_id"); + return queryProvider.getObject(); + } +} From 79a0da6b1b55d9446c0c7890b7a24f0843ad4d29 Mon Sep 17 00:00:00 2001 From: yang Date: Thu, 9 May 2024 03:14:15 +0900 Subject: [PATCH 05/19] =?UTF-8?q?RAC-360=20feat=20:=20=EC=A0=95=EC=82=B0?= =?UTF-8?q?=20=EC=9E=90=EB=8F=99=20=EC=83=9D=EC=84=B1=20=EB=B0=B0=EC=B9=98?= =?UTF-8?q?=20=EC=9E=91=EC=97=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../{SalaryInfo.java => CreateSalary.java} | 4 +- .../batch/salary/CreateSalaryItemWriter.java | 24 +++++++ ...Config.java => CreateSalaryJobConfig.java} | 69 +++++++++++-------- .../batch/salary/CreateSalaryRepository.java | 43 ++++++++++++ .../batch/salary/CreateSalaryRowMapper.java | 19 +++++ .../batch/scheduler/JobSchedulerConfig.java | 12 +++- ...Test.java => CreateSalaryUseTypeTest.java} | 2 +- 7 files changed, 141 insertions(+), 32 deletions(-) rename src/main/java/com/postgraduate/global/batch/salary/{SalaryInfo.java => CreateSalary.java} (76%) create mode 100644 src/main/java/com/postgraduate/global/batch/salary/CreateSalaryItemWriter.java rename src/main/java/com/postgraduate/global/batch/salary/{SalaryJobConfig.java => CreateSalaryJobConfig.java} (53%) create mode 100644 src/main/java/com/postgraduate/global/batch/salary/CreateSalaryRepository.java create mode 100644 src/main/java/com/postgraduate/global/batch/salary/CreateSalaryRowMapper.java rename src/test/java/com/postgraduate/domain/salary/application/usecase/{SalaryInfoUseTypeTest.java => CreateSalaryUseTypeTest.java} (99%) diff --git a/src/main/java/com/postgraduate/global/batch/salary/SalaryInfo.java b/src/main/java/com/postgraduate/global/batch/salary/CreateSalary.java similarity index 76% rename from src/main/java/com/postgraduate/global/batch/salary/SalaryInfo.java rename to src/main/java/com/postgraduate/global/batch/salary/CreateSalary.java index 84fc3a2d..71c21f0b 100644 --- a/src/main/java/com/postgraduate/global/batch/salary/SalaryInfo.java +++ b/src/main/java/com/postgraduate/global/batch/salary/CreateSalary.java @@ -1,8 +1,6 @@ package com.postgraduate.global.batch.salary; -import java.time.LocalDate; - -public record SalaryInfo( +public record CreateSalary( Long seniorId, Long accountId, String bank, diff --git a/src/main/java/com/postgraduate/global/batch/salary/CreateSalaryItemWriter.java b/src/main/java/com/postgraduate/global/batch/salary/CreateSalaryItemWriter.java new file mode 100644 index 00000000..b41465e6 --- /dev/null +++ b/src/main/java/com/postgraduate/global/batch/salary/CreateSalaryItemWriter.java @@ -0,0 +1,24 @@ +package com.postgraduate.global.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); + } +} diff --git a/src/main/java/com/postgraduate/global/batch/salary/SalaryJobConfig.java b/src/main/java/com/postgraduate/global/batch/salary/CreateSalaryJobConfig.java similarity index 53% rename from src/main/java/com/postgraduate/global/batch/salary/SalaryJobConfig.java rename to src/main/java/com/postgraduate/global/batch/salary/CreateSalaryJobConfig.java index b6170f32..562c0dc1 100644 --- a/src/main/java/com/postgraduate/global/batch/salary/SalaryJobConfig.java +++ b/src/main/java/com/postgraduate/global/batch/salary/CreateSalaryJobConfig.java @@ -2,8 +2,6 @@ import com.postgraduate.domain.salary.domain.entity.Salary; import com.postgraduate.domain.salary.domain.service.SalaryGetService; -import com.postgraduate.global.batch.done.DoneMentoring; -import com.postgraduate.global.batch.done.DoneMentoringRowMapper; import com.postgraduate.global.slack.SlackSalaryMessage; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -15,7 +13,8 @@ import org.springframework.batch.core.scope.context.ChunkContext; import org.springframework.batch.core.step.builder.StepBuilder; import org.springframework.batch.core.step.tasklet.Tasklet; -import org.springframework.batch.item.ItemReader; +import org.springframework.batch.item.Chunk; +import org.springframework.batch.item.ItemWriter; import org.springframework.batch.item.database.JdbcPagingItemReader; import org.springframework.batch.item.database.PagingQueryProvider; import org.springframework.batch.item.database.builder.JdbcPagingItemReaderBuilder; @@ -26,68 +25,84 @@ 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 @Slf4j -public class SalaryJobConfig { +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 DataSource dataSource; private static final int CHUNK_SIZE = 10; @Bean(name = "salaryJob") - public Job salaryJob() { + public Job salaryJob() throws Exception { return new JobBuilder("salaryJob", jobRepository) .start(sendSlackStep()) - .next(makeSalaryStep()) + .next(createSalaryStep()) + .build(); } @Bean(name = "sendSlackStep") public Step sendSlackStep() { return new StepBuilder("sendSlackStep", jobRepository) - .tasklet(new Tasklet() { - @Override - public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception { - List salaries = salaryGetService.findAllLast(); - slackSalaryMessage.sendSlackSalary(salaries); - return RepeatStatus.FINISHED; - } + .tasklet((contribution, chunkContext) -> { + List salaries = salaryGetService.findAllLast(); + slackSalaryMessage.sendSlackSalary(salaries); + log.info("salarySize : {}", salaries.size()); // 임시 + salaries.forEach(salary -> log.info("salary : {}", salary.getTotalAmount())); // 임시 + return RepeatStatus.FINISHED; }, transactionManager) .build(); } - @Bean(name = "makeSalaryStep") - public Step makeSalaryStep() throws Exception { - return new StepBuilder("makeSalaryStep", jobRepository) - .chunk(CHUNK_SIZE, transactionManager) + @Bean(name = "createSalaryStep") + public Step createSalaryStep() throws Exception { + return new StepBuilder("createSalaryStep", jobRepository) + .chunk(CHUNK_SIZE, transactionManager) .reader(salaryReader()) + .writer(createSalaryItemWriter) + .build(); } @Bean(name = "salaryReader") - public JdbcPagingItemReader salaryReader() throws Exception { - return new JdbcPagingItemReaderBuilder() + 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 DoneMentoringRowMapper()) - .queryProvider(doneQueryProvider()) - .name("doneReader") + .rowMapper(new CreateSalaryRowMapper()) + .queryProvider(salaryQueryProvider()) + .parameterValues(parameters) + .name("salaryReader") .build(); } @Bean(name = "salaryQuery") - public PagingQueryProvider doneQueryProvider() throws Exception { + 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 left join account a on s.senior_id = a.senior_senior_id\n" + - "join user u on s.user_user_id = u.user_id"); - queryProvider.setWhereClause("where u.is_delete = false"); + 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/global/batch/salary/CreateSalaryRepository.java b/src/main/java/com/postgraduate/global/batch/salary/CreateSalaryRepository.java new file mode 100644 index 00000000..91454741 --- /dev/null +++ b/src/main/java/com/postgraduate/global/batch/salary/CreateSalaryRepository.java @@ -0,0 +1,43 @@ +package com.postgraduate.global.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/global/batch/salary/CreateSalaryRowMapper.java b/src/main/java/com/postgraduate/global/batch/salary/CreateSalaryRowMapper.java new file mode 100644 index 00000000..05bb97de --- /dev/null +++ b/src/main/java/com/postgraduate/global/batch/salary/CreateSalaryRowMapper.java @@ -0,0 +1,19 @@ +package com.postgraduate.global.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/global/batch/scheduler/JobSchedulerConfig.java b/src/main/java/com/postgraduate/global/batch/scheduler/JobSchedulerConfig.java index 65049c67..a13e8003 100644 --- a/src/main/java/com/postgraduate/global/batch/scheduler/JobSchedulerConfig.java +++ b/src/main/java/com/postgraduate/global/batch/scheduler/JobSchedulerConfig.java @@ -25,6 +25,8 @@ public class JobSchedulerConfig { private final Job cancelJob; @Qualifier("doneJob") private final Job doneJob; + @Qualifier("salaryJob") + private final Job salaryJob; // @Scheduled(fixedDelay = 60000) //todo : 스케줄링 수정 public void launchCancelJob() throws JobInstanceAlreadyCompleteException, JobExecutionAlreadyRunningException, JobParametersInvalidException, JobRestartException { @@ -34,11 +36,19 @@ public void launchCancelJob() throws JobInstanceAlreadyCompleteException, JobExe jobLauncher.run(cancelJob, jobParameters); } - @Scheduled(fixedDelay = 600000) +// @Scheduled(fixedDelay = 600000) public void launchDoneJob() throws JobInstanceAlreadyCompleteException, JobExecutionAlreadyRunningException, JobParametersInvalidException, JobRestartException { JobParameters jobParameters = new JobParametersBuilder() .addLocalDateTime("date", LocalDateTime.now()) .toJobParameters(); jobLauncher.run(doneJob, jobParameters); } + + @Scheduled(fixedDelay = 600000) + 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/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 From af400598d58118b1641dfb7cb7a133b61037d6bb Mon Sep 17 00:00:00 2001 From: yang Date: Wed, 8 May 2024 23:56:18 +0900 Subject: [PATCH 06/19] =?UTF-8?q?RAC-364=20HotFix=20:=20=EA=B3=84=EC=A2=8C?= =?UTF-8?q?=20=EC=97=85=EB=8D=B0=EC=9D=B4=ED=8A=B8=EC=8B=9C=20=EC=A0=95?= =?UTF-8?q?=EC=82=B0=20=EB=8F=99=EA=B8=B0=ED=99=94=20=EC=98=A4=EB=A5=98=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/repository/SalaryDslRepositoryImpl.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/postgraduate/domain/salary/domain/repository/SalaryDslRepositoryImpl.java b/src/main/java/com/postgraduate/domain/salary/domain/repository/SalaryDslRepositoryImpl.java index 28574ea8..3a73d664 100644 --- a/src/main/java/com/postgraduate/domain/salary/domain/repository/SalaryDslRepositoryImpl.java +++ b/src/main/java/com/postgraduate/domain/salary/domain/repository/SalaryDslRepositoryImpl.java @@ -127,13 +127,14 @@ public List findAllByDone() { @Override public List findAllBySalaryNoneAccount(LocalDate salaryDate, Senior searchSenior) { - Salary nowSalary = queryFactory.selectFrom(salary) + List nowSalaries = queryFactory.selectFrom(salary) .where( salary.senior.eq(searchSenior), salary.salaryDate.eq(salaryDate) + .or(salary.salaryDate.goe(salaryDate)) ) - .fetchOne(); - if (nowSalary.getAccount() == null) { + .fetch(); + if (nowSalaries.get(0).getAccount() == null) { return queryFactory.selectFrom(salary) .distinct() .where( @@ -144,7 +145,7 @@ public List findAllBySalaryNoneAccount(LocalDate salaryDate, Senior sear .fetchJoin() .fetch(); } - return List.of(nowSalary); + return nowSalaries; } } From 1be784b678afa3d8cc5688fbabf80f574e35bea6 Mon Sep 17 00:00:00 2001 From: yang Date: Thu, 9 May 2024 03:17:16 +0900 Subject: [PATCH 07/19] =?UTF-8?q?RAC-360=20feat=20:=20=EC=A0=95=EC=82=B0?= =?UTF-8?q?=20=EB=B0=B0=EC=B9=98=20=EC=98=88=EC=99=B8=20=EC=8A=A4=ED=82=B5?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../global/batch/salary/CreateSalaryJobConfig.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/com/postgraduate/global/batch/salary/CreateSalaryJobConfig.java b/src/main/java/com/postgraduate/global/batch/salary/CreateSalaryJobConfig.java index 562c0dc1..03aaefe5 100644 --- a/src/main/java/com/postgraduate/global/batch/salary/CreateSalaryJobConfig.java +++ b/src/main/java/com/postgraduate/global/batch/salary/CreateSalaryJobConfig.java @@ -71,6 +71,9 @@ public Step createSalaryStep() throws Exception { .chunk(CHUNK_SIZE, transactionManager) .reader(salaryReader()) .writer(createSalaryItemWriter) + .faultTolerant() + .skip(Exception.class) + .skipLimit(Integer.MAX_VALUE) .build(); } From 980827a1063e5a50fe951cbfacbefa275561fea5 Mon Sep 17 00:00:00 2001 From: yang Date: Thu, 9 May 2024 22:25:30 +0900 Subject: [PATCH 08/19] =?UTF-8?q?RAC-360=20feat=20:=20SkipListener?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../batch/cancel/CancelMentoringWriter.java | 4 +-- .../batch/done/DoneMentoringSkipListener.java | 31 +++++++++++++++++ .../salary/CreateSalarySkipListener.java | 31 +++++++++++++++++ .../batch/scheduler/JobSchedulerConfig.java | 4 +-- .../global/slack/SlackErrorMessage.java | 33 ++++++++++++++++--- 5 files changed, 95 insertions(+), 8 deletions(-) create mode 100644 src/main/java/com/postgraduate/global/batch/done/DoneMentoringSkipListener.java create mode 100644 src/main/java/com/postgraduate/global/batch/salary/CreateSalarySkipListener.java diff --git a/src/main/java/com/postgraduate/global/batch/cancel/CancelMentoringWriter.java b/src/main/java/com/postgraduate/global/batch/cancel/CancelMentoringWriter.java index 282e6846..7014333c 100644 --- a/src/main/java/com/postgraduate/global/batch/cancel/CancelMentoringWriter.java +++ b/src/main/java/com/postgraduate/global/batch/cancel/CancelMentoringWriter.java @@ -27,7 +27,7 @@ public void write(Chunk chunk) { log.info("ChunkSize : {}", chunk.size()); chunk.forEach(this::updateCancelWithAuto); } - //todo : User 조회 수정 (비즈뿌리오와 함께) + public void updateCancelWithAuto(CancelMentoring mentoring) { try { User user = userGetService.byUserId(mentoring.userId()); @@ -39,7 +39,7 @@ public void updateCancelWithAuto(CancelMentoring mentoring) { } catch (Exception ex) { log.error("mentoringId : {} 자동 취소 실패", mentoring.mentoringId()); log.error(ex.getMessage()); - slackErrorMessage.sendSlackError(mentoring.mentoringId(), ex); + slackErrorMessage.sendSlackMentoringError(mentoring.mentoringId(), ex); throw ex; } } diff --git a/src/main/java/com/postgraduate/global/batch/done/DoneMentoringSkipListener.java b/src/main/java/com/postgraduate/global/batch/done/DoneMentoringSkipListener.java new file mode 100644 index 00000000..86419030 --- /dev/null +++ b/src/main/java/com/postgraduate/global/batch/done/DoneMentoringSkipListener.java @@ -0,0 +1,31 @@ +package com.postgraduate.global.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/global/batch/salary/CreateSalarySkipListener.java b/src/main/java/com/postgraduate/global/batch/salary/CreateSalarySkipListener.java new file mode 100644 index 00000000..c705aa16 --- /dev/null +++ b/src/main/java/com/postgraduate/global/batch/salary/CreateSalarySkipListener.java @@ -0,0 +1,31 @@ +package com.postgraduate.global.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/global/batch/scheduler/JobSchedulerConfig.java b/src/main/java/com/postgraduate/global/batch/scheduler/JobSchedulerConfig.java index a13e8003..5848e920 100644 --- a/src/main/java/com/postgraduate/global/batch/scheduler/JobSchedulerConfig.java +++ b/src/main/java/com/postgraduate/global/batch/scheduler/JobSchedulerConfig.java @@ -36,7 +36,7 @@ public void launchCancelJob() throws JobInstanceAlreadyCompleteException, JobExe jobLauncher.run(cancelJob, jobParameters); } -// @Scheduled(fixedDelay = 600000) + @Scheduled(fixedDelay = 600000) public void launchDoneJob() throws JobInstanceAlreadyCompleteException, JobExecutionAlreadyRunningException, JobParametersInvalidException, JobRestartException { JobParameters jobParameters = new JobParametersBuilder() .addLocalDateTime("date", LocalDateTime.now()) @@ -44,7 +44,7 @@ public void launchDoneJob() throws JobInstanceAlreadyCompleteException, JobExecu jobLauncher.run(doneJob, jobParameters); } - @Scheduled(fixedDelay = 600000) +// @Scheduled(fixedDelay = 600000) public void launchSalaryJob() throws JobInstanceAlreadyCompleteException, JobExecutionAlreadyRunningException, JobParametersInvalidException, JobRestartException { JobParameters jobParameters = new JobParametersBuilder() .addLocalDateTime("date", LocalDateTime.now()) diff --git a/src/main/java/com/postgraduate/global/slack/SlackErrorMessage.java b/src/main/java/com/postgraduate/global/slack/SlackErrorMessage.java index d91e8fca..b50e130e 100644 --- a/src/main/java/com/postgraduate/global/slack/SlackErrorMessage.java +++ b/src/main/java/com/postgraduate/global/slack/SlackErrorMessage.java @@ -38,12 +38,25 @@ public void sendSlackError(Mentoring mentoring, Exception ex) { } } - public void sendSlackError(Long mentoringId, Exception ex) { + public void sendSlackMentoringError(Long mentoringId, Throwable ex) { try { slackClient.send(logWebHookUrl, Payload.builder() - .text("자동 갱신 에러 발생!! 백엔드팀 확인 요망!!") + .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(generateErrorSlackAttachment(mentoringId, ex)) + List.of(generateSalaryErrorSlackAttachment(seniorId, ex)) ) .build()); } catch (IOException e) { @@ -51,7 +64,7 @@ public void sendSlackError(Long mentoringId, Exception ex) { } } - private Attachment generateErrorSlackAttachment(Long mentoringId, Exception ex) { + 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") @@ -74,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(); + } } From 457b6ab4554752e81102067e9f6679cbfda9b113 Mon Sep 17 00:00:00 2001 From: yang Date: Fri, 10 May 2024 01:07:19 +0900 Subject: [PATCH 09/19] =?UTF-8?q?RAC-360=20refactor=20:=20=ED=8C=A8?= =?UTF-8?q?=ED=82=A4=EC=A7=80=20=EC=88=98=EC=A0=95=20=EB=B0=8F=20=EC=8A=A4?= =?UTF-8?q?=EC=BC=80=EC=A4=84=EB=9F=AC=20=EC=A1=B0=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../{global => }/batch/cancel/CancelJobConfig.java | 4 ++-- .../{global => }/batch/cancel/CancelMentoring.java | 2 +- .../batch/cancel/CancelMentoringRepository.java | 2 +- .../batch/cancel/CancelMentoringRowMapper.java | 2 +- .../{global => }/batch/cancel/CancelMentoringWriter.java | 4 ++-- .../{global => }/batch/done/DoneJobConfig.java | 4 ++-- .../{global => }/batch/done/DoneMentoring.java | 2 +- .../{global => }/batch/done/DoneMentoringProcessor.java | 2 +- .../{global => }/batch/done/DoneMentoringRepository.java | 2 +- .../{global => }/batch/done/DoneMentoringRowMapper.java | 2 +- .../batch/done/DoneMentoringSkipListener.java | 2 +- .../{global => }/batch/done/DoneMentoringWriter.java | 2 +- .../{global => }/batch/salary/CreateSalary.java | 2 +- .../batch/salary/CreateSalaryItemWriter.java | 3 ++- .../{global => }/batch/salary/CreateSalaryJobConfig.java | 9 ++------- .../batch/salary/CreateSalaryRepository.java | 2 +- .../{global => }/batch/salary/CreateSalaryRowMapper.java | 2 +- .../batch/salary/CreateSalarySkipListener.java | 2 +- .../{global => }/batch/scheduler/JobSchedulerConfig.java | 8 ++++---- 19 files changed, 27 insertions(+), 31 deletions(-) rename src/main/java/com/postgraduate/{global => }/batch/cancel/CancelJobConfig.java (97%) rename src/main/java/com/postgraduate/{global => }/batch/cancel/CancelMentoring.java (71%) rename src/main/java/com/postgraduate/{global => }/batch/cancel/CancelMentoringRepository.java (97%) rename src/main/java/com/postgraduate/{global => }/batch/cancel/CancelMentoringRowMapper.java (91%) rename src/main/java/com/postgraduate/{global => }/batch/cancel/CancelMentoringWriter.java (97%) rename src/main/java/com/postgraduate/{global => }/batch/done/DoneJobConfig.java (97%) rename src/main/java/com/postgraduate/{global => }/batch/done/DoneMentoring.java (76%) rename src/main/java/com/postgraduate/{global => }/batch/done/DoneMentoringProcessor.java (94%) rename src/main/java/com/postgraduate/{global => }/batch/done/DoneMentoringRepository.java (97%) rename src/main/java/com/postgraduate/{global => }/batch/done/DoneMentoringRowMapper.java (92%) rename src/main/java/com/postgraduate/{global => }/batch/done/DoneMentoringSkipListener.java (96%) rename src/main/java/com/postgraduate/{global => }/batch/done/DoneMentoringWriter.java (95%) rename src/main/java/com/postgraduate/{global => }/batch/salary/CreateSalary.java (77%) rename src/main/java/com/postgraduate/{global => }/batch/salary/CreateSalaryItemWriter.java (86%) rename src/main/java/com/postgraduate/{global => }/batch/salary/CreateSalaryJobConfig.java (92%) rename src/main/java/com/postgraduate/{global => }/batch/salary/CreateSalaryRepository.java (97%) rename src/main/java/com/postgraduate/{global => }/batch/salary/CreateSalaryRowMapper.java (92%) rename src/main/java/com/postgraduate/{global => }/batch/salary/CreateSalarySkipListener.java (96%) rename src/main/java/com/postgraduate/{global => }/batch/scheduler/JobSchedulerConfig.java (91%) diff --git a/src/main/java/com/postgraduate/global/batch/cancel/CancelJobConfig.java b/src/main/java/com/postgraduate/batch/cancel/CancelJobConfig.java similarity index 97% rename from src/main/java/com/postgraduate/global/batch/cancel/CancelJobConfig.java rename to src/main/java/com/postgraduate/batch/cancel/CancelJobConfig.java index 1d875620..760226cb 100644 --- a/src/main/java/com/postgraduate/global/batch/cancel/CancelJobConfig.java +++ b/src/main/java/com/postgraduate/batch/cancel/CancelJobConfig.java @@ -1,4 +1,4 @@ -package com.postgraduate.global.batch.cancel; +package com.postgraduate.batch.cancel; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -32,7 +32,7 @@ public class CancelJobConfig { private final CancelMentoringWriter cancelMentoringWriter; private final DataSource dataSource; - private static final int CHUNK_SIZE = 10; + private static final int CHUNK_SIZE = 50; @Bean(name = "cancelJob") public Job cancelJob() throws Exception { diff --git a/src/main/java/com/postgraduate/global/batch/cancel/CancelMentoring.java b/src/main/java/com/postgraduate/batch/cancel/CancelMentoring.java similarity index 71% rename from src/main/java/com/postgraduate/global/batch/cancel/CancelMentoring.java rename to src/main/java/com/postgraduate/batch/cancel/CancelMentoring.java index c583e3eb..dcffb003 100644 --- a/src/main/java/com/postgraduate/global/batch/cancel/CancelMentoring.java +++ b/src/main/java/com/postgraduate/batch/cancel/CancelMentoring.java @@ -1,4 +1,4 @@ -package com.postgraduate.global.batch.cancel; +package com.postgraduate.batch.cancel; public record CancelMentoring( Long mentoringId, diff --git a/src/main/java/com/postgraduate/global/batch/cancel/CancelMentoringRepository.java b/src/main/java/com/postgraduate/batch/cancel/CancelMentoringRepository.java similarity index 97% rename from src/main/java/com/postgraduate/global/batch/cancel/CancelMentoringRepository.java rename to src/main/java/com/postgraduate/batch/cancel/CancelMentoringRepository.java index 8ca80586..d3b7d5aa 100644 --- a/src/main/java/com/postgraduate/global/batch/cancel/CancelMentoringRepository.java +++ b/src/main/java/com/postgraduate/batch/cancel/CancelMentoringRepository.java @@ -1,4 +1,4 @@ -package com.postgraduate.global.batch.cancel; +package com.postgraduate.batch.cancel; import lombok.RequiredArgsConstructor; import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; diff --git a/src/main/java/com/postgraduate/global/batch/cancel/CancelMentoringRowMapper.java b/src/main/java/com/postgraduate/batch/cancel/CancelMentoringRowMapper.java similarity index 91% rename from src/main/java/com/postgraduate/global/batch/cancel/CancelMentoringRowMapper.java rename to src/main/java/com/postgraduate/batch/cancel/CancelMentoringRowMapper.java index 25ff0a16..fdcd9d7f 100644 --- a/src/main/java/com/postgraduate/global/batch/cancel/CancelMentoringRowMapper.java +++ b/src/main/java/com/postgraduate/batch/cancel/CancelMentoringRowMapper.java @@ -1,4 +1,4 @@ -package com.postgraduate.global.batch.cancel; +package com.postgraduate.batch.cancel; import org.springframework.jdbc.core.RowMapper; diff --git a/src/main/java/com/postgraduate/global/batch/cancel/CancelMentoringWriter.java b/src/main/java/com/postgraduate/batch/cancel/CancelMentoringWriter.java similarity index 97% rename from src/main/java/com/postgraduate/global/batch/cancel/CancelMentoringWriter.java rename to src/main/java/com/postgraduate/batch/cancel/CancelMentoringWriter.java index 7014333c..1f3ac01b 100644 --- a/src/main/java/com/postgraduate/global/batch/cancel/CancelMentoringWriter.java +++ b/src/main/java/com/postgraduate/batch/cancel/CancelMentoringWriter.java @@ -1,4 +1,4 @@ -package com.postgraduate.global.batch.cancel; +package com.postgraduate.batch.cancel; import com.postgraduate.domain.payment.application.usecase.PaymentManageUseCase; import com.postgraduate.domain.user.domain.entity.User; @@ -31,9 +31,9 @@ public void write(Chunk chunk) { public void updateCancelWithAuto(CancelMentoring mentoring) { try { User user = userGetService.byUserId(mentoring.userId()); - paymentManageUseCase.refundPayByUser(mentoring.userId(), mentoring.paymentId()); 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) { diff --git a/src/main/java/com/postgraduate/global/batch/done/DoneJobConfig.java b/src/main/java/com/postgraduate/batch/done/DoneJobConfig.java similarity index 97% rename from src/main/java/com/postgraduate/global/batch/done/DoneJobConfig.java rename to src/main/java/com/postgraduate/batch/done/DoneJobConfig.java index 5632274a..ffded85c 100644 --- a/src/main/java/com/postgraduate/global/batch/done/DoneJobConfig.java +++ b/src/main/java/com/postgraduate/batch/done/DoneJobConfig.java @@ -1,4 +1,4 @@ -package com.postgraduate.global.batch.done; +package com.postgraduate.batch.done; import lombok.RequiredArgsConstructor; import org.springframework.batch.core.Job; @@ -25,7 +25,7 @@ public class DoneJobConfig { private final DoneMentoringProcessor doneMentoringProcessor; private final DoneMentoringWriter doneMentoringWriter; - private static final int CHUNK_SIZE = 10; + private static final int CHUNK_SIZE = 50; @Bean(name = "doneJob") public Job doneJob() throws Exception { diff --git a/src/main/java/com/postgraduate/global/batch/done/DoneMentoring.java b/src/main/java/com/postgraduate/batch/done/DoneMentoring.java similarity index 76% rename from src/main/java/com/postgraduate/global/batch/done/DoneMentoring.java rename to src/main/java/com/postgraduate/batch/done/DoneMentoring.java index cea75132..301ad211 100644 --- a/src/main/java/com/postgraduate/global/batch/done/DoneMentoring.java +++ b/src/main/java/com/postgraduate/batch/done/DoneMentoring.java @@ -1,4 +1,4 @@ -package com.postgraduate.global.batch.done; +package com.postgraduate.batch.done; public record DoneMentoring( Long mentoringId, diff --git a/src/main/java/com/postgraduate/global/batch/done/DoneMentoringProcessor.java b/src/main/java/com/postgraduate/batch/done/DoneMentoringProcessor.java similarity index 94% rename from src/main/java/com/postgraduate/global/batch/done/DoneMentoringProcessor.java rename to src/main/java/com/postgraduate/batch/done/DoneMentoringProcessor.java index 6f16fc9d..e1535553 100644 --- a/src/main/java/com/postgraduate/global/batch/done/DoneMentoringProcessor.java +++ b/src/main/java/com/postgraduate/batch/done/DoneMentoringProcessor.java @@ -1,4 +1,4 @@ -package com.postgraduate.global.batch.done; +package com.postgraduate.batch.done; import org.springframework.batch.item.ItemProcessor; import org.springframework.stereotype.Component; diff --git a/src/main/java/com/postgraduate/global/batch/done/DoneMentoringRepository.java b/src/main/java/com/postgraduate/batch/done/DoneMentoringRepository.java similarity index 97% rename from src/main/java/com/postgraduate/global/batch/done/DoneMentoringRepository.java rename to src/main/java/com/postgraduate/batch/done/DoneMentoringRepository.java index 8b5ca74a..15db419f 100644 --- a/src/main/java/com/postgraduate/global/batch/done/DoneMentoringRepository.java +++ b/src/main/java/com/postgraduate/batch/done/DoneMentoringRepository.java @@ -1,4 +1,4 @@ -package com.postgraduate.global.batch.done; +package com.postgraduate.batch.done; import com.postgraduate.domain.mentoring.domain.entity.constant.TermUnit; import lombok.RequiredArgsConstructor; diff --git a/src/main/java/com/postgraduate/global/batch/done/DoneMentoringRowMapper.java b/src/main/java/com/postgraduate/batch/done/DoneMentoringRowMapper.java similarity index 92% rename from src/main/java/com/postgraduate/global/batch/done/DoneMentoringRowMapper.java rename to src/main/java/com/postgraduate/batch/done/DoneMentoringRowMapper.java index cfa0c426..a7ee0d71 100644 --- a/src/main/java/com/postgraduate/global/batch/done/DoneMentoringRowMapper.java +++ b/src/main/java/com/postgraduate/batch/done/DoneMentoringRowMapper.java @@ -1,4 +1,4 @@ -package com.postgraduate.global.batch.done; +package com.postgraduate.batch.done; import org.springframework.jdbc.core.RowMapper; diff --git a/src/main/java/com/postgraduate/global/batch/done/DoneMentoringSkipListener.java b/src/main/java/com/postgraduate/batch/done/DoneMentoringSkipListener.java similarity index 96% rename from src/main/java/com/postgraduate/global/batch/done/DoneMentoringSkipListener.java rename to src/main/java/com/postgraduate/batch/done/DoneMentoringSkipListener.java index 86419030..6f75a1df 100644 --- a/src/main/java/com/postgraduate/global/batch/done/DoneMentoringSkipListener.java +++ b/src/main/java/com/postgraduate/batch/done/DoneMentoringSkipListener.java @@ -1,4 +1,4 @@ -package com.postgraduate.global.batch.done; +package com.postgraduate.batch.done; import com.postgraduate.global.slack.SlackErrorMessage; import lombok.RequiredArgsConstructor; diff --git a/src/main/java/com/postgraduate/global/batch/done/DoneMentoringWriter.java b/src/main/java/com/postgraduate/batch/done/DoneMentoringWriter.java similarity index 95% rename from src/main/java/com/postgraduate/global/batch/done/DoneMentoringWriter.java rename to src/main/java/com/postgraduate/batch/done/DoneMentoringWriter.java index b165e9c5..22b1403f 100644 --- a/src/main/java/com/postgraduate/global/batch/done/DoneMentoringWriter.java +++ b/src/main/java/com/postgraduate/batch/done/DoneMentoringWriter.java @@ -1,4 +1,4 @@ -package com.postgraduate.global.batch.done; +package com.postgraduate.batch.done; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; diff --git a/src/main/java/com/postgraduate/global/batch/salary/CreateSalary.java b/src/main/java/com/postgraduate/batch/salary/CreateSalary.java similarity index 77% rename from src/main/java/com/postgraduate/global/batch/salary/CreateSalary.java rename to src/main/java/com/postgraduate/batch/salary/CreateSalary.java index 71c21f0b..e143f0e2 100644 --- a/src/main/java/com/postgraduate/global/batch/salary/CreateSalary.java +++ b/src/main/java/com/postgraduate/batch/salary/CreateSalary.java @@ -1,4 +1,4 @@ -package com.postgraduate.global.batch.salary; +package com.postgraduate.batch.salary; public record CreateSalary( Long seniorId, diff --git a/src/main/java/com/postgraduate/global/batch/salary/CreateSalaryItemWriter.java b/src/main/java/com/postgraduate/batch/salary/CreateSalaryItemWriter.java similarity index 86% rename from src/main/java/com/postgraduate/global/batch/salary/CreateSalaryItemWriter.java rename to src/main/java/com/postgraduate/batch/salary/CreateSalaryItemWriter.java index b41465e6..d8bd95d8 100644 --- a/src/main/java/com/postgraduate/global/batch/salary/CreateSalaryItemWriter.java +++ b/src/main/java/com/postgraduate/batch/salary/CreateSalaryItemWriter.java @@ -1,4 +1,4 @@ -package com.postgraduate.global.batch.salary; +package com.postgraduate.batch.salary; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -20,5 +20,6 @@ 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/global/batch/salary/CreateSalaryJobConfig.java b/src/main/java/com/postgraduate/batch/salary/CreateSalaryJobConfig.java similarity index 92% rename from src/main/java/com/postgraduate/global/batch/salary/CreateSalaryJobConfig.java rename to src/main/java/com/postgraduate/batch/salary/CreateSalaryJobConfig.java index 03aaefe5..27eb3afa 100644 --- a/src/main/java/com/postgraduate/global/batch/salary/CreateSalaryJobConfig.java +++ b/src/main/java/com/postgraduate/batch/salary/CreateSalaryJobConfig.java @@ -1,4 +1,4 @@ -package com.postgraduate.global.batch.salary; +package com.postgraduate.batch.salary; import com.postgraduate.domain.salary.domain.entity.Salary; import com.postgraduate.domain.salary.domain.service.SalaryGetService; @@ -7,14 +7,9 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.batch.core.Job; import org.springframework.batch.core.Step; -import org.springframework.batch.core.StepContribution; import org.springframework.batch.core.job.builder.JobBuilder; import org.springframework.batch.core.repository.JobRepository; -import org.springframework.batch.core.scope.context.ChunkContext; import org.springframework.batch.core.step.builder.StepBuilder; -import org.springframework.batch.core.step.tasklet.Tasklet; -import org.springframework.batch.item.Chunk; -import org.springframework.batch.item.ItemWriter; import org.springframework.batch.item.database.JdbcPagingItemReader; import org.springframework.batch.item.database.PagingQueryProvider; import org.springframework.batch.item.database.builder.JdbcPagingItemReaderBuilder; @@ -42,7 +37,7 @@ public class CreateSalaryJobConfig { private final CreateSalaryItemWriter createSalaryItemWriter; private final DataSource dataSource; - private static final int CHUNK_SIZE = 10; + private static final int CHUNK_SIZE = 50; @Bean(name = "salaryJob") public Job salaryJob() throws Exception { diff --git a/src/main/java/com/postgraduate/global/batch/salary/CreateSalaryRepository.java b/src/main/java/com/postgraduate/batch/salary/CreateSalaryRepository.java similarity index 97% rename from src/main/java/com/postgraduate/global/batch/salary/CreateSalaryRepository.java rename to src/main/java/com/postgraduate/batch/salary/CreateSalaryRepository.java index 91454741..2a50b27d 100644 --- a/src/main/java/com/postgraduate/global/batch/salary/CreateSalaryRepository.java +++ b/src/main/java/com/postgraduate/batch/salary/CreateSalaryRepository.java @@ -1,4 +1,4 @@ -package com.postgraduate.global.batch.salary; +package com.postgraduate.batch.salary; import lombok.RequiredArgsConstructor; import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; diff --git a/src/main/java/com/postgraduate/global/batch/salary/CreateSalaryRowMapper.java b/src/main/java/com/postgraduate/batch/salary/CreateSalaryRowMapper.java similarity index 92% rename from src/main/java/com/postgraduate/global/batch/salary/CreateSalaryRowMapper.java rename to src/main/java/com/postgraduate/batch/salary/CreateSalaryRowMapper.java index 05bb97de..dccd6887 100644 --- a/src/main/java/com/postgraduate/global/batch/salary/CreateSalaryRowMapper.java +++ b/src/main/java/com/postgraduate/batch/salary/CreateSalaryRowMapper.java @@ -1,4 +1,4 @@ -package com.postgraduate.global.batch.salary; +package com.postgraduate.batch.salary; import org.springframework.jdbc.core.RowMapper; diff --git a/src/main/java/com/postgraduate/global/batch/salary/CreateSalarySkipListener.java b/src/main/java/com/postgraduate/batch/salary/CreateSalarySkipListener.java similarity index 96% rename from src/main/java/com/postgraduate/global/batch/salary/CreateSalarySkipListener.java rename to src/main/java/com/postgraduate/batch/salary/CreateSalarySkipListener.java index c705aa16..b3396e5c 100644 --- a/src/main/java/com/postgraduate/global/batch/salary/CreateSalarySkipListener.java +++ b/src/main/java/com/postgraduate/batch/salary/CreateSalarySkipListener.java @@ -1,4 +1,4 @@ -package com.postgraduate.global.batch.salary; +package com.postgraduate.batch.salary; import com.postgraduate.global.slack.SlackErrorMessage; import lombok.RequiredArgsConstructor; diff --git a/src/main/java/com/postgraduate/global/batch/scheduler/JobSchedulerConfig.java b/src/main/java/com/postgraduate/batch/scheduler/JobSchedulerConfig.java similarity index 91% rename from src/main/java/com/postgraduate/global/batch/scheduler/JobSchedulerConfig.java rename to src/main/java/com/postgraduate/batch/scheduler/JobSchedulerConfig.java index 5848e920..a2c675ac 100644 --- a/src/main/java/com/postgraduate/global/batch/scheduler/JobSchedulerConfig.java +++ b/src/main/java/com/postgraduate/batch/scheduler/JobSchedulerConfig.java @@ -1,4 +1,4 @@ -package com.postgraduate.global.batch.scheduler; +package com.postgraduate.batch.scheduler; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -28,7 +28,7 @@ public class JobSchedulerConfig { @Qualifier("salaryJob") private final Job salaryJob; -// @Scheduled(fixedDelay = 60000) //todo : 스케줄링 수정 + @Scheduled(cron = "0 59 23 * * *", zone = "Asia/Seoul") public void launchCancelJob() throws JobInstanceAlreadyCompleteException, JobExecutionAlreadyRunningException, JobParametersInvalidException, JobRestartException { JobParameters jobParameters = new JobParametersBuilder() .addLocalDateTime("date", LocalDateTime.now()) @@ -36,7 +36,7 @@ public void launchCancelJob() throws JobInstanceAlreadyCompleteException, JobExe jobLauncher.run(cancelJob, jobParameters); } - @Scheduled(fixedDelay = 600000) + @Scheduled(cron = "0 59 23 * * *", zone = "Asia/Seoul") public void launchDoneJob() throws JobInstanceAlreadyCompleteException, JobExecutionAlreadyRunningException, JobParametersInvalidException, JobRestartException { JobParameters jobParameters = new JobParametersBuilder() .addLocalDateTime("date", LocalDateTime.now()) @@ -44,7 +44,7 @@ public void launchDoneJob() throws JobInstanceAlreadyCompleteException, JobExecu jobLauncher.run(doneJob, jobParameters); } -// @Scheduled(fixedDelay = 600000) + @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()) From f73e2ccd58cd92f0b0274463367dad182b70bbdd Mon Sep 17 00:00:00 2001 From: yang Date: Fri, 10 May 2024 01:11:23 +0900 Subject: [PATCH 10/19] =?UTF-8?q?RAC-360=20feat=20:=20SkipListener=20Step?= =?UTF-8?q?=EC=97=90=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../postgraduate/batch/done/DoneJobConfig.java | 2 ++ .../batch/salary/CreateSalaryJobConfig.java | 2 ++ .../usecase/MentoringManageUseCase.java | 9 --------- .../usecase/MentoringRenewalUseCase.java | 17 ----------------- 4 files changed, 4 insertions(+), 26 deletions(-) diff --git a/src/main/java/com/postgraduate/batch/done/DoneJobConfig.java b/src/main/java/com/postgraduate/batch/done/DoneJobConfig.java index ffded85c..f0966f78 100644 --- a/src/main/java/com/postgraduate/batch/done/DoneJobConfig.java +++ b/src/main/java/com/postgraduate/batch/done/DoneJobConfig.java @@ -24,6 +24,7 @@ public class DoneJobConfig { private final DataSource dataSource; private final DoneMentoringProcessor doneMentoringProcessor; private final DoneMentoringWriter doneMentoringWriter; + private final DoneMentoringSkipListener doneMentoringSkipListener; private static final int CHUNK_SIZE = 50; @@ -44,6 +45,7 @@ public Step doneStep() throws Exception { .faultTolerant() .skip(Exception.class) .skipLimit(Integer.MAX_VALUE) + .listener(doneMentoringSkipListener) .build(); } diff --git a/src/main/java/com/postgraduate/batch/salary/CreateSalaryJobConfig.java b/src/main/java/com/postgraduate/batch/salary/CreateSalaryJobConfig.java index 27eb3afa..d5c14b23 100644 --- a/src/main/java/com/postgraduate/batch/salary/CreateSalaryJobConfig.java +++ b/src/main/java/com/postgraduate/batch/salary/CreateSalaryJobConfig.java @@ -35,6 +35,7 @@ public class CreateSalaryJobConfig { 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; @@ -69,6 +70,7 @@ public Step createSalaryStep() throws Exception { .faultTolerant() .skip(Exception.class) .skipLimit(Integer.MAX_VALUE) + .listener(createSalarySkipListener) .build(); } 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..66c79efe 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 @@ -115,15 +115,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(); 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 index a7ac361f..5c43f3e9 100644 --- a/src/main/java/com/postgraduate/domain/mentoring/application/usecase/MentoringRenewalUseCase.java +++ b/src/main/java/com/postgraduate/domain/mentoring/application/usecase/MentoringRenewalUseCase.java @@ -34,23 +34,6 @@ public class MentoringRenewalUseCase { 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()); From dae3e324cd6f1cc3ad96b7c18427af1a3283c02e Mon Sep 17 00:00:00 2001 From: yang Date: Fri, 10 May 2024 01:26:49 +0900 Subject: [PATCH 11/19] =?UTF-8?q?RAC-360=20refactor=20:=20=EA=B8=B0?= =?UTF-8?q?=EC=A1=B4=20=EB=B0=B0=EC=B9=98=20=ED=94=84=EB=A1=9C=EC=84=B8?= =?UTF-8?q?=EC=8A=A4=20=EC=8A=A4=ED=94=84=EB=A7=81=20=EB=B0=B0=EC=B9=98?= =?UTF-8?q?=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../batch/salary/CreateSalaryJobConfig.java | 4 -- .../usecase/MentoringManageUseCase.java | 20 +------ .../usecase/MentoringRenewalUseCase.java | 52 ------------------- .../usecase/SalaryManageUseCase.java | 36 ------------- .../usecase/SalaryRenewalUseCase.java | 25 --------- .../domain/service/SalaryGetService.java | 5 -- 6 files changed, 1 insertion(+), 141 deletions(-) delete mode 100644 src/main/java/com/postgraduate/domain/mentoring/application/usecase/MentoringRenewalUseCase.java delete mode 100644 src/main/java/com/postgraduate/domain/salary/application/usecase/SalaryManageUseCase.java delete mode 100644 src/main/java/com/postgraduate/domain/salary/application/usecase/SalaryRenewalUseCase.java diff --git a/src/main/java/com/postgraduate/batch/salary/CreateSalaryJobConfig.java b/src/main/java/com/postgraduate/batch/salary/CreateSalaryJobConfig.java index d5c14b23..bfcdb05c 100644 --- a/src/main/java/com/postgraduate/batch/salary/CreateSalaryJobConfig.java +++ b/src/main/java/com/postgraduate/batch/salary/CreateSalaryJobConfig.java @@ -4,7 +4,6 @@ import com.postgraduate.domain.salary.domain.service.SalaryGetService; import com.postgraduate.global.slack.SlackSalaryMessage; 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; @@ -28,7 +27,6 @@ @Configuration @RequiredArgsConstructor -@Slf4j public class CreateSalaryJobConfig { private final JobRepository jobRepository; private final PlatformTransactionManager transactionManager; @@ -54,8 +52,6 @@ public Step sendSlackStep() { .tasklet((contribution, chunkContext) -> { List salaries = salaryGetService.findAllLast(); slackSalaryMessage.sendSlackSalary(salaries); - log.info("salarySize : {}", salaries.size()); // 임시 - salaries.forEach(salary -> log.info("salary : {}", salary.getTotalAmount())); // 임시 return RepeatStatus.FINISHED; }, transactionManager) .build(); 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 66c79efe..c5693a9c 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 @@ -23,7 +23,6 @@ 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 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,21 +112,6 @@ public Boolean updateExpected(User user, Long mentoringId, MentoringDateRequest return account.isPresent(); } - @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 5c43f3e9..00000000 --- a/src/main/java/com/postgraduate/domain/mentoring/application/usecase/MentoringRenewalUseCase.java +++ /dev/null @@ -1,52 +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 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/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); From 2ee23afca458526a2796d0327e8aba6b9652d838 Mon Sep 17 00:00:00 2001 From: yang Date: Fri, 10 May 2024 02:01:55 +0900 Subject: [PATCH 12/19] =?UTF-8?q?RAC-360=20test=20:=20=EA=B8=B0=EC=A1=B4?= =?UTF-8?q?=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=BD=94=EB=93=9C=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD=EC=82=AC=ED=95=AD=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Integration/AuthControllerTest.java | 6 +-- .../Integration/MentoringControllerTest.java | 20 ++++----- .../Integration/SalaryControllerTest.java | 2 +- .../Integration/SeniorControllerTest.java | 4 +- .../Integration/UserControllerTest.java | 2 +- .../usecase/MentoringManageUseTypeTest.java | 41 +----------------- .../usecase/SalaryManageUseTypeTest.java | 43 ------------------- .../usecase/SalaryRenewalUseTypeTest.java | 33 -------------- 8 files changed, 18 insertions(+), 133 deletions(-) delete mode 100644 src/test/java/com/postgraduate/domain/salary/application/usecase/SalaryManageUseTypeTest.java delete mode 100644 src/test/java/com/postgraduate/domain/salary/application/usecase/SalaryRenewalUseTypeTest.java diff --git a/src/test/java/com/postgraduate/Integration/AuthControllerTest.java b/src/test/java/com/postgraduate/Integration/AuthControllerTest.java index 5de6f65e..84a50fe0 100644 --- a/src/test/java/com/postgraduate/Integration/AuthControllerTest.java +++ b/src/test/java/com/postgraduate/Integration/AuthControllerTest.java @@ -39,11 +39,11 @@ class AuthControllerTest extends IntegrationTest { private static final String AUTHORIZATION = "Authorization"; private static final String BEARER = "Bearer "; private User user; - private final Long anonymousUserSocialId = 2L; + private final Long anonymousUserSocialId = -5L; @BeforeEach void setUp() { - user = new User(0L, 1L, "mail", "후배", "011", "profile", 0, USER, true, now(), now(), false); + user = new User(-1L, -1L, "mail", "후배", "011", "profile", 0, USER, true, now(), now(), false); userRepository.save(user); doNothing().when(slackLogErrorMessage).sendSlackLog(any()); doNothing().when(slackSignUpMessage).sendSeniorSignUp(any()); @@ -299,7 +299,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); + User senior = new User(-3L, -3L, "mail", "선배", "011", "profile", 0, SENIOR, true, now(), now(), false); userRepository.save(senior); String token = jwtUtil.generateAccessToken(senior.getUserId(), USER); diff --git a/src/test/java/com/postgraduate/Integration/MentoringControllerTest.java b/src/test/java/com/postgraduate/Integration/MentoringControllerTest.java index 0ecf6e89..8af7193a 100644 --- a/src/test/java/com/postgraduate/Integration/MentoringControllerTest.java +++ b/src/test/java/com/postgraduate/Integration/MentoringControllerTest.java @@ -52,22 +52,22 @@ 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 = new User(-1L, -1L, "mail", "후배", "011", "profile", 0, Role.USER, true, now(), now(), false); userRepository.save(user); - User userOfSenior = new User(0L, 2L, "mail", "선배", "012", "profile", 0, Role.SENIOR, true, now(), now(), false); + User userOfSenior = new User(-2L, -2L, "mail", "선배", "012", "profile", 0, Role.SENIOR, true, now(), now(), false); userRepository.save(userOfSenior); 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()); + senior = new Senior(-1L, userOfSenior, "certification", WAITING, 0, info, profile, now(), now()); seniorRepository.save(senior); SalaryAccount salaryAccount = new SalaryAccount("bank", "1234", "holder"); - salary = new Salary(0L, false, senior, 20000, getSalaryDate(), LocalDateTime.now(), salaryAccount); + salary = new Salary(-1L, false, senior, 20000, getSalaryDate(), LocalDateTime.now(), salaryAccount); salaryRepository.save(salary); - payment = new Payment(0L, user, senior, 20000, "1", "123", "123", LocalDateTime.now(), LocalDateTime.now(), DONE); + payment = new Payment(-1L, user, senior, 20000, "1", "123", "123", LocalDateTime.now(), LocalDateTime.now(), DONE); paymentRepository.save(payment); userAccessToken = jwtUtil.generateAccessToken(user.getUserId(), Role.USER); @@ -124,9 +124,9 @@ 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); + User otherUser = new User(-3L, -3L, "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(-3L, otherUser, senior, payment, null, "topic", "question", "date", 40, Status.EXPECTED, now(), now()); mentoringRepository.save(mentoring); mvc.perform(get("/mentoring/me/{mentoringId}", mentoring.getMentoringId()) @@ -293,14 +293,14 @@ 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); + User otherUser = new User(-3L, -3L, "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()); + Senior otherSenior = new Senior(-3L, 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(-3L, otherUser, otherSenior, payment, null, "topic", "question", "date", 40, Status.EXPECTED, now(), now()); mentoringRepository.save(mentoring); mvc.perform(get("/mentoring/senior/me/{mentoringId}", mentoring.getMentoringId()) diff --git a/src/test/java/com/postgraduate/Integration/SalaryControllerTest.java b/src/test/java/com/postgraduate/Integration/SalaryControllerTest.java index 6011c3a1..7fd55953 100644 --- a/src/test/java/com/postgraduate/Integration/SalaryControllerTest.java +++ b/src/test/java/com/postgraduate/Integration/SalaryControllerTest.java @@ -35,7 +35,7 @@ class SalaryControllerTest extends IntegrationTest { @BeforeEach void setUp() throws IOException { - User user = new User(0L, 1L, "mail", "후배", "011", "profile", 0, Role.SENIOR, true, now(), now(), false); + User user = new User(0L, -1L, "mail", "후배", "011", "profile", 0, Role.SENIOR, true, now(), now(), false); userRepository.save(user); Info info = new Info("major", "postgradu", "교수님", "keyword1,keyword2", "랩실", "field", false, false, "field,keyword1,keyword2", "chatLink", 30); diff --git a/src/test/java/com/postgraduate/Integration/SeniorControllerTest.java b/src/test/java/com/postgraduate/Integration/SeniorControllerTest.java index 27288a5b..ce79bad2 100644 --- a/src/test/java/com/postgraduate/Integration/SeniorControllerTest.java +++ b/src/test/java/com/postgraduate/Integration/SeniorControllerTest.java @@ -56,8 +56,8 @@ class SeniorControllerTest extends IntegrationTest { @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 = new User(-2L, -2L, "mail", "후배1", "011", "profile", 0, Role.SENIOR, true, now(), now(), false); + otherUser = new User(-1L, -1L, "mail", "후배2", "011", "profile", 0, Role.SENIOR, true, now(), now(), false); userRepository.save(user); userRepository.save(otherUser); diff --git a/src/test/java/com/postgraduate/Integration/UserControllerTest.java b/src/test/java/com/postgraduate/Integration/UserControllerTest.java index aa1b6db0..6c2c7b73 100644 --- a/src/test/java/com/postgraduate/Integration/UserControllerTest.java +++ b/src/test/java/com/postgraduate/Integration/UserControllerTest.java @@ -32,7 +32,7 @@ class UserControllerTest extends IntegrationTest { @BeforeEach void setUp() throws IOException { - User user = new User(0L, 1L, "mail", "후배", "011", "profile", 0, Role.USER, true, now(), now(), false); + User user = new User(-1L, -1L, "mail", "후배", "011", "profile", 0, Role.USER, true, now(), now(), false); userRepository.save(user); token = jwtUtil.generateAccessToken(user.getUserId(), Role.USER); 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..681e06b6 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 @@ -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/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()); - } -} From 8d97ad82f3c66f5f9a1e9654f28da01721d9cb2b Mon Sep 17 00:00:00 2001 From: yang Date: Fri, 10 May 2024 03:52:46 +0900 Subject: [PATCH 13/19] =?UTF-8?q?RAC-360=20test=20:=20=EC=98=A4=EB=A5=98?= =?UTF-8?q?=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/java/com/postgraduate/support/Resource.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/java/com/postgraduate/support/Resource.java b/src/test/java/com/postgraduate/support/Resource.java index d531faaf..800632f9 100644 --- a/src/test/java/com/postgraduate/support/Resource.java +++ b/src/test/java/com/postgraduate/support/Resource.java @@ -24,8 +24,8 @@ 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(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 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()); From 582e4d8f482134fd5e2109b15b16855ad5ec5587 Mon Sep 17 00:00:00 2001 From: yang Date: Mon, 13 May 2024 22:00:06 +0900 Subject: [PATCH 14/19] =?UTF-8?q?RAC-360=20test=20:=20=EC=98=A4=EB=A5=98?= =?UTF-8?q?=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/presentation/AuthControllerTest.java | 2 +- .../com/postgraduate/support/Resource.java | 22 +++++++++---------- 2 files changed, 12 insertions(+), 12 deletions(-) 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/support/Resource.java b/src/test/java/com/postgraduate/support/Resource.java index 800632f9..f457f09d 100644 --- a/src/test/java/com/postgraduate/support/Resource.java +++ b/src/test/java/com/postgraduate/support/Resource.java @@ -24,21 +24,21 @@ 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 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 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 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 getSeniorUser(){return userOfSenior;} public Senior getSenior() {return senior;} From c66af398d47232caeb7c0ebda9e8a9b6df26873c Mon Sep 17 00:00:00 2001 From: yang Date: Mon, 13 May 2024 23:37:58 +0900 Subject: [PATCH 15/19] =?UTF-8?q?RAC-360=20test=20:=20=EC=98=A4=EB=A5=98?= =?UTF-8?q?=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Integration/AuthControllerTest.java | 38 +++---- .../Integration/MentoringControllerTest.java | 80 ++++++------- .../Integration/SalaryControllerTest.java | 22 ++-- .../Integration/SeniorControllerTest.java | 105 +++++------------- .../Integration/UserControllerTest.java | 5 +- .../com/postgraduate/support/Resource.java | 11 +- 6 files changed, 105 insertions(+), 156 deletions(-) diff --git a/src/test/java/com/postgraduate/Integration/AuthControllerTest.java b/src/test/java/com/postgraduate/Integration/AuthControllerTest.java index 84a50fe0..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 Wish wish; + private User seniorUser; + private Senior senior; private final Long anonymousUserSocialId = -5L; @BeforeEach void setUp() { - user = new User(-1L, -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(-3L, -3L, "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 8af7193a..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(-1L, -1L, "mail", "후배", "011", "profile", 0, Role.USER, true, now(), now(), false); + user = resource.getUser(); userRepository.save(user); - User userOfSenior = new User(-2L, -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(-1L, 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(-1L, false, senior, 20000, getSalaryDate(), LocalDateTime.now(), salaryAccount); + otherSenior = resource.getOtherSenior(); + seniorRepository.save(otherSenior); + + salary = resource.getSalary(); salaryRepository.save(salary); - payment = new Payment(-1L, 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(-3L, -3L, "mail", "다른 후배", "011", "profile", 0, Role.USER, true, now(), now(), false); - userRepository.save(otherUser); - Mentoring mentoring = new Mentoring(-3L, 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(-3L, -3L, "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(-3L, otherUser, "certification", WAITING, 0, info, null, now(), now()); - seniorRepository.save(otherSenior); - - Mentoring mentoring = new Mentoring(-3L, 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 7fd55953..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 ce79bad2..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, -2L, "mail", "후배1", "011", "profile", 0, Role.SENIOR, true, now(), now(), false); - otherUser = new User(-1L, -1L, "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 6c2c7b73..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(-1L, -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/support/Resource.java b/src/test/java/com/postgraduate/support/Resource.java index f457f09d..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; @@ -25,24 +27,31 @@ public class Resource { 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(-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(-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(-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;} From 8dc837332fed3b2996af311e46d2a841cadeddf1 Mon Sep 17 00:00:00 2001 From: yang Date: Tue, 14 May 2024 14:42:46 +0900 Subject: [PATCH 16/19] =?UTF-8?q?RAC-367=20refactor=20:=20=EB=B6=88?= =?UTF-8?q?=ED=95=84=EC=9A=94=ED=95=9C=20=EC=9D=98=EC=A1=B4=EC=84=B1=20?= =?UTF-8?q?=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 1 - 1 file changed, 1 deletion(-) diff --git a/build.gradle b/build.gradle index a37e0eda..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' From d3c18fe6e8cf48533c890a2ea671a4031194cf28 Mon Sep 17 00:00:00 2001 From: yang Date: Tue, 14 May 2024 17:18:11 +0900 Subject: [PATCH 17/19] =?UTF-8?q?RAC-367=20feat=20:=20=EB=A7=A4=EC=B9=AD?= =?UTF-8?q?=20=EA=B4=80=EB=A0=A8=20=EC=95=8C=EB=A6=BC=ED=86=A1=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/req/JuniorMatchingFailRequest.java | 6 ++ .../dto/req/JuniorMatchingSuccessRequest.java | 6 ++ .../dto/req/JuniorMatchingWaitingRequest.java | 7 ++ .../content/JuniorMatchingFailMessage.java | 11 +++ .../content/JuniorMatchingSuccessMessage.java | 11 +++ .../content/JuniorMatchingWaitingMessage.java | 8 ++ .../mapper/BizppurioMapper.java | 94 +++++++++++++++---- .../usecase/BizppurioJuniorMessage.java | 19 +++- .../usecase/BizppurioSend.java | 6 +- 9 files changed, 146 insertions(+), 22 deletions(-) create mode 100644 src/main/java/com/postgraduate/global/bizppurio/application/dto/req/JuniorMatchingFailRequest.java create mode 100644 src/main/java/com/postgraduate/global/bizppurio/application/dto/req/JuniorMatchingSuccessRequest.java create mode 100644 src/main/java/com/postgraduate/global/bizppurio/application/dto/req/JuniorMatchingWaitingRequest.java create mode 100644 src/main/java/com/postgraduate/global/bizppurio/application/dto/req/content/JuniorMatchingFailMessage.java create mode 100644 src/main/java/com/postgraduate/global/bizppurio/application/dto/req/content/JuniorMatchingSuccessMessage.java create mode 100644 src/main/java/com/postgraduate/global/bizppurio/application/dto/req/content/JuniorMatchingWaitingMessage.java rename src/main/java/com/postgraduate/global/bizppurio/{ => application}/mapper/BizppurioMapper.java (69%) rename src/main/java/com/postgraduate/global/bizppurio/{ => application}/usecase/BizppurioJuniorMessage.java (54%) rename src/main/java/com/postgraduate/global/bizppurio/{ => application}/usecase/BizppurioSend.java (89%) 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/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/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/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; From 145d953f54e00ed1415810d977c8c2d58a3d046f Mon Sep 17 00:00:00 2001 From: yang Date: Tue, 14 May 2024 17:18:44 +0900 Subject: [PATCH 18/19] =?UTF-8?q?RAC-367=20feat=20:=20=EC=95=8C=EB=A6=BC?= =?UTF-8?q?=ED=86=A1=20=EC=88=98=EB=8F=99=20=EC=A0=84=EC=86=A1=20API?= =?UTF-8?q?=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../presantation/BizppurioController.java | 39 +++++++++++++++++++ .../config/security/SecurityConfig.java | 3 +- 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/postgraduate/global/bizppurio/presantation/BizppurioController.java 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()) From c5ce3c5f81442de146526152309f9dc764f750b7 Mon Sep 17 00:00:00 2001 From: yang Date: Tue, 14 May 2024 17:19:30 +0900 Subject: [PATCH 19/19] =?UTF-8?q?RAC-367=20refactor=20:=20=ED=8C=A8?= =?UTF-8?q?=ED=82=A4=EC=A7=80=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/postgraduate/batch/cancel/CancelMentoringWriter.java | 2 +- .../adminssr/application/usecase/AdminSeniorUseCase.java | 2 +- .../domain/auth/application/usecase/oauth/SignUpUseCase.java | 2 +- .../application/usecase/MentoringApplyingUseCase.java | 4 ++-- .../application/usecase/MentoringManageUseCase.java | 4 ++-- .../bizppurio/{ => application}/dto/req/CommonRequest.java | 2 +- .../global/bizppurio/application/dto/req/ContentRequest.java | 5 +++++ .../dto/req/content/CertificationApproveMessage.java | 4 ++-- .../dto/req/content/CertificationDeniedMessage.java | 4 ++-- .../dto/req/content/JuniorAcceptMessage.java | 2 +- .../dto/req/content/JuniorApplyMessage.java | 2 +- .../dto/req/content/JuniorFinishMessage.java | 4 ++-- .../dto/req/content/JuniorRefuseMessage.java | 4 ++-- .../bizppurio/application/dto/req/content/Message.java | 4 ++++ .../dto/req/content/SeniorAcceptMessage.java | 2 +- .../dto/req/content/SeniorApplyMessage.java | 4 ++-- .../dto/req/content/SeniorFinishMessage.java | 2 +- .../dto/req/content/SeniorSingUpMessage.java | 4 ++-- .../dto/req/content/button/WebLinkButton.java | 2 +- .../{ => application}/dto/res/BizppurioTokenResponse.java | 2 +- .../bizppurio/{ => application}/dto/res/MessageResponse.java | 2 +- .../bizppurio/{ => application}/usecase/BizppurioAuth.java | 4 ++-- .../{ => application}/usecase/BizppurioSeniorMessage.java | 4 ++-- .../global/bizppurio/dto/req/ContentRequest.java | 5 ----- .../global/bizppurio/dto/req/content/Message.java | 4 ---- .../auth/application/usecase/oauth/SignUpUseTypeTest.java | 2 +- .../application/usecase/MentoringApplyingUseTypeTest.java | 4 ++-- .../application/usecase/MentoringManageUseTypeTest.java | 4 ++-- 28 files changed, 45 insertions(+), 45 deletions(-) rename src/main/java/com/postgraduate/global/bizppurio/{ => application}/dto/req/CommonRequest.java (73%) create mode 100644 src/main/java/com/postgraduate/global/bizppurio/application/dto/req/ContentRequest.java rename src/main/java/com/postgraduate/global/bizppurio/{ => application}/dto/req/content/CertificationApproveMessage.java (52%) rename src/main/java/com/postgraduate/global/bizppurio/{ => application}/dto/req/content/CertificationDeniedMessage.java (52%) rename src/main/java/com/postgraduate/global/bizppurio/{ => application}/dto/req/content/JuniorAcceptMessage.java (66%) rename src/main/java/com/postgraduate/global/bizppurio/{ => application}/dto/req/content/JuniorApplyMessage.java (65%) rename src/main/java/com/postgraduate/global/bizppurio/{ => application}/dto/req/content/JuniorFinishMessage.java (51%) rename src/main/java/com/postgraduate/global/bizppurio/{ => application}/dto/req/content/JuniorRefuseMessage.java (51%) create mode 100644 src/main/java/com/postgraduate/global/bizppurio/application/dto/req/content/Message.java rename src/main/java/com/postgraduate/global/bizppurio/{ => application}/dto/req/content/SeniorAcceptMessage.java (66%) rename src/main/java/com/postgraduate/global/bizppurio/{ => application}/dto/req/content/SeniorApplyMessage.java (51%) rename src/main/java/com/postgraduate/global/bizppurio/{ => application}/dto/req/content/SeniorFinishMessage.java (66%) rename src/main/java/com/postgraduate/global/bizppurio/{ => application}/dto/req/content/SeniorSingUpMessage.java (51%) rename src/main/java/com/postgraduate/global/bizppurio/{ => application}/dto/req/content/button/WebLinkButton.java (61%) rename src/main/java/com/postgraduate/global/bizppurio/{ => application}/dto/res/BizppurioTokenResponse.java (58%) rename src/main/java/com/postgraduate/global/bizppurio/{ => application}/dto/res/MessageResponse.java (61%) rename src/main/java/com/postgraduate/global/bizppurio/{ => application}/usecase/BizppurioAuth.java (94%) rename src/main/java/com/postgraduate/global/bizppurio/{ => application}/usecase/BizppurioSeniorMessage.java (91%) delete mode 100644 src/main/java/com/postgraduate/global/bizppurio/dto/req/ContentRequest.java delete mode 100644 src/main/java/com/postgraduate/global/bizppurio/dto/req/content/Message.java diff --git a/src/main/java/com/postgraduate/batch/cancel/CancelMentoringWriter.java b/src/main/java/com/postgraduate/batch/cancel/CancelMentoringWriter.java index 1f3ac01b..4a81521a 100644 --- a/src/main/java/com/postgraduate/batch/cancel/CancelMentoringWriter.java +++ b/src/main/java/com/postgraduate/batch/cancel/CancelMentoringWriter.java @@ -3,7 +3,7 @@ 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.usecase.BizppurioJuniorMessage; +import com.postgraduate.global.bizppurio.application.usecase.BizppurioJuniorMessage; import com.postgraduate.global.slack.SlackErrorMessage; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; 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 c5693a9c..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,8 +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.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; 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/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/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/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/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/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/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 681e06b6..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;