Skip to content

Commit

Permalink
Merge pull request #122 from TeamSynergyy/test/post
Browse files Browse the repository at this point in the history
게시글 도메인 리팩터링 및 캐싱 테스트
  • Loading branch information
rivkode authored Sep 9, 2024
2 parents f8656bc + 5ef4bd6 commit 0952104
Show file tree
Hide file tree
Showing 40 changed files with 848 additions and 992 deletions.
34 changes: 22 additions & 12 deletions .github/workflows/docker-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ permissions:

# Job 실행
jobs:
build:
ci-test:

runs-on: ubuntu-22.04

Expand Down Expand Up @@ -62,15 +62,23 @@ jobs:
java-version: '17'
distribution: 'adopt'

- name: Gradle Caching
uses: actions/cache@v3
# 캐싱 포함
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
build-scan-publish: true
build-scan-terms-of-use-url: "https://gradle.com/terms-of-service"
build-scan-terms-of-use-agree: "yes"

# - name: Gradle Caching
# uses: actions/cache@v3
# with:
# path: |
# ~/.gradle/caches
# ~/.gradle/wrapper
# key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
# restore-keys: |
# ${{ runner.os }}-gradle-

# - name: MySQL 설치
# uses: mirromutth/mysql-action@v1
Expand Down Expand Up @@ -107,7 +115,9 @@ jobs:
- name: properties 파일 생성
run: |
cd ./src/main
mkdir resources
if [ ! -d "resources" ]; then
mkdir resources
fi
cd ./resources
touch ./application.properties
echo "${{ secrets.APPLICATION_PROPERTIES }}" > ./application.properties
Expand All @@ -123,8 +133,8 @@ jobs:
- name: Run chmod to make gradlew executable
run: chmod +x ./gradlew

- name: 빌드 진행
run: ./gradlew build -x test
# - name: 빌드 진행
# run: ./gradlew build -x test

- name: 테스트 코드 실행
run: ./gradlew --info test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

