Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: sonarCloud를 참고한 코드 리팩토링 #274

Merged
merged 9 commits into from
Oct 17, 2023
4 changes: 4 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ comment:
branches:
- develop
- main

coverage:
status:
patch: off
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
@Component
public class FcmService {

private final String API_URL = "https://fcm.googleapis.com/v1/projects/blabla-391200/messages:send";
private final ObjectMapper objectMapper;

public Map<String, String> sendMessageTo(FcmMessageRequestDto fcmMessageRequestDto) throws IOException {
Expand All @@ -40,7 +39,7 @@ public Map<String, String> sendMessageTo(FcmMessageRequestDto fcmMessageRequestD
OkHttpClient client = new OkHttpClient();
RequestBody requestBody = RequestBody.create(message, MediaType.get("application/json; charset=utf-8"));
Request request = new Request.Builder()
.url(API_URL)
.url("https://fcm.googleapis.com/v1/projects/blabla-391200/messages:send")
.post(requestBody)
.addHeader("Authorization", "Bearer " + getAccessToken())
.addHeader(HttpHeaders.CONTENT_TYPE, "application/json; UTF-8")
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/com/gsm/blabla/agora/RtcTokenBuilder2.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.gsm.blabla.agora;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class RtcTokenBuilder2 {
public enum Role {
ROLE_PUBLISHER(1),
Expand Down Expand Up @@ -32,7 +35,7 @@ public String buildTokenWithUserAccount(String appId, String appCertificate, Str
try {
return accessToken.build();
} catch (Exception e) {
e.printStackTrace();
log.error(e.getMessage(), e);
return "";
}
}
Expand All @@ -59,7 +62,7 @@ public String buildTokenWithUserAccount(String appId, String appCertificate, Str
try {
return accessToken.build();
} catch (Exception e) {
e.printStackTrace();
log.error(e.getMessage(), e);
return "";
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/com/gsm/blabla/agora/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
import java.util.zip.Inflater;
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.codec.binary.Base64;

@Slf4j
public class Utils {
public static final long HMAC_SHA256_LENGTH = 32;
public static final int VERSION_LENGTH = 3;
Expand Down Expand Up @@ -112,7 +114,7 @@ public static byte[] decompress(byte[] data) {
bos.write(buf, 0, i);
}
} catch (Exception e) {
e.printStackTrace();
log.error(e.getMessage(), e);
} finally {
inflater.end();
}
Expand Down
35 changes: 17 additions & 18 deletions src/main/java/com/gsm/blabla/auth/application/AuthService.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,22 +63,20 @@ public JwtDto signUp(String providerAuthorization, MemberRequestDto memberReques
if (googleAccountRepository.findById(googleAccountDto.getId()).isPresent()) {
throw new GeneralException(Code.ALREADY_REGISTERED, "이미 가입된 구글 계정입니다.");
}

member = memberRepository.save(memberRequestDto.toEntity(nickname, profileImage));
googleAccountRepository.save(GoogleAccount.builder()
.id(googleAccountDto.getId())
.member(member)
.build()
);

}

case "APPLE" -> {
AppleTokenDto appleTokenDto = appleService.getAppleToken(providerAuthorization);
AppleAccountDto appleAccountDto = appleService.getAppleAccount(appleTokenDto.getIdToken());
if (appleAccountRepository.findById(appleAccountDto.getSub()).isPresent()) {
throw new GeneralException(Code.ALREADY_REGISTERED, "이미 가입된 애플 계정입니다.");
}

member = memberRepository.save(memberRequestDto.toEntity(nickname, profileImage));
appleAccountRepository.save(AppleAccount.builder()
.id(appleAccountDto.getSub())
Expand All @@ -87,7 +85,11 @@ public JwtDto signUp(String providerAuthorization, MemberRequestDto memberReques
.build()
);
}
case "TEST" -> member = memberRepository.save(memberRequestDto.toEntity(nickname, profileImage));

case "TEST" ->
member = memberRepository.save(memberRequestDto.toEntity(nickname, profileImage));

default -> throw new GeneralException(Code.BAD_REQUEST, "잘못된 요청입니다.");
}

return jwtService.issueJwt(member);
Expand All @@ -97,21 +99,18 @@ public JwtDto signUp(String providerAuthorization, MemberRequestDto memberReques
public Object login(SocialLoginType socialLoginType, String providerAuthorization) {
Optional<Member> member = Optional.empty();

switch (socialLoginType) {
case GOOGLE -> {
GoogleAccountDto googleAccountDto = googleService.getGoogleAccountInfo(providerAuthorization);
member = googleAccountRepository.findById(googleAccountDto.getId()).map(GoogleAccount::getMember);
if (member.isEmpty()) {
throw new GeneralException(Code.MEMBER_NOT_FOUND, "가입되지 않은 유저입니다.");
}
if (socialLoginType == SocialLoginType.GOOGLE) {
GoogleAccountDto googleAccountDto = googleService.getGoogleAccountInfo(providerAuthorization);
member = googleAccountRepository.findById(googleAccountDto.getId()).map(GoogleAccount::getMember);
if (member.isEmpty()) {
throw new GeneralException(Code.MEMBER_NOT_FOUND, "가입되지 않은 유저입니다.");
}
case APPLE -> {
AppleTokenDto appleTokenDto = appleService.getAppleToken(providerAuthorization);
AppleAccountDto appleAccountDto = appleService.getAppleAccount(appleTokenDto.getIdToken());
member = appleAccountRepository.findById(appleAccountDto.getSub()).map(AppleAccount::getMember);
if (member.isEmpty()) {
throw new GeneralException(Code.MEMBER_NOT_FOUND, "가입되지 않은 유저입니다.");
}
} else if (socialLoginType == SocialLoginType.APPLE) {
AppleTokenDto appleTokenDto = appleService.getAppleToken(providerAuthorization);
AppleAccountDto appleAccountDto = appleService.getAppleAccount(appleTokenDto.getIdToken());
member = appleAccountRepository.findById(appleAccountDto.getSub()).map(AppleAccount::getMember);
if (member.isEmpty()) {
throw new GeneralException(Code.MEMBER_NOT_FOUND, "가입되지 않은 유저입니다.");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ public class GoogleService {
private final GoogleAccountRepository googleAccountRepository;

public GoogleAccountDto getGoogleAccountInfo(String googleAccessToken) {
String GOOGLE_USERINFO_REQUEST_URL="https://www.googleapis.com/oauth2/v1/userinfo";

// 1. header에 Access Token을 담는다
HttpHeaders headers = new HttpHeaders();
headers.set("Authorization", "Bearer " + googleAccessToken);
Expand All @@ -35,7 +33,7 @@ public GoogleAccountDto getGoogleAccountInfo(String googleAccessToken) {
ResponseEntity<GoogleAccountDto> response;
try {
response = restTemplate.exchange(
GOOGLE_USERINFO_REQUEST_URL,
"https://www.googleapis.com/oauth2/v1/userinfo",
HttpMethod.GET,
request,
GoogleAccountDto.class
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package com.gsm.blabla.content.dto;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.gsm.blabla.content.domain.MemberContentDetail;
import lombok.*;

import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public class AIPracticeFeedbackResponseDto {

private Double contextScore;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.gsm.blabla.content.dto;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.gsm.blabla.content.domain.MemberContentDetail;
import lombok.*;

Expand Down
1 change: 0 additions & 1 deletion src/main/java/com/gsm/blabla/crew/api/CrewController.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.gsm.blabla.crew.application.CrewService;
import com.gsm.blabla.crew.dto.*;
import com.gsm.blabla.global.response.DataResponseDto;
import com.gsm.blabla.member.dto.MemberProfileResponseDto;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
import java.time.format.DateTimeFormatter;
import java.util.*;

import com.gsm.blabla.member.domain.Member;
import com.gsm.blabla.member.dto.MemberProfileResponseDto;
import com.gsm.blabla.member.dto.MemberResponseDto;

import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -180,7 +178,7 @@ public Map<String, String> createReport(Long reportId) {
try {
aiCrewReportResponseDto = objectMapper.readValue(response, AiCrewReportResponseDto.class);
} catch (JsonProcessingException e) {
e.printStackTrace();
log.error(e.getMessage(), e);
}

if (aiCrewReportResponseDto == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.gsm.blabla.crew.domain.VoiceFile;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.Collection;
import java.util.List;

public interface VoiceFileRepository extends JpaRepository<VoiceFile, Long> {
Expand Down
3 changes: 0 additions & 3 deletions src/main/java/com/gsm/blabla/crew/domain/VoiceFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.time.Duration;
import java.time.LocalDateTime;

@Entity
@Getter
@Builder
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/gsm/blabla/jwt/TokenProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
public class TokenProvider {
private static final String AUTHORITIES_KEY = "auth";
private static final String BEARER_TYPE = "Bearer";
private static final long ACCESS_TOKEN_EXPIRE_TIME = 1000 * 60 * 30; // 30분
private static final long REFRESH_TOKEN_EXPIRE_TIME = 1000 * 60 * 60 * 24 * 7; // 7일
private static final long ACCESS_TOKEN_EXPIRE_TIME = 1000L * 60 * 30; // 30분
private static final long REFRESH_TOKEN_EXPIRE_TIME = 1000L * 60 * 60 * 24 * 7; // 7일

private final Key key;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.gsm.blabla.jwt.dao.JwtRepository;
import com.gsm.blabla.member.dao.MemberRepository;

import com.gsm.blabla.member.domain.SocialLoginType;
import java.util.*;

import com.gsm.blabla.member.domain.Member;
Expand Down Expand Up @@ -48,13 +49,10 @@ public Map<String, String> withdrawal() {
jwtRepository.deleteByMemberId(memberId);
memberRepository.delete(member);

switch (member.getSocialLoginType()) {
case GOOGLE -> {
googleService.unlinkGoogleAccount(memberId);
}
case APPLE -> {
appleService.revokeAppleAccount(memberId);
}
if (member.getSocialLoginType() == SocialLoginType.GOOGLE) {
googleService.unlinkGoogleAccount(memberId);
} else if (member.getSocialLoginType() == SocialLoginType.APPLE) {
appleService.revokeAppleAccount(memberId);
}

log.info("{} 님이 회원 탈퇴를 하였습니다.", member.getNickname());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,19 @@
package com.gsm.blabla.content.application;

import com.gsm.blabla.content.dao.ContentDetailRepository;
import com.gsm.blabla.content.dao.ContentRepository;
import com.gsm.blabla.content.dao.MemberContentDetailRepository;
import com.gsm.blabla.content.domain.Content;
import com.gsm.blabla.content.domain.ContentDetail;
import com.gsm.blabla.content.domain.MemberContentDetail;
import com.gsm.blabla.content.dto.ContentDetailDto;
import com.gsm.blabla.content.dto.ContentDetailResponseDto;
import com.gsm.blabla.content.dto.ContentDetailsResponseDto;
import com.gsm.blabla.content.dto.ContentsResponseDto;
import com.gsm.blabla.global.IntegrationTestSupport;
import com.gsm.blabla.global.WithCustomMockUser;
import com.gsm.blabla.global.exception.GeneralException;
import com.gsm.blabla.global.response.Code;
import com.gsm.blabla.global.util.SecurityUtil;
import com.gsm.blabla.member.dao.MemberRepository;
import com.gsm.blabla.member.domain.Member;
import lombok.RequiredArgsConstructor;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;

import java.time.LocalTime;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -144,4 +133,4 @@ void getContentDetail() {
.containsExactly("소개 인사하기", "인턴을 통해 소개 인사를 배워봅시다.", "https://www.youtu.be/sHpGT4SQwgw", "나는 오스틴 입니다. About the Fit의 창업자 입니다.", "I'm Jules Ostin. I'm the founder of About the Fit.", 43200, 43210, 43220);
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.gsm.blabla.global.RepositoryTestSupport;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalTime;
Expand Down Expand Up @@ -87,4 +86,4 @@ void findAllByMemberId() {
LocalTime.of(13, 0, 10),
LocalTime.of(13, 0, 20), 100L);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import com.gsm.blabla.auth.api.AuthController;
import com.gsm.blabla.auth.application.AuthService;
import com.gsm.blabla.content.dto.ContentDetailDto;
import com.gsm.blabla.content.dto.ContentDetailsResponseDto;
import com.gsm.blabla.content.dto.ContentsResponseDto;
import com.gsm.blabla.crew.api.CrewController;
import com.gsm.blabla.crew.api.ScheduleController;
Expand All @@ -23,10 +22,6 @@
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.web.servlet.MockMvc;

import java.util.List;

import static org.springframework.test.web.client.match.MockRestRequestMatchers.jsonPath;

@WebMvcTest(
controllers = {
CrewController.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import org.junit.jupiter.api.AfterEach;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.transaction.annotation.Transactional;

@SpringBootTest(
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
Expand Down