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

채팅 메시지 조회 API 추가 #272

Merged
merged 172 commits into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
172 commits
Select commit Hold shift + click to select a range
9187ffb
fix: 브랜치 최신화
swonny Aug 8, 2023
d9c01db
style: 메소드 체이닝 개행 추가
swonny Jul 30, 2023
ecfcb1d
style: 필드 사이 개행 추가
swonny Aug 1, 2023
bfcd17b
fix: 브랜치 최신화
swonny Aug 10, 2023
ed7d6db
feat: 특정 아이디 이후에 추가된 메시지 조회 기능 추가
swonny Aug 8, 2023
21cfeb8
test: 실패하는 테스트 수정
swonny Aug 8, 2023
fd5ea44
refactor: 엔티티 조회 로직 메서드 분리
swonny Aug 8, 2023
7077413
refactor: null 아이디 검사 분기문 메서드 분리
swonny Aug 8, 2023
3c04a27
style: 메서드 체이닝 개행 추가
swonny Aug 8, 2023
f91b2e2
style: 불필요한 주석 제거
swonny Aug 8, 2023
9b7e31b
fix: 브랜치 최신화
swonny Aug 8, 2023
89b433b
style: 불필요한 주석 제거
swonny Aug 8, 2023
023ebe5
style: 메소드 체이닝 개행 추가
swonny Jul 30, 2023
648c1fb
style: 필드 사이 개행 추가
swonny Aug 1, 2023
d64d9ca
feat: 특정 아이디 이후에 추가된 메시지 조회 기능 추가
swonny Aug 8, 2023
1bf2c06
feat: 메시지 조회 기능 추가
swonny Aug 8, 2023
aa30943
feat: 메시지 조회 API 추가
swonny Aug 8, 2023
bdef09b
style: 테스트 주석 추가
swonny Aug 8, 2023
54e90cb
test: 실패하는 테스트 수정
swonny Aug 8, 2023
fbe196e
test: 메시지 조회 시 잘못된 사용자에 대한 예외 테스트 추가
swonny Aug 8, 2023
255835b
refactor: 엔티티 조회 로직 메서드 분리
swonny Aug 8, 2023
117132b
refactor: null 아이디 검사 분기문 메서드 분리
swonny Aug 8, 2023
32f7e42
style: 메서드 체이닝 개행 추가
swonny Aug 8, 2023
b1fff68
fix: API 명세에 맞춰 API 수정
swonny Aug 8, 2023
e072b9e
feat: 채팅 가능한 시간이 초과한 경우 예외 처리 추가
swonny Aug 8, 2023
f9cc294
fix: 패키지 이동 반영 안되는 오류 수정
swonny Aug 8, 2023
7f8369a
!hotfix: 버그 리포팅을 위한 이슈 템플릿 추가
apptie Aug 7, 2023
8757402
!hotfix: 버그 리포팅용 이슈 템플릿의 설명을 조금 더 명확하게 변경
apptie Aug 7, 2023
3ae35b0
!hotfix: 개발 도중 버그가 발생했을 때의 이슈 템플릿의 설명을 명확하게 변경
apptie Aug 7, 2023
440d9f3
feat: 특정 아이디 이후에 추가된 메시지 조회 기능 추가
swonny Aug 8, 2023
249edca
feat: 메시지 조회 API 추가
swonny Aug 8, 2023
236c438
style: 테스트 주석 추가
swonny Aug 8, 2023
d85b198
test: 실패하는 테스트 수정
swonny Aug 8, 2023
3b0c9ed
test: 메시지 조회 시 잘못된 사용자에 대한 예외 테스트 추가
swonny Aug 8, 2023
d687e6d
refactor: 엔티티 조회 로직 메서드 분리
swonny Aug 8, 2023
3f4ccca
refactor: null 아이디 검사 분기문 메서드 분리
swonny Aug 8, 2023
8258f17
style: 불필요한 주석 제거
swonny Aug 8, 2023
56fb7c2
feat: 특정 아이디 이후에 추가된 메시지 조회 기능 추가
swonny Aug 8, 2023
1b1cf5c
feat: 메시지 조회 API 추가
swonny Aug 8, 2023
e7eb645
style: 테스트 주석 추가
swonny Aug 8, 2023
7b6b1e8
test: 실패하는 테스트 수정
swonny Aug 8, 2023
8d7b0f3
test: 메시지 조회 시 잘못된 사용자에 대한 예외 테스트 추가
swonny Aug 8, 2023
310c8d7
refactor: 엔티티 조회 로직 메서드 분리
swonny Aug 8, 2023
d27a3c7
refactor: null 아이디 검사 분기문 메서드 분리
swonny Aug 8, 2023
ac72ac4
style: 메서드 체이닝 개행 추가
swonny Aug 8, 2023
3aeaa25
style: 개행 추가
swonny Aug 9, 2023
b06204d
refactor: 수신자가 메시지를 조회할 수 있도록 변경
swonny Aug 10, 2023
0636dd9
refactor: find 메서드 대신 repository 직접 조회하도록 변경
swonny Aug 10, 2023
9912a40
refactor: 불변 리스트 반환하도록 수정
swonny Aug 10, 2023
e1f1466
채팅방 신고 등록 및 조회 api 추가 (#262)
JJ503 Aug 10, 2023
22c3410
feat: 특정 아이디 이후에 추가된 메시지 조회 기능 추가
swonny Aug 8, 2023
fd1e38a
feat: 메시지 조회 API 추가
swonny Aug 8, 2023
49c81c0
style: 테스트 주석 추가
swonny Aug 8, 2023
df36658
test: 실패하는 테스트 수정
swonny Aug 8, 2023
ec8765b
test: 메시지 조회 시 잘못된 사용자에 대한 예외 테스트 추가
swonny Aug 8, 2023
6301f30
refactor: 엔티티 조회 로직 메서드 분리
swonny Aug 8, 2023
fd163b3
refactor: null 아이디 검사 분기문 메서드 분리
swonny Aug 8, 2023
c71ba70
style: 메서드 체이닝 개행 추가
swonny Aug 8, 2023
3d23190
feat: 특정 아이디 이후에 추가된 메시지 조회 기능 추가
swonny Aug 8, 2023
3d33105
feat: 메시지 조회 API 추가
swonny Aug 8, 2023
1871ebf
style: 테스트 주석 추가
swonny Aug 8, 2023
4f1a8ca
test: 실패하는 테스트 수정
swonny Aug 8, 2023
2148ef9
test: 메시지 조회 시 잘못된 사용자에 대한 예외 테스트 추가
swonny Aug 8, 2023
4ff2eb3
refactor: 엔티티 조회 로직 메서드 분리
swonny Aug 8, 2023
530c868
feat: 특정 아이디 이후에 추가된 메시지 조회 기능 추가
swonny Aug 8, 2023
7f22501
feat: 메시지 조회 API 추가
swonny Aug 8, 2023
19507ee
style: 테스트 주석 추가
swonny Aug 8, 2023
f1e4e75
test: 실패하는 테스트 수정
swonny Aug 8, 2023
5945b32
test: 메시지 조회 시 잘못된 사용자에 대한 예외 테스트 추가
swonny Aug 8, 2023
cf3ef98
refactor: 엔티티 조회 로직 메서드 분리
swonny Aug 8, 2023
d38de09
refactor: null 아이디 검사 분기문 메서드 분리
swonny Aug 8, 2023
99efba8
feat: 특정 아이디 이후에 추가된 메시지 조회 기능 추가
swonny Aug 8, 2023
df8415d
feat: 메시지 조회 API 추가
swonny Aug 8, 2023
9fb541c
style: 테스트 주석 추가
swonny Aug 8, 2023
d531de4
test: 실패하는 테스트 수정
swonny Aug 8, 2023
d8cb38f
test: 메시지 조회 시 잘못된 사용자에 대한 예외 테스트 추가
swonny Aug 8, 2023
e68d19e
refactor: 엔티티 조회 로직 메서드 분리
swonny Aug 8, 2023
8058997
refactor: null 아이디 검사 분기문 메서드 분리
swonny Aug 8, 2023
3115fa1
style: 메서드 체이닝 개행 추가
swonny Aug 8, 2023
f1858d4
feat: 특정 아이디 이후에 추가된 메시지 조회 기능 추가
swonny Aug 8, 2023
369cec0
feat: 메시지 조회 API 추가
swonny Aug 8, 2023
a5432de
style: 테스트 주석 추가
swonny Aug 8, 2023
8a3b8d2
test: 실패하는 테스트 수정
swonny Aug 8, 2023
dd22324
test: 메시지 조회 시 잘못된 사용자에 대한 예외 테스트 추가
swonny Aug 8, 2023
6b8cf91
refactor: 엔티티 조회 로직 메서드 분리
swonny Aug 8, 2023
319979c
feat: 특정 아이디 이후에 추가된 메시지 조회 기능 추가
swonny Aug 8, 2023
55c1b9d
feat: 메시지 조회 API 추가
swonny Aug 8, 2023
15a742e
style: 테스트 주석 추가
swonny Aug 8, 2023
a874d8a
test: 실패하는 테스트 수정
swonny Aug 8, 2023
5bbae9c
test: 메시지 조회 시 잘못된 사용자에 대한 예외 테스트 추가
swonny Aug 8, 2023
ac81988
refactor: 엔티티 조회 로직 메서드 분리
swonny Aug 8, 2023
fa1be6c
refactor: null 아이디 검사 분기문 메서드 분리
swonny Aug 8, 2023
2f379c8
refactor: lastMessageId 계산 로직 삭제
swonny Aug 10, 2023
af7e50a
style: 잘못된 개행 수정
swonny Aug 10, 2023
f606c4d
style: 잘못된 개행 수정
swonny Aug 10, 2023
59956f5
feat: #258 로그아웃 api 추가 (#269)
apptie Aug 11, 2023
3058280
feat: 특정 아이디 이후에 추가된 메시지 조회 기능 추가
swonny Aug 8, 2023
944d0b5
feat: 메시지 조회 API 추가
swonny Aug 8, 2023
3b7bed4
style: 테스트 주석 추가
swonny Aug 8, 2023
cac9773
test: 실패하는 테스트 수정
swonny Aug 8, 2023
f44c2bc
test: 메시지 조회 시 잘못된 사용자에 대한 예외 테스트 추가
swonny Aug 8, 2023
d737a6e
refactor: 엔티티 조회 로직 메서드 분리
swonny Aug 8, 2023
cf509d6
refactor: null 아이디 검사 분기문 메서드 분리
swonny Aug 8, 2023
3cff8c9
style: 메서드 체이닝 개행 추가
swonny Aug 8, 2023
f50858d
feat: 특정 아이디 이후에 추가된 메시지 조회 기능 추가
swonny Aug 8, 2023
dc65fa5
feat: 메시지 조회 API 추가
swonny Aug 8, 2023
06c85f1
style: 테스트 주석 추가
swonny Aug 8, 2023
1366b62
test: 실패하는 테스트 수정
swonny Aug 8, 2023
4d20431
test: 메시지 조회 시 잘못된 사용자에 대한 예외 테스트 추가
swonny Aug 8, 2023
668d011
feat: 특정 아이디 이후에 추가된 메시지 조회 기능 추가
swonny Aug 8, 2023
9941c1a
feat: 메시지 조회 API 추가
swonny Aug 8, 2023
b8beea5
style: 테스트 주석 추가
swonny Aug 8, 2023
64b8b7e
test: 실패하는 테스트 수정
swonny Aug 8, 2023
1fa03e9
test: 메시지 조회 시 잘못된 사용자에 대한 예외 테스트 추가
swonny Aug 8, 2023
dce28aa
refactor: 엔티티 조회 로직 메서드 분리
swonny Aug 8, 2023
0ca92f1
refactor: null 아이디 검사 분기문 메서드 분리
swonny Aug 8, 2023
26d7029
feat: 특정 아이디 이후에 추가된 메시지 조회 기능 추가
swonny Aug 8, 2023
2d37787
feat: 메시지 조회 API 추가
swonny Aug 8, 2023
7a2d1d1
style: 테스트 주석 추가
swonny Aug 8, 2023
4e5fb7e
test: 실패하는 테스트 수정
swonny Aug 8, 2023
81c3cab
test: 메시지 조회 시 잘못된 사용자에 대한 예외 테스트 추가
swonny Aug 8, 2023
1b1ae70
refactor: 엔티티 조회 로직 메서드 분리
swonny Aug 8, 2023
a8a923b
refactor: null 아이디 검사 분기문 메서드 분리
swonny Aug 8, 2023
42aaef2
style: 메서드 체이닝 개행 추가
swonny Aug 8, 2023
9472926
feat: 특정 아이디 이후에 추가된 메시지 조회 기능 추가
swonny Aug 8, 2023
18df500
feat: 메시지 조회 API 추가
swonny Aug 8, 2023
2a087ac
style: 테스트 주석 추가
swonny Aug 8, 2023
5c87067
test: 실패하는 테스트 수정
swonny Aug 8, 2023
7001371
test: 메시지 조회 시 잘못된 사용자에 대한 예외 테스트 추가
swonny Aug 8, 2023
9ec5222
refactor: 엔티티 조회 로직 메서드 분리
swonny Aug 8, 2023
76d0cf9
feat: 특정 아이디 이후에 추가된 메시지 조회 기능 추가
swonny Aug 8, 2023
27251b6
feat: 메시지 조회 API 추가
swonny Aug 8, 2023
b8c0224
style: 테스트 주석 추가
swonny Aug 8, 2023
fec656c
test: 실패하는 테스트 수정
swonny Aug 8, 2023
19b5a49
test: 메시지 조회 시 잘못된 사용자에 대한 예외 테스트 추가
swonny Aug 8, 2023
e97a9ac
refactor: 엔티티 조회 로직 메서드 분리
swonny Aug 8, 2023
47c6015
refactor: null 아이디 검사 분기문 메서드 분리
swonny Aug 8, 2023
678e304
feat: 특정 아이디 이후에 추가된 메시지 조회 기능 추가
swonny Aug 8, 2023
5fef183
feat: 메시지 조회 API 추가
swonny Aug 8, 2023
b77d573
style: 테스트 주석 추가
swonny Aug 8, 2023
7b7304b
test: 실패하는 테스트 수정
swonny Aug 8, 2023
32cf54e
test: 메시지 조회 시 잘못된 사용자에 대한 예외 테스트 추가
swonny Aug 8, 2023
4ed81b1
refactor: 엔티티 조회 로직 메서드 분리
swonny Aug 8, 2023
08025bc
refactor: null 아이디 검사 분기문 메서드 분리
swonny Aug 8, 2023
a660d55
style: 메서드 체이닝 개행 추가
swonny Aug 8, 2023
6db8d16
feat: 특정 아이디 이후에 추가된 메시지 조회 기능 추가
swonny Aug 8, 2023
0bfdd6d
feat: 메시지 조회 API 추가
swonny Aug 8, 2023
06476aa
style: 테스트 주석 추가
swonny Aug 8, 2023
a6413c3
test: 실패하는 테스트 수정
swonny Aug 8, 2023
39744b0
test: 메시지 조회 시 잘못된 사용자에 대한 예외 테스트 추가
swonny Aug 8, 2023
5368aea
refactor: 엔티티 조회 로직 메서드 분리
swonny Aug 8, 2023
f594b18
feat: 특정 아이디 이후에 추가된 메시지 조회 기능 추가
swonny Aug 8, 2023
2edba97
feat: 메시지 조회 API 추가
swonny Aug 8, 2023
768b46c
style: 테스트 주석 추가
swonny Aug 8, 2023
85c9e87
test: 실패하는 테스트 수정
swonny Aug 8, 2023
7b9a1a9
test: 메시지 조회 시 잘못된 사용자에 대한 예외 테스트 추가
swonny Aug 8, 2023
13b7454
refactor: 엔티티 조회 로직 메서드 분리
swonny Aug 8, 2023
6d5312e
refactor: null 아이디 검사 분기문 메서드 분리
swonny Aug 8, 2023
4592bfc
test: lastMessageId null인 경우 빈 배열이 담겨서 전달되는지 확인하는 코드 추가
swonny Aug 10, 2023
504ab81
test: 적절한 변수를 사용하도록 수정
swonny Aug 10, 2023
7e22e01
fix: API 명세에 맞춰 예외 처리 추가
swonny Aug 10, 2023
6a1881c
fix: API 명세에 맞춰 응답값 변경
swonny Aug 10, 2023
8429598
refactor: 메서드 분리
swonny Aug 10, 2023
3275dc7
refactor: 빌더 삭제
swonny Aug 11, 2023
fbef2ec
refactor: 메서드 분리 제거
swonny Aug 11, 2023
49445aa
refactor: 메서드명 수정
swonny Aug 11, 2023
300785d
refactor: 메시지 조회 시 chatRoom fetch join하도록 수정
swonny Aug 11, 2023
098c20c
style: 잘못된 개행 수정
swonny Aug 11, 2023
b6c89e5
refactor: 인증/인가 연동
swonny Aug 11, 2023
37eda5b
refactor: 인증/인가 연동
swonny Aug 11, 2023
914d927
test: 불필요한 주석 제거
swonny Aug 11, 2023
3869b4e
style: 개행 변경
swonny Aug 11, 2023
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
47 changes: 47 additions & 0 deletions .github/ISSUE_TEMPLATE/bug-report.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: "\U0001F41E Bug Report"
Copy link
Member

Choose a reason for hiding this comment

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

버그 리포트가 왜 들어갔을까요??

Copy link
Collaborator

Choose a reason for hiding this comment

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

충돌 해결 과정 중 main 브랜치쪽에서 새로운 브랜치를 만드는 방식으로 작업을 해주셔서 그런게 아닐까 추측..?해봅니다

Copy link
Member

Choose a reason for hiding this comment

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

😭

description: "버그를 제보하고 싶으신가요?"
labels: "\U0001F41E Bug"
body:
- type: textarea
attributes:
label: 🐞 설명
description: 버그에 대한 설명을 작성해 주세요.
placeholder: 자세히 적을수록 좋습니다!
validations:
required: false
- type: textarea
attributes:
label: 📄 기대한 동작
description: 기대한 동작에 대해 작성해주세요.
placeholder: 자세히 적을수록 좋습니다!
validations:
required: false
- type: textarea
attributes:
label: 📄 실제 동작
description: 실제로 동작한 내용에 대해 작성해주세요.
placeholder: 자세히 적을수록 좋습니다!
validations:
required: false
- type: textarea
attributes:
label: 🙋🏻 재현 방법
description: 버그를 재현할 수 있는 방법을 알고 계신다면 작성해주세요.
placeholder: 자세히 적을수록 좋습니다!
validations:
required: false
- type: textarea
attributes:
label: 🌏 버그 발생 환경
description: 버그가 발생한 환경에 대해 작성해 주세요.
placeholder: |
OS: macOS
validations:
required: false
- type: textarea
attributes:
label: 📄 비고
description: 추가적인 정보를 입력해주세요.
placeholder: 단순히 느낀 점, 하고 싶으신 말씀 등 아무 내용이나 상관 없습니다!
validations:
required: false
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: "\U0001F41E Bug"
description: "버그가 발생했나요?"
description: "개발 도중 버그가 발생했나요?"
labels: "\U0001F41E Bug"
body:
- type: textarea
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,6 @@ public void deleteByAuctionId(final Long auctionId, final Long userId) {

private User findUser(final Long userId) {
return userRepository.findById(userId)
.orElseThrow(() -> new UserNotFoundException("회원 정보를 찾을 수 없습니다."));
.orElseThrow(() -> new UserNotFoundException("회원 정보를 찾을 수 없습니다."));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
import com.ddang.ddang.authentication.configuration.AuthenticateUser;
import com.ddang.ddang.authentication.domain.dto.AuthenticationUserInfo;
import jakarta.validation.Valid;
import java.net.URI;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
Expand All @@ -27,6 +25,9 @@
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.support.ServletUriComponentsBuilder;

import java.net.URI;
import java.util.List;

@RestController
@RequestMapping("/auctions")
@RequiredArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.ddang.ddang.authentication.application;

import com.ddang.ddang.authentication.domain.BlackListToken;
import com.ddang.ddang.authentication.domain.TokenDecoder;
import com.ddang.ddang.authentication.domain.TokenType;
import com.ddang.ddang.authentication.domain.exception.EmptyTokenException;
import com.ddang.ddang.authentication.infrastructure.persistence.JpaBlackListTokenRepository;
import java.util.ArrayList;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class BlackListTokenService {

private final JpaBlackListTokenRepository blackListTokenRepository;
private final TokenDecoder tokenDecoder;

@Transactional
public void registerBlackListToken(final String accessToken, final String refreshToken) {
validateEmptyToken(accessToken, refreshToken);

final List<BlackListToken> blackListTokens = new ArrayList<>();

if (isValidToken(TokenType.ACCESS, accessToken)) {
blackListTokens.add(new BlackListToken(TokenType.ACCESS, accessToken));
}
if (isValidToken(TokenType.REFRESH, refreshToken)) {
blackListTokens.add(new BlackListToken(TokenType.REFRESH, refreshToken));
}

blackListTokenRepository.saveAll(blackListTokens);
}

private void validateEmptyToken(final String accessToken, final String refreshToken) {
if (isEmptyToken(accessToken) || isEmptyToken(refreshToken)) {
throw new EmptyTokenException("비어있는 토큰입니다.");
}
}

private boolean isValidToken(final TokenType tokenType, final String targetToken) {
return tokenDecoder.decode(tokenType, targetToken).isPresent();
}

private boolean isEmptyToken(final String targetToken) {
return targetToken == null || targetToken.isBlank();
}

public boolean existsBlackListToken(final TokenType tokenType, final String targetToken) {
return blackListTokenRepository.existsByTokenTypeAndToken(tokenType, targetToken);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.ddang.ddang.authentication.configuration;

import com.ddang.ddang.authentication.application.BlackListTokenService;
import com.ddang.ddang.authentication.infrastructure.jwt.PrivateClaims;
import com.ddang.ddang.authentication.domain.TokenDecoder;
import com.ddang.ddang.authentication.domain.TokenType;
Expand All @@ -17,6 +18,7 @@
@RequiredArgsConstructor
public class AuthenticationInterceptor implements HandlerInterceptor {

private final BlackListTokenService blackListTokenService;
private final TokenDecoder tokenDecoder;
private final AuthenticationStore store;

Expand All @@ -26,16 +28,19 @@ public boolean preHandle(
final HttpServletResponse response,
final Object handler
) {
final String token = request.getHeader(HttpHeaders.AUTHORIZATION);
final String accessToken = request.getHeader(HttpHeaders.AUTHORIZATION);

if (isNotRequiredAuthenticate(token)) {
if (isNotRequiredAuthenticate(accessToken)) {
store.set(new AuthenticationUserInfo(null));
return true;
}

final PrivateClaims privateClaims = tokenDecoder.decode(TokenType.ACCESS, token)
validateLogoutToken(accessToken);

final PrivateClaims privateClaims = tokenDecoder.decode(TokenType.ACCESS, accessToken)
.orElseThrow(() ->
new InvalidTokenException("유효한 토큰이 아닙니다."));
new InvalidTokenException("유효한 토큰이 아닙니다.")
);

store.set(new AuthenticationUserInfo(privateClaims.userId()));
return true;
Expand All @@ -45,6 +50,12 @@ private boolean isNotRequiredAuthenticate(final String token) {
return token == null || token.length() == 0;
}

private void validateLogoutToken(final String accessToken) {
if (blackListTokenService.existsBlackListToken(TokenType.ACCESS, accessToken)) {
throw new InvalidTokenException("유효한 토큰이 아닙니다.");
}
}

@Override
public void afterCompletion(
final HttpServletRequest request,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.ddang.ddang.authentication.domain;

import com.ddang.ddang.authentication.domain.exception.EmptyTokenException;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import lombok.AccessLevel;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.ToString;

@Entity
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Getter
@EqualsAndHashCode(of = "id")
@ToString(of = {"id", "tokenType", "token"})
public class BlackListToken {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Enumerated(EnumType.STRING)
private TokenType tokenType;

@Column(length = 200, nullable = false)
private String token;

public BlackListToken(final TokenType tokenType, final String token) {
validateToken(token);

this.tokenType = tokenType;
this.token = token;
}

private void validateToken(final String targetToken) {
if (targetToken == null || targetToken.isBlank()) {
throw new EmptyTokenException("비어있는 토큰입니다.");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.ddang.ddang.authentication.domain.exception;

public class EmptyTokenException extends IllegalArgumentException {

public EmptyTokenException(final String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.ddang.ddang.authentication.infrastructure.persistence;

import com.ddang.ddang.authentication.domain.BlackListToken;
import com.ddang.ddang.authentication.domain.TokenType;
import org.springframework.data.jpa.repository.JpaRepository;

public interface JpaBlackListTokenRepository extends JpaRepository<BlackListToken, Long> {

boolean existsByTokenTypeAndToken(final TokenType tokenType, final String accessToken);
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package com.ddang.ddang.authentication.presentation;

import com.ddang.ddang.authentication.application.AuthenticationService;
import com.ddang.ddang.authentication.application.BlackListTokenService;
import com.ddang.ddang.authentication.application.dto.TokenDto;
import com.ddang.ddang.authentication.infrastructure.oauth2.Oauth2Type;
import com.ddang.ddang.authentication.presentation.dto.request.AccessTokenRequest;
import com.ddang.ddang.authentication.presentation.dto.request.LogoutRequest;
import com.ddang.ddang.authentication.presentation.dto.request.RefreshTokenRequest;
import com.ddang.ddang.authentication.presentation.dto.response.TokenResponse;
import com.ddang.ddang.authentication.presentation.dto.response.ValidatedTokenResponse;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpHeaders;
import org.springframework.http.ResponseEntity;
Expand All @@ -24,6 +27,7 @@
public class AuthenticationController {

private final AuthenticationService authenticationService;
private final BlackListTokenService blackListTokenService;

@PostMapping("/login/{oauth2Type}")
public ResponseEntity<Object> validate(
Expand All @@ -50,4 +54,15 @@ public ResponseEntity<ValidatedTokenResponse> validateToken(

return ResponseEntity.ok(new ValidatedTokenResponse(validated));
}

@PostMapping("/logout")
public ResponseEntity<Void> logout(
@RequestHeader(HttpHeaders.AUTHORIZATION) final String accessToken,
@RequestBody @Valid final LogoutRequest request
) {
blackListTokenService.registerBlackListToken(accessToken, request.refreshToken());

return ResponseEntity.noContent()
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.ddang.ddang.authentication.presentation.dto.request;

import jakarta.validation.constraints.NotEmpty;

public record LogoutRequest(@NotEmpty(message = "refreshToken을 입력해주세요.") String refreshToken) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@
import com.ddang.ddang.auction.domain.Auction;
import com.ddang.ddang.auction.infrastructure.persistence.JpaAuctionRepository;
import com.ddang.ddang.bid.application.dto.CreateBidDto;
import com.ddang.ddang.bid.application.dto.LoginUserDto;
import com.ddang.ddang.bid.application.dto.ReadBidDto;
import com.ddang.ddang.bid.application.exception.InvalidAuctionToBidException;
import com.ddang.ddang.bid.application.exception.InvalidBidPriceException;
import com.ddang.ddang.bid.application.exception.InvalidBidderException;
import com.ddang.ddang.user.application.exception.UserNotFoundException;
import com.ddang.ddang.bid.domain.Bid;
import com.ddang.ddang.bid.domain.BidPrice;
import com.ddang.ddang.bid.infrastructure.persistence.JpaBidRepository;
import com.ddang.ddang.user.application.exception.UserNotFoundException;
import com.ddang.ddang.user.domain.User;
import com.ddang.ddang.user.infrastructure.persistence.JpaUserRepository;
import lombok.RequiredArgsConstructor;
Expand All @@ -32,9 +31,8 @@ public class BidService {
private final JpaBidRepository bidRepository;

@Transactional
public Long create(final LoginUserDto userDto, final CreateBidDto bidDto) {
// TODO: 2023/07/28 추후 User 패키지 내에 UserNotFoundException이 생긴다면 해당 예외를 사용하도록 수정 하겠습니다.
final User bidder = userRepository.findById(userDto.usedId())
public Long create(final CreateBidDto bidDto) {
final User bidder = userRepository.findById(bidDto.userId())
.orElseThrow(() -> new UserNotFoundException("해당 사용자를 찾을 수 없습니다."));
final Auction auction = auctionRepository.findById(bidDto.auctionId())
.orElseThrow(() -> new AuctionNotFoundException("해당 경매를 찾을 수 없습니다."));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
import com.ddang.ddang.bid.presentation.dto.request.CreateBidRequest;
import com.ddang.ddang.user.domain.User;

public record CreateBidDto(Long auctionId, int bidPrice) {
public record CreateBidDto(Long auctionId, int bidPrice, Long userId) {

public static CreateBidDto from(final CreateBidRequest bidRequest) {
return new CreateBidDto(bidRequest.auctionId(), bidRequest.bidPrice());
public static CreateBidDto of(final CreateBidRequest bidRequest, final Long userId) {
return new CreateBidDto(bidRequest.auctionId(), bidRequest.bidPrice(), userId);
}

public Bid toEntity(final Auction auction, final User user) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package com.ddang.ddang.bid.presentation;

import com.ddang.ddang.authentication.configuration.AuthenticateUser;
import com.ddang.ddang.authentication.domain.dto.AuthenticationUserInfo;
import com.ddang.ddang.bid.application.BidService;
import com.ddang.ddang.bid.application.dto.CreateBidDto;
import com.ddang.ddang.bid.application.dto.LoginUserDto;
import com.ddang.ddang.bid.application.dto.ReadBidDto;
import com.ddang.ddang.bid.presentation.dto.request.CreateBidRequest;
import com.ddang.ddang.bid.presentation.dto.request.LoginUserRequest;
import com.ddang.ddang.bid.presentation.dto.response.ReadBidResponse;
import com.ddang.ddang.bid.presentation.dto.response.ReadBidsResponse;
import com.ddang.ddang.bid.presentation.resolver.LoginUser;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
Expand All @@ -29,13 +28,12 @@ public class BidController {

private final BidService bidService;

// TODO: 2023/08/09 임시로 사용하는 argument resolver 추후 수정
@PostMapping
public ResponseEntity<Void> create(
@LoginUser final LoginUserRequest userRequest,
@AuthenticateUser AuthenticationUserInfo userInfo,
@RequestBody @Valid final CreateBidRequest bidRequest
) {
bidService.create(LoginUserDto.from(userRequest), CreateBidDto.from(bidRequest));
bidService.create(CreateBidDto.of(bidRequest, userInfo.userId()));

return ResponseEntity.created(URI.create("/auctions/" + bidRequest.auctionId()))
.build();
Expand Down
Loading