Skip to content

Commit

Permalink
Merge pull request #613 from woowacourse-teams/dev
Browse files Browse the repository at this point in the history
feat: v1.2.0 배포
  • Loading branch information
xrabcde authored Oct 7, 2021
2 parents 5c842c8 + 49d1d68 commit de36841
Show file tree
Hide file tree
Showing 179 changed files with 4,612 additions and 1,030 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
.idea
.DS_Store


s3proxy/src/main/resources/static/docs/index.html
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@
path = backend/src/main/resources/config
url = git@github.com:zzimkkong/config.git
branch = main
[submodule "s3proxy/src/main/resources/s3proxy-config"]
path = s3proxy/src/main/resources/s3proxy-config
url = git@github.com:zzimkkong/s3proxy-config.git
branch = main
11 changes: 6 additions & 5 deletions backend/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-webflux'

implementation 'org.springframework.cloud:spring-cloud-starter-aws:2.2.6.RELEASE'

// Security
implementation 'org.springframework.boot:spring-boot-starter-security'
testImplementation 'org.springframework.security:spring-security-test'
Expand Down Expand Up @@ -66,6 +64,10 @@ dependencies {
// Mock Web Server
testImplementation 'com.squareup.okhttp3:okhttp:4.0.1'
testImplementation 'com.squareup.okhttp3:mockwebserver:4.0.1'

// Logstash
implementation 'net.logstash.logback:logstash-logback-encoder:6.6'

}

