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

[chore] main과 dev 브랜치 맞추기 #170

Merged
merged 4 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -96,21 +96,21 @@ List<AvgConsumptionGoalDto> findAvgGoalAmountByCategory(
List<MyConsumptionGoalDto> findAllGoalAmountByUserId(@Param("userId") Long userId);

@Query("SELECT new com.bbteam.budgetbuddies.domain.consumptiongoal.dto.CategoryConsumptionCountDto(" +
"e.category.id, COUNT(e)) " +
"FROM Expense e " +
"WHERE e.category.isDefault = true " +
"AND e.deleted = false " +
"AND e.user.age BETWEEN :peerAgeStart AND :peerAgeEnd " +
"AND e.user.gender = :peerGender " +
"AND e.expenseDate >= :currentMonth " +
"AND e.amount > 0 " +
"GROUP BY e.category.id " +
"ORDER BY COUNT(e) DESC")
"cg.category.id, COUNT(cg)) " +
"FROM ConsumptionGoal cg " +
"WHERE cg.category.isDefault = true " +
"AND cg.deleted = false " +
"AND cg.user.age BETWEEN :peerAgeStart AND :peerAgeEnd " +
"AND cg.user.gender = :peerGender " +
"AND cg.goalMonth >= :currentMonth " +
"AND cg.consumeAmount > 0 " +
"GROUP BY cg.category.id " +
"ORDER BY COUNT(cg) DESC")
List<CategoryConsumptionCountDto> findTopCategoriesByConsumptionCount(
@Param("peerAgeStart") int peerAgeStart,
@Param("peerAgeEnd") int peerAgeEnd,
@Param("peerGender") Gender peerGender,
@Param("currentMonth") LocalDateTime currentMonth);
@Param("currentMonth") LocalDate currentMonth);

@Modifying
@Query("UPDATE ConsumptionGoal cg SET cg.deleted = TRUE WHERE cg.category.id = :categoryId AND cg.user.id = :userId")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public List<TopCategoryConsumptionDto> getTopConsumptionCategories(Long userId,
checkPeerInfo(userId, peerAgeS, peerAgeE, peerG);

List<CategoryConsumptionCountDto> categoryConsumptionCountDto = consumptionGoalRepository
.findTopCategoriesByConsumptionCount(peerAgeStart, peerAgeEnd, peerGender, currentMonth.atStartOfDay());
.findTopCategoriesByConsumptionCount(peerAgeStart, peerAgeEnd, peerGender, currentMonth);

return categoryConsumptionCountDto.stream()
.limit(3)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import static org.assertj.core.api.Assertions.*;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

import org.junit.jupiter.api.BeforeEach;
Expand All @@ -19,8 +18,6 @@
import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.CategoryConsumptionCountDto;
import com.bbteam.budgetbuddies.domain.consumptiongoal.dto.MyConsumptionGoalDto;
import com.bbteam.budgetbuddies.domain.consumptiongoal.entity.ConsumptionGoal;
import com.bbteam.budgetbuddies.domain.expense.entity.Expense;
import com.bbteam.budgetbuddies.domain.expense.repository.ExpenseRepository;
import com.bbteam.budgetbuddies.domain.user.entity.User;
import com.bbteam.budgetbuddies.domain.user.repository.UserRepository;
import com.bbteam.budgetbuddies.enums.Gender;
Expand All @@ -35,15 +32,12 @@ class ConsumptionGoalRepositoryTest {
UserRepository userRepository;
@Autowired
CategoryRepository categoryRepository;
@Autowired
ExpenseRepository expenseRepository;

private User peerUser1;
private User peerUser2;
private Category defaultCategory1;
private Category defaultCategory2;
private LocalDate currentMonth;
private LocalDateTime now = LocalDateTime.now();

@BeforeEach
void setUp() {
Expand Down Expand Up @@ -99,30 +93,6 @@ void setUp() {
.category(defaultCategory2)
.goalMonth(currentMonth)
.build());

expenseRepository.save(
Expense.builder()
.amount(1L)
.category(defaultCategory1)
.user(peerUser1)
.expenseDate(now)
.build());

expenseRepository.save(
Expense.builder()
.amount(1L)
.category(defaultCategory1)
.user(peerUser1)
.expenseDate(now)
.build());

expenseRepository.save(
Expense.builder()
.amount(1L)
.category(defaultCategory2)
.user(peerUser1)
.expenseDate(now)
.build());
}

@Test
Expand Down Expand Up @@ -302,7 +272,7 @@ void findTopCategoriesByConsumptionCount_Success() {
LocalDate currentMonth = LocalDate.now();

List<CategoryConsumptionCountDto> result = consumptionGoalRepository.findTopCategoriesByConsumptionCount(
peerAgeStart, peerAgeEnd, peerGender, currentMonth.atStartOfDay());
peerAgeStart, peerAgeEnd, peerGender, currentMonth);

// then
assertThat(result).isNotEmpty();
Expand All @@ -317,7 +287,7 @@ void findTopCategoriesByConsumptionCount_Success() {
.findFirst()
.orElseThrow(() -> new AssertionError("Category ID " + defaultCategory2.getId() + " not found"));

assertThat(firstResult.getConsumptionCount()).isEqualTo(2);
assertThat(secondResult.getConsumptionCount()).isEqualTo(1);
assertThat(firstResult.getConsumptionCount()).isEqualTo(1);
assertThat(secondResult.getConsumptionCount()).isEqualTo(2);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ void getTopConsumptionCategories_Success() {

given(userRepository.findById(user.getId())).willReturn(Optional.of(user));
given(consumptionGoalRepository.findTopCategoriesByConsumptionCount(peerAgeStart, peerAgeEnd,
Gender.valueOf(peerGender), currentMonth.atStartOfDay()))
Gender.valueOf(peerGender), currentMonth))
.willReturn(List.of(topConsumption1, topConsumption2, topConsumption3));

given(categoryRepository.findById(defaultCategory1.getId())).willReturn(Optional.of(defaultCategory1));
Expand Down
Loading