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

#332 [feat] 메트릭 API 기간 입력 요구사항 반영 #333

Merged
merged 8 commits into from
Sep 1, 2024

Conversation

KWY0218
Copy link
Member

@KWY0218 KWY0218 commented Sep 1, 2024

✒️ 관련 이슈번호

Key Changes 🔑

  1. 내용
    • 메트릭 API 요구사항 수정에 따라서 비즈니스 로직을 수정했습니다.
`/metrics` : 전체 데이터
`/metric?from=2024-08-01` : from 부터 현재까지 , created_at > from
`/metric?to=2024-08-01` :  to 까지 ,  created_at < to
`/metric?from=2024-08-04&to=2024-08-30` from에서 to까지 , from <= created_at <= to

위와 같이 요청해주시면 좋을 것 같습니다.

To Reviewers 📢

  • Querydsl의 DateTimePath을 이용해서 분기처리를 통일했습니다. 만약 from, to가 null이라면 조건문이 자동으로 들어가지 않습니다.
  • 커밋 따라서 작업 내용 보시면 리뷰하시기 편하실 것이라 생각합니다~!

각 쿼리마다 조건문을 분기처리 하는 것은 비효율적이라고 생각했습니다.
그래서 querydsl의 BooleanExpression을 활용하는 방식으로 구현했습니다.

Querydsl의 DateTimePath을 아규먼트로 받아서
분기 처리 로직을 구현했습니다.

만약 null이 들어오면 조건식이 저절로 추가되지 않습니다.
created at이 들어있는 AuditingTimeEntity 가 abstract 클래스이기 때문에
entity manager를 사용하여 save 할 수 없었습니다.

그래서 sql을 이용해서 더미 값을 넣어줬습니다.

테스트 주요 대상은 createdAt 칼럼이기 때문에 나머지 값은 템플릿 화하고,
createdAt 만 beforeEach에서 별도로 넣어줬습니다.
from과 to로 null 값이 들어올 수 있기 때문에 서비스 로직을 일부 수정했습니다.
비즈니스 로직 변경에 따라서 테스트 코드도 수정하여 로직을 검증했습니다.
from과 to에 null이 들어올 수 있기 때문에 이를 반영했습니다.
@KWY0218 KWY0218 self-assigned this Sep 1, 2024
테스트 이후 값이 초기화가 되지 않아서 다른 테스트가 실패했습니다.
따라서 테스트 이후 값을 초기화하기 위해서
인수 테스트에 transactional을 추가했습니다.
Copy link
Member

@sohyundoh sohyundoh left a comment

Choose a reason for hiding this comment

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

고생하셨습니다!

from = null to = null 로 전해질 경우에 현재까지의 DB 모든 값을 반환하는 것 같은데 예상하신게 맞나요??

@KWY0218
Copy link
Member Author

KWY0218 commented Sep 1, 2024

@sohyundoh

넵 맞습니다~!
그래서 /metrics 로 보내면 총 데이터를 반환하려 합니다~!

따라서 from = null , to = null 이렇게 굳이 넣어주지 않고,
입력 받지 않은 부분은 쿼리 파라미터 지정을 안해주시면 됩니다!

@KWY0218 KWY0218 merged commit c972382 into develop Sep 1, 2024
4 checks passed
@KWY0218 KWY0218 deleted the feat/#332 branch September 1, 2024 13:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[feat] 메트릭 기간 입력 수정
2 participants