Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…anner-BE into release
  • Loading branch information
hajungIm committed May 18, 2024
2 parents 6bfc7f6 + a78c79d commit 3bcefb4
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ public Map<LocalDate, Long> findTotalCostDate(String memberId, LocalDate startDa

Map<LocalDate, Long> expenseMap = new HashMap<>();
List<Tuple> tuples = queryFactory
.select(expense.date, expense.cost.sum().as("totalCost"))
.select(expense.date, expense.cost.sum())
.from(expense)
.where(expense.date.between(startDate, endDate), expense.member.id.eq(memberId))
.groupBy(expense.date)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,18 @@
import java.nio.charset.StandardCharsets;
import java.util.stream.Collectors;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;

@Slf4j
public class FeignErrorDecoder implements ErrorDecoder {

@SneakyThrows
@Override
public Exception decode(String methodKey, Response response) {
Reader reader = response.body().asReader(StandardCharsets.UTF_8);
BufferedReader bufferedReader = new BufferedReader(reader);
String errorResult = bufferedReader.lines()
.collect(Collectors.joining(System.lineSeparator())).replace("\\", "");
String errorResult = bufferedReader.lines().collect(Collectors.joining(System.lineSeparator()));

HttpStatus status = HttpStatus.valueOf(response.status());
String url = response.request().url();
Expand Down
8 changes: 0 additions & 8 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,6 @@ server:
charset: UTF-8
enabled: true
force: true
tomcat:
basedir: '/home/ubuntu/logs'
access log:
enabled: true
pattern: "[%{yyyy-MM-dd HH:mm:ss.SSS}t]%{Referer}i(%a) %r -> [%s/%b/%Dms] | \t%{User-Agent}i"
directory: logs
encoding: utf-8
max-days: 60

logging.level:
org.hibernate.SQL: debug
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.umc5th.muffler.domain.expense.repository;

import com.umc5th.muffler.domain.member.repository.MemberRepository;
import com.umc5th.muffler.entity.Category;
import com.umc5th.muffler.entity.Expense;
import com.umc5th.muffler.entity.Member;
import com.umc5th.muffler.fixture.CategoryFixture;
import com.umc5th.muffler.fixture.ExpenseFixture;
import com.umc5th.muffler.fixture.MemberFixture;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

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

import static org.junit.jupiter.api.Assertions.*;

@SpringBootTest
class GetSumByDateTest {
@Autowired private ExpenseRepository expenseRepository;
@Autowired private MemberRepository memberRepository;
@Test
void getSumByDate() {
Member member = MemberFixture.create("test");
Category category = CategoryFixture.create(member);
member.addCategory(category);
member = memberRepository.save(member);

Expense ex1 = ExpenseFixture.create(1L, LocalDate.of(2024, 1, 1), member, category);
Expense ex2 = ExpenseFixture.create(2L, LocalDate.of(2024, 1, 1), member, category);
Expense ex3 = ExpenseFixture.create(3L, LocalDate.of(2024, 1, 1), member, category);
expenseRepository.save(ex1);
expenseRepository.save(ex2);
expenseRepository.save(ex3);

Map<LocalDate, Long> totalCostDate = expenseRepository.findTotalCostDate(member.getId(), LocalDate.of(2024, 1, 1),
LocalDate.of(2024, 1, 1));
assertEquals(1, totalCostDate.size());
assertEquals(300L, totalCostDate.get(LocalDate.of(2024, 1, 1)));
}

}
13 changes: 13 additions & 0 deletions src/test/java/com/umc5th/muffler/fixture/ExpenseFixture.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,19 @@ public static Expense create(LocalDate date) {
.build();
}

public static Expense create(long id, LocalDate date, Member member, Category category) {
return Expense.builder()
.id(id)
.date(date)
.title("title")
.cost(100L)
.memo("memo")
.member(member)
.category(category)
.build();
}


public static List<Expense> createList(int num, LocalDate date){
Member member = Member.builder().id("1").build();
Category category = Category.builder().id(1L).icon("icon").build();
Expand Down

0 comments on commit 3bcefb4

Please sign in to comment.