test {
Expand Down Expand Up @@ -109,10 +111,9 @@ jacocoTestCoverageVerification {
rule {
element = 'CLASS'
excludes = ["**.exception.**", "**.ControllerAdvice", "**.*ErrorResponse", "**.ValidatorMessage",
"**.ZzimkkongApplication", "**.*TimeConverter", "**.DataLoader", "**.*Config",
"**.ZzimkkongApplication", "**.DataLoader", "**.config.**",
"**.LoginInterceptor", "**.AuthenticationPrincipalArgumentResolver",
"**.slack.**", "**.Slack*", "**.datasource.**"]
//todo: 패키지 분리하면 더 멋있게 해보겠슴,,
"**.slack.**", "**.Slack*", "**.AdminPageController"]

limit {
counter = 'BRANCH'
Expand Down
12 changes: 0 additions & 12 deletions backend/src/docs/asciidoc/member.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,6 @@ include::{snippets}/member/token/success/http-response.adoc[]
==== Fail Response
include::{snippets}/member/token/fail/http-response.adoc[]

=== 멤버 구글 이메일 반환
==== Request
include::{snippets}/member/get/oauth/GOOGLE/http-request.adoc[]
==== Response
include::{snippets}/member/get/oauth/GOOGLE/http-response.adoc[]

=== 멤버 깃헙 이메일 반환
==== Request
include::{snippets}/member/get/oauth/GITHUB/http-request.adoc[]
==== Response
include::{snippets}/member/get/oauth/GITHUB/http-response.adoc[]

=== 멤버 구글 회원가입
==== Request
include::{snippets}/member/post/oauth/GOOGLE/http-request.adoc[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ public void run(String... args) {
LocalDate targetDate = LocalDate.now().plusDays(1L);

Reservation reservationBackEndTargetDate0To1 = Reservation.builder()
.date(targetDate)
.startTime(targetDate.atStartOfDay())
.endTime(targetDate.atTime(1, 0, 0))
.date(targetDate)
Expand All @@ -185,6 +186,7 @@ public void run(String... args) {
.build();

Reservation reservationBackEndTargetDate13To14 = Reservation.builder()
.date(targetDate)
.startTime(targetDate.atTime(13, 0, 0))
.endTime(targetDate.atTime(14, 0, 0))
.date(targetDate)
Expand All @@ -195,6 +197,7 @@ public void run(String... args) {
.build();

Reservation reservationBackEndTargetDate18To23 = Reservation.builder()
.date(targetDate)
.startTime(targetDate.atTime(18, 0, 0))
.endTime(targetDate.atTime(23, 59, 59))
.date(targetDate)
Expand All @@ -205,6 +208,7 @@ public void run(String... args) {
.build();

Reservation reservationBackEndTheDayAfterTargetDate = Reservation.builder()
.date(targetDate)
.startTime(targetDate.plusDays(1L).atStartOfDay())
.endTime(targetDate.plusDays(1L).atTime(1, 0, 0))
.date(targetDate)
Expand All @@ -215,6 +219,7 @@ public void run(String... args) {
.build();

Reservation reservationFrontEnd1TargetDate0to1 = Reservation.builder()
.date(targetDate)
.startTime(targetDate.atStartOfDay())
.endTime(targetDate.atTime(1, 0, 0))
.date(targetDate)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ public void addArgumentResolvers(List argumentResolvers) {
public void addInterceptors(InterceptorRegistry registry) {
List<String> pathsToAdd = List.of(
"/api/managers/token",
"/api/managers/**"
"/api/managers/**",
"/admin/api/**"
);

List<String> pathsToExclude = List.of(
Expand All @@ -44,7 +45,11 @@ public void addInterceptors(InterceptorRegistry registry) {
"/api/managers/GOOGLE/login/token",
"/api/managers/GITHUB/login/token",
"/api/managers/google/login/token",
"/api/managers/github/login/token"
"/api/managers/github/login/token",

//admin login
"/admin/login/",
"/admin/api/login"
);

registry.addInterceptor(loginInterceptor)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package com.woowacourse.zzimkkong.config;

import com.woowacourse.zzimkkong.config.logaspect.LogMethodExecutionTime;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;

import static net.logstash.logback.argument.StructuredArguments.value;

@Slf4j
@Component
@Aspect
public class LogAspect {
private static final String GROUP_NAME_OF_REPOSITORY = "repository";

@Around("@target(com.woowacourse.zzimkkong.config.logaspect.LogMethodExecutionTime) " +
"&& execution(* com.woowacourse..*(..))")
public Object logExecutionTime(ProceedingJoinPoint joinPoint) throws Throwable {

long startTime = System.currentTimeMillis();
Object result = joinPoint.proceed();
long endTime = System.currentTimeMillis();
long timeTaken = endTime - startTime;

String logGroup = getLogGroup(joinPoint);
MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();

logExecutionInfo(methodSignature, timeTaken, logGroup);

return result;
}

@Around("execution(public * org.springframework.data.repository.Repository+.*(..))")
public Object logExecutionTimeOfRepository(ProceedingJoinPoint joinPoint) throws Throwable {

long startTime = System.currentTimeMillis();
Object result = joinPoint.proceed();
long endTime = System.currentTimeMillis();
long timeTaken = endTime - startTime;

MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();

logExecutionInfo(methodSignature, timeTaken, GROUP_NAME_OF_REPOSITORY);

return result;
}

private String getLogGroup(ProceedingJoinPoint joinPoint) {
Class<?> targetClass = joinPoint.getTarget().getClass();
return targetClass.getAnnotation(LogMethodExecutionTime.class).group();
}

private void logExecutionInfo(MethodSignature methodSignature, long timeTaken, String logGroup) {
log.info("{} took {} ms. (info group by '{}')",
value("method", methodSignature.getDeclaringTypeName() + "." + methodSignature.getName() + "()"),
value("execution_time", timeTaken),
value("group", logGroup));
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package com.woowacourse.zzimkkong.config;

import org.apache.http.HttpHeaders;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpHeaders;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.List;
Expand All @@ -27,4 +28,10 @@ public void addCorsMappings(CorsRegistry registry) {
.exposedHeaders(HttpHeaders.LOCATION)
.allowedOriginPatterns(allowOriginUrlPatterns.toArray(new String[0]));
}

@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/admin", "/admin/**")
.addResourceLocations("classpath:/static/admin/");
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,89 +1,62 @@
package com.woowacourse.zzimkkong.config.datasource;

import com.woowacourse.zzimkkong.exception.infrastructure.NoMasterDataSourceException;
import com.zaxxer.hikari.HikariDataSource;
import org.springframework.boot.autoconfigure.orm.jpa.JpaProperties;
import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.context.properties.ConfigurationProperties;
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.context.annotation.Profile;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy;
import org.springframework.orm.jpa.JpaTransactionManager;
import org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean;
import org.springframework.orm.jpa.vendor.AbstractJpaVendorAdapter;
import org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import javax.persistence.EntityManagerFactory;
import javax.sql.DataSource;
import java.util.*;
import java.util.stream.Collectors;

import static com.woowacourse.zzimkkong.config.datasource.ReplicationRoutingDataSource.DATASOURCE_KEY_MASTER;
import static com.woowacourse.zzimkkong.config.datasource.ReplicationRoutingDataSource.DATASOURCE_KEY_SLAVE;

@Configuration
@EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class})
@EnableTransactionManagement
@EnableJpaRepositories(basePackages = {"com.woowacourse.zzimkkong"})
@Profile("prod")
public class CustomDataSourceConfig {
public static final String MASTER = "master";
public static final String SLAVE = "slave";
private static final String PACKAGE_PATH = "com.woowacourse.zzimkkong";
private final List<HikariDataSource> hikariDataSources;
private final JpaProperties jpaProperties;

public CustomDataSourceConfig(final List<HikariDataSource> hikariDataSources, final JpaProperties jpaProperties) {
this.hikariDataSources = hikariDataSources;
this.jpaProperties = jpaProperties;
}

@Bean
public DataSource dataSource() {
return new LazyConnectionDataSourceProxy(routingDataSource());
@ConfigurationProperties(prefix = "spring.datasource.hikari.master")
public DataSource masterDataSource() {
return DataSourceBuilder.create().type(HikariDataSource.class).build();
}

@Bean
public DataSource routingDataSource() {
final DataSource master = createMasterDataSource();
final Map<Object, Object> slaves = createSlaveDataSources();
slaves.put(MASTER, master);

ReplicationRoutingDataSource replicationRoutingDataSource = new ReplicationRoutingDataSource();
replicationRoutingDataSource.setDefaultTargetDataSource(master);
replicationRoutingDataSource.setTargetDataSources(slaves);
return replicationRoutingDataSource;
}

private DataSource createMasterDataSource() {
return hikariDataSources.stream()
.filter(dataSource -> dataSource.getPoolName().startsWith(MASTER))
.findFirst()
.orElseThrow(NoMasterDataSourceException::new);
@ConfigurationProperties(prefix = "spring.datasource.hikari.slave")
public DataSource slaveDataSource() {
return DataSourceBuilder.create().type(HikariDataSource.class).build();
}

private Map<Object, Object> createSlaveDataSources() {
final List<HikariDataSource> slaveDataSources = hikariDataSources.stream()
.filter(datasource -> Objects.nonNull(datasource.getPoolName()) && datasource.getPoolName().startsWith(SLAVE))
.collect(Collectors.toList());
@Bean
public DataSource routingDataSource(@Qualifier("masterDataSource") DataSource master,
@Qualifier("slaveDataSource") DataSource slave) {
ReplicationRoutingDataSource routingDataSource = new ReplicationRoutingDataSource();

final Map<Object, Object> result = new HashMap<>();
for (final HikariDataSource slaveDataSource : slaveDataSources) {
result.put(slaveDataSource.getPoolName(), slaveDataSource);
}
return result;
}
HashMap<Object, Object> sources = new HashMap<>();
sources.put(DATASOURCE_KEY_MASTER, master);
sources.put(DATASOURCE_KEY_SLAVE, slave);

@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
EntityManagerFactoryBuilder entityManagerFactoryBuilder = createEntityManagerFactoryBuilder(jpaProperties);
return entityManagerFactoryBuilder.dataSource(dataSource()).packages(PACKAGE_PATH).build();
}
routingDataSource.setTargetDataSources(sources);
routingDataSource.setDefaultTargetDataSource(master);

private EntityManagerFactoryBuilder createEntityManagerFactoryBuilder(JpaProperties jpaProperties) {
AbstractJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
return new EntityManagerFactoryBuilder(vendorAdapter, jpaProperties.getProperties(), null);
return routingDataSource;
}

@Primary
@Bean
public PlatformTransactionManager transactionManager(EntityManagerFactory entityManagerFactory) {
JpaTransactionManager tm = new JpaTransactionManager();
tm.setEntityManagerFactory(entityManagerFactory);
return tm;
public DataSource dataSource(@Qualifier("routingDataSource") DataSource routingDataSource) {
return new LazyConnectionDataSourceProxy(routingDataSource);
}
}
Loading

0 comments on commit de36841

Please sign in to comment.