Skip to content

Commit

Permalink
[HOTFIX/1.1.5] hotfix: Hotfix v1.1.5 릴리즈 (#162)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kwon770 authored Feb 12, 2024
1 parent ab047b4 commit 90e614c
Show file tree
Hide file tree
Showing 12 changed files with 103 additions and 36 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
name: "Pull Request 오토 템플릿 추가"
on: pull_request
on:
pull_request:
branches:
- dev

jobs:
update_pr_templates:
Expand All @@ -16,4 +19,4 @@ jobs:
---
https://no5ing.atlassian.net/browse/%headbranch%
body-update-action: 'suffix'
body-update-action: 'suffix'
16 changes: 16 additions & 0 deletions .github/workflows/mainPRTemplate.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: "Pull Request 오토 템플릿 추가"
on:
pull_request:
branches:
- main

jobs:
update_pr_templates:
runs-on: ubuntu-latest
steps:
- uses: tzkhan/pr-update-action@v2 # https://github.com/tzkhan/pr-update-action
with:
repo-token: "${{ secrets.GITHUB_TOKEN }}"
base-branch-regex: 'main'
head-branch-regex: '(release|hotfix)\/\d+.\d+.\d+' # release 또는 hotfix 브랜치 reges (ex: release/1.0.0)
title-template: '[%headbranch%] ' # PR Title Prefix 템플릿 (배포 속성) (ex: [RELEASE/1.0.0])
3 changes: 2 additions & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ name: 테스트 커버리지 워크플로우
on:
pull_request:
branches:
- master
- main
- dev
- 'release/**'
- 'hotfix/**'

env:
COVERAGE_PERCENT: 30
Expand Down
2 changes: 2 additions & 0 deletions common/src/main/java/com/oing/service/FamilyScoreBridge.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ public interface FamilyScoreBridge {
void setAllFamilyScoresByPostDateBetween(LocalDate startDate, LocalDate endDate);

void updateAllFamilyTopPercentageHistories(LocalDate historyDate);

int calculateFamilyTopPercentage(int rank, int familiesCount);
}
2 changes: 1 addition & 1 deletion family/src/main/java/com/oing/job/FamilyStatisticJob.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class FamilyStatisticJob {

private final FamilyScoreBridge familyScoreBridge;

@Scheduled(cron = "0 1 1 * * *")
@Scheduled(cron = "0 0 1 1 * *") // 매월 1일 01시
public void recordAllFamilyTopPercentageHistoriesMonthly() {
LocalDate historyDate = LocalDate.now().minusMonths(1);
familyScoreBridge.updateAllFamilyTopPercentageHistories(historyDate);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

import java.util.List;

public interface FamilyRepository extends JpaRepository<Family, String> {
long countByScoreGreaterThanEqual(int familyScore);

public interface FamilyRepository extends JpaRepository<Family, String>, FamilyRepositoryCustom {
List<Family> findAllByOrderByScoreDesc();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.oing.repository;

public interface FamilyRepositoryCustom {

int countByScoreDistinct();

int countByScoreGreaterThanEqualScoreDistinct(int familyScore);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.oing.repository;

import com.querydsl.jpa.impl.JPAQueryFactory;
import lombok.RequiredArgsConstructor;

import static com.oing.domain.QFamily.family;

@RequiredArgsConstructor
public class FamilyRepositoryCustomImpl implements FamilyRepositoryCustom {

private final JPAQueryFactory queryFactory;

@Override
public int countByScoreDistinct() {
return queryFactory
.select(family.score)
.from(family)
.groupBy(family.score)
.fetch()
.size();
}

@Override
public int countByScoreGreaterThanEqualScoreDistinct(int familyScore) {
return queryFactory
.select(family.score)
.from(family)
.where(family.score.goe(familyScore))
.groupBy(family.score)
.fetch()
.size();
}


}
19 changes: 6 additions & 13 deletions family/src/main/java/com/oing/service/FamilyService.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public class FamilyService {

private final FamilyRepository familyRepository;
private final FamilyTopPercentageHistoryService familyTopPercentageHistoryService;

private final FamilyScoreBridge familyScoreBridge;
private final IdentityGenerator identityGenerator;

public ZonedDateTime findFamilyCreatedAt(String familyId) {
Expand Down Expand Up @@ -53,10 +55,6 @@ public List<Family> findAll() {
return familyRepository.findAll();
}

public List<Family> findAllOrderByScoreDesc() {
return familyRepository.findAllByOrderByScoreDesc();
}

public int getFamilyTopPercentage(String familyId, LocalDate calendarDate) {
// 이번 달의 캘린더를 조회 시, 실시간으로 topPercentage를 계산
if (calendarDate.getYear() == LocalDate.now().getYear() && calendarDate.getMonth() == LocalDate.now().getMonth()) {
Expand All @@ -69,17 +67,12 @@ public int getFamilyTopPercentage(String familyId, LocalDate calendarDate) {
}

private int calculateLiveFamilyTopPercentage(String familyId) {
long allFamiliesCount = familyRepository.count();
int familyScore = getFamilyById(familyId).getScore();
long familyRank = familyRepository.countByScoreGreaterThanEqual(familyScore);

// divide by zero error 핸들링
if (allFamiliesCount == 0) {
return 0;
}
int familiesCount = familyRepository.countByScoreDistinct();
int score = getFamilyById(familyId).getScore();
int rank = familyRepository.countByScoreGreaterThanEqualScoreDistinct(score);

// score 를 통한 순위를 통해 전체 가족들 중 상위 백분율 계산 (1%에 가까울수록 고순위)
return (int) Math.ceil((familyRank / (double) allFamiliesCount) * 100);
return familyScoreBridge.calculateFamilyTopPercentage(rank, familiesCount);
}

private int getFamilyTopPercentageHistory(String familyId, LocalDate calendarDate) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@ public class FamilyTopPercentageHistoryService {
private final FamilyTopPercentageHistoryRepository familyTopPercentageHistoryRepository;


public void create(CreateNewFamilyTopPercentageHistoryDTO createNewFamilyTopPercentageHistoryDTO) {
FamilyTopPercentageHistory familyTopPercentageHistory = new FamilyTopPercentageHistory(createNewFamilyTopPercentageHistoryDTO);
familyTopPercentageHistoryRepository.save(familyTopPercentageHistory);
}

public int getTopPercentageByFamilyIdAndDate(String familyId, LocalDate historyDate) {
LocalDate firstDayOfMonth = historyDate.withDayOfMonth(1);
FamilyTopPercentageHistoryId familyTopPercentageHistoryId = new FamilyTopPercentageHistoryId(familyId, firstDayOfMonth);
Expand Down
35 changes: 24 additions & 11 deletions gateway/src/main/java/com/oing/service/FamilyScoreBridgeImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

import com.oing.domain.CreateNewFamilyTopPercentageHistoryDTO;
import com.oing.domain.Family;
import com.oing.domain.FamilyTopPercentageHistory;
import com.oing.domain.MemberPost;
import com.oing.repository.FamilyRepository;
import com.oing.repository.FamilyTopPercentageHistoryRepository;
import jakarta.transaction.Transactional;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
Expand All @@ -16,14 +19,14 @@
@RequiredArgsConstructor
public class FamilyScoreBridgeImpl implements FamilyScoreBridge {

private final FamilyService familyService;
private final FamilyTopPercentageHistoryService familyTopPercentageHistoryService;
private final FamilyRepository familyRepository;
private final FamilyTopPercentageHistoryRepository familyTopPercentageHistoryRepository;
private final MemberPostService memberPostService;

@Override
@Transactional
public void setAllFamilyScoresByPostDateBetween(LocalDate startDate, LocalDate endDate) {
List<Family> families = familyService.findAll();
List<Family> families = familyRepository.findAll();
for (Family family : families) {
family.resetScore();
family.addScore(calculateFamilyScoreByPostDateBetween(family.getId(), startDate, endDate));
Expand All @@ -45,23 +48,33 @@ private int calculateFamilyScoreByPostDateBetween(String familyId, LocalDate sta
@Override
@Transactional
public void updateAllFamilyTopPercentageHistories(LocalDate historyDate) {
List<Family> families = familyService.findAllOrderByScoreDesc();
int familiesCount = families.size();
List<Family> families = familyRepository.findAll();
int familiesCount = familyRepository.countByScoreDistinct();

for (int rank = 1; rank <= familiesCount; rank++) {
String familyId = families.get(rank - 1).getId();
Family family = families.get(rank - 1);
int topPercentage = (int) Math.ceil((double) rank / familiesCount * 100);
for (Family family : families) {
int rank = familyRepository.countByScoreGreaterThanEqualScoreDistinct(family.getScore());
int topPercentage = calculateFamilyTopPercentage(rank, familiesCount);

CreateNewFamilyTopPercentageHistoryDTO dto = new CreateNewFamilyTopPercentageHistoryDTO(
familyId,
family.getId(),
historyDate,
family,
topPercentage
);
familyTopPercentageHistoryService.create(dto);
FamilyTopPercentageHistory familyTopPercentageHistory = new FamilyTopPercentageHistory(dto);
familyTopPercentageHistoryRepository.save(familyTopPercentageHistory);

family.resetScore();
}
}

@Override
public int calculateFamilyTopPercentage(int rank, int familiesCount) {
// divide by zero error 핸들링
if (familiesCount == 0) {
return 0;
}

return (int) Math.ceil((double) rank / familiesCount * 100);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.oing.dto.response.PaginationResponse;
import com.oing.dto.response.PreSignedUrlResponse;
import com.oing.exception.AuthorizationFailedException;
import com.oing.service.MemberDeviceService;
import com.oing.service.MemberService;
import com.oing.util.AuthenticationHolder;
import com.oing.util.PreSignedUrlGenerator;
Expand Down Expand Up @@ -44,6 +45,8 @@ public class MemberControllerTest {
private AuthenticationHolder authenticationHolder;
@Mock
private PreSignedUrlGenerator preSignedUrlGenerator;
@Mock
private MemberDeviceService memberDeviceService;

@Test
void 멤버_프로필_조회_테스트() {
Expand Down

0 comments on commit 90e614c

Please sign in to comment.