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

report 정렬 추가 및 탈퇴 시 디바이스 토큰 제거 #429

Merged
merged 4 commits into from
Sep 21, 2023
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 @@ -14,6 +14,7 @@
import com.ddang.ddang.authentication.infrastructure.oauth2.Oauth2Type;
import com.ddang.ddang.device.application.DeviceTokenService;
import com.ddang.ddang.device.application.dto.PersistDeviceTokenDto;
import com.ddang.ddang.device.infrastructure.persistence.JpaDeviceTokenRepository;
import com.ddang.ddang.image.application.exception.ImageNotFoundException;
import com.ddang.ddang.image.domain.ProfileImage;
import com.ddang.ddang.image.infrastructure.persistence.JpaProfileImageRepository;
Expand Down Expand Up @@ -42,6 +43,7 @@ public class AuthenticationService {
private final TokenEncoder tokenEncoder;
private final TokenDecoder tokenDecoder;
private final BlackListTokenService blackListTokenService;
private final JpaDeviceTokenRepository deviceTokenRepository;

@Transactional
public TokenDto login(final Oauth2Type oauth2Type, final String oauth2AccessToken, final String deviceToken) {
Expand Down Expand Up @@ -142,6 +144,7 @@ public void withdrawal(

user.withdrawal();
blackListTokenService.registerBlackListToken(accessToken, refreshToken);
deviceTokenRepository.deleteByUserId(user.getId());
provider.unlinkUserBy(user.getOauthId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@
public interface JpaDeviceTokenRepository extends JpaRepository<DeviceToken, Long> {

Optional<DeviceToken> findByUserId(final Long userId);

void deleteByUserId(Long id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ private void checkInvalidAuctionReport(final User reporter, final Auction auctio
}

public List<ReadAuctionReportDto> readAll() {
final List<AuctionReport> auctionReports = auctionReportRepository.findAll();
final List<AuctionReport> auctionReports = auctionReportRepository.findAllByOrderByIdAsc();

return auctionReports.stream()
.map(ReadAuctionReportDto::from)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class ChatRoomReportService {
private final JpaChatRoomRepository chatRoomRepository;
private final JpaChatRoomReportRepository chatRoomReportRepository;


@Transactional
public Long create(final CreateChatRoomReportDto chatRoomReportDto) {
final User reporter = userRepository.findById(chatRoomReportDto.reporterId())
.orElseThrow(() -> new UserNotFoundException("해당 사용자를 찾을 수 없습니다."));
Expand All @@ -53,7 +53,7 @@ private void checkInvalidChatRoomReport(final User reporter, final ChatRoom chat
}

public List<ReadChatRoomReportDto> readAll() {
final List<ChatRoomReport> auctionReports = chatRoomReportRepository.findAll();
final List<ChatRoomReport> auctionReports = chatRoomReportRepository.findAllByOrderByIdAsc();

return auctionReports.stream()
.map(auctionReport -> ReadChatRoomReportDto.from(auctionReport, LocalDateTime.now()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ public interface JpaAuctionReportRepository extends JpaRepository<AuctionReport,

boolean existsByAuctionIdAndReporterId(final Long auctionId, final Long reporterId);

@Override
@EntityGraph(attributePaths = {"reporter", "auction", "auction.seller"})
List<AuctionReport> findAll();
List<AuctionReport> findAllByOrderByIdAsc();
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ public interface JpaChatRoomReportRepository extends JpaRepository<ChatRoomRepor

boolean existsByChatRoomIdAndReporterId(final Long chatRoomId, final Long reporterId);

@Override
@EntityGraph(attributePaths = {"reporter", "chatRoom", "chatRoom.buyer", "chatRoom.auction", "chatRoom.auction.seller"})
List<ChatRoomReport> findAll();
List<ChatRoomReport> findAllByOrderByIdAsc();
}
28 changes: 14 additions & 14 deletions backend/ddang/src/main/resources/static/docs/docs.html
Original file line number Diff line number Diff line change
Expand Up @@ -1399,7 +1399,7 @@ <h4 id="_요청_13"><a class="link" href="#_요청_13">요청</a></h4>
Content-Disposition: form-data; name=request; filename=request
Content-Type: application/json

{"title":"경매 상품 1","description":"이것은 경매 상품 1 입니다.","bidUnit":1000,"startPrice":1000,"closingTime":"2023-09-21T21:19:23.572151","subCategoryId":2,"thirdRegionIds":[3]}
{"title":"경매 상품 1","description":"이것은 경매 상품 1 입니다.","bidUnit":1000,"startPrice":1000,"closingTime":"2023-09-24T09:49:27.766331","subCategoryId":2,"thirdRegionIds":[3]}
--6o2knFse3p53ty9dmcQvWAIx1zInP11uCfbm--</code></pre>
</div>
</div>
Expand Down Expand Up @@ -2006,8 +2006,8 @@ <h4 id="_응답_17"><a class="link" href="#_응답_17">응답</a></h4>
"lastBidPrice" : null,
"status" : "FAILURE",
"bidUnit" : 1000,
"registerTime" : "2023-09-18T21:19:23",
"closingTime" : "2023-09-18T21:19:23",
"registerTime" : "2023-09-21T09:49:27",
"closingTime" : "2023-09-21T09:49:27",
"directRegions" : [ {
"first" : "서울특별시",
"second" : "강서구",
Expand Down Expand Up @@ -2339,12 +2339,12 @@ <h4 id="_응답_20"><a class="link" href="#_응답_20">응답</a></h4>
"name" : "사용자1",
"profileImage" : "http://localhost:8080/users/images/1",
"price" : 10000,
"bidTime" : "2023-09-18T21:19:25"
"bidTime" : "2023-09-21T09:49:29"
}, {
"name" : "사용자2",
"profileImage" : "http://localhost:8080/users/images/2",
"price" : 12000,
"bidTime" : "2023-09-18T21:19:25"
"bidTime" : "2023-09-21T09:49:29"
} ]
}</code></pre>
</div>
Expand Down Expand Up @@ -2539,7 +2539,7 @@ <h4 id="_응답_22"><a class="link" href="#_응답_22">응답</a></h4>
"price" : 10000
},
"lastMessage" : {
"createdAt" : "2023-09-18T21:19:27",
"createdAt" : "2023-09-21T09:49:31",
"contents" : "메시지1"
},
"isChatAvailable" : true
Expand All @@ -2557,7 +2557,7 @@ <h4 id="_응답_22"><a class="link" href="#_응답_22">응답</a></h4>
"price" : 20000
},
"lastMessage" : {
"createdAt" : "2023-09-18T21:19:27",
"createdAt" : "2023-09-21T09:49:31",
"contents" : "메시지2"
},
"isChatAvailable" : true
Expand Down Expand Up @@ -2995,7 +2995,7 @@ <h4 id="_응답_25"><a class="link" href="#_응답_25">응답</a></h4>

[ {
"id" : 1,
"createdAt" : "2023-09-18T21:19:27",
"createdAt" : "2023-09-21T09:49:31",
"isMyMessage" : true,
"contents" : "메시지내용"
} ]</code></pre>
Expand Down Expand Up @@ -3145,7 +3145,7 @@ <h4 id="_응답_27"><a class="link" href="#_응답_27">응답</a></h4>
"id" : 1,
"name" : "회원1"
},
"createdTime" : "2023-09-18T21:19:29",
"createdTime" : "2023-09-21T09:49:33",
"auction" : {
"id" : 1,
"title" : "제목"
Expand All @@ -3157,7 +3157,7 @@ <h4 id="_응답_27"><a class="link" href="#_응답_27">응답</a></h4>
"id" : 2,
"name" : "회원2"
},
"createdTime" : "2023-09-18T21:19:29",
"createdTime" : "2023-09-21T09:49:33",
"auction" : {
"id" : 1,
"title" : "제목"
Expand All @@ -3169,7 +3169,7 @@ <h4 id="_응답_27"><a class="link" href="#_응답_27">응답</a></h4>
"id" : 3,
"name" : "회원3"
},
"createdTime" : "2023-09-18T21:19:29",
"createdTime" : "2023-09-21T09:49:33",
"auction" : {
"id" : 1,
"title" : "제목"
Expand Down Expand Up @@ -3333,7 +3333,7 @@ <h4 id="_응답_29"><a class="link" href="#_응답_29">응답</a></h4>
"id" : 1,
"name" : "회원1"
},
"createdTime" : "2023-09-18T21:19:29",
"createdTime" : "2023-09-21T09:49:34",
"chatRoom" : {
"id" : 1
},
Expand All @@ -3344,7 +3344,7 @@ <h4 id="_응답_29"><a class="link" href="#_응답_29">응답</a></h4>
"id" : 1,
"name" : "회원1"
},
"createdTime" : "2023-09-18T21:19:29",
"createdTime" : "2023-09-21T09:49:34",
"chatRoom" : {
"id" : 1
},
Expand All @@ -3355,7 +3355,7 @@ <h4 id="_응답_29"><a class="link" href="#_응답_29">응답</a></h4>
"id" : 1,
"name" : "회원1"
},
"createdTime" : "2023-09-18T21:19:29",
"createdTime" : "2023-09-21T09:49:34",
"chatRoom" : {
"id" : 1
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ class AuthenticationServiceTest {
@Autowired
BlackListTokenService mockBlackListTokenService;

@Autowired
JpaDeviceTokenRepository mockDeviceTokenRepository;

@Autowired
JwtEncoder jwtEncoder;

Expand All @@ -93,14 +96,16 @@ void setUp(
mockProvider = mock(OAuth2UserInformationProvider.class);
mockProviderComposite = mock(Oauth2UserInformationProviderComposite.class);
mockBlackListTokenService = mock(BlackListTokenService.class);
mockDeviceTokenRepository = mock(JpaDeviceTokenRepository.class);
authenticationService = new AuthenticationService(
deviceTokenService,
mockProviderComposite,
userRepository,
profileImageRepository,
tokenEncoder,
tokenDecoder,
mockBlackListTokenService
mockBlackListTokenService,
mockDeviceTokenRepository
);

doNothing().when(deviceTokenService).persist(anyLong(), any(PersistDeviceTokenDto.class));
Expand Down Expand Up @@ -346,6 +351,7 @@ void setUp(

given(mockProviderComposite.findProvider(Oauth2Type.KAKAO)).willReturn(mockProvider);
given(mockProvider.findUserInformation(anyString())).willReturn(userInformationDto);
willDoNothing().given(mockDeviceTokenRepository).deleteById(anyLong());
willDoNothing().given(mockBlackListTokenService).registerBlackListToken(anyString(), anyString());

// when
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ class JpaAuctionReportRepositoryTest {
em.clear();

// when
final List<AuctionReport> actual = auctionReportRepository.findAll();
final List<AuctionReport> actual = auctionReportRepository.findAllByOrderByIdAsc();

// then
SoftAssertions.assertSoftly(softAssertions -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ class JpaChatRoomReportRepositoryTest {
em.clear();

// when
final List<ChatRoomReport> actual = chatRoomReportRepository.findAll();
final List<ChatRoomReport> actual = chatRoomReportRepository.findAllByOrderByIdAsc();

// then
SoftAssertions.assertSoftly(softAssertions -> {
Expand Down
Loading