@Builder
public record GetCommentResponse(
String commentId,
String userId,
String postId,
String commentToken,
String userToken,
String postToken,
String comment,
LocalDateTime updateAt
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import com.seoultech.synergybe.domain.common.paging.ListResponse;
import com.seoultech.synergybe.domain.notification.service.NotificationService;
import com.seoultech.synergybe.domain.post.Post;
import com.seoultech.synergybe.domain.post.implement.PostReader;
import com.seoultech.synergybe.domain.post.repository.PostRepository;
import com.seoultech.synergybe.domain.user.User;
import com.seoultech.synergybe.domain.user.service.UserServiceImpl;
import lombok.RequiredArgsConstructor;
Expand All @@ -25,15 +25,15 @@
@Transactional
@RequiredArgsConstructor
public class CommentService {
private final PostRepository postRepository;
private final CommentRepository commentRepository;
private final PostReader postReader;
private final UserServiceImpl userService;
private final NotificationService notificationService;
private final IdGenerator idGenerator;
private final TokenGenerator tokenGenerator;

public GetCommentResponse createComment(String userId, CreateCommentRequest request) {
Post post = postReader.read(request.postId());
Post post = postRepository.findByPostToken(request.postId());
User user = userService.getUserByToken(userId);
Long commentId = idGenerator.generateId();
String commentToken = tokenGenerator.generateToken(IdPrefix.COMMENT);
Expand All @@ -47,10 +47,9 @@ public GetCommentResponse createComment(String userId, CreateCommentRequest requ

Comment savedComment = commentRepository.save(comment);
savedComment.addPost(post);
// User postUser = post.getUser();
// notificationService.send(postUser, NotificationType.COMMENT, "댓글이 생성되었습니다", post.getId());
return GetCommentResponse.builder()
.commentId(savedComment.getCommentToken())
.commentToken(savedComment.getCommentToken())
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,4 @@ public ResponseEntity<ListResponse<String>> getFollowingIds(@LoginUser String us

return ResponseEntity.status(HttpStatus.OK).body(followService.getFollowingIds(userId));
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
public class FollowReader {
private final FollowRepository followRepository;

public List<String> readFollowingIds(String userId) {
return followRepository.findFollowingIdsByFollowerId(userId);
public List<Long> readFollowingIds(String userToken) {
return followRepository.findFollowingIdsByFollowerToken(userToken);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,6 @@
import java.util.Optional;

@Repository
public interface FollowRepository extends JpaRepository<Follow, Long> {
public interface FollowRepository extends JpaRepository<Follow, Long>, FollowRepositoryCustom {

@Query(value = "SELECT following_id FROM follow WHERE follower_id = :userId AND status = 'FOLLOW'", nativeQuery = true)
List<String> findFollowingIdsByFollowerId(@Param("userId") String userId);

@Query(value = "SELECT follower_id FROM follow WHERE following_id = :userId AND status = 'FOLLOW'", nativeQuery = true)
List<String> findFollowerIdsByFollowingId(@Param("userId") String userId);

@Query(value = "SELECT * FROM follow WHERE follower_id = :userId AND following_id = :followingId FOR UPDATE", nativeQuery = true)
Optional<Follow> findByFollowerIdAndFollowingId(@Param("userId") String userId, @Param("followingId") String followingId);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.seoultech.synergybe.domain.follow.repository;

import com.seoultech.synergybe.domain.follow.Follow;

import java.util.List;

public interface FollowRepositoryCustom {
List<Long> findFollowingIdsByFollowerToken(String followerToken);
List<Long> findFollowerIdsByFollowingToken(String followingToken);
Follow findByFollowerTokenAndFollowingToken(String userToken, String followingToken);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.seoultech.synergybe.domain.follow.repository;

import com.querydsl.jpa.impl.JPAQueryFactory;
import com.seoultech.synergybe.domain.follow.Follow;
import com.seoultech.synergybe.domain.follow.FollowStatus;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;

import java.util.List;

import static com.seoultech.synergybe.domain.follow.QFollow.follow;

@RequiredArgsConstructor
@Repository
public class FollowRepositoryCustomImpl implements FollowRepositoryCustom {
private final JPAQueryFactory queryFactory;

@Override
public List<Long> findFollowingIdsByFollowerToken(String followerToken) {
return queryFactory
.select(follow.follower.id)
.where(
follow.follower.userToken.eq(followerToken).and(follow.status.eq(FollowStatus.FOLLOW)))
.fetch();
}

@Override
public List<Long> findFollowerIdsByFollowingToken(String followingToken) {
return queryFactory
.select(follow.follower.id)
.where(
follow.following.userToken.eq(followingToken).and(follow.status.eq(FollowStatus.FOLLOW)))
.fetch();
}

@Override
public Follow findByFollowerTokenAndFollowingToken(String userToken, String followingToken) {
return queryFactory
.selectFrom(follow)
.where(
follow.follower.userToken.eq(userToken).and(follow.following.userToken.eq(followingToken))
)
.fetchOne();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ public class FollowService {
private final IdGenerator idGenerator;
private final TokenGenerator tokenGenerator;

public List<String> findFollowingIdsByUserId(String userId) {
return followRepository.findFollowingIdsByFollowerId(userId);
}

/**
*
* @param user 신청한 유저
Expand Down Expand Up @@ -64,14 +60,14 @@ public GetFollowResponse updateFollow(User user, String followingToken, CreateFo
}

public synchronized Follow update(User user, String followingId, FollowStatus status) {
Optional<Follow> followOptional = followRepository.findByFollowerIdAndFollowingId(user.getUserToken(), followingId);
Follow followOptional = followRepository.findByFollowerTokenAndFollowingToken(user.getUserToken(), followingId);

if (followOptional.isPresent()) {
followOptional.get().updateStatus(status);
if (followOptional != null) {
followOptional.updateStatus(status);
User following = userService.getUserByToken(followingId);
// notificationService.send(following, NotificationType.FOLLOW, "팔로우 신청이 완료되었습니다.", Long.valueOf(followingId));

return followOptional.get();
return followOptional;
} else {
User following = userService.getUserByToken(followingId);
Long followId = idGenerator.generateId();
Expand All @@ -88,27 +84,23 @@ public synchronized Follow update(User user, String followingId, FollowStatus st
}
}

public List<String> getFollowerIdList(String userId) {
return followRepository.findFollowerIdsByFollowingId(userId);
public List<Long> getFollowerIdList(String userToken) {
return followRepository.findFollowerIdsByFollowingToken(userToken);
}

public List<String> getFollowingIdList(String userId) {
return followRepository.findFollowingIdsByFollowerId(userId);
public List<Long> getFollowingIdList(String userToken) {
return followRepository.findFollowingIdsByFollowerToken(userToken);
}

public ListResponse<String> getFollowerIds(String userId) {
List<String> getFollowerIdList = getFollowerIdList(userId);
public ListResponse<String> getFollowerIds(String userToken) {
List<Long> getFollowerIdList = getFollowerIdList(userToken);

ListResponse<String> getUserIdListResponses = new ListResponse(getFollowerIdList);

return getUserIdListResponses;
return new ListResponse(getFollowerIdList);
}

public ListResponse<String> getFollowingIds(String userId) {
List<String> getFollowingIdList = getFollowingIdList(userId);

ListResponse<String> getUserIdListResponses = new ListResponse(getFollowingIdList);
public ListResponse<String> getFollowingIds(String userToken) {
List<Long> getFollowingIdList = getFollowingIdList(userToken);

return getUserIdListResponses;
return new ListResponse(getFollowingIdList);
}
}

This file was deleted.

Loading

0 comments on commit 0952104

Please sign in to comment.