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

release: deploy to prod #2

Merged
merged 22 commits into from
May 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
b6f5a33
fix: ๋ˆ„์  ์ž”์•ก์ด ์ •์ƒ ๋ฐ˜์˜๋˜๋„๋ก ํ•œ๋‹ค. (#75)
rlarltj Apr 10, 2024
822d9ba
feat: kakao ๋กœ๊ทธ์ธ ์˜ˆ์™ธ ์ฒ˜๋ฆฌ๋ฅผ ์„ธ๋ถ„ํ™”ํ•œ๋‹ค. (#76)
rlarltj Apr 20, 2024
5232cd4
feat: ์žฅ๋ถ€ ๋‚ด์—ญ ์กฐํšŒ api v2๋ฅผ ์ถ”๊ฐ€ํ•œ๋‹ค. (#77)
rlarltj Apr 24, 2024
4f9bc09
config: swagger scan ํŒจํ‚ค์ง€๋ฅผ ์ˆ˜์ •ํ•œ๋‹ค. (#79)
rlarltj May 1, 2024
4af195a
feat: Apple OAuth Login์„ ์ถ”๊ฐ€ํ•œ๋‹ค. (#80)
rlarltj May 9, 2024
271b9fb
feat: Apple ํšŒ์› ํƒˆํ‡ด๋ฅผ ๊ตฌํ˜„ํ•œ๋‹ค.
rlarltj May 9, 2024
1d4e6cb
feat: ํšŒ์›ํƒˆํ‡ด api v2๋ฅผ ์ถ”๊ฐ€ํ•œ๋‹ค.
rlarltj May 9, 2024
00bee67
chore: CI build๊ฐ€ ์‹คํŒจํ•˜์ง€ ์•Š๋„๋ก ํ•œ๋‹ค.
rlarltj May 9, 2024
3c903ce
feat: ์†Œ์† ์กฐํšŒ ๊ฒฐ๊ณผ์— ์†Œ์† ์ƒ์„ฑ์ผ์ž๋ฅผ ํฌํ•จํ•œ๋‹ค. (#82)
rlarltj May 12, 2024
f1ab63c
feat: ์†Œ์† ์กฐํšŒ ๊ฒฐ๊ณผ์— ์†Œ์† ์ƒ์„ฑ์ผ์ž๋ฅผ ํฌํ•จํ•œ๋‹ค. (#82)
rlarltj May 12, 2024
49f16f3
chore: log๋ฅผ ์ถ”๊ฐ€ํ•œ๋‹ค.
rlarltj May 12, 2024
7faec57
chore: apple revoke url๋ฅผ ๋ณ€๊ฒฝํ•œ๋‹ค.
rlarltj May 12, 2024
97c97c8
refactor: ํšŒ์› ํƒˆํ‡ด ์‹œ AppleUser ๋ฐ์ดํ„ฐ๋ฅผ hardDeleteํ•œ๋‹ค.
rlarltj May 12, 2024
478bea6
remove: ํšŒ์› ํƒˆํ‡ด v2 api๋ฅผ ์‚ญ์ œํ•œ๋‹ค.
rlarltj May 12, 2024
f3396ca
chore: resolve merge confilct
rlarltj May 14, 2024
fa95493
refactor: ์žฅ๋ถ€ ์ƒ์„ธ๋‚ด์—ญ CUD ๋ฆฌํŒฉํ† ๋ง
rlarltj May 19, 2024
972bb7b
fix: ์žฅ๋ถ€ ์กฐํšŒ ์‹œ endMonth์˜ ๊ธฐ๊ฐ„๋„ ํฌํ•จํ•œ๋‹ค.
rlarltj May 20, 2024
66cdfe7
chore: github workflow๋ฅผ ์žฌ์„ค์ •ํ•œ๋‹ค.
rlarltj May 26, 2024
fd00d44
Merge branch 'dev' into feat/oauth-revoke
rlarltj May 26, 2024
d2f5dfb
Merge pull request #1 from MONEYMONG/feat/oauth-revoke
rlarltj May 26, 2024
10955b2
Merge branch 'main' into dev
rlarltj May 26, 2024
074d074
chore: resolve merge conflict
rlarltj May 26, 2024
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
9 changes: 4 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ name: gradle build

on:
pull_request:
branches: [ main ]
branches:
- main
- dev


# ๊ถŒํ•œ ์„ค์ •
permissions: write-all
Expand All @@ -25,10 +28,6 @@ jobs:
- name: Set up Environment
run: echo "${{ secrets.ENV_PROPERTIES_LOCAL }}" > ./.env

# docker๋กœ Test์šฉ mysql ๋„์šฐ๊ธฐ
- name: Create Mysql Docker Container
run: sudo docker run -d -p 3306:3306 --env MYSQL_DATABASE="${{ secrets.TEST_DATABASE }}" --env MYSQL_ROOT_PASSWORD="${{ secrets.TEST_DATASOURCE_PASSWORD }}" mysql:8.0.31

# ๋นŒ๋“œ์‹œ ์บ์‹œ ์ ์šฉ
- name: Cache Gradle Packages
uses: actions/cache@v3
Expand Down
16 changes: 6 additions & 10 deletions .github/workflows/deploy-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,12 @@ jobs:
- name: Send env file
uses: appleboy/scp-action@master
with:
username: ${{ secrets.USERNAME }}
host: ${{ secrets.NCP_HOST }}
username: root
host: ${{ secrets.NCP_DEV_IP }}
password: ${{ secrets.NCP_PASSWORD }}
source: "./.env"
target: "/home/ubuntu"

# ๋„์ปค MYSQL ์ด๋ฏธ์ง€ ์‹คํ–‰
- name: Create Mysql Docker Container
run: sudo docker run -d -p 3306:3306 --env MYSQL_DATABASE="${{ secrets.TEST_DATABASE }}" --env MYSQL_ROOT_PASSWORD="${{ secrets.TEST_DATASOURCE_PASSWORD }}" mysql:8.0.31

# ๋นŒ๋“œ
- name: Build with Gradle
run: ./gradlew clean bootJar
Expand All @@ -55,8 +51,8 @@ jobs:
- name: Send docker-compose.yml
uses: appleboy/scp-action@master
with:
username: ${{ secrets.USERNAME }}
host: ${{ secrets.NCP_HOST }}
username: root
host: ${{ secrets.NCP_DEV_IP }}
password: ${{ secrets.NCP_PASSWORD }}
port: 22
source: "./.docker/docker-compose.yml"
Expand All @@ -66,8 +62,8 @@ jobs:
- name: Deploy to Dev
uses: appleboy/ssh-action@master
with:
username: ${{ secrets.USERNAME }}
host: ${{ secrets.NCP_HOST }}
username: root
host: ${{ secrets.NCP_DEV_IP }}
password: ${{ secrets.NCP_PASSWORD }}
script: |
sudo cp /home/ubuntu/.docker/docker-compose.yml /home/ubuntu
Expand Down
18 changes: 7 additions & 11 deletions .github/workflows/deploy-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,12 @@ jobs:
- name: Send env file
uses: appleboy/scp-action@master
with:
username: ${{ secrets.USERNAME }}
host: ${{ secrets.NCP_PROD_HOST }}
username: root
host: ${{ secrets.NCP_PROD_IP }}
password: ${{ secrets.NCP_PROD_PASSWORD }}
source: "./.env"
target: "/home/ubuntu"

# ๋„์ปค MYSQL ์ด๋ฏธ์ง€ ์‹คํ–‰
- name: Create Mysql Docker Container
run: sudo docker run -d -p 3306:3306 --env MYSQL_DATABASE="${{ secrets.TEST_DATABASE }}" --env MYSQL_ROOT_PASSWORD="${{ secrets.TEST_DATASOURCE_PASSWORD }}" mysql:8.0.31

# ๋นŒ๋“œ
- name: Build with Gradle
run: ./gradlew clean bootJar
Expand All @@ -55,19 +51,19 @@ jobs:
- name: Send docker-compose.yml
uses: appleboy/scp-action@master
with:
username: ${{ secrets.USERNAME }}
host: ${{ secrets.NCP_PROD_HOST }}
username: root
host: ${{ secrets.NCP_PROD_IP }}
password: ${{ secrets.NCP_PROD_PASSWORD }}
port: 22
source: "./.docker/docker-compose.yml"
target: "/home/ubuntu/"

# ๋„์ปค ์ปดํฌ์ฆˆ ์‹คํ–‰
- name: Deploy to Dev
- name: Deploy to Prod
uses: appleboy/ssh-action@master
with:
username: ${{ secrets.USERNAME }}
host: ${{ secrets.NCP_PROD_HOST }}
username: root
host: ${{ secrets.NCP_PROD_IP }}
password: ${{ secrets.NCP_PROD_PASSWORD }}
script: |
sudo cp /home/ubuntu/.docker/docker-compose.yml /home/ubuntu
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import java.time.ZonedDateTime;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.hibernate.validator.constraints.Length;

@Getter
@NoArgsConstructor
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/com/moneymong/domain/ledger/entity/LedgerDetail.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,18 @@ public void updateBalance(int balance) {
this.balance = balance;
}

public void updateLedgerDetailInfo(
String storeInfo,
int amount,
String description,
ZonedDateTime paymentDate
) {
this.storeInfo = storeInfo;
this.amount = amount;
this.description = description;
this.paymentDate = paymentDate;
}

public static LedgerDetail of(
final Ledger ledger,
final User user,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
import com.moneymong.domain.ledger.entity.LedgerDetail;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;

public interface LedgerDetailRepository extends JpaRepository<LedgerDetail, Long>, LedgerDetailCustom {
boolean existsByLedger(Ledger ledger);

List<LedgerDetail> findAllByLedger(Ledger ledger);
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
import com.moneymong.domain.ledger.entity.enums.FundType;
import com.moneymong.domain.ledger.repository.LedgerDetailCustom;
import com.querydsl.jpa.impl.JPAQueryFactory;

import java.time.LocalTime;
import java.time.ZonedDateTime;
import java.time.temporal.TemporalAdjusters;
import java.util.List;
import java.util.Optional;

Expand Down Expand Up @@ -62,9 +65,12 @@ public List<LedgerDetail> searchByPeriod(
ZonedDateTime to,
PageRequest pageable
) {
ZonedDateTime endOfMonth = to.with(TemporalAdjusters.lastDayOfMonth())
.with(LocalTime.MAX);

return jpaQueryFactory.selectFrom(ledgerDetail)
.where(ledgerDetail.ledger.eq(ledger))
.where(ledgerDetail.paymentDate.between(from, to))
.where(ledgerDetail.paymentDate.between(from, endOfMonth))
.orderBy(ledgerDetail.paymentDate.desc())
.offset((long) pageable.getPageNumber() * pageable.getPageSize())
.limit(pageable.getPageSize())
Expand All @@ -79,10 +85,13 @@ public List<LedgerDetail> searchByPeriodAndFundType(
FundType fundType,
PageRequest pageable
) {
ZonedDateTime endOfMonth = to.with(TemporalAdjusters.lastDayOfMonth())
.with(LocalTime.MAX);

return jpaQueryFactory.selectFrom(ledgerDetail)
.where(ledgerDetail.ledger.eq(ledger))
.where(ledgerDetail.fundType.eq(fundType))
.where(ledgerDetail.paymentDate.between(from, to))
.where(ledgerDetail.paymentDate.between(from, endOfMonth))
.orderBy(ledgerDetail.paymentDate.desc())
.offset((long) pageable.getPageNumber() * pageable.getPageSize())
.limit(pageable.getPageSize())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.moneymong.domain.ledger.repository.LedgerDetailRepository;
import com.moneymong.domain.ledger.repository.LedgerDocumentRepository;
import com.moneymong.domain.ledger.repository.LedgerReceiptRepository;
import com.moneymong.domain.ledger.repository.LedgerRepository;
import com.moneymong.domain.ledger.service.mapper.LedgerAssembler;
import com.moneymong.domain.ledger.service.reader.LedgerDocumentReader;
import com.moneymong.domain.ledger.service.reader.LedgerReceiptReader;
Expand All @@ -22,19 +23,22 @@
import com.moneymong.global.exception.custom.NotFoundException;
import com.moneymong.global.exception.enums.ErrorCode;
import java.time.ZonedDateTime;
import java.util.Comparator;
import java.util.List;
import java.util.Optional;

import com.moneymong.utils.AmountCalculatorByFundType;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import static com.moneymong.domain.ledger.entity.enums.FundType.INCOME;

@Service
@Slf4j
@RequiredArgsConstructor
public class LedgerDetailService {
private final LedgerRepository ledgerRepository;
private final LedgerAssembler ledgerAssembler;
private final LedgerReceiptReader ledgerReceiptReader;
private final LedgerDocumentReader ledgerDocumentReader;
Expand Down Expand Up @@ -69,51 +73,44 @@ public LedgerDetail createLedgerDetail(

int newAmount = AmountCalculatorByFundType.calculate(fundType, amount);

/**
* ๊ฐ€์žฅ ์˜ค๋ž˜๋œ ์žฅ๋ถ€ ๋‚ด์—ญ์ธ ๊ฒฝ์šฐ ์ž”๊ณ ๋ฅผ amount ๊ฐ’์œผ๋กœ ์„ค์ •ํ•œ๋‹ค.
* ์ด์ „ ๋‚ด์—ญ์ด ์žˆ๋Š” ๊ฒฝ์šฐ, ๊ฐ€์žฅ ๊ฐ€๊นŒ์šด ์‹œ์ผ์— ์ƒ์„ฑ๋œ ์žฅ๋ถ€ ๋‚ด์—ญ์„ ๊ธฐ์ค€์œผ๋กœ ์ž”๊ณ ๋ฅผ ์ €์žฅํ•œ๋‹ค.
*/
Optional<LedgerDetail> mostRecentLedgerDetail = ledgerDetailRepository.findMostRecentLedgerDetail(ledger, paymentDate);

if (mostRecentLedgerDetail.isPresent()) {
LedgerDetail recentDetail = mostRecentLedgerDetail.get();

int newBalance = recentDetail.getBalance() + newAmount;
ledgerDetail.updateBalance(newBalance);
}else {
ledgerDetail.updateBalance(newAmount);
}

ledger.updateTotalBalance(newAmount);

ledgerDetailRepository.bulkUpdateLedgerDetailBalance(
ledger,
paymentDate,
newAmount
);
ledgerDetailRepository.save(ledgerDetail);

return ledgerDetailRepository.save(ledgerDetail);
updateBalance(ledger);

return ledgerDetail;
}

@Transactional
public LedgerDetailInfoView updateLedgerDetail(
User user,
Ledger ledger,
LedgerDetail ledgerDetail,
UpdateLedgerRequest updateLedgerRequest
) {
long ledgerDetailId = ledgerDetail.getId();

// LedgerDetail createdLedgerDetail = createLedgerDetail(ledger,
// user,
// updateLedgerRequest.getStoreInfo(),
// ledgerDetail.getFundType(),
// updateLedgerRequest.getAmount(),
// ledger.getTotalBalance(),
// updateLedgerRequest.getDescription(),
// updateLedgerRequest.getPaymentDate()
// );
Ledger ledger = ledgerDetail.getLedger();

long ledgerDetailId = ledgerDetail.getId();
int newAmount = AmountCalculatorByFundType.calculate(
ledgerDetail.getFundType(),
ledgerDetail.getAmount() - updateLedgerRequest.getAmount()
);

ledger.updateTotalBalance(-newAmount);

ledgerDetail.updateLedgerDetailInfo(
updateLedgerRequest.getStoreInfo(),
updateLedgerRequest.getAmount(),
updateLedgerRequest.getDescription(),
updateLedgerRequest.getPaymentDate()
);

AgencyUser agencyUser = getAgencyUser(user, ledgerDetail);

validateStaffUserRole(agencyUser.getAgencyUserRole());

updateBalance(ledger);

// 2. ์žฅ๋ถ€ ์ƒ์„ธ ๋‚ด์—ญ ์กฐํšŒ
List<LedgerReceipt> ledgerReceipts = ledgerReceiptReader.getLedgerReceipts(ledgerDetailId);
Expand Down Expand Up @@ -151,13 +148,9 @@ public void removeLedgerDetail(

int newAmount = AmountCalculatorByFundType.calculate(ledgerDetail.getFundType(), ledgerDetail.getAmount());

ledgerDetailRepository.bulkUpdateLedgerDetailBalance(
ledger,
ledgerDetail.getPaymentDate(),
-newAmount
);

ledger.updateTotalBalance(-newAmount);

updateBalance(ledger);
}

private void validateStaffUserRole(AgencyUserRole userRole) {
Expand All @@ -183,4 +176,24 @@ private User getUser(Long userId) {
.findById(userId)
.orElseThrow(() -> new NotFoundException(ErrorCode.USER_NOT_FOUND));
}

private void updateBalance(Ledger ledger) {
List<LedgerDetail> ledgerDetails = ledgerDetailRepository.findAllByLedger(ledger);

ledgerDetails.sort(Comparator.comparing(LedgerDetail::getPaymentDate));

int previousBalance = 0;

for (int i = 0; i < ledgerDetails.size(); i++) {
LedgerDetail detail = ledgerDetails.get(i);

if (detail.getFundType() == INCOME) {
previousBalance += detail.getAmount();
} else {
previousBalance -= detail.getAmount();
}

detail.updateBalance(previousBalance);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import com.moneymong.global.exception.custom.InvalidAccessException;
import com.moneymong.global.exception.custom.NotFoundException;
import com.moneymong.global.exception.enums.ErrorCode;
import com.moneymong.utils.AmountCalculatorByFundType;
import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -100,36 +99,12 @@ public LedgerDetailInfoView updateLedger(
final Long ledgerDetailId,
final UpdateLedgerRequest updateLedgerRequest
) {
// === ์œ ์ € ===
User user = getUser(userId);

// === ์žฅ๋ถ€ ===
LedgerDetail ledgerDetail = getLedgerDetail(ledgerDetailId);

Ledger ledger = ledgerDetail.getLedger();

// === ์†Œ์† ===
AgencyUser agencyUser = getAgencyUser(userId, ledger);

// === ๊ถŒํ•œ ===
validateStaffUserRole(agencyUser.getAgencyUserRole());

ledgerDetailService.createLedgerDetail(
ledger,
user,
updateLedgerRequest.getStoreInfo(),
ledgerDetail.getFundType(),
updateLedgerRequest.getAmount(),
ledger.getTotalBalance(),
updateLedgerRequest.getDescription(),
updateLedgerRequest.getPaymentDate()
);

ledgerDetailService.removeLedgerDetail(userId, ledgerDetailId);

return ledgerDetailService.updateLedgerDetail(
user,
ledger,
ledgerDetail,
updateLedgerRequest
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package com.moneymong.domain.user.api.request;

import jakarta.validation.constraints.NotBlank;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@AllArgsConstructor
@NoArgsConstructor
public class UserDeleteRequest {
@NotBlank
private String provider;

@NotBlank
private String token;
}
Loading
Loading