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

#175 컨벤션 통일하기 #176

Merged
merged 5 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ public class BookmarkController {
public ResponseEntity<?> createBookmark(
@RequestBody @Valid
BookmarkRequestDto.BookmarkAddDto dto,
Errors errors,
@AuthenticationPrincipal CustomUserDetails user
) {
bookmarkCreateService.addBookmark(dto, user.getUser());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ public class BookmarkCustomRepositoryImpl implements BookmarkCustomRepository {

@Override
public void batchInsertBookmark(List<Bookmark> bookmarkList) {
// 중복되는 값이 있다면 무시한다.
String insertQuery = String.format("INSERT INTO %s ( category_id, bookmark_name, bookmark_link, "
+ "bookmark_description, bookmark_thumbnail, created_at, last_modified_at) "
+ "VALUES (?, ?, ?, ?, ?, ?, ?)", TABLE);
LocalDateTime now = LocalDateTime.now();

BatchPreparedStatementSetter batchSetter = new BatchPreparedStatementSetter() {
@Override
Expand All @@ -37,8 +37,8 @@ public void setValues(PreparedStatement preparedStatement, int index) throws SQL
preparedStatement.setString(3, bookmark.getBookmarkLink());
preparedStatement.setString(4, bookmark.getBookmarkDescription());
preparedStatement.setString(5, bookmark.getBookmarkThumbnail());
preparedStatement.setTimestamp(6, Timestamp.valueOf(LocalDateTime.now()));
preparedStatement.setTimestamp(7, Timestamp.valueOf(LocalDateTime.now()));
preparedStatement.setTimestamp(6, Timestamp.valueOf(now));
preparedStatement.setTimestamp(7, Timestamp.valueOf(now));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,9 @@ public void addBookmark(BookmarkRequestDto.BookmarkAddDto bookmarkAddDto, User u

bookmarkJpaRepository.save(bookmark);

//새로운 Tag일 경우 Tag 테이블에 등록해야 한다.
List<Tag> tagEntities = new ArrayList<>();

List<BookmarkTag> bookmarkTagList = new ArrayList<>();
for (String tagName : bookmarkAddDto.getTags()) {
// 해당 태그가 존재하지 않는다면 새롭게 생성해야 한다.
// 생성된 태그는 태그 테이블에 등록되어야 한다.
// 해당 태그가 존재하지 않는다면 새롭게 생성한다.
Tag tag = tagSearchService.searchByTagNameAndUserId(tagName, userDetails.getUserId())
.orElseGet(() -> {
Tag newTag = Tag.builder()
Expand All @@ -68,18 +65,13 @@ public void addBookmark(BookmarkRequestDto.BookmarkAddDto bookmarkAddDto, User u
tagSaveService.createTag(newTag);
return newTag;
});
tagEntities.add(tag);
}

// BookmarkTag 테이블에 등록
List<BookmarkTag> bookmarkTagList = tagEntities.stream()
.map(tag -> BookmarkTag.builder()
bookmarkTagList.add(BookmarkTag.builder()
.bookmark(bookmark)
.tag(tag)
.build())
.toList();
.build());
}

bookmarkTagSaveService.createPairs(bookmarkTagList);
bookmarkTagSaveService.create(bookmarkTagList);
}

public void batchInsertBookmark(List<Bookmark> bookmarkList) {
Expand All @@ -88,7 +80,7 @@ public void batchInsertBookmark(List<Bookmark> bookmarkList) {

public void addBookmark(Bookmark bookmark, Category newCategory, List<Tag> tagList, User userDetails) {

//category는 새로만든 카테고리, 북마크는 과거 북마크 user는 새로운 유저
// category는 새로만든 카테고리, 북마크는 과거 북마크 user는 새로운 유저
Bookmark newBookmark = Bookmark.builder()
.bookmarkName(bookmark.getBookmarkName())
.bookmarkDescription(bookmark.getBookmarkDescription())
Expand All @@ -97,7 +89,7 @@ public void addBookmark(Bookmark bookmark, Category newCategory, List<Tag> tagLi
.category(newCategory)
.build();

//Bookmark 테이블에 bookmark 항목 추가
// Bookmark 테이블에 bookmark 항목 추가
newCategory = categoryJpaRepository.findByIdFetchJoinWorkspace(newCategory.getCategoryId())
.orElseThrow(() -> new Exception404(CategoryExceptionStatus.CATEGORY_NOT_FOUND));

Expand All @@ -122,7 +114,7 @@ public void addBookmark(Bookmark bookmark, Category newCategory, List<Tag> tagLi
.build())
.toList();

bookmarkTagSaveService.createPairs(bookmarkTagList);
bookmarkTagSaveService.create(bookmarkTagList);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Transactional
@RequiredArgsConstructor
@Service
@Transactional
public class BookmarkDeleteService {
private final BookmarkJpaRepository bookmarkJpaRepository;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@

import java.util.List;

@Transactional(readOnly = true)
@RequiredArgsConstructor
@Service
@Transactional(readOnly = true)
public class BookmarkReadService {

private final BookmarkJpaRepository bookmarkJpaRepository;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
import com.kakao.linknamu.tag.entity.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Transactional(readOnly = true)
@RequiredArgsConstructor
@Service
public class BookmarkTagReadService {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class BookmarkTagSaveService {
private final TagSearchService tagSearchService;
private final TagSaveService tagSaveService;

public void createPairs(List<BookmarkTag> bookmarkTagList) {
public void create(List<BookmarkTag> bookmarkTagList) {
bookmarkTagJPARepository.saveAll(bookmarkTagList);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
import com.kakao.linknamu.user.entity.User;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@RequiredArgsConstructor
@Transactional
@Service
public class CategoryDeleteService {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

@RequiredArgsConstructor
@Transactional(readOnly = true)
@Service
public class CategoryReadService {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
import com.kakao.linknamu.workspace.repository.WorkspaceJpaRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
@RequiredArgsConstructor
public class CategorySaveService {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
@Transactional
@Service
public class CategoryUpdateService {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,13 @@ public class HttpConnectionProxyConfig {
private static final String PROXY_HOST = "krmp-proxy.9rum.cc";
private static final int PROXY_PORT = 3128;


@Bean
public RestTemplate restTemplateWithProxy() {
SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(PROXY_HOST, PROXY_PORT));
requestFactory.setProxy(proxy);
requestFactory.setConnectTimeout(5000); // 연결시간초과, ms
requestFactory.setReadTimeout(5000); // 읽기시간초과, ms
return new RestTemplate(requestFactory);
}
@Bean
public RestTemplate restTemplateWithProxy() {
SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(PROXY_HOST, PROXY_PORT));
requestFactory.setProxy(proxy);
requestFactory.setConnectTimeout(5000);
requestFactory.setReadTimeout(5000);
return new RestTemplate(requestFactory);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException;
import org.springframework.web.multipart.support.MissingServletRequestPartException;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

@RestControllerAdvice
@RequiredArgsConstructor
Expand Down Expand Up @@ -68,12 +70,10 @@ public ResponseEntity<?> serverException(ServerException exception) {
}

@ExceptionHandler({Exception.class})
public ResponseEntity<?> unknownServerError(Exception exception) {

public ResponseEntity<?> unknownServerError(Exception e) {
log.error(String.format("Location: %s, Cause: %s", e.getStackTrace()[0].toString(), e.getMessage()));
return new ResponseEntity<>(
ApiUtils.error("서버에서 알 수 없는 에러가 발생했습니다."
+ exception.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR.value(),
"05000"),
ApiUtils.error("internal server error", HttpStatus.INTERNAL_SERVER_ERROR.value(), "05000"),
HttpStatus.INTERNAL_SERVER_ERROR
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ public void doFilter(ServletRequest request, ServletResponse response, FilterCha

chain.doFilter(requestWrapper, response);


log.info("\n"
+ "[REQUEST] {} - {} {}\n"
+ "Body : {}",
log.info("\n[REQUEST] {} - {} {}\nBody : {}",
httpRequest.getMethod(),
httpRequest.getRequestURI(),
httpResponse.getStatus(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,14 @@ public List<KakaoSendMeResponseDto> extractLink(MultipartFile multipartFile) {

try {
byte[] fileBytes = multipartFile.getBytes();
String fileContent = new String(fileBytes, StandardCharsets.UTF_8); // byte 배열을 문자열로 변환

// https 링크를 추출하기 위한 정규 표현식
// byte 배열을 문자열로 변환
String fileContent = new String(fileBytes, StandardCharsets.UTF_8);

// https 링크를 추출하기 위한 정규 표현식
String regex = "https?://[a-zA-Z0-9\\-\\.]+(\\:[0-9]+)?\\.[a-zA-Z]{2,3}(\\S*)?";

// \bhttps?://\S+ => 모든 http, https 도메인 검출
// https?://\S+ => 모든 http, https 도메인 검출
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(fileContent);

Expand All @@ -66,17 +68,7 @@ public List<KakaoSendMeResponseDto> extractLink(MultipartFile multipartFile) {
);
});

// while (matcher.find()) {
// String httpsLink = matcher.group();
// if(httpsLink.endsWith("\""))
// httpsLink = httpsLink.substring(0, httpsLink.length()-1);
//
// String title = jsoupUtils.getTitle(httpsLink);
// responseDtos.add(new KakaoSendMeResponseDto(
// title.equals(httpsLink) ? DEFAULT_TITLE : title,
// httpsLink)
// );
// }

return responseDtos;
} catch (IOException e) {
throw new Exception500(KakaoExceptionStatus.FILE_READ_FAILED);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class ShareController {
private final GetCategoryFromEncodedIdService getCategoryFromEncodedIdService;
private final CreateCategoryFromEncodedIdService createCategoryFromEncodedIdService;

//워크스페이스
// 워크스페이스
@GetMapping("/workspace/{workSpaceId}")
public ResponseEntity<?> createLinkFromWorkSpaceId(
@PathVariable("workSpaceId") @Positive(message = "id는 양수여야함.") Long workSpaceId) {
Expand All @@ -57,7 +57,7 @@ public ResponseEntity<?> createWorkspaceFromEncodedId(
return ResponseEntity.ok(ApiUtils.success(null));
}

//카테고리
// 카테고리
@GetMapping("/category/{categoryId}")
public ResponseEntity<?> createLinkFromCategoryId(
@PathVariable("categoryId") @Positive(message = "id는 양수여야함.") Long categoryId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Transactional
@RequiredArgsConstructor
@Service
@Transactional
public class GoogleDocsApiCreateService {
private final GooglePageJpaRepository googlePageJpaRepository;
private final WorkspaceReadService workspaceReadService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@

import java.util.List;

@Service
@RequiredArgsConstructor

@Transactional(readOnly = true)
@RequiredArgsConstructor
@Service
public class GoogleDocsApiGetService {
private final GooglePageJpaRepository googlePageJpaRepository;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Transactional
@RequiredArgsConstructor
@Service
@Transactional
public class NotionApiCreateService {
private final NotionAccountJpaRepository notionAccountJpaRepository;
private final NotionPageJpaRepository notionPageJpaRepository;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@

import java.util.List;

@Service
@RequiredArgsConstructor

@Transactional(readOnly = true)
@RequiredArgsConstructor
@Service
public class NotionApiGetService {
private final NotionPageJpaRepository notionPageJpaRepository;
private final NotionAccountJpaRepository notionAccountJpaRepository;

public List<NotionPage> getActiveNotionPage() {
return notionPageJpaRepository.findByActivePageFetchJoin();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,17 @@

import java.util.UUID;

@Service
@RequiredArgsConstructor
@Transactional(readOnly = true)
@Slf4j
@Transactional
@RequiredArgsConstructor
@Service
public class UserService {
private final PasswordEncoder passwordEncoder;
private final UserJpaRepository userJpaRepository;
private final RefreshTokenService refreshTokenService;
private final BlackListTokenService blackListTokenService;
private final WorkspaceSaveService workspaceSaveService;

@Transactional
public LoginResponseDto socialLogin(OauthUserInfo userInfo) {
User user = userJpaRepository.findByEmail(userInfo.email()).orElseGet(
() -> {
Expand Down Expand Up @@ -82,7 +81,6 @@ public void logout(String accessToken) {
blackListTokenService.save(accessToken);
}

@Transactional
public void withdrawal(User user, String accessToken) {
userJpaRepository.findById(user.getUserId()).ifPresentOrElse(
userJpaRepository::delete,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ public Workspace createNotionWorkspace(String workspaceName, User user) {
return workspaceJpaRepository.saveAndFlush(workspace);
}

// createNotionWorkspace 메서드와 코드 중복이 심하다. 추후 리펙토링 필요.
public Workspace createDocsWorkspace(String workspaceName, User user) {
Workspace workspace = workspaceJpaRepository.findByUserIdAndWorkspaceName(user.getUserId(), workspaceName)
.orElseGet(() -> Workspace.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public void updateWorkspaceName(Long workspaceId, WorkspaceUpdateRequestDto requ

validationCheck(workspace.getUser().getUserId(), user.getUserId());

// 만약 수정하고자하는 이름이 같다면 DB에 Update할 이유가 없다.
// 만약 수정하고자하는 이름이 같다면 DB에 update할 이유가 없다.
if (requestDto.workspaceName().equals(workspace.getWorkspaceName())) {
return;
}
Expand Down