Skip to content

Commit

Permalink
refactor: 클래스 명 및 패키지 위치 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
waterricecake committed Jul 27, 2023
1 parent 50ce07a commit f144428
Show file tree
Hide file tree
Showing 23 changed files with 123 additions and 143 deletions.
41 changes: 0 additions & 41 deletions backend/src/main/java/hanglog/expense/Currency.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package hanglog.expense;
package hanglog.expense.domain;

import static jakarta.persistence.GenerationType.IDENTITY;
import static lombok.AccessLevel.PROTECTED;
Expand All @@ -16,7 +16,7 @@
@Getter
@AllArgsConstructor
@NoArgsConstructor(access = PROTECTED)
public class Currencies {
public class Currency {

@Id
@GeneratedValue(strategy = IDENTITY)
Expand Down Expand Up @@ -54,8 +54,9 @@ public class Currencies {
@Column(nullable = false)
private Double krw;

public static Currencies ofDefault() {
return new Currencies();
// TODO : 추후 currency 데이터 입력 후 default 값 생성시 삭제
public static Currency ofDefault() {
return new Currency();
}

public double getUnitRateOfJpy() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package hanglog.expense;
package hanglog.expense.domain;

import static jakarta.persistence.FetchType.LAZY;
import static jakarta.persistence.GenerationType.IDENTITY;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package hanglog.expense.domain.repository;

import hanglog.expense.domain.Currency;
import java.time.LocalDate;
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;

public interface CurrencyRepository extends JpaRepository<Currency, Long> {

Optional<Currency> findCurrenciesBySearchDate(final LocalDate searchDate);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package hanglog.expense.repository;
package hanglog.expense.domain.repository;

import hanglog.expense.Expense;
import hanglog.expense.domain.Expense;
import org.springframework.data.jpa.repository.JpaRepository;

public interface ExpenseRepository extends JpaRepository<Expense, Long> {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package hanglog.expense.domain.type;

import static hanglog.global.exception.ExceptionCode.INVALID_CURRENCY;

import hanglog.expense.domain.Currency;
import hanglog.global.exception.InvalidDomainException;
import java.util.Arrays;
import java.util.function.Function;
import lombok.Getter;

@Getter
public enum CurrencyCodeType {

USD("usd", Currency::getUsd),
EUR("eur", Currency::getEur),
GBP("gbp", Currency::getGbp),
JPY("jpy", Currency::getUnitRateOfJpy),
CNY("cny", Currency::getCny),
CHF("chf", Currency::getChf),
SGD("sgd", Currency::getSgd),
THB("thb", Currency::getThb),
HKD("hkd", Currency::getHkd),
KRW("krw", Currency::getKrw);

private final String code;
private final Function<Currency, Double> getRate;

CurrencyCodeType(final String code, final Function<Currency, Double> getRate) {
this.code = code;
this.getRate = getRate;
}

public static double mappingCurrency(final String currency, final Currency currencies) {
return Arrays.stream(values())
.filter(value -> value.code.equals(currency.toLowerCase()))
.findAny().orElseThrow(() -> new InvalidDomainException(INVALID_CURRENCY))
.getRate.apply(currencies);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,27 @@


import hanglog.category.domain.Category;
import hanglog.category.dto.CategoryResponse;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.ToString;

@Getter
@RequiredArgsConstructor
@ToString
public class CategoriesInExpenseResponse {

private final CategoryInExpenseResponse category;
private final CategoryResponse category;
private final int amount;
private final BigDecimal percentage;

public static List<CategoriesInExpenseResponse> of(final Map<Category, Integer> categories) {
final int totalAmount = categories.values().stream().reduce(Integer::sum).orElse(0);
final int totalAmount = categories.values().stream()
.reduce(Integer::sum)
.orElse(0);
if (totalAmount == 0) {
return categories.entrySet().stream()
.map(entry -> getResponse(0, entry))
Expand All @@ -37,7 +38,7 @@ private static CategoriesInExpenseResponse getResponse(
final Entry<Category, Integer> entry
) {
return new CategoriesInExpenseResponse(
CategoryInExpenseResponse.of(entry.getKey()),
CategoryResponse.of(entry.getKey()),
entry.getValue(),
BigDecimal.valueOf(amount * 100).setScale(2, RoundingMode.CEILING)//.setScale(2)
);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@

@Getter
@RequiredArgsConstructor
public class CitiesInExpenseResponse {
public class CityInExpenseResponse {

private final long id;
private final String name;

public static List<CitiesInExpenseResponse> of(final List<TripCity> cities) {
public static List<CityInExpenseResponse> of(final List<TripCity> cities) {
return cities.stream().map(city ->
new CitiesInExpenseResponse(
new CityInExpenseResponse(
city.getCity().getId(),
city.getCity().getName()
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package hanglog.expense.dto.response;

import hanglog.expense.Currencies;
import hanglog.expense.Currency;
import hanglog.expense.domain.Currency;
import hanglog.expense.domain.type.CurrencyCodeType;
import java.util.Arrays;
import java.util.List;
import lombok.Getter;
Expand All @@ -14,9 +14,9 @@ public class CurrencyInExpenseResponse {
private final String currency;
private final double rate;

public static List<CurrencyInExpenseResponse> of(final Currencies currencies) {
return Arrays.stream(Currency.values())
.map(value -> new CurrencyInExpenseResponse(value.getCurrency(), value.getGetRate().apply(currencies)))
public static List<CurrencyInExpenseResponse> of(final Currency currency) {
return Arrays.stream(CurrencyCodeType.values())
.map(value -> new CurrencyInExpenseResponse(value.getCode(), value.getGetRate().apply(currency)))
.toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


import hanglog.category.domain.Category;
import hanglog.expense.Currencies;
import hanglog.expense.domain.Currency;
import hanglog.trip.domain.DayLog;
import hanglog.trip.domain.Trip;
import hanglog.trip.domain.TripCity;
Expand All @@ -20,7 +20,7 @@ public class ExpenseGetResponse {
private final String title;
private final LocalDate startDate;
private final LocalDate endDate;
private final List<CitiesInExpenseResponse> cities;
private final List<CityInExpenseResponse> cities;
private final int totalAmount;
private final List<CategoriesInExpenseResponse> categories;
private final RatesInExpenseResponse rates;
Expand All @@ -31,18 +31,18 @@ public static ExpenseGetResponse of(
final int totalAmount,
final List<TripCity> cities,
final Map<Category, Integer> categories,
final Currencies currencies,
final Currency currency,
final Map<DayLog, Integer> dayLogs
) {
return new ExpenseGetResponse(
trip.getId(),
trip.getTitle(),
trip.getStartDate(),
trip.getEndDate(),
CitiesInExpenseResponse.of(cities),
CityInExpenseResponse.of(cities),
totalAmount,
CategoriesInExpenseResponse.of(categories),
RatesInExpenseResponse.of(currencies),
RatesInExpenseResponse.of(currency),
DayLogInExpenseResponse.of(dayLogs)
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package hanglog.expense.dto.response;

import hanglog.expense.Expense;
import hanglog.category.dto.CategoryResponse;
import hanglog.expense.domain.Expense;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

Expand All @@ -11,14 +12,14 @@ public class ExpenseInItemResponse {
private final long id;
private final String currency;
private final double amount;
private final CategoryInExpenseResponse category;
private final CategoryResponse category;

public static ExpenseInItemResponse of(final Expense expense) {
return new ExpenseInItemResponse(
expense.getId(),
expense.getCurrency(),
expense.getAmount(),
CategoryInExpenseResponse.of(expense.getCategory())
CategoryResponse.of(expense.getCategory())
);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package hanglog.expense.dto.response;

import hanglog.expense.Currencies;
import hanglog.expense.domain.Currency;
import java.time.LocalDate;
import java.util.List;
import lombok.Getter;
Expand All @@ -13,10 +13,10 @@ public class RatesInExpenseResponse {
private final LocalDate date;
private final List<CurrencyInExpenseResponse> values;

public static RatesInExpenseResponse of(final Currencies currencies) {
public static RatesInExpenseResponse of(final Currency currency) {
return new RatesInExpenseResponse(
currencies.getSearchDate(),
CurrencyInExpenseResponse.of(currencies)
currency.getSearchDate(),
CurrencyInExpenseResponse.of(currency)
);
}
}

This file was deleted.

Loading

0 comments on commit f144428

Please sign in to comment.