Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.genesis.unipocket.accountbook.command.application.command.DeleteAccountBookCommand;
import com.genesis.unipocket.accountbook.command.application.command.UpdateAccountBookCommand;
import com.genesis.unipocket.accountbook.command.application.result.AccountBookBudgetUpdateResult;
import com.genesis.unipocket.accountbook.command.facade.port.AccountBookDefaultWidgetPort;
import com.genesis.unipocket.accountbook.command.presentation.request.AccountBookBudgetUpdateRequest;
import com.genesis.unipocket.accountbook.command.presentation.request.AccountBookCreateRequest;
import com.genesis.unipocket.accountbook.command.presentation.request.AccountBookUpdateRequest;
Expand All @@ -21,6 +22,7 @@ public class AccountBookCommandFacade {

private final AccountBookCommandService accountBookCommandService;
private final UserQueryService userQueryService;
private final AccountBookDefaultWidgetPort accountBookDefaultWidgetPort;

@Transactional
public Long createAccountBook(UUID userId, AccountBookCreateRequest req) {
Expand All @@ -29,7 +31,9 @@ public Long createAccountBook(UUID userId, AccountBookCreateRequest req) {
CreateAccountBookCommand command =
CreateAccountBookCommand.of(userId, userResponse.name(), req);

return accountBookCommandService.create(command);
Long accountBookId = accountBookCommandService.create(command);
accountBookDefaultWidgetPort.setDefaultWidget(accountBookId);
return accountBookId;
}

@Transactional
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.genesis.unipocket.accountbook.command.facade.port;

public interface AccountBookDefaultWidgetPort {
public void setDefaultWidget(Long accountBookId);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

인터페이스의 메서드에 public 접근 제어자는 불필요합니다. Java 인터페이스의 모든 메서드는 기본적으로 public이므로 명시적으로 선언할 필요가 없습니다. 코드를 간결하게 유지하기 위해 제거하는 것이 좋습니다.

Suggested change
public void setDefaultWidget(Long accountBookId);
void setDefaultWidget(Long accountBookId);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.genesis.unipocket.widget.command.facade.provide;

import com.genesis.unipocket.accountbook.command.facade.port.AccountBookDefaultWidgetPort;
import com.genesis.unipocket.global.common.enums.WidgetType;
import com.genesis.unipocket.widget.command.application.WidgetCommandService;
import com.genesis.unipocket.widget.command.application.command.UpdateAccountBookWidgetsCommand;
import com.genesis.unipocket.widget.common.WidgetItem;
import com.genesis.unipocket.widget.common.enums.CurrencyType;
import com.genesis.unipocket.widget.common.enums.Period;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

@Component
@RequiredArgsConstructor
public class AccountBookDefaultWidgetSetter implements AccountBookDefaultWidgetPort {

private final WidgetCommandService widgetCommandService;

@Override
public void setDefaultWidget(Long accountBookId) {
List<WidgetItem> items =
List.of(
new WidgetItem(0, WidgetType.BUDGET, CurrencyType.BASE, Period.MONTHLY),
new WidgetItem(1, WidgetType.PERIOD, CurrencyType.BASE, Period.MONTHLY),
new WidgetItem(2, WidgetType.CATEGORY, CurrencyType.BASE, Period.MONTHLY));

widgetCommandService.updateAccountBookWidgets(
new UpdateAccountBookWidgetsCommand(accountBookId, items));
}
}
Comment on lines +16 to +31

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

기본 위젯 목록이 setDefaultWidget 메서드 내에서 매번 생성되고 있습니다. 이 목록은 불변이므로 private static final 상수로 추출하여 클래스 수준에서 관리하는 것이 더 효율적이고 가독성이 좋습니다. 이렇게 하면 기본 위젯 구성이 명확해지고, 향후 수정이 필요할 때 한 곳에서 관리할 수 있습니다.

Suggested change
public class AccountBookDefaultWidgetSetter implements AccountBookDefaultWidgetPort {
private final WidgetCommandService widgetCommandService;
@Override
public void setDefaultWidget(Long accountBookId) {
List<WidgetItem> items =
List.of(
new WidgetItem(0, WidgetType.BUDGET, CurrencyType.BASE, Period.MONTHLY),
new WidgetItem(1, WidgetType.PERIOD, CurrencyType.BASE, Period.MONTHLY),
new WidgetItem(2, WidgetType.CATEGORY, CurrencyType.BASE, Period.MONTHLY));
widgetCommandService.updateAccountBookWidgets(
new UpdateAccountBookWidgetsCommand(accountBookId, items));
}
}
public class AccountBookDefaultWidgetSetter implements AccountBookDefaultWidgetPort {
private final WidgetCommandService widgetCommandService;
private static final List<WidgetItem> DEFAULT_WIDGETS =
List.of(
new WidgetItem(0, WidgetType.BUDGET, CurrencyType.BASE, Period.MONTHLY),
new WidgetItem(1, WidgetType.PERIOD, CurrencyType.BASE, Period.MONTHLY),
new WidgetItem(2, WidgetType.CATEGORY, CurrencyType.BASE, Period.MONTHLY));
@Override
public void setDefaultWidget(Long accountBookId) {
widgetCommandService.updateAccountBookWidgets(
new UpdateAccountBookWidgetsCommand(accountBookId, DEFAULT_WIDGETS));
}
}