diff --git a/backend/ddang/src/docs/asciidoc/docs.adoc b/backend/ddang/src/docs/asciidoc/docs.adoc index 6cae5f611..d1e61d4e8 100644 --- a/backend/ddang/src/docs/asciidoc/docs.adoc +++ b/backend/ddang/src/docs/asciidoc/docs.adoc @@ -75,19 +75,6 @@ include::{snippets}/authentication-controller-test/access-token과_refresh-token include::{snippets}/authentication-controller-test/access-token과_refresh-token을_전달하면_로그아웃한다/http-response.adoc[] -=== 탈퇴 - -==== 요청 - -include::{snippets}/authentication-controller-test/ouath2-type과_access-token과_refresh-token을_전달하면_탈퇴한다/http-request.adoc[] -include::{snippets}/authentication-controller-test/ouath2-type과_access-token과_refresh-token을_전달하면_탈퇴한다/path-parameters.adoc[] -include::{snippets}/authentication-controller-test/ouath2-type과_access-token과_refresh-token을_전달하면_탈퇴한다/request-headers.adoc[] -include::{snippets}/authentication-controller-test/ouath2-type과_access-token과_refresh-token을_전달하면_탈퇴한다/request-fields.adoc[] - -==== 응답 - -include::{snippets}/authentication-controller-test/ouath2-type과_access-token과_refresh-token을_전달하면_탈퇴한다/http-response.adoc[] - == 사용자 정보 API === 사용자 정보 조회 diff --git a/backend/ddang/src/main/java/com/ddang/ddang/auction/application/dto/ReadAuctionDto.java b/backend/ddang/src/main/java/com/ddang/ddang/auction/application/dto/ReadAuctionDto.java index 82e2af4b1..ee6b1e35a 100644 --- a/backend/ddang/src/main/java/com/ddang/ddang/auction/application/dto/ReadAuctionDto.java +++ b/backend/ddang/src/main/java/com/ddang/ddang/auction/application/dto/ReadAuctionDto.java @@ -2,7 +2,6 @@ import com.ddang.ddang.auction.domain.Auction; import com.ddang.ddang.bid.domain.Bid; -import com.ddang.ddang.image.application.util.ImageIdProcessor; import com.ddang.ddang.image.domain.AuctionImage; import java.time.LocalDateTime; @@ -26,8 +25,7 @@ public record ReadAuctionDto( Long sellerId, Long sellerProfileId, String sellerName, - double sellerReliability, - boolean isSellerDeleted + double sellerReliability ) { public static ReadAuctionDto from(final Auction auction) { @@ -47,10 +45,9 @@ public static ReadAuctionDto from(final Auction auction) { auction.getSubCategory().getMainCategory().getName(), auction.getSubCategory().getName(), auction.getSeller().getId(), - ImageIdProcessor.process(auction.getSeller().getProfileImage()), + auction.getSeller().getProfileImage().getId(), auction.getSeller().getName(), - auction.getSeller().getReliability(), - auction.getSeller().isDeleted() + auction.getSeller().getReliability() ); } diff --git a/backend/ddang/src/main/java/com/ddang/ddang/auction/presentation/dto/response/ChatRoomInAuctionResponse.java b/backend/ddang/src/main/java/com/ddang/ddang/auction/presentation/dto/response/ChatRoomInAuctionResponse.java index 952f94a52..6f8b99b13 100644 --- a/backend/ddang/src/main/java/com/ddang/ddang/auction/presentation/dto/response/ChatRoomInAuctionResponse.java +++ b/backend/ddang/src/main/java/com/ddang/ddang/auction/presentation/dto/response/ChatRoomInAuctionResponse.java @@ -5,6 +5,7 @@ public record ChatRoomInAuctionResponse(Long id, boolean isChatParticipant) { public static ChatRoomInAuctionResponse from(final ReadChatRoomDto readChatRoomDto) { + return new ChatRoomInAuctionResponse(readChatRoomDto.id(), readChatRoomDto.isChatParticipant()); } } diff --git a/backend/ddang/src/main/java/com/ddang/ddang/authentication/application/AuthenticationService.java b/backend/ddang/src/main/java/com/ddang/ddang/authentication/application/AuthenticationService.java index 26c617e7b..d1a4a0f43 100644 --- a/backend/ddang/src/main/java/com/ddang/ddang/authentication/application/AuthenticationService.java +++ b/backend/ddang/src/main/java/com/ddang/ddang/authentication/application/AuthenticationService.java @@ -1,8 +1,6 @@ package com.ddang.ddang.authentication.application; import com.ddang.ddang.authentication.application.dto.TokenDto; -import com.ddang.ddang.authentication.application.exception.InvalidWithdrawalException; -import com.ddang.ddang.authentication.application.util.RandomNameGenerator; import com.ddang.ddang.authentication.domain.Oauth2UserInformationProviderComposite; import com.ddang.ddang.authentication.domain.TokenDecoder; import com.ddang.ddang.authentication.domain.TokenEncoder; @@ -35,7 +33,6 @@ public class AuthenticationService { private final JpaUserRepository userRepository; private final TokenEncoder tokenEncoder; private final TokenDecoder tokenDecoder; - private final BlackListTokenService blackListTokenService; @Transactional public TokenDto login(final Oauth2Type oauth2Type, final String oauth2AccessToken, final String deviceToken) { @@ -54,10 +51,10 @@ private void updateOrPersistDeviceToken(final String deviceToken, final User per } private User findOrPersistUser(final Oauth2Type oauth2Type, final UserInformationDto userInformationDto) { - return userRepository.findByOauthIdAndDeletedIsFalse(userInformationDto.findUserId()) + return userRepository.findByOauthId(userInformationDto.findUserId()) .orElseGet(() -> { final User user = User.builder() - .name(oauth2Type.calculateNickname(calculateRandomNumber())) + .name(oauth2Type.calculateNickname(userInformationDto)) .profileImage(null) .reliability(0.0d) .oauthId(userInformationDto.findUserId()) @@ -67,20 +64,6 @@ private User findOrPersistUser(final Oauth2Type oauth2Type, final UserInformatio }); } - private String calculateRandomNumber() { - String name = RandomNameGenerator.generate(); - - while (isAlreadyExist(name)) { - name = RandomNameGenerator.generate(); - } - - return name; - } - - private boolean isAlreadyExist(final String name) { - return userRepository.existsByNameEndingWith(name); - } - private TokenDto convertTokenDto(final User persistUser) { final String accessToken = tokenEncoder.encode( LocalDateTime.now(), @@ -114,20 +97,4 @@ public boolean validateToken(final String accessToken) { return tokenDecoder.decode(TokenType.ACCESS, accessToken) .isPresent(); } - - @Transactional - public void withdrawal( - final Oauth2Type oauth2Type, - final String oauth2AccessToken, - final String refreshToken - ) throws InvalidWithdrawalException { - final OAuth2UserInformationProvider provider = providerComposite.findProvider(oauth2Type); - final UserInformationDto userInformationDto = provider.findUserInformation(oauth2AccessToken); - final User user = userRepository.findByOauthIdAndDeletedIsFalse(userInformationDto.findUserId()) - .orElseThrow(() -> new InvalidWithdrawalException("탈퇴에 대한 권한 없습니다.")); - - user.withdrawal(); - blackListTokenService.registerBlackListToken(oauth2AccessToken, refreshToken); - provider.unlinkUserBy(oauth2AccessToken, user.getOauthId()); - } } diff --git a/backend/ddang/src/main/java/com/ddang/ddang/authentication/application/exception/InvalidWithdrawalException.java b/backend/ddang/src/main/java/com/ddang/ddang/authentication/application/exception/InvalidWithdrawalException.java deleted file mode 100644 index 55e4c693e..000000000 --- a/backend/ddang/src/main/java/com/ddang/ddang/authentication/application/exception/InvalidWithdrawalException.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.ddang.ddang.authentication.application.exception; - -public class InvalidWithdrawalException extends IllegalArgumentException { - - public InvalidWithdrawalException(final String message) { - super(message); - } -} diff --git a/backend/ddang/src/main/java/com/ddang/ddang/authentication/application/util/RandomNameGenerator.java b/backend/ddang/src/main/java/com/ddang/ddang/authentication/application/util/RandomNameGenerator.java deleted file mode 100644 index d88a60158..000000000 --- a/backend/ddang/src/main/java/com/ddang/ddang/authentication/application/util/RandomNameGenerator.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.ddang.ddang.authentication.application.util; - -import java.util.Random; - -public class RandomNameGenerator { - - private static final int NAME_LENGTH = 10; - - private static final Random random = new Random(); - - private RandomNameGenerator() { - } - - public static String generate() { - StringBuilder name = new StringBuilder(); - - for (int i = 0; i < NAME_LENGTH; i++) { - int digit = random.nextInt(10); - name.append(digit); - } - - return name.toString(); - } -} diff --git a/backend/ddang/src/main/java/com/ddang/ddang/authentication/configuration/KakaoProvidersConfigurationProperties.java b/backend/ddang/src/main/java/com/ddang/ddang/authentication/configuration/KakaoProvidersConfigurationProperties.java index c83341654..45c13c5b6 100644 --- a/backend/ddang/src/main/java/com/ddang/ddang/authentication/configuration/KakaoProvidersConfigurationProperties.java +++ b/backend/ddang/src/main/java/com/ddang/ddang/authentication/configuration/KakaoProvidersConfigurationProperties.java @@ -3,5 +3,5 @@ import org.springframework.boot.context.properties.ConfigurationProperties; @ConfigurationProperties("oauth2.client.providers.kakao") -public record KakaoProvidersConfigurationProperties(String userInfoUri, String userUnlinkUri) { +public record KakaoProvidersConfigurationProperties(String userInfoUri) { } diff --git a/backend/ddang/src/main/java/com/ddang/ddang/authentication/infrastructure/oauth2/OAuth2UserInformationProvider.java b/backend/ddang/src/main/java/com/ddang/ddang/authentication/infrastructure/oauth2/OAuth2UserInformationProvider.java index d1b3f05cb..87996d889 100644 --- a/backend/ddang/src/main/java/com/ddang/ddang/authentication/infrastructure/oauth2/OAuth2UserInformationProvider.java +++ b/backend/ddang/src/main/java/com/ddang/ddang/authentication/infrastructure/oauth2/OAuth2UserInformationProvider.java @@ -7,6 +7,4 @@ public interface OAuth2UserInformationProvider { Oauth2Type supportsOauth2Type(); UserInformationDto findUserInformation(final String accessToken); - - UserInformationDto unlinkUserBy(final String accessToken, final String oauthId); } diff --git a/backend/ddang/src/main/java/com/ddang/ddang/authentication/infrastructure/oauth2/Oauth2Type.java b/backend/ddang/src/main/java/com/ddang/ddang/authentication/infrastructure/oauth2/Oauth2Type.java index 5e10a21e6..89da5853f 100644 --- a/backend/ddang/src/main/java/com/ddang/ddang/authentication/infrastructure/oauth2/Oauth2Type.java +++ b/backend/ddang/src/main/java/com/ddang/ddang/authentication/infrastructure/oauth2/Oauth2Type.java @@ -1,7 +1,7 @@ package com.ddang.ddang.authentication.infrastructure.oauth2; +import com.ddang.ddang.authentication.domain.dto.UserInformationDto; import com.ddang.ddang.authentication.domain.exception.UnsupportedSocialLoginException; - import java.util.Locale; public enum Oauth2Type { @@ -16,9 +16,9 @@ public static Oauth2Type from(final String typeName) { } } - public String calculateNickname(final String name) { + public String calculateNickname(final UserInformationDto dto) { return this.name() .toLowerCase(Locale.ENGLISH) - .concat(name); + .concat(String.valueOf(dto.id())); } } diff --git a/backend/ddang/src/main/java/com/ddang/ddang/authentication/infrastructure/oauth2/kakao/KakaoUserInformationProvider.java b/backend/ddang/src/main/java/com/ddang/ddang/authentication/infrastructure/oauth2/kakao/KakaoUserInformationProvider.java index 859a0db78..2da4b1102 100644 --- a/backend/ddang/src/main/java/com/ddang/ddang/authentication/infrastructure/oauth2/kakao/KakaoUserInformationProvider.java +++ b/backend/ddang/src/main/java/com/ddang/ddang/authentication/infrastructure/oauth2/kakao/KakaoUserInformationProvider.java @@ -12,8 +12,6 @@ import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Component; -import org.springframework.util.LinkedMultiValueMap; -import org.springframework.util.MultiValueMap; import org.springframework.web.client.HttpClientErrorException; import org.springframework.web.client.RestTemplate; @@ -56,32 +54,4 @@ public UserInformationDto findUserInformation(final String accessToken) { throw new InvalidTokenException(message, ex); } } - - @Override - public UserInformationDto unlinkUserBy(final String accessToken, final String oauthId) { - final HttpHeaders headers = new HttpHeaders(); - headers.setContentType(MediaType.APPLICATION_JSON); - headers.set(HttpHeaders.AUTHORIZATION, TOKEN_TYPE + accessToken); - - final MultiValueMap parameters = new LinkedMultiValueMap<>(); - parameters.add("target_id_type", "user_id"); - parameters.add("target_id", oauthId); - - final HttpEntity> request = new HttpEntity<>(parameters, headers); - - try { - final ResponseEntity response = restTemplate.exchange( - providersConfigurationProperties.userUnlinkUri(), - HttpMethod.POST, - request, - UserInformationDto.class - ); - - return response.getBody(); - } catch (final HttpClientErrorException ex) { - final String message = ex.getMessage().split(REST_TEMPLATE_MESSAGE_SEPARATOR)[MESSAGE_INDEX]; - - throw new InvalidTokenException(message, ex); - } - } } diff --git a/backend/ddang/src/main/java/com/ddang/ddang/authentication/presentation/AuthenticationController.java b/backend/ddang/src/main/java/com/ddang/ddang/authentication/presentation/AuthenticationController.java index 8f8c1b6bd..7331a83bd 100644 --- a/backend/ddang/src/main/java/com/ddang/ddang/authentication/presentation/AuthenticationController.java +++ b/backend/ddang/src/main/java/com/ddang/ddang/authentication/presentation/AuthenticationController.java @@ -7,14 +7,12 @@ import com.ddang.ddang.authentication.presentation.dto.request.LoginTokenRequest; 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.request.WithdrawalRequest; 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; -import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; @@ -67,16 +65,4 @@ public ResponseEntity logout( return ResponseEntity.noContent() .build(); } - - @DeleteMapping("/withdrawal/{oauth2Type}") - public ResponseEntity withdrawal( - @PathVariable final Oauth2Type oauth2Type, - @RequestHeader(HttpHeaders.AUTHORIZATION) final String accessToken, - @RequestBody @Valid final WithdrawalRequest request - ) { - authenticationService.withdrawal(oauth2Type, accessToken, request.refreshToken()); - - return ResponseEntity.noContent() - .build(); - } } diff --git a/backend/ddang/src/main/java/com/ddang/ddang/authentication/presentation/dto/request/WithdrawalRequest.java b/backend/ddang/src/main/java/com/ddang/ddang/authentication/presentation/dto/request/WithdrawalRequest.java deleted file mode 100644 index df304fd9d..000000000 --- a/backend/ddang/src/main/java/com/ddang/ddang/authentication/presentation/dto/request/WithdrawalRequest.java +++ /dev/null @@ -1,6 +0,0 @@ -package com.ddang.ddang.authentication.presentation.dto.request; - -import jakarta.validation.constraints.NotEmpty; - -public record WithdrawalRequest(@NotEmpty(message = "refreshToken을 입력해주세요.") String refreshToken) { -} diff --git a/backend/ddang/src/main/java/com/ddang/ddang/bid/application/dto/ReadBidDto.java b/backend/ddang/src/main/java/com/ddang/ddang/bid/application/dto/ReadBidDto.java index d4cf89c82..7c3f80f6e 100644 --- a/backend/ddang/src/main/java/com/ddang/ddang/bid/application/dto/ReadBidDto.java +++ b/backend/ddang/src/main/java/com/ddang/ddang/bid/application/dto/ReadBidDto.java @@ -1,7 +1,6 @@ package com.ddang.ddang.bid.application.dto; import com.ddang.ddang.bid.domain.Bid; -import com.ddang.ddang.image.application.util.ImageIdProcessor; import com.ddang.ddang.user.domain.User; import java.time.LocalDateTime; @@ -9,7 +8,6 @@ public record ReadBidDto( String name, Long profileImageId, - boolean isDeletedUser, int price, LocalDateTime bidTime ) { @@ -19,8 +17,7 @@ public static ReadBidDto from(final Bid bid) { return new ReadBidDto( bidder.getName(), - ImageIdProcessor.process(bidder.getProfileImage()), - bidder.isDeleted(), + bidder.getProfileImage().getId(), bid.getPrice().getValue(), bid.getCreatedTime() ); diff --git a/backend/ddang/src/main/java/com/ddang/ddang/bid/presentation/dto/response/ReadBidResponse.java b/backend/ddang/src/main/java/com/ddang/ddang/bid/presentation/dto/response/ReadBidResponse.java index 6f8fdb00d..68f6301ca 100644 --- a/backend/ddang/src/main/java/com/ddang/ddang/bid/presentation/dto/response/ReadBidResponse.java +++ b/backend/ddang/src/main/java/com/ddang/ddang/bid/presentation/dto/response/ReadBidResponse.java @@ -3,7 +3,6 @@ import com.ddang.ddang.bid.application.dto.ReadBidDto; import com.ddang.ddang.image.presentation.util.ImageBaseUrl; import com.ddang.ddang.image.presentation.util.ImageUrlCalculator; -import com.ddang.ddang.user.presentation.util.NameProcessor; import com.fasterxml.jackson.annotation.JsonFormat; import java.time.LocalDateTime; @@ -20,8 +19,7 @@ public record ReadBidResponse( ) { public static ReadBidResponse from(final ReadBidDto dto) { - final String name = NameProcessor.process(dto.isDeletedUser(), dto.name()); - return new ReadBidResponse(name, convertImageUrl(dto.profileImageId()), dto.price(), dto.bidTime()); + return new ReadBidResponse(dto.name(), convertImageUrl(dto.profileImageId()), dto.price(), dto.bidTime()); } private static String convertImageUrl(final Long id) { diff --git a/backend/ddang/src/main/java/com/ddang/ddang/chat/application/MessageService.java b/backend/ddang/src/main/java/com/ddang/ddang/chat/application/MessageService.java index 01acd27e9..bef15485a 100644 --- a/backend/ddang/src/main/java/com/ddang/ddang/chat/application/MessageService.java +++ b/backend/ddang/src/main/java/com/ddang/ddang/chat/application/MessageService.java @@ -10,7 +10,7 @@ import com.ddang.ddang.chat.infrastructure.persistence.JpaChatRoomRepository; import com.ddang.ddang.chat.infrastructure.persistence.JpaMessageRepository; import com.ddang.ddang.chat.presentation.dto.request.ReadMessageRequest; -import com.ddang.ddang.image.application.util.ImageIdProcessor; +import com.ddang.ddang.image.application.ImageService; import com.ddang.ddang.notification.application.NotificationService; import com.ddang.ddang.notification.application.dto.CreateNotificationDto; import com.ddang.ddang.notification.domain.NotificationType; @@ -30,6 +30,7 @@ public class MessageService { private final NotificationService notificationService; + private final ImageService imageService; private final JpaMessageRepository messageRepository; private final JpaChatRoomRepository chatRoomRepository; private final JpaUserRepository userRepository; @@ -60,7 +61,7 @@ public Long create(final CreateMessageDto dto, final String baseUrl) { } private void sendNotification(final Message message, final String baseUrl) { - final Long profileImageId = ImageIdProcessor.process(message.getWriter().getProfileImage()); + final Long profileImageId = message.getWriter().getProfileImage().getId(); final String profileImageUrl = baseUrl.concat(String.valueOf(profileImageId)); final CreateNotificationDto dto = new CreateNotificationDto( diff --git a/backend/ddang/src/main/java/com/ddang/ddang/chat/application/dto/ReadUserInChatRoomDto.java b/backend/ddang/src/main/java/com/ddang/ddang/chat/application/dto/ReadUserInChatRoomDto.java index be7bbffc9..aa93502d7 100644 --- a/backend/ddang/src/main/java/com/ddang/ddang/chat/application/dto/ReadUserInChatRoomDto.java +++ b/backend/ddang/src/main/java/com/ddang/ddang/chat/application/dto/ReadUserInChatRoomDto.java @@ -1,17 +1,15 @@ package com.ddang.ddang.chat.application.dto; -import com.ddang.ddang.image.application.util.ImageIdProcessor; import com.ddang.ddang.user.domain.User; -public record ReadUserInChatRoomDto(Long id, String name, Long profileImageId, double reliability, boolean isDeleted) { +public record ReadUserInChatRoomDto(Long id, String name, Long profileImageId, double reliability) { public static ReadUserInChatRoomDto from(final User user) { return new ReadUserInChatRoomDto( user.getId(), user.getName(), - ImageIdProcessor.process(user.getProfileImage()), - user.getReliability(), - user.isDeleted() + user.getProfileImage().getId(), + user.getReliability() ); } } diff --git a/backend/ddang/src/main/java/com/ddang/ddang/chat/presentation/dto/response/ReadChatPartnerResponse.java b/backend/ddang/src/main/java/com/ddang/ddang/chat/presentation/dto/response/ReadChatPartnerResponse.java index 566b0b972..667e8daae 100644 --- a/backend/ddang/src/main/java/com/ddang/ddang/chat/presentation/dto/response/ReadChatPartnerResponse.java +++ b/backend/ddang/src/main/java/com/ddang/ddang/chat/presentation/dto/response/ReadChatPartnerResponse.java @@ -3,14 +3,11 @@ import com.ddang.ddang.chat.application.dto.ReadUserInChatRoomDto; import com.ddang.ddang.image.presentation.util.ImageBaseUrl; import com.ddang.ddang.image.presentation.util.ImageUrlCalculator; -import com.ddang.ddang.user.presentation.util.NameProcessor; public record ReadChatPartnerResponse(Long id, String name, String profileImage) { public static ReadChatPartnerResponse from(final ReadUserInChatRoomDto dto) { - final String name = NameProcessor.process(dto.isDeleted(), dto.name()); - - return new ReadChatPartnerResponse(dto.id(), name, convertImageUrl(dto.profileImageId())); + return new ReadChatPartnerResponse(dto.id(), dto.name(), convertImageUrl(dto.profileImageId())); } private static String convertImageUrl(final Long id) { diff --git a/backend/ddang/src/main/java/com/ddang/ddang/common/helper/QuerydslSliceHelper.java b/backend/ddang/src/main/java/com/ddang/ddang/common/helper/QuerydslSliceHelper.java index cfb21df88..9c5215c0a 100644 --- a/backend/ddang/src/main/java/com/ddang/ddang/common/helper/QuerydslSliceHelper.java +++ b/backend/ddang/src/main/java/com/ddang/ddang/common/helper/QuerydslSliceHelper.java @@ -5,7 +5,7 @@ import org.springframework.data.domain.Slice; import org.springframework.data.domain.SliceImpl; -public final class QuerydslSliceHelper { +public class QuerydslSliceHelper { private QuerydslSliceHelper() { } diff --git a/backend/ddang/src/main/java/com/ddang/ddang/exception/GlobalExceptionHandler.java b/backend/ddang/src/main/java/com/ddang/ddang/exception/GlobalExceptionHandler.java index e0749c2b3..28cb2af91 100644 --- a/backend/ddang/src/main/java/com/ddang/ddang/exception/GlobalExceptionHandler.java +++ b/backend/ddang/src/main/java/com/ddang/ddang/exception/GlobalExceptionHandler.java @@ -5,7 +5,6 @@ import com.ddang.ddang.auction.configuration.exception.InvalidSearchConditionException; import com.ddang.ddang.auction.domain.exception.InvalidPriceValueException; import com.ddang.ddang.auction.domain.exception.WinnerNotFoundException; -import com.ddang.ddang.authentication.application.exception.InvalidWithdrawalException; import com.ddang.ddang.authentication.configuration.exception.UserUnauthorizedException; import com.ddang.ddang.authentication.domain.exception.InvalidTokenException; import com.ddang.ddang.authentication.domain.exception.UnsupportedSocialLoginException; @@ -26,7 +25,7 @@ import com.ddang.ddang.region.application.exception.RegionNotFoundException; import com.ddang.ddang.report.application.exception.AlreadyReportAuctionException; import com.ddang.ddang.report.application.exception.AlreadyReportChatRoomException; -import com.ddang.ddang.report.application.exception.InvalidChatRoomReportException; +import com.ddang.ddang.report.application.exception.ChatRoomReportNotAccessibleException; import com.ddang.ddang.report.application.exception.InvalidReportAuctionException; import com.ddang.ddang.report.application.exception.InvalidReporterToAuctionException; import com.ddang.ddang.user.application.exception.UserNotFoundException; @@ -137,16 +136,6 @@ public ResponseEntity handleUserNotAuthorizationException( .body(new ExceptionResponse(ex.getMessage())); } - @ExceptionHandler(InvalidWithdrawalException.class) - public ResponseEntity handleInaccessibleWithdrawalException( - final InvalidWithdrawalException ex - ) { - logger.warn(String.format(EXCEPTION_FORMAT, InvalidWithdrawalException.class), ex); - - return ResponseEntity.status(HttpStatus.FORBIDDEN) - .body(new ExceptionResponse(ex.getMessage())); - } - @ExceptionHandler(InvalidPriceValueException.class) public ResponseEntity handleInvalidPriceValueException( final InvalidPriceValueException ex @@ -258,10 +247,10 @@ public ResponseEntity handleAlreadyReportAuctionException( .body(new ExceptionResponse(ex.getMessage())); } - @ExceptionHandler(InvalidChatRoomReportException.class) + @ExceptionHandler(ChatRoomReportNotAccessibleException.class) public ResponseEntity handleChatRoomReportNotAccessibleExceptionException( - final InvalidChatRoomReportException ex) { - logger.warn(String.format(EXCEPTION_FORMAT, InvalidChatRoomReportException.class), ex); + final ChatRoomReportNotAccessibleException ex) { + logger.warn(String.format(EXCEPTION_FORMAT, ChatRoomReportNotAccessibleException.class), ex); return ResponseEntity.status(HttpStatus.FORBIDDEN) .body(new ExceptionResponse(ex.getMessage())); diff --git a/backend/ddang/src/main/java/com/ddang/ddang/image/application/util/ImageIdProcessor.java b/backend/ddang/src/main/java/com/ddang/ddang/image/application/util/ImageIdProcessor.java deleted file mode 100644 index 31a7e24a2..000000000 --- a/backend/ddang/src/main/java/com/ddang/ddang/image/application/util/ImageIdProcessor.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.ddang.ddang.image.application.util; - -import com.ddang.ddang.image.domain.ProfileImage; - -public final class ImageIdProcessor { - - private ImageIdProcessor() { - } - - public static Long process(final ProfileImage profileImage) { - if (profileImage == null) { - return null; - } - - return profileImage.getId(); - } -} diff --git a/backend/ddang/src/main/java/com/ddang/ddang/image/presentation/util/ImageBaseUrl.java b/backend/ddang/src/main/java/com/ddang/ddang/image/presentation/util/ImageBaseUrl.java index ae5e674e5..a94ac3bd7 100644 --- a/backend/ddang/src/main/java/com/ddang/ddang/image/presentation/util/ImageBaseUrl.java +++ b/backend/ddang/src/main/java/com/ddang/ddang/image/presentation/util/ImageBaseUrl.java @@ -4,7 +4,7 @@ public enum ImageBaseUrl { - AUCTION("/auctions/images/"), + AUCTION("/auctions/images"), USER("/users/images/"); private final String value; diff --git a/backend/ddang/src/main/java/com/ddang/ddang/image/presentation/util/ImageUrlCalculator.java b/backend/ddang/src/main/java/com/ddang/ddang/image/presentation/util/ImageUrlCalculator.java index ebde7e3f5..3ec8226f3 100644 --- a/backend/ddang/src/main/java/com/ddang/ddang/image/presentation/util/ImageUrlCalculator.java +++ b/backend/ddang/src/main/java/com/ddang/ddang/image/presentation/util/ImageUrlCalculator.java @@ -1,15 +1,11 @@ package com.ddang.ddang.image.presentation.util; -public final class ImageUrlCalculator { +public class ImageUrlCalculator { private ImageUrlCalculator() { } public static String calculate(final ImageBaseUrl imageBaseUrl, final Long id) { - if (id == null) { - return null; - } - final String baseUrl = imageBaseUrl.getBaseUrl(); return baseUrl.concat(String.valueOf(id)); diff --git a/backend/ddang/src/main/java/com/ddang/ddang/report/application/ChatRoomReportService.java b/backend/ddang/src/main/java/com/ddang/ddang/report/application/ChatRoomReportService.java index a063f039d..3b06a3db6 100644 --- a/backend/ddang/src/main/java/com/ddang/ddang/report/application/ChatRoomReportService.java +++ b/backend/ddang/src/main/java/com/ddang/ddang/report/application/ChatRoomReportService.java @@ -6,7 +6,7 @@ import com.ddang.ddang.report.application.dto.CreateChatRoomReportDto; import com.ddang.ddang.report.application.dto.ReadChatRoomReportDto; import com.ddang.ddang.report.application.exception.AlreadyReportChatRoomException; -import com.ddang.ddang.report.application.exception.InvalidChatRoomReportException; +import com.ddang.ddang.report.application.exception.ChatRoomReportNotAccessibleException; import com.ddang.ddang.report.domain.ChatRoomReport; import com.ddang.ddang.report.infrastructure.persistence.JpaChatRoomReportRepository; import com.ddang.ddang.user.application.exception.UserNotFoundException; @@ -45,7 +45,7 @@ public Long create(final CreateChatRoomReportDto chatRoomReportDto) { private void checkInvalidChatRoomReport(final User reporter, final ChatRoom chatRoom) { if (!chatRoom.isParticipant(reporter)) { - throw new InvalidChatRoomReportException("해당 채팅방을 신고할 권한이 없습니다."); + throw new ChatRoomReportNotAccessibleException("해당 채팅방을 신고할 권한이 없습니다."); } if (chatRoomReportRepository.existsByChatRoomIdAndReporterId(chatRoom.getId(), reporter.getId())) { throw new AlreadyReportChatRoomException("이미 신고한 채팅방입니다."); diff --git a/backend/ddang/src/main/java/com/ddang/ddang/report/application/dto/ReadReporterDto.java b/backend/ddang/src/main/java/com/ddang/ddang/report/application/dto/ReadReporterDto.java index eecb87cab..29302f21e 100644 --- a/backend/ddang/src/main/java/com/ddang/ddang/report/application/dto/ReadReporterDto.java +++ b/backend/ddang/src/main/java/com/ddang/ddang/report/application/dto/ReadReporterDto.java @@ -1,17 +1,15 @@ package com.ddang.ddang.report.application.dto; -import com.ddang.ddang.image.application.util.ImageIdProcessor; import com.ddang.ddang.user.domain.User; -public record ReadReporterDto(Long id, String name, Long profileImageId, double reliability, boolean isDeleted) { +public record ReadReporterDto(Long id, String name, Long profileImage, double reliability) { public static ReadReporterDto from(final User reporter) { return new ReadReporterDto( reporter.getId(), reporter.getName(), - ImageIdProcessor.process(reporter.getProfileImage()), - reporter.getReliability(), - reporter.isDeleted() + reporter.getProfileImage().getId(), + reporter.getReliability() ); } } diff --git a/backend/ddang/src/main/java/com/ddang/ddang/report/application/dto/ReadUserInReportDto.java b/backend/ddang/src/main/java/com/ddang/ddang/report/application/dto/ReadUserInReportDto.java index 324e62ea8..cf79de3b7 100644 --- a/backend/ddang/src/main/java/com/ddang/ddang/report/application/dto/ReadUserInReportDto.java +++ b/backend/ddang/src/main/java/com/ddang/ddang/report/application/dto/ReadUserInReportDto.java @@ -1,25 +1,16 @@ package com.ddang.ddang.report.application.dto; -import com.ddang.ddang.image.application.util.ImageIdProcessor; import com.ddang.ddang.user.domain.User; -public record ReadUserInReportDto( - Long id, - String name, - Long profileImageId, - double reliability, - String oauthId, - boolean isSellerDeleted -) { +public record ReadUserInReportDto(Long id, String name, Long profileImageId, double reliability, String oauthId) { public static ReadUserInReportDto from(final User user) { return new ReadUserInReportDto( user.getId(), user.getName(), - ImageIdProcessor.process(user.getProfileImage()), + user.getProfileImage().getId(), user.getReliability(), - user.getOauthId(), - user.isDeleted() + user.getOauthId() ); } } diff --git a/backend/ddang/src/main/java/com/ddang/ddang/report/application/exception/ChatRoomReportNotAccessibleException.java b/backend/ddang/src/main/java/com/ddang/ddang/report/application/exception/ChatRoomReportNotAccessibleException.java new file mode 100644 index 000000000..dd7c4f274 --- /dev/null +++ b/backend/ddang/src/main/java/com/ddang/ddang/report/application/exception/ChatRoomReportNotAccessibleException.java @@ -0,0 +1,8 @@ +package com.ddang.ddang.report.application.exception; + +public class ChatRoomReportNotAccessibleException extends IllegalArgumentException { + + public ChatRoomReportNotAccessibleException(final String message) { + super(message); + } +} diff --git a/backend/ddang/src/main/java/com/ddang/ddang/report/application/exception/InvalidChatRoomReportException.java b/backend/ddang/src/main/java/com/ddang/ddang/report/application/exception/InvalidChatRoomReportException.java deleted file mode 100644 index e52fcb1e7..000000000 --- a/backend/ddang/src/main/java/com/ddang/ddang/report/application/exception/InvalidChatRoomReportException.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.ddang.ddang.report.application.exception; - -public class InvalidChatRoomReportException extends IllegalArgumentException { - - public InvalidChatRoomReportException(final String message) { - super(message); - } -} diff --git a/backend/ddang/src/main/java/com/ddang/ddang/report/presentation/dto/response/ReadReporterResponse.java b/backend/ddang/src/main/java/com/ddang/ddang/report/presentation/dto/response/ReadReporterResponse.java index 7cc03e1a0..6b656a677 100644 --- a/backend/ddang/src/main/java/com/ddang/ddang/report/presentation/dto/response/ReadReporterResponse.java +++ b/backend/ddang/src/main/java/com/ddang/ddang/report/presentation/dto/response/ReadReporterResponse.java @@ -1,12 +1,10 @@ package com.ddang.ddang.report.presentation.dto.response; import com.ddang.ddang.report.application.dto.ReadReporterDto; -import com.ddang.ddang.user.presentation.util.NameProcessor; public record ReadReporterResponse(Long id, String name) { public static ReadReporterResponse from(final ReadReporterDto reporterDto) { - final String name = NameProcessor.process(reporterDto.isDeleted(), reporterDto.name()); - return new ReadReporterResponse(reporterDto.id(), name); + return new ReadReporterResponse(reporterDto.id(), reporterDto.name()); } } diff --git a/backend/ddang/src/main/java/com/ddang/ddang/user/application/UserService.java b/backend/ddang/src/main/java/com/ddang/ddang/user/application/UserService.java index db5947839..a32d27e13 100644 --- a/backend/ddang/src/main/java/com/ddang/ddang/user/application/UserService.java +++ b/backend/ddang/src/main/java/com/ddang/ddang/user/application/UserService.java @@ -36,4 +36,12 @@ public ReadUserDto updateById(final Long userId, final UpdateUserDto userDto) { return ReadUserDto.from(user); } + + @Transactional + public void deleteById(final Long userId) { + final User user = userRepository.findByIdAndDeletedIsFalse(userId) + .orElseThrow(() -> new UserNotFoundException("사용자 정보를 사용할 수 없습니다.")); + + user.withdrawal(); + } } diff --git a/backend/ddang/src/main/java/com/ddang/ddang/user/application/dto/ReadUserDto.java b/backend/ddang/src/main/java/com/ddang/ddang/user/application/dto/ReadUserDto.java index b82952650..b25265b7e 100644 --- a/backend/ddang/src/main/java/com/ddang/ddang/user/application/dto/ReadUserDto.java +++ b/backend/ddang/src/main/java/com/ddang/ddang/user/application/dto/ReadUserDto.java @@ -1,25 +1,16 @@ package com.ddang.ddang.user.application.dto; -import com.ddang.ddang.image.application.util.ImageIdProcessor; import com.ddang.ddang.user.domain.User; -public record ReadUserDto( - Long id, - String name, - Long profileImageId, - double reliability, - String oauthId, - boolean isDeleted -) { +public record ReadUserDto(Long id, String name, Long profileImageId, double reliability, String oauthId) { public static ReadUserDto from(final User user) { return new ReadUserDto( user.getId(), user.getName(), - ImageIdProcessor.process(user.getProfileImage()), + user.getProfileImage().getId(), user.getReliability(), - user.getOauthId(), - user.isDeleted() + user.getOauthId() ); } } diff --git a/backend/ddang/src/main/java/com/ddang/ddang/user/domain/User.java b/backend/ddang/src/main/java/com/ddang/ddang/user/domain/User.java index 25c12ba9c..f67b0a093 100644 --- a/backend/ddang/src/main/java/com/ddang/ddang/user/domain/User.java +++ b/backend/ddang/src/main/java/com/ddang/ddang/user/domain/User.java @@ -29,7 +29,6 @@ public class User extends BaseTimeEntity { private static final boolean DELETED_STATUS = true; - private static final String UNKOWN_NAME = "알 수 없음"; @Id @GeneratedValue(strategy = GenerationType.IDENTITY) @@ -44,6 +43,7 @@ public class User extends BaseTimeEntity { private double reliability; + @Column(unique = true) private String oauthId; @Column(name = "is_deleted") diff --git a/backend/ddang/src/main/java/com/ddang/ddang/user/infrastructure/persistence/JpaUserRepository.java b/backend/ddang/src/main/java/com/ddang/ddang/user/infrastructure/persistence/JpaUserRepository.java index 390768b88..44bda95bb 100644 --- a/backend/ddang/src/main/java/com/ddang/ddang/user/infrastructure/persistence/JpaUserRepository.java +++ b/backend/ddang/src/main/java/com/ddang/ddang/user/infrastructure/persistence/JpaUserRepository.java @@ -7,11 +7,9 @@ public interface JpaUserRepository extends JpaRepository { - Optional findByOauthIdAndDeletedIsFalse(final String oauthId); + Optional findByOauthId(final String oauthId); Optional findByIdAndDeletedIsFalse(final Long id); boolean existsByIdAndDeletedIsTrue(final Long id); - - boolean existsByNameEndingWith(final String name); } diff --git a/backend/ddang/src/main/java/com/ddang/ddang/user/presentation/UserController.java b/backend/ddang/src/main/java/com/ddang/ddang/user/presentation/UserController.java index 352fd739d..e8060a39b 100644 --- a/backend/ddang/src/main/java/com/ddang/ddang/user/presentation/UserController.java +++ b/backend/ddang/src/main/java/com/ddang/ddang/user/presentation/UserController.java @@ -10,6 +10,7 @@ import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PatchMapping; import org.springframework.web.bind.annotation.RequestMapping; @@ -46,4 +47,12 @@ public ResponseEntity updateById( return ResponseEntity.ok(response); } + + @DeleteMapping("/withdrawal") + public ResponseEntity delete(@AuthenticateUser final AuthenticationUserInfo userInfo) { + userService.deleteById(userInfo.userId()); + + return ResponseEntity.noContent() + .build(); + } } diff --git a/backend/ddang/src/main/java/com/ddang/ddang/user/presentation/dto/ReadUserResponse.java b/backend/ddang/src/main/java/com/ddang/ddang/user/presentation/dto/ReadUserResponse.java deleted file mode 100644 index 56ff08a7b..000000000 --- a/backend/ddang/src/main/java/com/ddang/ddang/user/presentation/dto/ReadUserResponse.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.ddang.ddang.user.presentation.dto; - -import com.ddang.ddang.image.presentation.util.ImageBaseUrl; -import com.ddang.ddang.image.presentation.util.ImageUrlCalculator; -import com.ddang.ddang.user.application.dto.ReadUserDto; -import com.ddang.ddang.user.presentation.util.NameProcessor; - -public record ReadUserResponse(String name, String profileImage, double reliability) { - - public static ReadUserResponse from(final ReadUserDto readUserDto) { - final String name = NameProcessor.process(readUserDto.isDeleted(), readUserDto.name()); - final String profileImageUrl = ImageUrlCalculator.calculate(ImageBaseUrl.USER, readUserDto.profileImageId()); - - return new ReadUserResponse(name, profileImageUrl, readUserDto.reliability()); - } -} diff --git a/backend/ddang/src/main/java/com/ddang/ddang/user/presentation/dto/response/ReadUserResponse.java b/backend/ddang/src/main/java/com/ddang/ddang/user/presentation/dto/response/ReadUserResponse.java index 1068c70da..8eb2a874a 100644 --- a/backend/ddang/src/main/java/com/ddang/ddang/user/presentation/dto/response/ReadUserResponse.java +++ b/backend/ddang/src/main/java/com/ddang/ddang/user/presentation/dto/response/ReadUserResponse.java @@ -3,13 +3,12 @@ import com.ddang.ddang.image.presentation.util.ImageBaseUrl; import com.ddang.ddang.image.presentation.util.ImageUrlCalculator; import com.ddang.ddang.user.application.dto.ReadUserDto; -import com.ddang.ddang.user.presentation.util.NameProcessor; public record ReadUserResponse(String name, String profileImage, double reliability) { public static ReadUserResponse from(final ReadUserDto readUserDto) { return new ReadUserResponse( - NameProcessor.process(readUserDto.isDeleted(), readUserDto.name()), + readUserDto.name(), convertImageUrl(readUserDto.profileImageId()), readUserDto.reliability() ); diff --git a/backend/ddang/src/main/java/com/ddang/ddang/user/presentation/util/NameProcessor.java b/backend/ddang/src/main/java/com/ddang/ddang/user/presentation/util/NameProcessor.java deleted file mode 100644 index 2e82a0949..000000000 --- a/backend/ddang/src/main/java/com/ddang/ddang/user/presentation/util/NameProcessor.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.ddang.ddang.user.presentation.util; - -public class NameProcessor { - - private static final String UNKNOWN_NAME = "알 수 없음"; - - private NameProcessor() { - } - - public static String process(final boolean isDeleted, final String name) { - if (isDeleted) { - return UNKNOWN_NAME; - } - - return name; - } -} diff --git a/backend/ddang/src/main/resources/application-local.yml b/backend/ddang/src/main/resources/application-local.yml index adbb27f43..af0703301 100644 --- a/backend/ddang/src/main/resources/application-local.yml +++ b/backend/ddang/src/main/resources/application-local.yml @@ -50,7 +50,6 @@ oauth2: providers: kakao: user-info-uri: https://kapi.kakao.com/v2/user/me - user-unlink-uri: https://kapi.kakao.com/v1/user/unlink fcm: enabled: false diff --git a/backend/ddang/src/main/resources/db/migration/V12__alter_user_tables.sql b/backend/ddang/src/main/resources/db/migration/V12__alter_user_tables.sql deleted file mode 100644 index ab1a30431..000000000 --- a/backend/ddang/src/main/resources/db/migration/V12__alter_user_tables.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE users DROP INDEX uq_oauth_id; diff --git a/backend/ddang/src/main/resources/static/docs/docs.html b/backend/ddang/src/main/resources/static/docs/docs.html index e9ba9e7a7..bb6fb65ec 100644 --- a/backend/ddang/src/main/resources/static/docs/docs.html +++ b/backend/ddang/src/main/resources/static/docs/docs.html @@ -453,7 +453,6 @@

땅땅땅 API 문서

  • AccessToken 재발급
  • AccessToken 유효성 검사
  • 로그아웃
  • -
  • 탈퇴
  • 사용자 정보 API @@ -871,89 +870,6 @@

    응답

    -
    -

    탈퇴

    -
    -

    요청

    -
    -
    -
    DELETE /oauth2/withdrawal/kakao HTTP/1.1
    -Content-Type: application/json
    -Authorization: Bearer accessToken
    -
    -{
    -  "refreshToken" : "Bearer refreshToken"
    -}
    -
    -
    - - ---- - - - - - - - - - - - - -
    Table 2. /oauth2/withdrawal/{oauth2Type}
    ParameterDescription

    oauth2Type

    소셜 로그인을 할 서비스 선택(kakao로 고정)

    - ---- - - - - - - - - - - - - -
    NameDescription

    Authorization

    회원 Bearer 인증 정보

    - ----- - - - - - - - - - - - - - - -
    PathTypeDescription

    refreshToken

    String

    refreshToken

    -
    -
    -

    응답

    -
    -
    -
    HTTP/1.1 204 No Content
    -
    -
    -
    -
    @@ -962,7 +878,7 @@

    사용자 정보 조회

    -

    요청

    +

    요청

    GET /users HTTP/1.1
    @@ -971,7 +887,7 @@ 

    요청

    -

    응답

    +

    응답

    HTTP/1.1 200 OK
    @@ -1020,7 +936,7 @@ 

    응답

    사용자 정보 수정

    -

    요청

    +

    요청

    PATCH /users HTTP/1.1
    @@ -1030,7 +946,7 @@ 

    요청

    -

    응답

    +

    응답

    HTTP/1.1 200 OK
    @@ -1084,7 +1000,7 @@ 

    카테고

    메인 카테고리 조회

    -

    요청

    +

    요청

    GET /categories HTTP/1.1
    @@ -1093,7 +1009,7 @@ 

    요청

    -

    응답

    +

    응답

    HTTP/1.1 200 OK
    @@ -1139,7 +1055,7 @@ 

    응답

    서브 카테고리 조회

    -

    요청

    +

    요청

    GET /categories/1 HTTP/1.1
    @@ -1148,7 +1064,7 @@ 

    요청

    -

    응답

    +

    응답

    HTTP/1.1 200 OK
    @@ -1199,7 +1115,7 @@ 

    첫 번째 직거래 지역 조회

    -

    요청

    +

    요청

    GET /regions HTTP/1.1
    @@ -1208,7 +1124,7 @@ 

    요청

    -

    응답

    +

    응답

    HTTP/1.1 200 OK
    @@ -1259,7 +1175,7 @@ 

    응답

    두 번째 직거래 지역 조회

    -

    요청

    +

    요청

    GET /regions/1 HTTP/1.1
    @@ -1267,7 +1183,7 @@ 

    요청

    - +@@ -1287,7 +1203,7 @@

    요청

    Table 3. /regions/{firstId}Table 2. /regions/{firstId}
    -

    응답

    +

    응답

    HTTP/1.1 200 OK
    @@ -1338,7 +1254,7 @@ 

    응답

    세 번째 직거래 지역 조회

    -

    요청

    +

    요청

    GET /regions/1/2 HTTP/1.1
    @@ -1346,7 +1262,7 @@ 

    요청

    - +@@ -1370,7 +1286,7 @@

    요청

    Table 4. /regions/{firstId}/{secondId}Table 3. /regions/{firstId}/{secondId}
    -

    응답

    +

    응답

    HTTP/1.1 200 OK
    @@ -1426,7 +1342,7 @@ 

    경매 API

    경매 등록

    -

    요청

    +

    요청

    POST /auctions HTTP/1.1
    @@ -1442,7 +1358,7 @@ 

    요청

    Content-Disposition: form-data; name=request; filename=request Content-Type: application/json -{"title":"경매 상품 1","description":"이것은 경매 상품 1 입니다.","bidUnit":1000,"startPrice":1000,"closingTime":"2023-09-18T18:56:49.863763","subCategoryId":2,"thirdRegionIds":[3]} +{"title":"경매 상품 1","description":"이것은 경매 상품 1 입니다.","bidUnit":1000,"startPrice":1000,"closingTime":"2023-09-18T17:34:45.856598","subCategoryId":2,"thirdRegionIds":[3]} --6o2knFse3p53ty9dmcQvWAIx1zInP11uCfbm--
    @@ -1488,7 +1404,7 @@

    요청

    -

    응답

    +

    응답

    HTTP/1.1 201 Created
    @@ -1556,7 +1472,7 @@ 

    응답

    경매 목록 조회

    -

    요청

    +

    요청

    GET /auctions?size=10 HTTP/1.1
    @@ -1606,7 +1522,7 @@ 

    요청

    -

    응답

    +

    응답

    HTTP/1.1 200 OK
    @@ -1698,7 +1614,7 @@ 

    응답

    자신이 등록한 경매 목록 조회

    -

    요청

    +

    요청

    GET /users/auctions/mine?size=10&page=1 HTTP/1.1
    @@ -1748,7 +1664,7 @@ 

    요청

    -

    응답

    +

    응답

    HTTP/1.1 200 OK
    @@ -1840,7 +1756,7 @@ 

    응답

    자신이 참여한 경매 목록 조회

    -

    요청

    +

    요청

    GET /users/auctions/bids?size=10&page=1 HTTP/1.1
    @@ -1890,7 +1806,7 @@ 

    요청

    -

    응답

    +

    응답

    HTTP/1.1 200 OK
    @@ -1982,7 +1898,7 @@ 

    응답

    경매 상세 조회

    -

    요청

    +

    요청

    GET /auctions/1 HTTP/1.1
    @@ -1991,7 +1907,7 @@ 

    요청

    - +@@ -2029,7 +1945,7 @@

    요청

    Table 5. /auctions/{auctionId}Table 4. /auctions/{auctionId}
    -

    응답

    +

    응답

    HTTP/1.1 200 OK
    @@ -2049,8 +1965,8 @@ 

    응답

    "lastBidPrice" : null, "status" : "FAILURE", "bidUnit" : 1000, - "registerTime" : "2023-09-15T18:56:49", - "closingTime" : "2023-09-15T18:56:49", + "registerTime" : "2023-09-15T17:34:45", + "closingTime" : "2023-09-15T17:34:45", "directRegions" : [ { "first" : "서울특별시", "second" : "강서구", @@ -2228,7 +2144,7 @@

    응답

    경매 삭제

    -

    요청

    +

    요청

    DELETE /auctions/1 HTTP/1.1
    @@ -2237,7 +2153,7 @@ 

    요청

    - +@@ -2275,7 +2191,7 @@

    요청

    Table 6. /auctions/{auctionId}Table 5. /auctions/{auctionId}
    -

    응답

    +

    응답

    HTTP/1.1 204 No Content
    @@ -2291,7 +2207,7 @@

    입찰 API

    입찰 등록

    -

    요청

    +

    요청

    POST /bids HTTP/1.1
    @@ -2350,7 +2266,7 @@ 

    요청

    -

    응답

    +

    응답

    HTTP/1.1 201 Created
    @@ -2362,7 +2278,7 @@ 

    응답

    입찰 조회

    -

    요청

    +

    요청

    GET /bids/1 HTTP/1.1
    @@ -2371,7 +2287,7 @@ 

    요청

    -

    응답

    +

    응답

    HTTP/1.1 200 OK
    @@ -2382,12 +2298,12 @@ 

    응답

    "name" : "사용자1", "profileImage" : "http://localhost:8080/users/images/1", "price" : 10000, - "bidTime" : "2023-09-15T18:56:51" + "bidTime" : "2023-09-15T17:34:48" }, { "name" : "사용자2", "profileImage" : "http://localhost:8080/users/images/2", "price" : 12000, - "bidTime" : "2023-09-15T18:56:51" + "bidTime" : "2023-09-15T17:34:48" } ] }
    @@ -2443,7 +2359,7 @@

    채팅 API

    채팅방 등록

    -

    요청

    +

    요청

    POST /chattings HTTP/1.1
    @@ -2496,7 +2412,7 @@ 

    요청

    -

    응답

    +

    응답

    HTTP/1.1 201 Created
    @@ -2534,7 +2450,7 @@ 

    응답

    채팅방 목록 조회

    -

    요청

    +

    요청

    GET /chattings HTTP/1.1
    @@ -2562,7 +2478,7 @@ 

    요청

    -

    응답

    +

    응답

    HTTP/1.1 200 OK
    @@ -2582,7 +2498,7 @@ 

    응답

    "price" : 10000 }, "lastMessage" : { - "createdAt" : "2023-09-15T18:56:53", + "createdAt" : "2023-09-15T17:34:49", "contents" : "메시지1" }, "isChatAvailable" : true @@ -2600,7 +2516,7 @@

    응답

    "price" : 20000 }, "lastMessage" : { - "createdAt" : "2023-09-15T18:56:53", + "createdAt" : "2023-09-15T17:34:49", "contents" : "메시지2" }, "isChatAvailable" : true @@ -2703,7 +2619,7 @@

    응답

    채팅방 상세 조회

    -

    요청

    +

    요청

    GET /chattings/1 HTTP/1.1
    @@ -2712,7 +2628,7 @@ 

    요청

    - +@@ -2750,7 +2666,7 @@

    요청

    Table 7. /chattings/{chatRoomId}Table 6. /chattings/{chatRoomId}
    -

    응답

    +

    응답

    HTTP/1.1 200 OK
    @@ -2849,7 +2765,7 @@ 

    응답

    메시지 전송

    -

    요청

    +

    요청

    POST /chattings/1/messages HTTP/1.1
    @@ -2863,7 +2779,7 @@ 

    요청

    - +@@ -2927,7 +2843,7 @@

    요청

    Table 8. /chattings/{chatRoomId}/messagesTable 7. /chattings/{chatRoomId}/messages
    -

    응답

    +

    응답

    HTTP/1.1 201 Created
    @@ -2965,7 +2881,7 @@ 

    응답

    메시지 목록 조회

    -

    요청

    +

    요청

    GET /chattings/1/messages?lastMessageId=1 HTTP/1.1
    @@ -2974,7 +2890,7 @@ 

    요청

    - +@@ -3030,7 +2946,7 @@

    요청

    Table 9. /chattings/{chatRoomId}/messagesTable 8. /chattings/{chatRoomId}/messages
    -

    응답

    +

    응답

    HTTP/1.1 200 OK
    @@ -3038,7 +2954,7 @@ 

    응답

    [ { "id" : 1, - "createdAt" : "2023-09-15T18:56:53", + "createdAt" : "2023-09-15T17:34:49", "isMyMessage" : true, "contents" : "메시지내용" } ]
    @@ -3095,7 +3011,7 @@

    신고 API

    경매 신고 등록

    -

    요청

    +

    요청

    POST /reports/auctions HTTP/1.1
    @@ -3154,7 +3070,7 @@ 

    요청

    -

    응답

    +

    응답

    HTTP/1.1 201 Created
    @@ -3166,7 +3082,7 @@ 

    응답

    경매 신고 조회

    -

    요청

    +

    요청

    GET /reports/auctions HTTP/1.1
    @@ -3175,7 +3091,7 @@ 

    요청

    -

    응답

    +

    응답

    HTTP/1.1 200 OK
    @@ -3188,7 +3104,7 @@ 

    응답

    "id" : 1, "name" : "회원1" }, - "createdTime" : "2023-09-15T18:56:55", + "createdTime" : "2023-09-15T17:34:51", "auction" : { "id" : 1, "title" : "제목" @@ -3200,7 +3116,7 @@

    응답

    "id" : 2, "name" : "회원2" }, - "createdTime" : "2023-09-15T18:56:55", + "createdTime" : "2023-09-15T17:34:51", "auction" : { "id" : 1, "title" : "제목" @@ -3212,7 +3128,7 @@

    응답

    "id" : 3, "name" : "회원3" }, - "createdTime" : "2023-09-15T18:56:55", + "createdTime" : "2023-09-15T17:34:51", "auction" : { "id" : 1, "title" : "제목" @@ -3283,7 +3199,7 @@

    응답

    채팅방 신고 등록

    -

    요청

    +

    요청

    POST /reports/chat-rooms HTTP/1.1
    @@ -3342,7 +3258,7 @@ 

    요청

    -

    응답

    +

    응답

    HTTP/1.1 201 Created
    @@ -3354,7 +3270,7 @@ 

    응답

    채팅방 신고 조회

    -

    요청

    +

    요청

    GET /reports/chat-rooms HTTP/1.1
    @@ -3363,7 +3279,7 @@ 

    요청

    -

    응답

    +

    응답

    HTTP/1.1 200 OK
    @@ -3376,7 +3292,7 @@ 

    응답

    "id" : 1, "name" : "회원1" }, - "createdTime" : "2023-09-15T18:56:55", + "createdTime" : "2023-09-15T17:34:51", "chatRoom" : { "id" : 1 }, @@ -3387,7 +3303,7 @@

    응답

    "id" : 1, "name" : "회원1" }, - "createdTime" : "2023-09-15T18:56:55", + "createdTime" : "2023-09-15T17:34:51", "chatRoom" : { "id" : 1 }, @@ -3398,7 +3314,7 @@

    응답

    "id" : 1, "name" : "회원1" }, - "createdTime" : "2023-09-15T18:56:55", + "createdTime" : "2023-09-15T17:34:51", "chatRoom" : { "id" : 1 }, @@ -3468,7 +3384,7 @@

    디바이스 토큰 갱신

    -

    요청

    +

    요청

    PATCH /device-token HTTP/1.1
    @@ -3521,7 +3437,7 @@ 

    요청

    -

    응답

    +

    응답

    HTTP/1.1 200 OK
    @@ -3535,7 +3451,7 @@

    응답

    diff --git a/backend/ddang/src/test/java/com/ddang/ddang/auction/application/AuctionServiceTest.java b/backend/ddang/src/test/java/com/ddang/ddang/auction/application/AuctionServiceTest.java index 66f537863..b20313da6 100644 --- a/backend/ddang/src/test/java/com/ddang/ddang/auction/application/AuctionServiceTest.java +++ b/backend/ddang/src/test/java/com/ddang/ddang/auction/application/AuctionServiceTest.java @@ -29,7 +29,7 @@ import com.ddang.ddang.user.application.exception.UserNotFoundException; import com.ddang.ddang.user.domain.User; import com.ddang.ddang.user.infrastructure.persistence.JpaUserRepository; -import org.assertj.core.api.SoftAssertions; +import org.assertj.core.api.*; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; import org.junit.jupiter.api.Test; diff --git a/backend/ddang/src/test/java/com/ddang/ddang/auction/presentation/AuctionControllerTest.java b/backend/ddang/src/test/java/com/ddang/ddang/auction/presentation/AuctionControllerTest.java index 027088c12..c923e40a1 100644 --- a/backend/ddang/src/test/java/com/ddang/ddang/auction/presentation/AuctionControllerTest.java +++ b/backend/ddang/src/test/java/com/ddang/ddang/auction/presentation/AuctionControllerTest.java @@ -211,7 +211,6 @@ void setUp(@Autowired RestDocumentationContextProvider provider) { ); } - // TODO: 2023/09/13 [고민] 회원과 사용자라는 용어를 통일할까요? @Test void 경매_등록시_유효한_회원이_아니라면_404을_반환한다() throws Exception { // given @@ -500,8 +499,7 @@ void setUp(@Autowired RestDocumentationContextProvider provider) { 1L, 1L, "판매자", - 3.5d, - false + 3.5d ); final ReadChatRoomDto chatRoomDto = new ReadChatRoomDto(1L, true); @@ -614,8 +612,7 @@ void setUp(@Autowired RestDocumentationContextProvider provider) { 1L, 1L, "판매자", - 3.5d, - false + 3.5d ); final ReadAuctionDto auction2 = new ReadAuctionDto( 2L, @@ -635,8 +632,7 @@ void setUp(@Autowired RestDocumentationContextProvider provider) { 1L, 1L, "판매자", - 3.5d, - true + 3.5d ); final PrivateClaims privateClaims = new PrivateClaims(1L); final ReadAuctionsDto readAuctionsDto = new ReadAuctionsDto(List.of(auction2, auction1), true); diff --git a/backend/ddang/src/test/java/com/ddang/ddang/authentication/application/AuthenticationServiceTest.java b/backend/ddang/src/test/java/com/ddang/ddang/authentication/application/AuthenticationServiceTest.java index 20f609451..e7e504179 100644 --- a/backend/ddang/src/test/java/com/ddang/ddang/authentication/application/AuthenticationServiceTest.java +++ b/backend/ddang/src/test/java/com/ddang/ddang/authentication/application/AuthenticationServiceTest.java @@ -1,7 +1,6 @@ package com.ddang.ddang.authentication.application; import com.ddang.ddang.authentication.application.dto.TokenDto; -import com.ddang.ddang.authentication.application.exception.InvalidWithdrawalException; import com.ddang.ddang.authentication.domain.Oauth2UserInformationProviderComposite; import com.ddang.ddang.authentication.domain.TokenDecoder; import com.ddang.ddang.authentication.domain.TokenEncoder; @@ -40,7 +39,6 @@ import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.BDDMockito.given; -import static org.mockito.BDDMockito.willDoNothing; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.mock; @@ -70,9 +68,6 @@ class AuthenticationServiceTest { @Autowired TokenDecoder tokenDecoder; - @Autowired - BlackListTokenService mockBlackListTokenService; - @Autowired JwtEncoder jwtEncoder; @@ -87,14 +82,12 @@ void setUp( ) { mockProvider = mock(OAuth2UserInformationProvider.class); mockProviderComposite = mock(Oauth2UserInformationProviderComposite.class); - mockBlackListTokenService = mock(BlackListTokenService.class); authenticationService = new AuthenticationService( deviceTokenService, mockProviderComposite, userRepository, tokenEncoder, - tokenDecoder, - mockBlackListTokenService + tokenDecoder ); doNothing().when(deviceTokenService).persist(anyLong(), any(PersistDeviceTokenDto.class)); @@ -172,34 +165,6 @@ void setUp( }); } - @Test - void 탈퇴한_회원이_소셜_로그인을_할_경우_accessToken과_refreshToken을_반환한다() { - // given - final User user = User.builder() - .name("kakao12345") - .profileImage(new ProfileImage("upload.png", "store.png")) - .reliability(0.0d) - .oauthId("12345") - .build(); - - userRepository.save(user); - user.withdrawal(); - - final UserInformationDto userInformationDto = new UserInformationDto(12345L); - - given(mockProviderComposite.findProvider(Oauth2Type.KAKAO)).willReturn(mockProvider); - given(mockProvider.findUserInformation(anyString())).willReturn(userInformationDto); - - // when - final TokenDto actual = authenticationService.login(Oauth2Type.KAKAO, "accessToken", "deviceToken"); - - // then - SoftAssertions.assertSoftly(softAssertions -> { - softAssertions.assertThat(actual.accessToken()).isNotEmpty(); - softAssertions.assertThat(actual.refreshToken()).isNotEmpty(); - }); - } - @Test void refreshToken을_전달하면_새로운_accessToken을_반환한다() { // given @@ -291,86 +256,4 @@ void setUp( // then assertThat(actual).isFalse(); } - - @Test - void 가입한_회원이_탈퇴하는_경우_정상처리한다() throws InvalidWithdrawalException { - // given - final User user = User.builder() - .name("kakao12345") - .profileImage(new ProfileImage("upload.png", "store.png")) - .reliability(0.0d) - .oauthId("12345") - .build(); - - userRepository.save(user); - - final Map privateClaims = Map.of("userId", user.getId()); - final String refreshToken = "Bearer " + tokenEncoder.encode( - LocalDateTime.now(), - TokenType.REFRESH, - privateClaims - ); - - final UserInformationDto userInformationDto = new UserInformationDto(12345L); - - given(mockProviderComposite.findProvider(Oauth2Type.KAKAO)).willReturn(mockProvider); - given(mockProvider.findUserInformation(anyString())).willReturn(userInformationDto); - given(mockProvider.unlinkUserBy(anyString(), anyString())).willReturn(userInformationDto); - willDoNothing().given(mockBlackListTokenService).registerBlackListToken(anyString(), anyString()); - - // when - authenticationService.withdrawal(Oauth2Type.KAKAO, "accessToken", refreshToken); - - // then - assertThat(user.isDeleted()).isTrue(); - } - - @Test - void 이미_탈퇴한_회원이_탈퇴하는_경우_예외가_발생한다() { - // given - final User user = User.builder() - .name("kakao12345") - .profileImage(new ProfileImage("upload.png", "store.png")) - .reliability(0.0d) - .oauthId("12345") - .build(); - - userRepository.save(user); - - final Map privateClaims = Map.of("userId", user.getId()); - final String refreshToken = "Bearer " + tokenEncoder.encode( - LocalDateTime.now(), - TokenType.REFRESH, - privateClaims - ); - - user.withdrawal(); - - final UserInformationDto userInformationDto = new UserInformationDto(12345L); - - given(mockProviderComposite.findProvider(Oauth2Type.KAKAO)).willReturn(mockProvider); - given(mockProvider.findUserInformation(anyString())).willReturn(userInformationDto); - given(mockProvider.unlinkUserBy(anyString(), anyString())).willReturn(userInformationDto); - - // when && then - assertThatThrownBy(() -> authenticationService.withdrawal(Oauth2Type.KAKAO, "accessToken", refreshToken)) - .isInstanceOf(InvalidWithdrawalException.class) - .hasMessage("탈퇴에 대한 권한 없습니다."); - } - - @Test - void 존재하지_않는_회원이_탈퇴하는_경우_예외가_발생한다() { - // given - given(mockProviderComposite.findProvider(Oauth2Type.KAKAO)).willReturn(mockProvider); - given(mockProvider.findUserInformation(anyString())) - .willThrow(new InvalidTokenException("401 Unauthorized")); - - final String invalidAccessToken = "invalidAccessToken"; - final String invalidRefreshToken = "invalidRefreshToken"; - - // when & then - assertThatThrownBy(() -> authenticationService.withdrawal(Oauth2Type.KAKAO, invalidAccessToken, invalidRefreshToken)) - .isInstanceOf(InvalidTokenException.class) - .hasMessage("401 Unauthorized"); - } } diff --git a/backend/ddang/src/test/java/com/ddang/ddang/authentication/infrastructure/oauth2/KakaoOauth2TypeTest.java b/backend/ddang/src/test/java/com/ddang/ddang/authentication/infrastructure/oauth2/KakaoOauth2TypeTest.java index dc8b804bf..c6a99dd0a 100644 --- a/backend/ddang/src/test/java/com/ddang/ddang/authentication/infrastructure/oauth2/KakaoOauth2TypeTest.java +++ b/backend/ddang/src/test/java/com/ddang/ddang/authentication/infrastructure/oauth2/KakaoOauth2TypeTest.java @@ -1,13 +1,14 @@ package com.ddang.ddang.authentication.infrastructure.oauth2; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +import com.ddang.ddang.authentication.domain.dto.UserInformationDto; import com.ddang.ddang.authentication.domain.exception.UnsupportedSocialLoginException; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; import org.junit.jupiter.api.Test; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; - @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) @SuppressWarnings("NonAsciiCharacters") class KakaoOauth2TypeTest { @@ -38,10 +39,10 @@ class KakaoOauth2TypeTest { @Test void 카카오_회원_ID를_전달하면_고유한_닉네임을_반환한다() { // given - final String randomNumber = "12345"; + final UserInformationDto userInformationDto = new UserInformationDto(12345L); // when - final String actual = Oauth2Type.KAKAO.calculateNickname(randomNumber); + final String actual = Oauth2Type.KAKAO.calculateNickname(userInformationDto); // then assertThat(actual).isEqualTo("kakao12345"); diff --git a/backend/ddang/src/test/java/com/ddang/ddang/authentication/infrastructure/oauth2/kakao/KakaoUserInformationProviderTest.java b/backend/ddang/src/test/java/com/ddang/ddang/authentication/infrastructure/oauth2/kakao/KakaoUserInformationProviderTest.java index 1e15e2108..2659612f8 100644 --- a/backend/ddang/src/test/java/com/ddang/ddang/authentication/infrastructure/oauth2/kakao/KakaoUserInformationProviderTest.java +++ b/backend/ddang/src/test/java/com/ddang/ddang/authentication/infrastructure/oauth2/kakao/KakaoUserInformationProviderTest.java @@ -1,5 +1,12 @@ package com.ddang.ddang.authentication.infrastructure.oauth2.kakao; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.hamcrest.Matchers.matchesPattern; +import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo; +import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess; +import static org.springframework.test.web.client.response.MockRestResponseCreators.withUnauthorizedRequest; + import com.ddang.ddang.authentication.configuration.KakaoProvidersConfigurationProperties; import com.ddang.ddang.authentication.configuration.Oauth2PropertiesConfiguration; import com.ddang.ddang.authentication.domain.dto.UserInformationDto; @@ -17,13 +24,6 @@ import org.springframework.test.web.client.MockRestServiceServer; import org.springframework.web.client.RestTemplate; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.hamcrest.Matchers.matchesPattern; -import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo; -import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess; -import static org.springframework.test.web.client.response.MockRestResponseCreators.withUnauthorizedRequest; - @RestClientTest({KakaoUserInformationProvider.class}) @Import({RestTemplateConfiguration.class, Oauth2PropertiesConfiguration.class}) @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) @@ -91,27 +91,4 @@ void setUp() { .isInstanceOf(RuntimeException.class) .hasMessage("401 Unauthorized"); } - - @Test - void 유효한_카카오_토큰을_전달한_경우_카카오_연결을_끊는다() throws Exception { - // given - final UserInformationDto userInformationDto = new UserInformationDto(12345L); - - mockRestServiceServer.expect(requestTo(matchesPattern(kakaoProperties.userUnlinkUri()))) - .andRespond( - withSuccess( - objectMapper.writeValueAsString(userInformationDto), - MediaType.APPLICATION_JSON - ) - ); - - final String accessToken = "Bearer accessToken"; - final String oauthId = "12345"; - - // when - final UserInformationDto actual = provider.unlinkUserBy(accessToken, oauthId); - - // then - assertThat(actual.id()).isEqualTo(userInformationDto.id()); - } } diff --git a/backend/ddang/src/test/java/com/ddang/ddang/authentication/presentation/AuthenticationControllerTest.java b/backend/ddang/src/test/java/com/ddang/ddang/authentication/presentation/AuthenticationControllerTest.java index ffd196c46..e0b6107e9 100644 --- a/backend/ddang/src/test/java/com/ddang/ddang/authentication/presentation/AuthenticationControllerTest.java +++ b/backend/ddang/src/test/java/com/ddang/ddang/authentication/presentation/AuthenticationControllerTest.java @@ -3,7 +3,6 @@ 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.application.exception.InvalidWithdrawalException; import com.ddang.ddang.authentication.configuration.Oauth2TypeConverter; import com.ddang.ddang.authentication.domain.exception.InvalidTokenException; import com.ddang.ddang.authentication.domain.exception.UnsupportedSocialLoginException; @@ -11,7 +10,6 @@ import com.ddang.ddang.authentication.presentation.dto.request.LoginTokenRequest; 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.request.WithdrawalRequest; import com.ddang.ddang.configuration.RestDocsConfiguration; import com.ddang.ddang.exception.GlobalExceptionHandler; import com.fasterxml.jackson.databind.ObjectMapper; @@ -38,7 +36,6 @@ import org.springframework.test.web.servlet.setup.MockMvcBuilders; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; -import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.BDDMockito.given; @@ -295,55 +292,4 @@ void setUp(@Autowired RestDocumentationContextProvider provider) { ) ); } - - @Test - void ouath2Type과_accessToken과_refreshToken을_전달하면_탈퇴한다() throws Exception { - // given - final WithdrawalRequest request = new WithdrawalRequest("Bearer refreshToken"); - - willDoNothing().given(authenticationService).withdrawal(any(), anyString(), anyString()); - - // when & then - mockMvc.perform(RestDocumentationRequestBuilders.delete("/oauth2/withdrawal/{oauth2Type}", "kakao") - .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(request)) - .header(HttpHeaders.AUTHORIZATION, "Bearer accessToken") - ) - .andExpectAll( - status().isNoContent() - ) - .andDo( - restDocs.document( - pathParameters( - parameterWithName("oauth2Type").description("소셜 로그인을 할 서비스 선택(kakao로 고정)") - ), - requestHeaders( - headerWithName("Authorization").description("회원 Bearer 인증 정보") - ), - requestFields( - fieldWithPath("refreshToken").description("refreshToken") - ) - ) - ); - } - - @Test - void ouath2Type과_accessToken과_refreshToken을_전달시_이미_탈퇴_혹은_존재하지_않아_권한이_없는_회원인_경우_403을_반환한다() throws Exception { - // given - final WithdrawalRequest request = new WithdrawalRequest("Bearer refreshToken"); - - willThrow(new InvalidWithdrawalException("탈퇴에 대한 권한 없습니다.")).given(authenticationService) - .withdrawal(any(), anyString(), anyString()); - - // when & then - mockMvc.perform(RestDocumentationRequestBuilders.delete("/oauth2/withdrawal/{oauth2Type}", "kakao") - .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(request)) - .header(HttpHeaders.AUTHORIZATION, "Bearer accessToken") - ) - .andExpectAll( - status().isForbidden(), - jsonPath("$.message").value("탈퇴에 대한 권한 없습니다.") - ); - } } diff --git a/backend/ddang/src/test/java/com/ddang/ddang/bid/presentation/BidControllerTest.java b/backend/ddang/src/test/java/com/ddang/ddang/bid/presentation/BidControllerTest.java index daa2cc021..a0f6180f2 100644 --- a/backend/ddang/src/test/java/com/ddang/ddang/bid/presentation/BidControllerTest.java +++ b/backend/ddang/src/test/java/com/ddang/ddang/bid/presentation/BidControllerTest.java @@ -470,8 +470,8 @@ void setUp(@Autowired RestDocumentationContextProvider provider) { @Test void 특정_경매에_대한_입찰_목록을_조회한다() throws Exception { // given - final ReadBidDto bid1 = new ReadBidDto("사용자1", 1L, false, 10_000, LocalDateTime.now()); - final ReadBidDto bid2 = new ReadBidDto("사용자2", 2L, false, 12_000, LocalDateTime.now()); + final ReadBidDto bid1 = new ReadBidDto("사용자1", 1L, 10_000, LocalDateTime.now()); + final ReadBidDto bid2 = new ReadBidDto("사용자2", 2L, 12_000, LocalDateTime.now()); given(bidService.readAllByAuctionId(anyLong())).willReturn(List.of(bid1, bid2)); diff --git a/backend/ddang/src/test/java/com/ddang/ddang/category/presentation/CategoryControllerTest.java b/backend/ddang/src/test/java/com/ddang/ddang/category/presentation/CategoryControllerTest.java index 6e6c013eb..760de82e8 100644 --- a/backend/ddang/src/test/java/com/ddang/ddang/category/presentation/CategoryControllerTest.java +++ b/backend/ddang/src/test/java/com/ddang/ddang/category/presentation/CategoryControllerTest.java @@ -13,9 +13,8 @@ import com.ddang.ddang.category.application.dto.ReadCategoryDto; import com.ddang.ddang.category.application.exception.CategoryNotFoundException; import com.ddang.ddang.configuration.RestDocsConfiguration; -import java.util.List; - import com.ddang.ddang.exception.GlobalExceptionHandler; +import java.util.List; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; diff --git a/backend/ddang/src/test/java/com/ddang/ddang/chat/presentation/ChatRoomControllerTest.java b/backend/ddang/src/test/java/com/ddang/ddang/chat/presentation/ChatRoomControllerTest.java index faf5b5e89..986842e96 100644 --- a/backend/ddang/src/test/java/com/ddang/ddang/chat/presentation/ChatRoomControllerTest.java +++ b/backend/ddang/src/test/java/com/ddang/ddang/chat/presentation/ChatRoomControllerTest.java @@ -30,6 +30,7 @@ import com.ddang.ddang.chat.presentation.dto.response.ReadMessageResponse; import com.ddang.ddang.configuration.RestDocsConfiguration; import com.ddang.ddang.exception.GlobalExceptionHandler; +import com.ddang.ddang.notification.application.exception.NotificationFailedException; import com.ddang.ddang.user.application.exception.UserNotFoundException; import com.fasterxml.jackson.databind.ObjectMapper; import org.junit.jupiter.api.BeforeEach; @@ -236,6 +237,34 @@ void setUp(@Autowired RestDocumentationContextProvider provider) { ); } + @Test + void 알림_전송_실패_시_500을_반환한다() throws Exception { + // given + final PrivateClaims privateClaims = new PrivateClaims(1L); + + given(mockTokenDecoder.decode(eq(TokenType.ACCESS), anyString())).willReturn(Optional.of(privateClaims)); + + final Long invalidWriterId = -999L; + final Long chatRoomId = 1L; + final CreateMessageRequest request = new CreateMessageRequest(invalidWriterId, "메시지 내용"); + + final NotificationFailedException notificationFailedException = new NotificationFailedException( + "알림 전송에 실패했습니다." + ); + + given(messageService.create(any(CreateMessageDto.class), anyString())).willThrow(notificationFailedException); + + // when & then + mockMvc.perform(post("/chattings/{chatRoomId}/messages", chatRoomId) + .header(HttpHeaders.AUTHORIZATION, "Bearer accessToken") + .content(objectMapper.writeValueAsString(request)) + .contentType(MediaType.APPLICATION_JSON)) + .andExpectAll( + status().isInternalServerError(), + jsonPath("$.message", is(notificationFailedException.getMessage())) + ); + } + @Test void 마지막_조회_메시지_이후_메시지를_조회한다() throws Exception { // given @@ -369,9 +398,9 @@ void setUp(@Autowired RestDocumentationContextProvider provider) { given(mockTokenDecoder.decode(eq(TokenType.ACCESS), anyString())).willReturn(Optional.of(privateClaims)); - ReadUserInChatRoomDto seller = new ReadUserInChatRoomDto(1L, "사용자1", 1L, 5.0d, false); - final ReadUserInChatRoomDto buyer1 = new ReadUserInChatRoomDto(2L, "사용자2", 2L, 5.0d, false); - final ReadUserInChatRoomDto buyer2 = new ReadUserInChatRoomDto(3L, "사용자3", 3L, 5.0d, false); + ReadUserInChatRoomDto seller = new ReadUserInChatRoomDto(1L, "사용자1", 1L, 5.0d); + final ReadUserInChatRoomDto buyer1 = new ReadUserInChatRoomDto(2L, "사용자2", 2L, 5.0d); + final ReadUserInChatRoomDto buyer2 = new ReadUserInChatRoomDto(3L, "사용자3", 3L, 5.0d); final ReadAuctionInChatRoomDto auctionDto1 = new ReadAuctionInChatRoomDto( 1L, "경매1", @@ -490,8 +519,7 @@ void setUp(@Autowired RestDocumentationContextProvider provider) { 2L, "채팅 상대방", 2L, - 5.0, - false + 5.0 ); final ReadParticipatingChatRoomDto chatRoom = new ReadParticipatingChatRoomDto( diff --git a/backend/ddang/src/test/java/com/ddang/ddang/report/application/ChatRoomReportServiceTest.java b/backend/ddang/src/test/java/com/ddang/ddang/report/application/ChatRoomReportServiceTest.java index 0bb64ee3d..b014282b9 100644 --- a/backend/ddang/src/test/java/com/ddang/ddang/report/application/ChatRoomReportServiceTest.java +++ b/backend/ddang/src/test/java/com/ddang/ddang/report/application/ChatRoomReportServiceTest.java @@ -12,7 +12,7 @@ import com.ddang.ddang.report.application.dto.CreateChatRoomReportDto; import com.ddang.ddang.report.application.dto.ReadChatRoomReportDto; import com.ddang.ddang.report.application.exception.AlreadyReportChatRoomException; -import com.ddang.ddang.report.application.exception.InvalidChatRoomReportException; +import com.ddang.ddang.report.application.exception.ChatRoomReportNotAccessibleException; import com.ddang.ddang.user.application.exception.UserNotFoundException; import com.ddang.ddang.user.domain.User; import com.ddang.ddang.user.infrastructure.persistence.JpaUserRepository; @@ -232,7 +232,7 @@ class ChatRoomReportServiceTest { // when & then assertThatThrownBy(() -> chatRoomReportService.create(createChatRoomReportDto)) - .isInstanceOf(InvalidChatRoomReportException.class) + .isInstanceOf(ChatRoomReportNotAccessibleException.class) .hasMessage("해당 채팅방을 신고할 권한이 없습니다."); } diff --git a/backend/ddang/src/test/java/com/ddang/ddang/report/presentation/ReportControllerTest.java b/backend/ddang/src/test/java/com/ddang/ddang/report/presentation/ReportControllerTest.java index c61525eb4..82ed9679c 100644 --- a/backend/ddang/src/test/java/com/ddang/ddang/report/presentation/ReportControllerTest.java +++ b/backend/ddang/src/test/java/com/ddang/ddang/report/presentation/ReportControllerTest.java @@ -24,7 +24,7 @@ import com.ddang.ddang.report.application.dto.ReadUserInReportDto; import com.ddang.ddang.report.application.exception.AlreadyReportAuctionException; import com.ddang.ddang.report.application.exception.AlreadyReportChatRoomException; -import com.ddang.ddang.report.application.exception.InvalidChatRoomReportException; +import com.ddang.ddang.report.application.exception.ChatRoomReportNotAccessibleException; import com.ddang.ddang.report.application.exception.InvalidReportAuctionException; import com.ddang.ddang.report.application.exception.InvalidReporterToAuctionException; import com.ddang.ddang.report.presentation.dto.request.CreateAuctionReportRequest; @@ -349,7 +349,7 @@ void setUp(@Autowired RestDocumentationContextProvider provider) { final PrivateClaims privateClaims = new PrivateClaims(1L); given(mockTokenDecoder.decode(eq(TokenType.ACCESS), anyString())).willReturn(Optional.of(privateClaims)); - final ReadUserInReportDto userDto = new ReadUserInReportDto(1L, "판매자", 1L, 4.0d, "12345", false); + final ReadUserInReportDto userDto = new ReadUserInReportDto(1L, "판매자", 1L, 4.0d, "12345"); final ReadAuctionInReportDto auctionDto = new ReadAuctionInReportDto( 1L, userDto, @@ -363,21 +363,21 @@ void setUp(@Autowired RestDocumentationContextProvider provider) { ); final ReadAuctionReportDto auctionReportDto1 = new ReadAuctionReportDto( 1L, - new ReadReporterDto(1L, "회원1", 1L, 5.0, false), + new ReadReporterDto(1L, "회원1", 1L, 5.0), LocalDateTime.now(), auctionDto, "신고합니다." ); final ReadAuctionReportDto auctionReportDto2 = new ReadAuctionReportDto( 2L, - new ReadReporterDto(2L, "회원2", 2L, 5.0, false), + new ReadReporterDto(2L, "회원2", 2L, 5.0), LocalDateTime.now(), auctionDto, "신고합니다." ); final ReadAuctionReportDto auctionReportDto3 = new ReadAuctionReportDto( 3L, - new ReadReporterDto(3L, "회원3", 3L, 5.0, false), + new ReadReporterDto(3L, "회원3", 3L, 5.0), LocalDateTime.now(), auctionDto, "신고합니다." @@ -513,10 +513,10 @@ void setUp(@Autowired RestDocumentationContextProvider provider) { final Long unaccessibleUserId = 999L; final PrivateClaims privateClaims = new PrivateClaims(unaccessibleUserId); final CreateChatRoomReportRequest createChatRoomReportRequest = new CreateChatRoomReportRequest(1L, "신고합니다"); - final InvalidChatRoomReportException invalidChatRoomReportException = new InvalidChatRoomReportException("해당 채팅방을 신고할 권한이 없습니다."); + final ChatRoomReportNotAccessibleException chatRoomReportNotAccessibleException = new ChatRoomReportNotAccessibleException("해당 채팅방을 신고할 권한이 없습니다."); given(mockTokenDecoder.decode(eq(TokenType.ACCESS), anyString())).willReturn(Optional.of(privateClaims)); - given(chatRoomReportService.create(any(CreateChatRoomReportDto.class))).willThrow(invalidChatRoomReportException); + given(chatRoomReportService.create(any(CreateChatRoomReportDto.class))).willThrow(chatRoomReportNotAccessibleException); // when & then mockMvc.perform(post("/reports/chat-rooms") @@ -526,7 +526,7 @@ void setUp(@Autowired RestDocumentationContextProvider provider) { ) .andExpectAll( status().isForbidden(), - jsonPath("$.message", is(invalidChatRoomReportException.getMessage())) + jsonPath("$.message", is(chatRoomReportNotAccessibleException.getMessage())) ); } @@ -623,7 +623,7 @@ void setUp(@Autowired RestDocumentationContextProvider provider) { final PrivateClaims privateClaims = new PrivateClaims(1L); given(mockTokenDecoder.decode(eq(TokenType.ACCESS), anyString())).willReturn(Optional.of(privateClaims)); - final ReadUserInReportDto sellerDto = new ReadUserInReportDto(1L, "판매자", 1L, 4.0d, "12345", false); + final ReadUserInReportDto sellerDto = new ReadUserInReportDto(1L, "판매자", 1L, 4.0d, "12345"); final ReadAuctionInReportDto auctionInReportDto = new ReadAuctionInReportDto( 1L, sellerDto, @@ -635,26 +635,26 @@ void setUp(@Autowired RestDocumentationContextProvider provider) { LocalDateTime.now().plusDays(2), 2 ); - final ReadUserInReportDto buyerDto1 = new ReadUserInReportDto(2L, "구매자1", 2L, 4.0d, "12346", false); + final ReadUserInReportDto buyerDto1 = new ReadUserInReportDto(2L, "구매자1", 2L, 4.0d, "12346"); final ReadChatRoomReportDto chatRoomReportDto1 = new ReadChatRoomReportDto( 1L, - new ReadReporterDto(1L, "회원1", 1L, 5.0, false), + new ReadReporterDto(1L, "회원1", 1L, 5.0), LocalDateTime.now(), new ReadChatRoomInReportDto(1L, auctionInReportDto, buyerDto1, false), "신고합니다." ); - final ReadUserInReportDto buyerDto2 = new ReadUserInReportDto(3L, "구매자2", 3L, 4.0d, "12347", false); + final ReadUserInReportDto buyerDto2 = new ReadUserInReportDto(3L, "구매자2", 2L, 4.0d, "12347"); final ReadChatRoomReportDto chatRoomReportDto2 = new ReadChatRoomReportDto( 2L, - new ReadReporterDto(1L, "회원1", 1L, 5.0, false), + new ReadReporterDto(1L, "회원1", 1L, 5.0), LocalDateTime.now(), new ReadChatRoomInReportDto(1L, auctionInReportDto, buyerDto2, false), "신고합니다." ); - final ReadUserInReportDto buyerDto3 = new ReadUserInReportDto(4L, "구매자3", 4L, 4.0d, "12348", false); + final ReadUserInReportDto buyerDto3 = new ReadUserInReportDto(4L, "구매자3", 3L, 4.0d, "12348"); final ReadChatRoomReportDto chatRoomReportDto3 = new ReadChatRoomReportDto( 3L, - new ReadReporterDto(1L, "회원1", 1L, 5.0, false), + new ReadReporterDto(1L, "회원1", 1L, 5.0), LocalDateTime.now(), new ReadChatRoomInReportDto(1L, auctionInReportDto, buyerDto3, false), "신고합니다." diff --git a/backend/ddang/src/test/java/com/ddang/ddang/user/application/UserServiceTest.java b/backend/ddang/src/test/java/com/ddang/ddang/user/application/UserServiceTest.java index c2424a5d2..9ff5ac6d8 100644 --- a/backend/ddang/src/test/java/com/ddang/ddang/user/application/UserServiceTest.java +++ b/backend/ddang/src/test/java/com/ddang/ddang/user/application/UserServiceTest.java @@ -18,6 +18,8 @@ import org.springframework.http.MediaType; import org.springframework.mock.web.MockMultipartFile; +import java.util.Optional; + import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; @@ -93,10 +95,11 @@ class UserServiceTest { new byte[]{1} ); - final UpdateUserDto updateUserDto = new UpdateUserDto("updateName", updateImage); - // when - userService.updateById(user.getId(), updateUserDto); + final ReadUserDto updateName = userService.updateById( + user.getId(), + new UpdateUserDto("updateName", updateImage) + ); // then SoftAssertions.assertSoftly(softAssertions -> { @@ -124,4 +127,58 @@ class UserServiceTest { .isInstanceOf(UserNotFoundException.class) .hasMessage("사용자 정보를 사용할 수 없습니다."); } + + @Test + void 회원_탈퇴한다() { + // given + final User user = User.builder() + .name("사용자") + .profileImage(new ProfileImage("upload.png", "store.png")) + .reliability(4.7d) + .oauthId("12345") + .build(); + + userRepository.save(user); + + // when + userService.deleteById(user.getId()); + + // then + final Optional actual = userRepository.findById(user.getId()); + + SoftAssertions.assertSoftly(softAssertions -> { + softAssertions.assertThat(actual).isPresent(); + softAssertions.assertThat(actual.get().isDeleted()).isTrue(); + }); + } + + @Test + void 회원_탈퇴할때_이미_탈퇴한_회원이면_예외가_발생한다() { + // given + final User user = User.builder() + .name("사용자") + .profileImage(new ProfileImage("upload.png", "store.png")) + .reliability(4.7d) + .oauthId("12345") + .build(); + + user.withdrawal(); + userRepository.save(user); + + // when & then + assertThatThrownBy(() -> userService.deleteById(user.getId())) + .isInstanceOf(UserNotFoundException.class) + .hasMessage("사용자 정보를 사용할 수 없습니다."); + } + + @Test + void 회원_탈퇴할때_존재하지_않는_사용자_정보_조회시_예외를_반환한다() { + // given + final Long invalidUserId = -999L; + + // when & then + assertThatThrownBy(() -> userService.deleteById(invalidUserId)) + .isInstanceOf(UserNotFoundException.class) + .hasMessage("사용자 정보를 사용할 수 없습니다."); + } } diff --git a/backend/ddang/src/test/java/com/ddang/ddang/user/application/dto/ReadUserDtoTest.java b/backend/ddang/src/test/java/com/ddang/ddang/user/application/dto/ReadUserDtoTest.java deleted file mode 100644 index 0db4b66b5..000000000 --- a/backend/ddang/src/test/java/com/ddang/ddang/user/application/dto/ReadUserDtoTest.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.ddang.ddang.user.application.dto; - -import com.ddang.ddang.image.domain.ProfileImage; -import com.ddang.ddang.user.domain.User; -import org.junit.jupiter.api.Test; - -import static org.assertj.core.api.Assertions.assertThat; - -@SuppressWarnings("NonAsciiCharacters") -class ReadUserDtoTest { - - @Test - void dto_생성시_이미지가_있다면_해당_이미지의_아이디가_포함되어_반환된다() { - // given - final User user = User.builder() - .name("회원") - .profileImage(new ProfileImage("upload.png", "store.png")) - .reliability(4.7d) - .oauthId("12345") - .build(); - - // when - final ReadUserDto actual = ReadUserDto.from(user); - - // then - assertThat(actual.profileImageId()).isEqualTo(user.getProfileImage().getId()); - } - - @Test - void dto_생성시_이미지가_없다면_이미지가_null로_처리되어_반환된다() { - // given - final User user = User.builder() - .name("회원") - .reliability(4.7d) - .oauthId("12345") - .build(); - - // when - final ReadUserDto actual = ReadUserDto.from(user); - - // then - assertThat(actual.profileImageId()).isNull(); - } -} diff --git a/backend/ddang/src/test/java/com/ddang/ddang/user/infrastructure/persistence/JpaUserRepositoryTest.java b/backend/ddang/src/test/java/com/ddang/ddang/user/infrastructure/persistence/JpaUserRepositoryTest.java index 5f38a4fff..69a6f94f3 100644 --- a/backend/ddang/src/test/java/com/ddang/ddang/user/infrastructure/persistence/JpaUserRepositoryTest.java +++ b/backend/ddang/src/test/java/com/ddang/ddang/user/infrastructure/persistence/JpaUserRepositoryTest.java @@ -46,7 +46,7 @@ class JpaUserRepositoryTest { em.clear(); // when - final Optional actual = userRepository.findByOauthIdAndDeletedIsFalse(user.getOauthId()); + final Optional actual = userRepository.findByOauthId(user.getOauthId()); // then assertThat(actual).isPresent(); @@ -58,7 +58,7 @@ class JpaUserRepositoryTest { final String invalidOauthId = "invalidOauthId"; // when - final Optional actual = userRepository.findByOauthIdAndDeletedIsFalse(invalidOauthId); + final Optional actual = userRepository.findByOauthId(invalidOauthId); // then assertThat(actual).isEmpty(); @@ -165,39 +165,4 @@ class JpaUserRepositoryTest { // then assertThat(actual).isFalse(); } - - @Test - void 이름이_아직_없다면_거짓을_반환한다() { - // given - final String name = "12345"; - - // when - final boolean actual = userRepository.existsByNameEndingWith(name); - - // then - assertThat(actual).isFalse(); - } - - @Test - void 이름이_있다면_참을_반환한다() { - // given - final String randomNumber = "54321"; - final User user = User.builder() - .name("kakao".concat(randomNumber)) - .profileImage(new ProfileImage("upload.png", "store.png")) - .reliability(4.7d) - .oauthId("12345") - .build(); - - userRepository.save(user); - - em.flush(); - em.clear(); - - // when - final boolean actual = userRepository.existsByNameEndingWith(randomNumber); - - // then - assertThat(actual).isTrue(); - } } diff --git a/backend/ddang/src/test/java/com/ddang/ddang/user/presentation/UserAuctionControllerTest.java b/backend/ddang/src/test/java/com/ddang/ddang/user/presentation/UserAuctionControllerTest.java index 8376dacbd..d8729e386 100644 --- a/backend/ddang/src/test/java/com/ddang/ddang/user/presentation/UserAuctionControllerTest.java +++ b/backend/ddang/src/test/java/com/ddang/ddang/user/presentation/UserAuctionControllerTest.java @@ -69,7 +69,6 @@ @AutoConfigureRestDocs @Import(RestDocsConfiguration.class) @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) -@SuppressWarnings("NonAsciiCharacters") class UserAuctionControllerTest { @MockBean @@ -143,8 +142,7 @@ void setUp(@Autowired RestDocumentationContextProvider provider) { 1L, 1L, "판매자", - 3.5d, - false + 3.5d ); final ReadAuctionDto auction2 = new ReadAuctionDto( 2L, @@ -164,8 +162,7 @@ void setUp(@Autowired RestDocumentationContextProvider provider) { 1L, 1L, "판매자", - 3.5d, - false + 3.5d ); final PrivateClaims privateClaims = new PrivateClaims(1L); final ReadAuctionsDto readAuctionsDto = new ReadAuctionsDto(List.of(auction2, auction1), true); @@ -245,8 +242,7 @@ void setUp(@Autowired RestDocumentationContextProvider provider) { 1L, 1L, "판매자", - 3.5d, - false + 3.5d ); final ReadAuctionDto auction2 = new ReadAuctionDto( 2L, @@ -266,8 +262,7 @@ void setUp(@Autowired RestDocumentationContextProvider provider) { 1L, 1L, "판매자", - 3.5d, - false + 3.5d ); final PrivateClaims privateClaims = new PrivateClaims(1L); final ReadAuctionsDto readAuctionsDto = new ReadAuctionsDto(List.of(auction2, auction1), true); diff --git a/backend/ddang/src/test/java/com/ddang/ddang/user/presentation/UserControllerTest.java b/backend/ddang/src/test/java/com/ddang/ddang/user/presentation/UserControllerTest.java index 9087cc5b3..000c46227 100644 --- a/backend/ddang/src/test/java/com/ddang/ddang/user/presentation/UserControllerTest.java +++ b/backend/ddang/src/test/java/com/ddang/ddang/user/presentation/UserControllerTest.java @@ -46,9 +46,11 @@ import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.BDDMockito.given; +import static org.mockito.BDDMockito.willDoNothing; import static org.mockito.Mockito.mock; import static org.springframework.restdocs.headers.HeaderDocumentation.headerWithName; import static org.springframework.restdocs.headers.HeaderDocumentation.requestHeaders; +import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.delete; import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get; import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath; import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields; @@ -119,7 +121,7 @@ void setUp(@Autowired RestDocumentationContextProvider provider) { @Test void 사용자_정보를_조회한다() throws Exception { // given - final ReadUserDto readUserDto = new ReadUserDto(1L, "사용자1", 1L, 4.6d, "12345", false); + final ReadUserDto readUserDto = new ReadUserDto(1L, "사용자1", 1L, 4.6d, "12345"); final PrivateClaims privateClaims = new PrivateClaims(1L); given(mockTokenDecoder.decode(eq(TokenType.ACCESS), anyString())).willReturn(Optional.of(privateClaims)); @@ -151,24 +153,22 @@ void setUp(@Autowired RestDocumentationContextProvider provider) { } @Test - void 탈퇴한_사용자_정보를_조회한다() throws Exception { + void 존재하지_않는_사용자_정보_조회시_404를_반환한다() throws Exception { // given - final ReadUserDto readUserDto = new ReadUserDto(1L, "사용자1", 1L, 4.6d, "12345", true); + final UserNotFoundException userNotFoundException = new UserNotFoundException("사용자 정보를 사용할 수 없습니다."); final PrivateClaims privateClaims = new PrivateClaims(1L); given(mockTokenDecoder.decode(eq(TokenType.ACCESS), anyString())).willReturn(Optional.of(privateClaims)); - given(userService.readById(anyLong())).willReturn(readUserDto); + given(userService.readById(anyLong())).willThrow(userNotFoundException); // when & then mockMvc.perform(get("/users") .header(HttpHeaders.AUTHORIZATION, "Bearer accessToken") ) .andExpectAll( - status().isOk(), - jsonPath("$.name", is("알 수 없음")), - jsonPath("$.profileImage").exists(), - jsonPath("$.reliability", is(readUserDto.reliability())) - ); + status().isNotFound(), + jsonPath("$.message", is(userNotFoundException.getMessage())) + ); } @Test @@ -188,7 +188,7 @@ void setUp(@Autowired RestDocumentationContextProvider provider) { objectMapper.writeValueAsBytes(updateUserRequest) ); - final ReadUserDto readUserDto = new ReadUserDto(1L, "사용자1", 1L, 4.6d, "12345", false); + final ReadUserDto readUserDto = new ReadUserDto(1L, "사용자1", 1L, 4.6d, "12345"); final PrivateClaims privateClaims = new PrivateClaims(1L); given(userService.updateById(anyLong(), any())).willReturn(readUserDto); @@ -227,21 +227,18 @@ void setUp(@Autowired RestDocumentationContextProvider provider) { } @Test - void 존재하지_않는_사용자_정보_조회시_404를_반환한다() throws Exception { + void 회원_탈퇴한다() throws Exception { // given - final UserNotFoundException userNotFoundException = new UserNotFoundException("사용자 정보를 사용할 수 없습니다."); final PrivateClaims privateClaims = new PrivateClaims(1L); given(mockTokenDecoder.decode(eq(TokenType.ACCESS), anyString())).willReturn(Optional.of(privateClaims)); - given(userService.readById(anyLong())).willThrow(userNotFoundException); + willDoNothing().given(userService).deleteById(anyLong()); // when & then - mockMvc.perform(get("/users") - .header(HttpHeaders.AUTHORIZATION, "Bearer accessToken") - ) - .andExpectAll( - status().isNotFound(), - jsonPath("$.message", is(userNotFoundException.getMessage())) - ); + mockMvc.perform(delete("/users/withdrawal") + .header(HttpHeaders.AUTHORIZATION, "Bearer accessToken") + ).andExpectAll( + status().isNoContent() + ); } } diff --git a/backend/ddang/src/test/resources/application.yml b/backend/ddang/src/test/resources/application.yml index a19fe1833..cc1bc93d5 100644 --- a/backend/ddang/src/test/resources/application.yml +++ b/backend/ddang/src/test/resources/application.yml @@ -40,7 +40,6 @@ oauth2: providers: kakao: user-info-uri: https://kapi.kakao.com/v2/user/me - user-unlink-uri: https://kapi.kakao.com/v1/user/unlink fcm: enabled: false