Skip to content

Commit

Permalink
Refactor | #4 | @lcomment | @value 생성자 주입으로 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
lcomment committed May 3, 2024
1 parent 4fad91b commit ae83192
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 25 deletions.
7 changes: 5 additions & 2 deletions cakk-api/src/main/java/com/cakk/api/config/GoogleConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@
@Configuration
public class GoogleConfig {

@Value("${oauth.google.client-id}")
private String googleClientId;
private final String googleClientId;

public GoogleConfig(@Value("${oauth.google.client-id}") String googleClientId) {
this.googleClientId = googleClientId;
}

@Bean
public GoogleIdTokenVerifier googleIdTokenVerifier() {
Expand Down
7 changes: 5 additions & 2 deletions cakk-api/src/main/java/com/cakk/api/config/JwtConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@
@Configuration
public class JwtConfig {

@Value("${jwt.secret}")
private String secretKey;
private final String secretKey;

public JwtConfig(@Value("${jwt.secret}") String secretKey) {
this.secretKey = secretKey;
}

@Bean
public Key key() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@
@Configuration
public class SlackWebhookConfig {

@Value("${slack.webhook.url}")
private String slackWebhookUrl;
private final String slackWebhookUrl;

public SlackWebhookConfig(@Value("${slack.webhook.url}") String slackWebhookUrl) {
this.slackWebhookUrl = slackWebhookUrl;
}

@Bean
public SlackApi slackApi() {
Expand Down
33 changes: 22 additions & 11 deletions cakk-api/src/main/java/com/cakk/api/provider/jwt/JwtProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,38 @@
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;

import lombok.RequiredArgsConstructor;

import com.cakk.api.vo.JsonWebToken;
import com.cakk.api.vo.OAuthUserDetails;
import com.cakk.common.exception.CakkException;
import com.cakk.domain.entity.user.User;

@Component
@RequiredArgsConstructor
public class JwtProvider {

private final Key key;

@Value("${jwt.expiration.access-token}")
private Long accessTokenExpiredSecond;
@Value("${jwt.expiration.refresh-token}")
private Long refreshTokenExpiredSecond;
@Value("${jwt.grant-type}")
private String grantType;
@Value("${jwt.user-key}")
private String userKey;
private final Long accessTokenExpiredSecond;
private final Long refreshTokenExpiredSecond;
private final String grantType;
private final String userKey;

public JwtProvider(
Key key,
@Value("${jwt.expiration.access-token}")
Long accessTokenExpiredSecond,
@Value("${jwt.expiration.refresh-token}")
Long refreshTokenExpiredSecond,
@Value("${jwt.grant-type}")
String grantType,
@Value("${jwt.user-key}")
String userKey
) {
this.key = key;
this.accessTokenExpiredSecond = accessTokenExpiredSecond;
this.refreshTokenExpiredSecond = refreshTokenExpiredSecond;
this.grantType = grantType;
this.userKey = userKey;
}

public JsonWebToken generateToken(final User user) {
if (isNull(user)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,32 @@
import jakarta.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Service;

import net.gpedro.integrations.slack.SlackApi;
import net.gpedro.integrations.slack.SlackAttachment;
import net.gpedro.integrations.slack.SlackField;
import net.gpedro.integrations.slack.SlackMessage;

import lombok.RequiredArgsConstructor;

@Service
@RequiredArgsConstructor
public class SlackService {

private final SlackApi slackApi;
private final Environment environment;

@Value("${slack.webhook.is-enable}")
private boolean isEnable;
private final String profile;
private final boolean isEnable;

public SlackService(
SlackApi slackApi,
@Value("${spring.profiles.default}")
String profile,
@Value("${slack.webhook.is-enable}")
boolean isEnable
) {
this.slackApi = slackApi;
this.profile = profile;
this.isEnable = isEnable;
}

public void sendSlackForError(Exception exception, HttpServletRequest request) {
if (!isEnable) {
Expand All @@ -50,7 +57,6 @@ public void sendSlackForError(Exception exception, HttpServletRequest request) {
)
);

String profile = environment.getProperty("spring.profiles.default");
SlackMessage slackMessage = new SlackMessage();

slackMessage.setAttachments(List.of(slackAttachment));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.context.annotation.Import;
import org.springframework.test.context.ActiveProfiles;

import com.cakk.domain.config.JpaConfig;
import com.navercorp.fixturemonkey.FixtureMonkey;
import com.navercorp.fixturemonkey.api.introspector.ConstructorPropertiesArbitraryIntrospector;

@Import(JpaConfig.class)
@ActiveProfiles("test")
@ExtendWith(MockitoExtension.class)
public abstract class ProviderTest {

Expand Down

0 comments on commit ae83192

Please sign in to comment.