Skip to content

Commit

Permalink
백엔드 배포 작업 (#724)
Browse files Browse the repository at this point in the history
* 리프레시 토큰 관리를 Redis로 변경 (#710)

* feat: redis 설정 추가

* refactor: RefreshToken 관리를 redis로 업데이트

* test: refreshToken 관련 service 테스트 수정

* refactor: EmbbedRedis 설정 제거

* feat: Redis Test Container 설정 추가

* refactor: 테스트가 용이하게 RefreshToken TTL을 외부에서 관리

* test: OauthComand관련 테스트 수정

* test: Restdocs 테스트 수정

* refactor: OauthCommandService 생성자에 refreshTokenExpireMinutes를 받도록 수정

* test: RefreshToken 추가

* test: 사용하지 않는 RefreshToken 삭제

* refactor: RefreshToken2 를 RefreshToken으로 이름 변경

* refactor: expire minutes 이름 변경

* test: RefreshTokenFixture로 리팩토링

* refactor: Facade 패턴 적용

* refactor: ttl 단위를 분으로 변경

* refactor: RedisConfig에 username과 password 추가

* feat: docker-compose 에 redis 설정 추가

* refactor: 사용하지 않는 Restemplate 제거

* refactor: 스프링 부트 버전 3.1.8로 업그레이드

* refactor: redis.conf bind를 localhost만 가능하도록 변경

* 게시글 조회 API에 게시글 총 개수 포함해서 반환 (#711)

refactor: 글 조회시 전체 개수가 같이 반환되도록 구현

* 완료된 리뷰가 많은 서포터 순대로 조회하는 기능 구현 (#712)

* feat: 리뷰가 많은 사람 랭킹 구하는 기능 구현

* test: 랭킹 인수테스트와 restdocs 테스트 구현

* feat: 랭킹에 company 항목 추가

* refactor: 다른 랭킹도 추가할 수 있도록 Rankable 마커 인터페이스 구현

* feat: review 완료 시 reviewCount 증가 기능 구현 (#721)

* feat: review 완료 시 reviewCount 증가 기능 구현

* test: reviewCount 증가로직 테스트 구현

* refactor: 리뷰수 증가 로직을 RunnerPost 안으로 옮김

* reviewCount가 0인 항목이 조회가 되면 제외되도록 구현 (#722)

* refactor: reviewCount가 0인 항목이 조회가 되면 제외되도록 구현

* refactor: count 할 때 reviewStatus가 포함되도록 변경
  • Loading branch information
cookienc authored Feb 19, 2024
1 parent 9660003 commit 98b27f4
Show file tree
Hide file tree
Showing 16 changed files with 160 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ public void updateCompany(final Company company) {
this.member.updateCompany(company);
}

public void increaseReviewCount() {
this.reviewCount.increase();
}

@Override
public boolean equals(final Object o) {
if (this == o) return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,8 @@ public class ReviewCount {
public ReviewCount(final int value) {
this.value = value;
}

public void increase() {
value += 1;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;
import touch.baton.domain.member.command.Supporter;
import touch.baton.domain.member.command.vo.ReviewCount;

import java.util.List;

Expand All @@ -19,6 +20,7 @@ public class RankQuerydslRepository {
public List<Supporter> findMostReviewSupporterByCount(final int count) {
return jpaQueryFactory.selectFrom(supporter)
.join(supporter.member, member).fetchJoin()
.where(supporter.reviewCount.ne(new ReviewCount(0)))
.orderBy(supporter.reviewCount.value.desc())
.limit(count)
.fetch();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ public void addAllRunnerPostTags(final List<RunnerPostTag> postTags) {

public void finishReview() {
updateReviewStatus(ReviewStatus.DONE);
this.supporter.increaseReviewCount();
}

public void finishFeedback() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import touch.baton.domain.runnerpost.command.service.dto.RunnerPostApplicantCreateRequest;
import touch.baton.domain.runnerpost.command.service.dto.RunnerPostCreateRequest;
import touch.baton.domain.runnerpost.command.service.dto.RunnerPostUpdateRequest;
import touch.baton.domain.runnerpost.query.repository.RunnerPostQueryRepository;
import touch.baton.domain.tag.command.RunnerPostTag;
import touch.baton.domain.tag.command.Tag;
import touch.baton.domain.tag.command.repository.TagCommandRepository;
Expand All @@ -34,6 +35,7 @@
public class RunnerPostCommandService {

private final RunnerPostCommandRepository runnerPostCommandRepository;
private final RunnerPostQueryRepository runnerPostQueryRepository;
private final TagCommandRepository tagCommandRepository;
private final SupporterCommandRepository supporterCommandRepository;
private final SupporterRunnerPostCommandRepository supporterRunnerPostCommandRepository;
Expand Down Expand Up @@ -125,7 +127,7 @@ public Long createRunnerPostApplicant(final Supporter supporter,
}

public void updateRunnerPostReviewStatusDone(final Long runnerPostId, final Supporter supporter) {
final RunnerPost foundRunnerPost = runnerPostCommandRepository.findById(runnerPostId)
final RunnerPost foundRunnerPost = runnerPostQueryRepository.joinSupporterByRunnerPostId(runnerPostId)
.orElseThrow(() -> new RunnerPostBusinessException("해당 식별자의 러너 게시글이 존재하지 않습니다."));

if (Objects.isNull(foundRunnerPost.getSupporter())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ public Page<RunnerPost> pageByReviewStatusAndTagReducedName(final Long previousL
.where(tag.tagReducedName.eq(tagReducedName));
}

final JPAQuery<RunnerPost> countQuery = jpaQueryFactory.selectFrom(runnerPost);
final JPAQuery<RunnerPost> countQuery = jpaQueryFactory.selectFrom(runnerPost)
.where(reviewStatusEq(reviewStatus));

if (tagReducedName != null) {
countQuery.leftJoin(runnerPost.runnerPostTags.runnerPostTags, runnerPostTag)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,25 @@ void findMostReviewSupporterByCount() {
() -> assertThat(actual.get(1).getReviewCount().getValue()).isEqualTo(4)
);
}

@DisplayName("Supporter의 count가 안되더라도 ReviewCount가 0이면 조회되지 않는다.")
@Test
void findMostReviewSupporterByCount_having_count_is_zero() {
// given
persistSupporter(new ReviewCount(0), MemberFixture.createEthan());
persistSupporter(new ReviewCount(3), MemberFixture.createHyena());
persistSupporter(new ReviewCount(8), MemberFixture.createDitoo());

// when
final int count = 3;
final int zeroCount = 1;
final List<Supporter> actual = rankQueryDslRepository.findMostReviewSupporterByCount(count);

// then
assertAll(
() -> assertThat(actual).hasSize(count - zeroCount),
() -> assertThat(actual.get(0).getReviewCount().getValue()).isEqualTo(8),
() -> assertThat(actual.get(1).getReviewCount().getValue()).isEqualTo(3)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ void setUp() {
@Test
void readMostReviewSupporter() {
// given

for (int reviewedCount = 0; reviewedCount < 5; reviewedCount++) {
persistSupporter(new ReviewCount(reviewedCount), MemberFixture.create(memberName("member" + reviewedCount)));
}
Expand Down Expand Up @@ -73,6 +72,48 @@ void readMostReviewSupporter() {
);
}

@DisplayName("Supporter의 ReviewCount가 높은 순으로 count 개수 만큼 조회하고, 그 중 ReviewCount가 0이면 제외된다.")
@Test
void readMostReviewSupporter_when_has_zero_reviewCount() {
// given
final TechnicalTag javaTag = technicalTagQueryRepository.save(TechnicalTagFixture.createJava());
final TechnicalTag springTag = technicalTagQueryRepository.save(TechnicalTagFixture.createSpring());
final TechnicalTag reactTag = technicalTagQueryRepository.save(TechnicalTagFixture.createReact());

final Member fourthRankMember = persistMember(MemberFixture.create(memberName("fourth")));
final List<TechnicalTag> fourthRankMembersTechnicalTags = List.of(javaTag, springTag);
persistSupporter(new ReviewCount(12), fourthRankMember, fourthRankMembersTechnicalTags);

final Member thirdRankMember = persistMember(MemberFixture.create(memberName("third")));
final List<TechnicalTag> thirdRankMembersTechnicalTags = List.of(javaTag, reactTag);
persistSupporter(new ReviewCount(13), thirdRankMember, thirdRankMembersTechnicalTags);

final Member firstRankMember = persistMember(MemberFixture.create(memberName("first")));
final List<TechnicalTag> firstRankMembersTechnicalTags = List.of(javaTag, springTag);
persistSupporter(new ReviewCount(15), firstRankMember, firstRankMembersTechnicalTags);

final Member secondRankMember = persistMember(MemberFixture.create(memberName("second")));
final List<TechnicalTag> secondRankMembersTechnicalTags = List.of(javaTag);
persistSupporter(new ReviewCount(14), secondRankMember, secondRankMembersTechnicalTags);

final Member fifthRankMember = persistMember(MemberFixture.create(memberName("fifth")));
final List<TechnicalTag> fifthMembersTechnicalTags = List.of(reactTag);
persistSupporter(new ReviewCount(0), fifthRankMember, fifthMembersTechnicalTags);

// when
final int maxCount = 5;
final RankResponses<RankResponses.SupporterRank> actual = rankQueryService.readMostReviewSupporter(maxCount);

// then
assertAll(
() -> assertThat(actual.data()).hasSize(4),
() -> assertResponse(actual.data().get(0), 1, "first", 15),
() -> assertResponse(actual.data().get(1), 2, "second", 14),
() -> assertResponse(actual.data().get(2), 3, "third", 13),
() -> assertResponse(actual.data().get(3), 4, "fourth", 12)
);
}

private static void assertResponse(final RankResponses.SupporterRank response, final int rank, final String memberName, final int reviewCount) {
assertAll(
() -> assertThat(response.rank()).isEqualTo(rank),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package touch.baton.domain.member.vo;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import touch.baton.domain.member.command.vo.ReviewCount;

import static org.assertj.core.api.Assertions.assertThat;

class ReviewCountTest {

@DisplayName("increaseCount가 호출 되면 value가 1 증가한다.")
@Test
void increaseCount() {
// given
final int initialValue = 0;
final ReviewCount reviewCount = new ReviewCount(initialValue);

// when
reviewCount.increase();

// then
assertThat(reviewCount.getValue()).isEqualTo(initialValue + 1);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package touch.baton.domain.runnerpost;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -71,11 +72,16 @@ class RunnerPostTest {
.runnerTechnicalTags(RunnerTechnicalTagsFixture.create(new ArrayList<>()))
.build();

private final Supporter supporter = Supporter.builder()
.reviewCount(new ReviewCount(10))
.member(supporterMember)
.supporterTechnicalTags(new SupporterTechnicalTags(new ArrayList<>()))
.build();
private Supporter supporter;

@BeforeEach
void setUp() {
supporter = Supporter.builder()
.reviewCount(new ReviewCount(10))
.member(supporterMember)
.supporterTechnicalTags(new SupporterTechnicalTags(new ArrayList<>()))
.build();
}

@DisplayName("runnerPostTags 전체를 추가할 수 있다.")
@Test
Expand Down Expand Up @@ -584,4 +590,34 @@ void fail_same_to_same(final ReviewStatus reviewStatus) {
.isInstanceOf(RunnerPostDomainException.class);
}
}

@DisplayName("리뷰완료가 되면 ReviewStatus가 Done으로 바뀌고 리뷰를 작성한 ReviewCount가 1 증가한다.")
@Test
void finishReview() {
// given
final ReviewCount originReviewCount = new ReviewCount(supporter.getReviewCount().getValue());
final RunnerPost runnerPost = RunnerPost.builder()
.title(new Title("러너가 작성하는 리뷰 요청 게시글의 테스트 제목입니다."))
.implementedContents(new ImplementedContents("안녕하세요. 테스트 내용입니다."))
.curiousContents(new CuriousContents("궁금한 점입니다."))
.postscriptContents(new PostscriptContents("잘 부탁드립니다."))
.pullRequestUrl(new PullRequestUrl("https://github.com"))
.deadline(new Deadline(LocalDateTime.now().plusHours(100)))
.watchedCount(new WatchedCount(0))
.reviewStatus(ReviewStatus.IN_PROGRESS)
.isReviewed(IsReviewed.notReviewed())
.runner(runner)
.supporter(supporter)
.runnerPostTags(new RunnerPostTags(new ArrayList<>()))
.build();

// when
runnerPost.finishReview();

// then
assertAll(
() -> assertThat(runnerPost.getReviewStatus()).isEqualTo(ReviewStatus.DONE),
() -> assertThat(supporter.getReviewCount()).isEqualTo(new ReviewCount(originReviewCount.getValue() + 1))
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class RunnerPostCommandServiceCreateTest extends ServiceTestConfig {
void setUp() {
runnerPostCommandService = new RunnerPostCommandService(
runnerPostCommandRepository,
runnerPostQueryRepository,
tagCommandRepository,
supporterCommandRepository,
supporterRunnerPostCommandRepository,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class RunnerPostCommandServiceDeleteTest extends ServiceTestConfig {
void setUp() {
runnerPostCommandService = new RunnerPostCommandService(
runnerPostCommandRepository,
runnerPostQueryRepository,
tagCommandRepository,
supporterCommandRepository,
supporterRunnerPostCommandRepository,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class RunnerPostCommandServiceEventTest extends ServiceTestConfig {
void setUp() {
runnerPostCommandService = new RunnerPostCommandService(
runnerPostCommandRepository,
runnerPostQueryRepository,
tagCommandRepository,
supporterCommandRepository,
supporterRunnerPostCommandRepository,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import touch.baton.domain.member.command.Member;
import touch.baton.domain.member.command.Runner;
import touch.baton.domain.member.command.Supporter;
import touch.baton.domain.member.command.vo.ReviewCount;
import touch.baton.domain.runnerpost.command.RunnerPost;
import touch.baton.domain.runnerpost.command.exception.RunnerPostBusinessException;
import touch.baton.domain.runnerpost.command.exception.RunnerPostDomainException;
Expand Down Expand Up @@ -43,6 +44,7 @@ class RunnerPostCommandServiceUpdateTest extends ServiceTestConfig {
void setUp() {
runnerPostCommandService = new RunnerPostCommandService(
runnerPostCommandRepository,
runnerPostQueryRepository,
tagCommandRepository,
supporterCommandRepository,
supporterRunnerPostCommandRepository,
Expand Down Expand Up @@ -143,6 +145,7 @@ void updateRunnerPostReviewStatusDone() {
// given
final IsReviewed isReviewed = IsReviewed.notReviewed();
final RunnerPost targetRunnerPost = runnerPostQueryRepository.save(RunnerPostFixture.createWithSupporter(runner, assignedSupporter, IN_PROGRESS, isReviewed));
final ReviewCount originalReviewCount = new ReviewCount(assignedSupporter.getReviewCount().getValue());

// when
runnerPostCommandService.updateRunnerPostReviewStatusDone(targetRunnerPost.getId(), assignedSupporter);
Expand All @@ -152,6 +155,7 @@ void updateRunnerPostReviewStatusDone() {
assertThat(maybeRunnerPost).isPresent();
final RunnerPost actualRunnerPost = maybeRunnerPost.get();
assertThat(actualRunnerPost.getReviewStatus()).isEqualTo(ReviewStatus.DONE);
assertThat(assignedSupporter.getReviewCount()).isEqualTo(new ReviewCount(originalReviewCount.getValue() + 1));
}

@DisplayName("없는 게시글의 상태를 리뷰 완료로 변경할 수 없다.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class RunnerPostUpdateApplicantCancelationServiceTest extends ServiceTestConfig
void setUp() {
runnerPostCommandService = new RunnerPostCommandService(
runnerPostCommandRepository,
runnerPostQueryRepository,
tagCommandRepository,
supporterCommandRepository,
supporterRunnerPostCommandRepository,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ void readRunnerPostByPageInfoAndTagNameAndReviewStatus_firstPage() {

final Tag javaTag = tagCommandRepository.save(TagFixture.create(tagName("자바")));
final Tag springTag = tagCommandRepository.save(TagFixture.create(tagName("스프링")));
final int totalJavaTagPost = 3;
final int totalJavaTagAndNotStartedPost = 2;

final RunnerPost expectedRunnerPostOne = runnerPostQueryRepository.save(RunnerPostFixture.create(
hyenaRunner,
Expand Down Expand Up @@ -124,7 +124,7 @@ void readRunnerPostByPageInfoAndTagNameAndReviewStatus_firstPage() {
List.of(RunnerPostResponse.Simple.of(expectedRunnerPostTwo, 0L, runnerPostTags),
RunnerPostResponse.Simple.of(expectedRunnerPostOne, 0L, runnerPostTags)),
pageParams,
totalJavaTagPost
totalJavaTagAndNotStartedPost
);

// then
Expand All @@ -140,7 +140,7 @@ void readRunnerPostByPageInfoAndTagNameAndReviewStatus_middlePage() {

final Tag javaTag = tagCommandRepository.save(TagFixture.create(tagName("자바")));
final Tag springTag = tagCommandRepository.save(TagFixture.create(tagName("스프링")));
final int totalJavaTagPost = 4;
final int totalJavaTagAndNotStartedPost = 3;

final RunnerPost expectedRunnerPostOne = runnerPostQueryRepository.save(RunnerPostFixture.create(
hyenaRunner,
Expand Down Expand Up @@ -194,7 +194,7 @@ void readRunnerPostByPageInfoAndTagNameAndReviewStatus_middlePage() {
List.of(RunnerPostResponse.Simple.of(expectedRunnerPostTwo, 0L, runnerPostTags),
RunnerPostResponse.Simple.of(expectedRunnerPostOne, 0L, runnerPostTags)),
pageParams,
totalJavaTagPost
totalJavaTagAndNotStartedPost
);

// then
Expand All @@ -210,7 +210,7 @@ void readRunnerPostByPageInfoAndReviewStatus_firstPage() {

final Tag javaTag = tagCommandRepository.save(TagFixture.create(tagName("자바")));
final Tag springTag = tagCommandRepository.save(TagFixture.create(tagName("스프링")));
final int totalPost = 4;
final int totalNotStartedPost = 3;

final RunnerPost expectedRunnerPostOne = runnerPostQueryRepository.save(RunnerPostFixture.create(
hyenaRunner,
Expand Down Expand Up @@ -260,7 +260,7 @@ void readRunnerPostByPageInfoAndReviewStatus_firstPage() {
RunnerPostResponse.Simple.of(expectedRunnerPostTwo, 0L, runnerPostTags),
RunnerPostResponse.Simple.of(expectedRunnerPostOne, 0L, runnerPostTags)),
pageParams,
totalPost
totalNotStartedPost
);

// then
Expand All @@ -276,7 +276,7 @@ void readRunnerPostByPageInfoAndReviewStatus_middlePage() {

final Tag javaTag = tagCommandRepository.save(TagFixture.create(tagName("자바")));
final Tag springTag = tagCommandRepository.save(TagFixture.create(tagName("스프링")));
final int totalPost = 5;
final int notStartedPost = 4;

final RunnerPost expectedRunnerPostOne = runnerPostQueryRepository.save(RunnerPostFixture.create(
hyenaRunner,
Expand Down Expand Up @@ -332,7 +332,7 @@ void readRunnerPostByPageInfoAndReviewStatus_middlePage() {
RunnerPostResponse.Simple.of(expectedRunnerPostTwo, 0L, runnerPostTags),
RunnerPostResponse.Simple.of(expectedRunnerPostOne, 0L, runnerPostTags)),
pageParams,
totalPost
notStartedPost
);

// then
Expand Down

0 comments on commit 98b27f4

Please sign in to comment.