-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'prod' of https://github.com/Team-Clody/Clody_server int…
…o prod
- Loading branch information
Showing
55 changed files
with
767 additions
and
231 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 58 additions & 57 deletions
115
clody-app/src/main/java/com/clody/clodyapi/diary/mapper/DiaryMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,60 @@ | ||
package com.clody.clodyapi.diary.mapper; | ||
|
||
import com.clody.clodyapi.diary.controller.dto.response.DiaryCreatedResponse; | ||
import com.clody.clodyapi.diary.controller.dto.response.DiaryCreatedTimeResponse; | ||
import com.clody.clodyapi.diary.controller.dto.response.DiaryResponse; | ||
import com.clody.domain.diary.dto.DiaryContent; | ||
import com.clody.domain.diary.dto.DiaryDateInfo; | ||
import com.clody.domain.diary.dto.DiaryDeletionInfo; | ||
import com.clody.domain.diary.dto.DiaryDomainInfo; | ||
import com.clody.domain.diary.dto.response.DiaryListGetResponse; | ||
import com.clody.domain.diary.dto.response.DiaryCalenderGetResponse; | ||
import com.clody.domain.diary.dto.response.DiaryCreatedInfo; | ||
import com.clody.domain.diary.dto.response.DiaryDayInfo; | ||
import com.clody.domain.diary.dto.response.DiaryListInfo; | ||
import com.clody.domain.reply.ReplyType; | ||
import com.clody.support.security.util.JwtUtil; | ||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
|
||
public class DiaryMapper { | ||
|
||
public static DiaryResponse toDiaryResponse(List<DiaryContent> diaryContentList) { | ||
return DiaryResponse.of(diaryContentList); | ||
} | ||
|
||
public static DiaryCreatedResponse toDiaryCreatedResponse(DiaryDomainInfo domainInfo) { | ||
ReplyType type = domainInfo.replyType(); | ||
LocalDateTime createdAt = domainInfo.diaryList().getFirst().getCreatedAt(); | ||
return DiaryCreatedResponse.of(createdAt, type); | ||
} | ||
|
||
public static DiaryDeletionInfo toDiaryDeletionInfo(int year, int month, int date) { | ||
Long userId = JwtUtil.getLoginMemberId(); | ||
return DiaryDeletionInfo.of(userId, year, month, date); | ||
} | ||
|
||
public static DiaryDateInfo toDiaryDateInfo(int year, int month, int date) { | ||
return DiaryDateInfo.of(year, month, date); | ||
} | ||
package com.clody.clodyapi.diary.mapper; | ||
|
||
import com.clody.clodyapi.diary.controller.dto.response.DiaryCreatedResponse; | ||
import com.clody.clodyapi.diary.controller.dto.response.DiaryCreatedTimeResponse; | ||
import com.clody.clodyapi.diary.controller.dto.response.DiaryResponse; | ||
import com.clody.domain.diary.dto.DiaryContent; | ||
import com.clody.domain.diary.dto.DiaryDateInfo; | ||
import com.clody.domain.diary.dto.DiaryDeletionInfo; | ||
import com.clody.domain.diary.dto.DiaryDomainInfo; | ||
import com.clody.domain.diary.dto.response.DiaryListGetResponse; | ||
import com.clody.domain.diary.dto.response.DiaryCalenderGetResponse; | ||
import com.clody.domain.diary.dto.response.DiaryCreatedInfo; | ||
import com.clody.domain.diary.dto.response.DiaryDayInfo; | ||
import com.clody.domain.diary.dto.response.DiaryListInfo; | ||
import com.clody.domain.reply.ReplyType; | ||
import com.clody.support.security.util.JwtUtil; | ||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
|
||
public class DiaryMapper { | ||
|
||
public static DiaryResponse toDiaryResponse(List<DiaryContent> diaryContentList, | ||
boolean userHasDeletedDiary) { | ||
return DiaryResponse.of(diaryContentList, userHasDeletedDiary); | ||
} | ||
|
||
public static DiaryCreatedResponse toDiaryCreatedResponse(DiaryDomainInfo domainInfo) { | ||
ReplyType type = domainInfo.replyType(); | ||
LocalDateTime createdAt = domainInfo.diaryList().getFirst().getCreatedAt(); | ||
return DiaryCreatedResponse.of(createdAt, type); | ||
} | ||
|
||
public static DiaryDeletionInfo toDiaryDeletionInfo(int year, int month, int date) { | ||
Long userId = JwtUtil.getLoginMemberId(); | ||
return DiaryDeletionInfo.of(userId, year, month, date); | ||
} | ||
|
||
public static DiaryDateInfo toDiaryDateInfo(int year, int month, int date) { | ||
return DiaryDateInfo.of(year, month, date); | ||
} | ||
|
||
public static DiaryCreatedTimeResponse toDiaryCreatedTimeResponse(DiaryCreatedInfo info) { | ||
return DiaryCreatedTimeResponse.of(info.HH(), info.MM(), info.SS(), info.replyType()); | ||
} | ||
|
||
public static DiaryListGetResponse toDiaryListResponse(DiaryListInfo diaryListInfo) { | ||
|
||
int totalCloverCount = diaryListInfo.totalCloverCount(); | ||
List<DiaryDayInfo> diaries = diaryListInfo.diaries(); | ||
return DiaryListGetResponse.of(totalCloverCount, diaries); | ||
} | ||
|
||
public static DiaryCalenderGetResponse toDiaryCalendarResponse(DiaryListInfo diaryListInfo) { | ||
|
||
int totalCloverCount = diaryListInfo.totalCloverCount(); | ||
List<DiaryDayInfo> diaries = diaryListInfo.diaries(); | ||
return DiaryCalenderGetResponse.of(totalCloverCount, diaries); | ||
} | ||
|
||
public static DiaryCreatedTimeResponse toDiaryCreatedTimeResponse(DiaryCreatedInfo info) { | ||
return DiaryCreatedTimeResponse.of(info.HH(), info.MM(), info.SS(), info.replyType()); | ||
} | ||
|
||
public static DiaryListGetResponse toDiaryListResponse(DiaryListInfo diaryListInfo){ | ||
|
||
int totalCloverCount = diaryListInfo.totalCloverCount(); | ||
List<DiaryDayInfo> diaries = diaryListInfo.diaries(); | ||
return DiaryListGetResponse.of(totalCloverCount, diaries); | ||
} | ||
|
||
public static DiaryCalenderGetResponse toDiaryCalendarResponse(DiaryListInfo diaryListInfo){ | ||
|
||
int totalCloverCount = diaryListInfo.totalCloverCount(); | ||
List<DiaryDayInfo> diaries = diaryListInfo.diaries(); | ||
return DiaryCalenderGetResponse.of(totalCloverCount, diaries); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
Empty file.
22 changes: 13 additions & 9 deletions
22
clody-batch/src/main/java/com/clody/clodybatch/ClodyBatchApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,26 @@ | ||
package com.clody.clodybatch; | ||
|
||
import lombok.extern.slf4j.Slf4j; | ||
import static com.clody.clodybatch.config.BatchConfig.BATCH_DATASOURCE; | ||
import static com.clody.clodybatch.config.BatchConfig.BATCH_TRANSACTION_MANAGER; | ||
|
||
import com.clody.clodybatch.config.BatchConfig; | ||
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing; | ||
import org.springframework.batch.core.configuration.support.DefaultBatchConfiguration; | ||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.WebApplicationType; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; | ||
import org.springframework.boot.builder.SpringApplicationBuilder; | ||
import org.springframework.context.annotation.Import; | ||
|
||
@EnableBatchProcessing | ||
@Import({BatchConfig.class}) | ||
@EnableBatchProcessing(dataSourceRef = BATCH_DATASOURCE, transactionManagerRef = BATCH_TRANSACTION_MANAGER) | ||
@SpringBootApplication | ||
@Slf4j | ||
@ConditionalOnMissingBean(value = DefaultBatchConfiguration.class, annotation = EnableBatchProcessing.class) | ||
public class ClodyBatchApplication { | ||
|
||
public static void main(String[] args) { | ||
int exit = SpringApplication.exit(SpringApplication.run(ClodyBatchApplication.class, args)); | ||
log.info("exit = {}", exit); | ||
System.exit(exit); | ||
System.setProperty("spring.config.name","application-batch"); | ||
SpringApplication springApplication = new SpringApplicationBuilder(ClodyBatchApplication.class).web( | ||
WebApplicationType.NONE).build(); | ||
springApplication.run(args); | ||
} | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
clody-batch/src/main/java/com/clody/clodybatch/config/BatchAutoConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.clody.clodybatch.config; | ||
|
||
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing; | ||
import org.springframework.batch.core.configuration.support.DefaultBatchConfiguration; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; | ||
|
||
@ConditionalOnMissingBean(value = DefaultBatchConfiguration.class, annotation = EnableBatchProcessing.class) | ||
public class BatchAutoConfiguration { | ||
} |
81 changes: 65 additions & 16 deletions
81
clody-batch/src/main/java/com/clody/clodybatch/config/BatchConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,75 @@ | ||
package com.clody.clodybatch.config; | ||
|
||
import com.clody.infra.meta.JpaScheduleMetaRepository; | ||
import com.clody.meta.Schedule; | ||
import java.time.LocalDateTime; | ||
import java.time.temporal.ChronoUnit; | ||
import java.util.Collections; | ||
import org.springframework.batch.core.configuration.support.DefaultBatchConfiguration; | ||
import org.springframework.batch.item.data.RepositoryItemReader; | ||
import com.zaxxer.hikari.HikariDataSource; | ||
import java.util.Collection; | ||
import javax.sql.DataSource; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.batch.core.Job; | ||
import org.springframework.batch.core.explore.JobExplorer; | ||
import org.springframework.batch.core.launch.JobLauncher; | ||
import org.springframework.batch.core.repository.JobRepository; | ||
import org.springframework.beans.factory.ObjectProvider; | ||
import org.springframework.beans.factory.annotation.Qualifier; | ||
import org.springframework.boot.autoconfigure.batch.BatchDataSource; | ||
import org.springframework.boot.autoconfigure.batch.BatchDataSourceScriptDatabaseInitializer; | ||
import org.springframework.boot.autoconfigure.batch.BatchProperties; | ||
import org.springframework.boot.autoconfigure.batch.JobLauncherApplicationRunner; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
import org.springframework.boot.context.properties.EnableConfigurationProperties; | ||
import org.springframework.boot.jdbc.DataSourceBuilder; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Primary; | ||
import org.springframework.jdbc.datasource.DataSourceTransactionManager; | ||
import org.springframework.transaction.PlatformTransactionManager; | ||
import org.springframework.util.StringUtils; | ||
|
||
@Configuration | ||
public class BatchConfig extends DefaultBatchConfiguration { | ||
@RequiredArgsConstructor | ||
@EnableConfigurationProperties(BatchProperties.class) | ||
public class BatchConfig { | ||
|
||
public static final String BATCH_DATASOURCE = "batchDataSource"; | ||
public static final String BATCH_TRANSACTION_MANAGER = "batchTransactionManager"; | ||
|
||
@Bean | ||
@ConditionalOnMissingBean | ||
@ConditionalOnProperty(prefix = "spring.batch.job", name = "enabled", havingValue = "true", matchIfMissing = true) | ||
public JobLauncherApplicationRunner jobLauncherApplicationRunner(JobLauncher jobLauncher, JobExplorer jobExplorer, | ||
JobRepository jobRepository, BatchProperties properties, Collection<Job> jobs) { | ||
JobLauncherApplicationRunner runner = new JobLauncherApplicationRunner(jobLauncher, jobExplorer, jobRepository); | ||
String jobNames = properties.getJob().getName(); | ||
if (StringUtils.hasText(jobNames)) { | ||
if (jobs.stream().map(Job::getName).noneMatch(s -> s.equals(jobNames))){ | ||
throw new IllegalArgumentException(jobNames + "는 등록되지 않은 job name입니다. job name을 확인하세요."); | ||
} | ||
runner.setJobName(jobNames); | ||
} | ||
return runner; | ||
} | ||
|
||
@Bean | ||
public RepositoryItemReader<Schedule> metaScheduleReader( | ||
JpaScheduleMetaRepository scheduleMetaRepository){ | ||
RepositoryItemReader<Schedule> reader = new RepositoryItemReader<>(); | ||
reader.setRepository(scheduleMetaRepository); | ||
reader.setMethodName("findByNotificationTime"); | ||
reader.setArguments(Collections.singletonList(LocalDateTime.now().truncatedTo(ChronoUnit.SECONDS))); | ||
reader.setPageSize(10); | ||
return reader; | ||
@ConditionalOnMissingBean(BatchDataSourceScriptDatabaseInitializer.class) | ||
BatchDataSourceScriptDatabaseInitializer batchDataSourceInitializer(DataSource dataSource, | ||
@BatchDataSource ObjectProvider<DataSource> batchDataSource, BatchProperties properties) { | ||
return new BatchDataSourceScriptDatabaseInitializer( | ||
batchDataSource.getIfAvailable(() -> dataSource), | ||
properties.getJdbc()); | ||
} | ||
|
||
@Primary | ||
@BatchDataSource | ||
@Bean(BATCH_DATASOURCE) | ||
@ConfigurationProperties(prefix = "spring.datasource.batch.hikari") | ||
public DataSource batchDataSource() { | ||
return DataSourceBuilder.create().type(HikariDataSource.class).build(); | ||
} | ||
|
||
@Bean(BATCH_TRANSACTION_MANAGER) | ||
public PlatformTransactionManager batchTransactionManager( | ||
@Qualifier(BATCH_DATASOURCE) DataSource batchDataSource) { | ||
return new DataSourceTransactionManager(batchDataSource); | ||
} | ||
} |
Oops, something went wrong.