diff --git a/Api/build.gradle b/Api/build.gradle index 92930493..93615c1b 100644 --- a/Api/build.gradle +++ b/Api/build.gradle @@ -11,12 +11,9 @@ repositories { dependencies { implementation 'org.springframework.boot:spring-boot-starter-web' - implementation 'org.springframework.boot:spring-boot-starter-validation' implementation 'org.springframework.boot:spring-boot-starter-security' // swagger -// implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.0.4' -// implementation 'org.springdoc:springdoc-openapi-starter-webmvc-api:2.0.4' implementation 'org.springdoc:springdoc-openapi-ui:1.6.12' implementation project(':Domain') diff --git a/Api/src/main/java/allchive/server/api/archiving/service/UpdateArchivingScrapUseCase.java b/Api/src/main/java/allchive/server/api/archiving/service/UpdateArchivingScrapUseCase.java index 5e8bcd0d..4bce3f22 100644 --- a/Api/src/main/java/allchive/server/api/archiving/service/UpdateArchivingScrapUseCase.java +++ b/Api/src/main/java/allchive/server/api/archiving/service/UpdateArchivingScrapUseCase.java @@ -27,7 +27,7 @@ public void execute(Long archivingId, Boolean cancel) { archivingValidator.validateExistById(archivingId); Long userId = SecurityUtil.getCurrentUserId(); archivingValidator.validateDeleteStatus(archivingId, userId); - User user = userAdaptor.queryUserById(userId); + User user = userAdaptor.findUserById(userId); if (cancel) { scrapDomainService.deleteScrapByUserAndArchivingId(user, archivingId); archivingDomainService.updateScrapCount(archivingId, -1); diff --git a/Api/src/main/java/allchive/server/api/auth/controller/AuthController.java b/Api/src/main/java/allchive/server/api/auth/controller/AuthController.java index 87e83022..6cb01deb 100644 --- a/Api/src/main/java/allchive/server/api/auth/controller/AuthController.java +++ b/Api/src/main/java/allchive/server/api/auth/controller/AuthController.java @@ -24,8 +24,11 @@ public class AuthController { @Operation(summary = "회원탈퇴를 합니다.") @DeleteMapping("/withdrawal/{provider}") - public void withDrawUser(@PathVariable OauthProvider provider) { - withdrawUserUseCase.execute(provider); + public void withDrawUser( + @PathVariable OauthProvider provider, + @RequestParam(required = false, name = "appleAccessToken", value = "") + String appleAccessToken) { + withdrawUserUseCase.execute(provider, appleAccessToken); } @Operation(summary = "로그아웃을 합니다.") diff --git a/Api/src/main/java/allchive/server/api/auth/model/dto/request/RegisterRequest.java b/Api/src/main/java/allchive/server/api/auth/model/dto/request/RegisterRequest.java index 039fd65c..fe3d10f2 100644 --- a/Api/src/main/java/allchive/server/api/auth/model/dto/request/RegisterRequest.java +++ b/Api/src/main/java/allchive/server/api/auth/model/dto/request/RegisterRequest.java @@ -1,7 +1,11 @@ package allchive.server.api.auth.model.dto.request; +import allchive.server.core.annotation.ValidEnum; +import allchive.server.domain.domains.archiving.domain.enums.Category; +import io.swagger.v3.oas.annotations.media.ArraySchema; import io.swagger.v3.oas.annotations.media.Schema; +import java.util.List; import javax.validation.constraints.NotBlank; import lombok.Getter; import lombok.NoArgsConstructor; @@ -10,12 +14,16 @@ @NoArgsConstructor public class RegisterRequest { @Schema( - defaultValue = "staging/archiving/1/d241218a-a64c-4443-8aa4-ce98017a3d12", + defaultValue = + "https://asset.allchive.co.kr/staging/archiving/1/d241218a-a64c-4443-8aa4-ce98017a3d12", description = "프로필 이미지 url") - @NotBlank(message = "프로필 이미지 key를 입력하세요") - private String profileImgKey; + @NotBlank(message = "프로필 이미지 url을 입력하세요") + private String profileImgUrl; @Schema(defaultValue = "닉네임", description = "닉네임") @NotBlank(message = "닉네임을 입력하세요") private String nickname; + + @ArraySchema(schema = @Schema(description = "관심 주제", defaultValue = "FOOD")) + private List<@ValidEnum(target = Category.class) Category> categories; } diff --git a/Api/src/main/java/allchive/server/api/auth/service/OauthLinkUseCase.java b/Api/src/main/java/allchive/server/api/auth/service/OauthLinkUseCase.java index a746502f..2892db3a 100644 --- a/Api/src/main/java/allchive/server/api/auth/service/OauthLinkUseCase.java +++ b/Api/src/main/java/allchive/server/api/auth/service/OauthLinkUseCase.java @@ -2,38 +2,21 @@ import allchive.server.api.auth.model.dto.response.OauthLoginLinkResponse; -import allchive.server.api.auth.service.helper.AppleOAuthHelper; -import allchive.server.api.auth.service.helper.KakaoOauthHelper; +import allchive.server.api.auth.service.helper.OauthHelper; import allchive.server.core.annotation.UseCase; -import allchive.server.core.error.exception.InvalidOauthProviderException; import allchive.server.domain.domains.user.domain.enums.OauthProvider; import lombok.RequiredArgsConstructor; @UseCase @RequiredArgsConstructor public class OauthLinkUseCase { - private final KakaoOauthHelper kakaoOauthHelper; - private final AppleOAuthHelper appleOAuthHelper; + private final OauthHelper oauthHelper; public OauthLoginLinkResponse getOauthLinkDev(OauthProvider provider) { - switch (provider) { - case KAKAO: - return new OauthLoginLinkResponse(kakaoOauthHelper.getKaKaoOauthLinkDev()); - case APPLE: - return new OauthLoginLinkResponse(appleOAuthHelper.getAppleOauthLinkDev()); - default: - throw InvalidOauthProviderException.EXCEPTION; - } + return oauthHelper.getOauthLinkDev(provider); } public OauthLoginLinkResponse getOauthLink(OauthProvider provider, String referer) { - switch (provider) { - case KAKAO: - return new OauthLoginLinkResponse(kakaoOauthHelper.getKaKaoOauthLink(referer)); - case APPLE: - return new OauthLoginLinkResponse(appleOAuthHelper.getAppleOAuthLink(referer)); - default: - throw InvalidOauthProviderException.EXCEPTION; - } + return oauthHelper.getOauthLink(provider, referer); } } diff --git a/Api/src/main/java/allchive/server/api/auth/service/OauthLoginUseCase.java b/Api/src/main/java/allchive/server/api/auth/service/OauthLoginUseCase.java index 7de13592..2886b644 100644 --- a/Api/src/main/java/allchive/server/api/auth/service/OauthLoginUseCase.java +++ b/Api/src/main/java/allchive/server/api/auth/service/OauthLoginUseCase.java @@ -3,11 +3,9 @@ import allchive.server.api.auth.model.dto.response.OauthSignInResponse; import allchive.server.api.auth.model.dto.response.OauthTokenResponse; -import allchive.server.api.auth.service.helper.AppleOAuthHelper; -import allchive.server.api.auth.service.helper.KakaoOauthHelper; +import allchive.server.api.auth.service.helper.OauthHelper; import allchive.server.api.auth.service.helper.TokenGenerateHelper; import allchive.server.core.annotation.UseCase; -import allchive.server.core.error.exception.InvalidOauthProviderException; import allchive.server.domain.domains.user.domain.User; import allchive.server.domain.domains.user.domain.enums.OauthInfo; import allchive.server.domain.domains.user.domain.enums.OauthProvider; @@ -17,13 +15,13 @@ @UseCase @RequiredArgsConstructor public class OauthLoginUseCase { - private final KakaoOauthHelper kakaoOauthHelper; - private final AppleOAuthHelper appleOAuthHelper; + private final OauthHelper oauthHelper; private final UserDomainService userDomainService; private final TokenGenerateHelper tokenGenerateHelper; public OauthSignInResponse loginWithCode(OauthProvider provider, String code, String referer) { - final OauthTokenResponse oauthTokenResponse = getCredential(provider, code, referer); + final OauthTokenResponse oauthTokenResponse = + oauthHelper.getCredential(provider, code, referer); return processLoginWithIdToken(provider, oauthTokenResponse.getIdToken()); } @@ -32,12 +30,12 @@ public OauthSignInResponse loginWithIdToken(OauthProvider provider, String idTok } public OauthSignInResponse devLogin(OauthProvider provider, String code) { - final OauthTokenResponse oauthTokenResponse = getCredentialDev(provider, code); + final OauthTokenResponse oauthTokenResponse = oauthHelper.getCredentialDev(provider, code); return processLoginWithIdToken(provider, oauthTokenResponse.getIdToken()); } private OauthSignInResponse processLoginWithIdToken(OauthProvider provider, String idToken) { - final OauthInfo oauthInfo = getOauthInfo(provider, idToken); + final OauthInfo oauthInfo = oauthHelper.getOauthInfo(provider, idToken); if (userDomainService.checkUserCanLogin(oauthInfo)) { User user = userDomainService.loginUser(oauthInfo); return tokenGenerateHelper.execute(user); @@ -45,39 +43,4 @@ private OauthSignInResponse processLoginWithIdToken(OauthProvider provider, Stri return OauthSignInResponse.cannotLogin(idToken); } } - - /** idtoken 가져오기 * */ - private OauthTokenResponse getCredential(OauthProvider provider, String code, String referer) { - switch (provider) { - case KAKAO: - return OauthTokenResponse.from(kakaoOauthHelper.getKakaoOauthToken(code, referer)); - case APPLE: - return OauthTokenResponse.from(appleOAuthHelper.getAppleOAuthToken(code, referer)); - default: - throw InvalidOauthProviderException.EXCEPTION; - } - } - - private OauthTokenResponse getCredentialDev(OauthProvider provider, String code) { - switch (provider) { - case KAKAO: - return OauthTokenResponse.from(kakaoOauthHelper.getKakaoOauthTokenDev(code)); - case APPLE: - return OauthTokenResponse.from(appleOAuthHelper.getAppleOAuthTokenDev(code)); - default: - throw InvalidOauthProviderException.EXCEPTION; - } - } - - /** idtoken 분석 * */ - private OauthInfo getOauthInfo(OauthProvider provider, String idToken) { - switch (provider) { - case KAKAO: - return kakaoOauthHelper.getKakaoOauthInfoByIdToken(idToken); - case APPLE: - return appleOAuthHelper.getAppleOAuthInfoByIdToken(idToken); - default: - throw InvalidOauthProviderException.EXCEPTION; - } - } } diff --git a/Api/src/main/java/allchive/server/api/auth/service/OauthRegisterUseCase.java b/Api/src/main/java/allchive/server/api/auth/service/OauthRegisterUseCase.java index f1259baf..377dc16d 100644 --- a/Api/src/main/java/allchive/server/api/auth/service/OauthRegisterUseCase.java +++ b/Api/src/main/java/allchive/server/api/auth/service/OauthRegisterUseCase.java @@ -3,11 +3,10 @@ import allchive.server.api.auth.model.dto.request.RegisterRequest; import allchive.server.api.auth.model.dto.response.OauthRegisterResponse; -import allchive.server.api.auth.service.helper.AppleOAuthHelper; -import allchive.server.api.auth.service.helper.KakaoOauthHelper; +import allchive.server.api.auth.service.helper.OauthHelper; import allchive.server.api.auth.service.helper.TokenGenerateHelper; +import allchive.server.api.common.util.UrlUtil; import allchive.server.core.annotation.UseCase; -import allchive.server.core.error.exception.InvalidOauthProviderException; import allchive.server.domain.domains.user.domain.User; import allchive.server.domain.domains.user.domain.enums.OauthInfo; import allchive.server.domain.domains.user.domain.enums.OauthProvider; @@ -17,31 +16,19 @@ @UseCase @RequiredArgsConstructor public class OauthRegisterUseCase { - private final KakaoOauthHelper kakaoOauthHelper; - private final AppleOAuthHelper appleOAuthHelper; + private final OauthHelper oauthHelper; private final UserDomainService userDomainService; private final TokenGenerateHelper tokenGenerateHelper; public OauthRegisterResponse execute( OauthProvider provider, String idToken, RegisterRequest registerRequest) { - final OauthInfo oauthInfo = getOauthInfo(provider, idToken); + final OauthInfo oauthInfo = oauthHelper.getOauthInfo(provider, idToken); final User user = userDomainService.registerUser( registerRequest.getNickname(), - registerRequest.getProfileImgKey(), + UrlUtil.convertUrlToKey(registerRequest.getProfileImgUrl()), + registerRequest.getCategories(), oauthInfo); return OauthRegisterResponse.from(tokenGenerateHelper.execute(user)); } - - /** idtoken 분석 * */ - private OauthInfo getOauthInfo(OauthProvider provider, String idToken) { - switch (provider) { - case KAKAO: - return kakaoOauthHelper.getKakaoOauthInfoByIdToken(idToken); - case APPLE: - return appleOAuthHelper.getAppleOAuthInfoByIdToken(idToken); - default: - throw InvalidOauthProviderException.EXCEPTION; - } - } } diff --git a/Api/src/main/java/allchive/server/api/auth/service/TokenRefreshUseCase.java b/Api/src/main/java/allchive/server/api/auth/service/TokenRefreshUseCase.java index db69553e..a0178221 100644 --- a/Api/src/main/java/allchive/server/api/auth/service/TokenRefreshUseCase.java +++ b/Api/src/main/java/allchive/server/api/auth/service/TokenRefreshUseCase.java @@ -22,7 +22,7 @@ public class TokenRefreshUseCase { public OauthRegisterResponse execute(String refreshToken) { RefreshTokenEntity oldToken = refreshTokenAdaptor.findTokenByRefreshToken(refreshToken); Long userId = jwtTokenProvider.parseRefreshToken(oldToken.getRefreshToken()); - User user = userAdaptor.queryUserById(userId); + User user = userAdaptor.findUserById(userId); return OauthRegisterResponse.from(tokenGenerateHelper.execute(user)); } } diff --git a/Api/src/main/java/allchive/server/api/auth/service/WithdrawUserUseCase.java b/Api/src/main/java/allchive/server/api/auth/service/WithdrawUserUseCase.java index 6adab4c3..3cc54328 100644 --- a/Api/src/main/java/allchive/server/api/auth/service/WithdrawUserUseCase.java +++ b/Api/src/main/java/allchive/server/api/auth/service/WithdrawUserUseCase.java @@ -1,42 +1,81 @@ package allchive.server.api.auth.service; -import allchive.server.api.auth.service.helper.AppleOAuthHelper; -import allchive.server.api.auth.service.helper.KakaoOauthHelper; +import allchive.server.api.auth.service.helper.OauthHelper; import allchive.server.api.config.security.SecurityUtil; import allchive.server.core.annotation.UseCase; import allchive.server.core.error.exception.InvalidOauthProviderException; +import allchive.server.domain.domains.archiving.adaptor.ArchivingAdaptor; +import allchive.server.domain.domains.archiving.domain.Archiving; +import allchive.server.domain.domains.block.service.BlockDomainService; +import allchive.server.domain.domains.content.adaptor.ContentAdaptor; +import allchive.server.domain.domains.content.adaptor.TagAdaptor; +import allchive.server.domain.domains.content.domain.Tag; +import allchive.server.domain.domains.content.service.ContentDomainService; +import allchive.server.domain.domains.content.service.ContentTagGroupDomainService; +import allchive.server.domain.domains.content.service.TagDomainService; +import allchive.server.domain.domains.recycle.service.RecycleDomainService; +import allchive.server.domain.domains.report.service.ReportDomainService; +import allchive.server.domain.domains.search.service.LatestSearchDomainService; import allchive.server.domain.domains.user.adaptor.RefreshTokenAdaptor; import allchive.server.domain.domains.user.adaptor.UserAdaptor; import allchive.server.domain.domains.user.domain.User; import allchive.server.domain.domains.user.domain.enums.OauthProvider; +import allchive.server.domain.domains.user.service.ScrapDomainService; import allchive.server.domain.domains.user.service.UserDomainService; import lombok.RequiredArgsConstructor; +import java.util.List; + @UseCase @RequiredArgsConstructor public class WithdrawUserUseCase { - private final KakaoOauthHelper kakaoOauthHelper; - private final AppleOAuthHelper appleOAuthHelper; private final UserAdaptor userAdaptor; + private final OauthHelper oauthHelper; private final RefreshTokenAdaptor refreshTokenAdaptor; + private final LatestSearchDomainService latestSearchDomainService; + private final ScrapDomainService scrapDomainService; + private final BlockDomainService blockDomainService; + private final ArchivingAdaptor archivingAdaptor; + private final TagAdaptor tagAdaptor; + private final ContentTagGroupDomainService contentTagGroupDomainService; + private final ContentDomainService contentDomainService; + private final TagDomainService tagDomainService; + private final RecycleDomainService recycleDomainService; + private final ReportDomainService reportDomainService; private final UserDomainService userDomainService; - public void execute(OauthProvider provider) { + public void execute(OauthProvider provider, String appleAccessToken) { Long userId = SecurityUtil.getCurrentUserId(); - User user = userAdaptor.queryUserById(userId); - // 우리쪽 탈퇴 - refreshTokenAdaptor.deleteTokenByUserId(userId); + User user = userAdaptor.findUserById(userId); // oauth쪽 탈퇴 + withdrawOauth(provider, appleAccessToken, user); + // 우리쪽 탈퇴 + withdrawService(userId, user); + } + + private void withdrawOauth(OauthProvider provider, String appleAccessToken, User user) { switch (provider) { - case KAKAO: - kakaoOauthHelper.withdrawKakaoOauthUser(user.getOauthInfo().getOid()); - break; - // case APPLE: - // appleOAuthHelper.withdrawAppleOauthUser(); - default: - throw InvalidOauthProviderException.EXCEPTION; + case KAKAO -> oauthHelper.withdraw(provider, user.getOauthInfo().getOid(), null); + case APPLE -> oauthHelper.withdraw(provider, null, appleAccessToken); + default -> throw InvalidOauthProviderException.EXCEPTION; } + + } + + private void withdrawService(Long userId, User user) { + refreshTokenAdaptor.deleteTokenByUserId(userId); + latestSearchDomainService.deleteAllByUserId(userId); + scrapDomainService.deleteAllByUser(user); + blockDomainService.queryDeleteBlockByBlockFromOrBlockUser(userId); + List archivingList = archivingAdaptor.findAllByUserId(userId); + List archivingId = archivingList.stream().map(Archiving::getId).toList(); + List tagList = tagAdaptor.findAllByUserId(userId); + contentTagGroupDomainService.deleteAllByTagIn(tagList); + tagDomainService.deleteAll(tagList); + contentDomainService.deleteAllByArchivingIdIn(archivingId); + recycleDomainService.deleteAllByUserId(userId); + reportDomainService.deleteAllByReportedUserId(userId); userDomainService.deleteUserById(userId); } } diff --git a/Api/src/main/java/allchive/server/api/auth/service/helper/AppleOAuthHelper.java b/Api/src/main/java/allchive/server/api/auth/service/helper/AppleOauthHelper.java similarity index 92% rename from Api/src/main/java/allchive/server/api/auth/service/helper/AppleOAuthHelper.java rename to Api/src/main/java/allchive/server/api/auth/service/helper/AppleOauthHelper.java index 2dbd9acf..5bdb06e0 100644 --- a/Api/src/main/java/allchive/server/api/auth/service/helper/AppleOAuthHelper.java +++ b/Api/src/main/java/allchive/server/api/auth/service/helper/AppleOauthHelper.java @@ -16,7 +16,7 @@ @Helper @RequiredArgsConstructor -public class AppleOAuthHelper { +public class AppleOauthHelper { private final AppleOAuthProperties appleOAuthProperties; private final AppleOAuthClient appleOAuthClient; private final AppleOIDCClient appleOIDCClient; @@ -76,11 +76,10 @@ public OIDCDecodePayload getOIDCDecodePayload(String token) { } /** apple측 회원 탈퇴 * */ - // public void withdrawAppleOauthUser(String appleOAuthAccessToken) { - // appleOAuthClient.revoke( - // appleOAuthProperties.getClientId(), appleOAuthAccessToken, - // this.getClientSecret()); - // } + public void withdrawAppleOauthUser(String appleOAuthAccessToken) { + appleOAuthClient.revoke( + appleOAuthProperties.getClientId(), appleOAuthAccessToken, this.getClientSecret()); + } /** client secret 가져오기 * */ private String getClientSecret() { diff --git a/Api/src/main/java/allchive/server/api/auth/service/helper/OauthHelper.java b/Api/src/main/java/allchive/server/api/auth/service/helper/OauthHelper.java new file mode 100644 index 00000000..b76acbbb --- /dev/null +++ b/Api/src/main/java/allchive/server/api/auth/service/helper/OauthHelper.java @@ -0,0 +1,88 @@ +package allchive.server.api.auth.service.helper; + + +import allchive.server.api.auth.model.dto.response.OauthLoginLinkResponse; +import allchive.server.api.auth.model.dto.response.OauthTokenResponse; +import allchive.server.core.annotation.Helper; +import allchive.server.core.error.exception.InvalidOauthProviderException; +import allchive.server.domain.domains.user.domain.enums.OauthInfo; +import allchive.server.domain.domains.user.domain.enums.OauthProvider; +import lombok.RequiredArgsConstructor; + +@Helper +@RequiredArgsConstructor +public class OauthHelper { + private final KakaoOauthHelper kakaoOauthHelper; + private final AppleOauthHelper appleOauthHelper; + + /** oauth link 가져오기 * */ + public OauthLoginLinkResponse getOauthLinkDev(OauthProvider provider) { + switch (provider) { + case KAKAO: + return new OauthLoginLinkResponse(kakaoOauthHelper.getKaKaoOauthLinkDev()); + case APPLE: + return new OauthLoginLinkResponse(appleOauthHelper.getAppleOauthLinkDev()); + default: + throw InvalidOauthProviderException.EXCEPTION; + } + } + + public OauthLoginLinkResponse getOauthLink(OauthProvider provider, String referer) { + switch (provider) { + case KAKAO: + return new OauthLoginLinkResponse(kakaoOauthHelper.getKaKaoOauthLink(referer)); + case APPLE: + return new OauthLoginLinkResponse(appleOauthHelper.getAppleOAuthLink(referer)); + default: + throw InvalidOauthProviderException.EXCEPTION; + } + } + + /** idtoken 가져오기 * */ + public OauthTokenResponse getCredential(OauthProvider provider, String code, String referer) { + switch (provider) { + case KAKAO: + return OauthTokenResponse.from(kakaoOauthHelper.getKakaoOauthToken(code, referer)); + case APPLE: + return OauthTokenResponse.from(appleOauthHelper.getAppleOAuthToken(code, referer)); + default: + throw InvalidOauthProviderException.EXCEPTION; + } + } + + public OauthTokenResponse getCredentialDev(OauthProvider provider, String code) { + switch (provider) { + case KAKAO: + return OauthTokenResponse.from(kakaoOauthHelper.getKakaoOauthTokenDev(code)); + case APPLE: + return OauthTokenResponse.from(appleOauthHelper.getAppleOAuthTokenDev(code)); + default: + throw InvalidOauthProviderException.EXCEPTION; + } + } + + /** idtoken 분석 * */ + public OauthInfo getOauthInfo(OauthProvider provider, String idToken) { + switch (provider) { + case KAKAO: + return kakaoOauthHelper.getKakaoOauthInfoByIdToken(idToken); + case APPLE: + return appleOauthHelper.getAppleOAuthInfoByIdToken(idToken); + default: + throw InvalidOauthProviderException.EXCEPTION; + } + } + + /** 회원탈퇴 * */ + public void withdraw(OauthProvider provider, String oid, String appleAccessToken) { + switch (provider) { + case KAKAO: + kakaoOauthHelper.withdrawKakaoOauthUser(oid); + break; + case APPLE: + appleOauthHelper.withdrawAppleOauthUser(appleAccessToken); + default: + throw InvalidOauthProviderException.EXCEPTION; + } + } +} diff --git a/Api/src/main/java/allchive/server/api/block/service/CreateBlockUseCase.java b/Api/src/main/java/allchive/server/api/block/service/CreateBlockUseCase.java index f66bdbaa..6fef2c73 100644 --- a/Api/src/main/java/allchive/server/api/block/service/CreateBlockUseCase.java +++ b/Api/src/main/java/allchive/server/api/block/service/CreateBlockUseCase.java @@ -28,6 +28,6 @@ public BlockResponse execute(BlockRequest request) { blockValidator.validateNotMyself(userId, request.getUserId()); Block block = blockMapper.toEntity(userId, request.getUserId()); blockDomainService.save(block); - return BlockResponse.from(userAdaptor.queryUserById(request.getUserId()).getNickname()); + return BlockResponse.from(userAdaptor.findUserById(request.getUserId()).getNickname()); } } diff --git a/Api/src/main/java/allchive/server/api/block/service/DeleteBlockUseCase.java b/Api/src/main/java/allchive/server/api/block/service/DeleteBlockUseCase.java index fb829c6a..b61eec5c 100644 --- a/Api/src/main/java/allchive/server/api/block/service/DeleteBlockUseCase.java +++ b/Api/src/main/java/allchive/server/api/block/service/DeleteBlockUseCase.java @@ -23,6 +23,6 @@ public BlockResponse execute(BlockRequest request) { Long userId = SecurityUtil.getCurrentUserId(); blockValidator.validateExist(userId, request.getUserId()); blockDomainService.deleteByBlockFromAndBlockUser(userId, request.getUserId()); - return BlockResponse.from(userAdaptor.queryUserById(request.getUserId()).getNickname()); + return BlockResponse.from(userAdaptor.findUserById(request.getUserId()).getNickname()); } } diff --git a/Api/src/main/java/allchive/server/api/config/security/SecurityConfig.java b/Api/src/main/java/allchive/server/api/config/security/SecurityConfig.java index 42cb8ee5..cfd71a98 100644 --- a/Api/src/main/java/allchive/server/api/config/security/SecurityConfig.java +++ b/Api/src/main/java/allchive/server/api/config/security/SecurityConfig.java @@ -35,6 +35,8 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { .permitAll() .mvcMatchers("/auth/oauth/**") .permitAll() + .mvcMatchers("/user/nickname") + .permitAll() .mvcMatchers("/auth/token/refresh") .permitAll() .mvcMatchers("/**/health/**") diff --git a/Api/src/main/java/allchive/server/api/report/model/mapper/ReportMapper.java b/Api/src/main/java/allchive/server/api/report/model/mapper/ReportMapper.java index 3cc73d79..b86c9e1c 100644 --- a/Api/src/main/java/allchive/server/api/report/model/mapper/ReportMapper.java +++ b/Api/src/main/java/allchive/server/api/report/model/mapper/ReportMapper.java @@ -8,7 +8,7 @@ @Mapper public class ReportMapper { - public Report toEntity(CreateReportRequest request, ReportObjectType type, Long userId) { + public Report toEntity(CreateReportRequest request, ReportObjectType type, Long userId, Long reportedUserId) { Report report = null; switch (type) { case CONTENT -> report = @@ -18,7 +18,8 @@ public Report toEntity(CreateReportRequest request, ReportObjectType type, Long request.getReportedType(), request.getId(), null, - userId); + userId, + reportedUserId); case ARCHIVING -> report = Report.of( type, @@ -26,7 +27,8 @@ public Report toEntity(CreateReportRequest request, ReportObjectType type, Long request.getReportedType(), null, request.getId(), - userId); + userId, + reportedUserId); } return report; } diff --git a/Api/src/main/java/allchive/server/api/report/service/CreateReportUseCase.java b/Api/src/main/java/allchive/server/api/report/service/CreateReportUseCase.java index 1f58aa1a..07681e8b 100644 --- a/Api/src/main/java/allchive/server/api/report/service/CreateReportUseCase.java +++ b/Api/src/main/java/allchive/server/api/report/service/CreateReportUseCase.java @@ -5,7 +5,9 @@ import allchive.server.api.report.model.dto.request.CreateReportRequest; import allchive.server.api.report.model.mapper.ReportMapper; import allchive.server.core.annotation.UseCase; +import allchive.server.domain.domains.archiving.adaptor.ArchivingAdaptor; import allchive.server.domain.domains.archiving.validator.ArchivingValidator; +import allchive.server.domain.domains.content.adaptor.ContentAdaptor; import allchive.server.domain.domains.content.validator.ContentValidator; import allchive.server.domain.domains.report.domain.Report; import allchive.server.domain.domains.report.domain.enums.ReportObjectType; @@ -19,6 +21,8 @@ public class CreateReportUseCase { private final ReportValidator reportValidator; private final ContentValidator contentValidator; + private final ContentAdaptor contentAdaptor; + private final ArchivingAdaptor archivingAdaptor; private final ArchivingValidator archivingValidator; private final ReportMapper reportMapper; private final ReportDomainService reportDomainService; @@ -27,11 +31,19 @@ public class CreateReportUseCase { public void execute(CreateReportRequest request, ReportObjectType type) { Long userId = SecurityUtil.getCurrentUserId(); reportValidator.validateNotDuplicateReport(userId, request.getId(), type); + Long reportedUserId = 0L; switch (type) { - case CONTENT -> contentValidator.validateExistById(request.getId()); - case ARCHIVING -> archivingValidator.validateExistById(request.getId()); + case CONTENT -> { + contentValidator.validateExistById(request.getId()); + Long archivingId = contentAdaptor.findById(request.getId()).getArchivingId(); + reportedUserId = archivingAdaptor.findById(archivingId).getUserId(); + } + case ARCHIVING -> { + archivingValidator.validateExistById(request.getId()); + reportedUserId = archivingAdaptor.findById(request.getId()).getUserId(); + } } - Report report = reportMapper.toEntity(request, type, userId); + Report report = reportMapper.toEntity(request, type, userId, reportedUserId); reportDomainService.save(report); } } diff --git a/Api/src/main/java/allchive/server/api/user/service/GetUserInfoUseCase.java b/Api/src/main/java/allchive/server/api/user/service/GetUserInfoUseCase.java index 6fc7c0c7..bff4bdbb 100644 --- a/Api/src/main/java/allchive/server/api/user/service/GetUserInfoUseCase.java +++ b/Api/src/main/java/allchive/server/api/user/service/GetUserInfoUseCase.java @@ -20,7 +20,7 @@ public class GetUserInfoUseCase { public GetUserInfoResponse execute() { Long userId = SecurityUtil.getCurrentUserId(); userValidator.validateUserStatusNormal(userId); - User user = userAdaptor.queryUserById(userId); + User user = userAdaptor.findUserById(userId); return GetUserInfoResponse.from(user); } } diff --git a/Api/src/main/java/allchive/server/api/user/service/GetUserProfileUseCase.java b/Api/src/main/java/allchive/server/api/user/service/GetUserProfileUseCase.java index 95afe46d..28354c88 100644 --- a/Api/src/main/java/allchive/server/api/user/service/GetUserProfileUseCase.java +++ b/Api/src/main/java/allchive/server/api/user/service/GetUserProfileUseCase.java @@ -26,7 +26,7 @@ public class GetUserProfileUseCase { public GetUserProfileResponse execute() { Long userId = SecurityUtil.getCurrentUserId(); userValidator.validateUserStatusNormal(userId); - User user = userAdaptor.queryUserById(userId); + User user = userAdaptor.findUserById(userId); List archivingList = archivingAdaptor.findAllByUserId(userId); return userMapper.toGetUserProfileResponse(archivingList, user); } diff --git a/Core/src/main/java/allchive/server/core/annotation/ValidEnum.java b/Core/src/main/java/allchive/server/core/annotation/ValidEnum.java index 7f6a724b..27ca8ce9 100644 --- a/Core/src/main/java/allchive/server/core/annotation/ValidEnum.java +++ b/Core/src/main/java/allchive/server/core/annotation/ValidEnum.java @@ -5,13 +5,14 @@ import allchive.server.core.validator.EnumValidator; import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.Target; import javax.validation.Constraint; import javax.validation.Payload; @Documented -@Target({FIELD}) +@Target({ElementType.TYPE_USE, FIELD}) @Retention(RUNTIME) @Constraint(validatedBy = {EnumValidator.class}) public @interface ValidEnum { diff --git a/Domain/build.gradle b/Domain/build.gradle index 1820de04..81b129c8 100644 --- a/Domain/build.gradle +++ b/Domain/build.gradle @@ -5,7 +5,6 @@ dependencies { implementation 'org.springframework.boot:spring-boot-starter-data-jpa' implementation 'mysql:mysql-connector-java:8.0.33' implementation 'org.springframework.boot:spring-boot-starter-web' - // TODO : Core에 impl 했는데 여기서 이용 못하는 문제 해결해야함 implementation 'org.springframework.boot:spring-boot-starter-validation' implementation project(':Core') diff --git a/Domain/src/main/java/allchive/server/domain/domains/block/adaptor/BlockAdaptor.java b/Domain/src/main/java/allchive/server/domain/domains/block/adaptor/BlockAdaptor.java index 2ca80c63..a7068d7c 100644 --- a/Domain/src/main/java/allchive/server/domain/domains/block/adaptor/BlockAdaptor.java +++ b/Domain/src/main/java/allchive/server/domain/domains/block/adaptor/BlockAdaptor.java @@ -27,4 +27,8 @@ public void save(Block block) { public void deleteByBlockFromAndBlockUser(Long blockFrom, Long blockUser) { blockRepository.deleteByBlockFromAndBlockUser(blockFrom, blockUser); } + + public void queryDeleteBlockByBlockFromOrBlockUser(Long userId) { + blockRepository.queryDeleteBlockByBlockFromOrBlockUser(userId); + } } diff --git a/Domain/src/main/java/allchive/server/domain/domains/block/repository/BlockCustomRepository.java b/Domain/src/main/java/allchive/server/domain/domains/block/repository/BlockCustomRepository.java index ae169ca0..fa0e4a09 100644 --- a/Domain/src/main/java/allchive/server/domain/domains/block/repository/BlockCustomRepository.java +++ b/Domain/src/main/java/allchive/server/domain/domains/block/repository/BlockCustomRepository.java @@ -2,4 +2,6 @@ public interface BlockCustomRepository { boolean queryBlockExistByBlockFromAndBlockUser(Long blockFrom, Long blockUser); + + void queryDeleteBlockByBlockFromOrBlockUser(Long userId); } diff --git a/Domain/src/main/java/allchive/server/domain/domains/block/repository/BlockCustomRepositoryImpl.java b/Domain/src/main/java/allchive/server/domain/domains/block/repository/BlockCustomRepositoryImpl.java index f172ef31..a7b7cf27 100644 --- a/Domain/src/main/java/allchive/server/domain/domains/block/repository/BlockCustomRepositoryImpl.java +++ b/Domain/src/main/java/allchive/server/domain/domains/block/repository/BlockCustomRepositoryImpl.java @@ -21,6 +21,13 @@ public boolean queryBlockExistByBlockFromAndBlockUser(Long blockFrom, Long block return fetchOne != null; } + @Override + public void queryDeleteBlockByBlockFromOrBlockUser(Long userId) { + queryFactory + .delete(block) + .where(blockUserEqOrBlockFromEq(userId)); + } + private BooleanExpression blockFromEq(Long blockFrom) { return block.blockFrom.eq(blockFrom); } @@ -28,4 +35,8 @@ private BooleanExpression blockFromEq(Long blockFrom) { private BooleanExpression blockUserEq(Long blockUser) { return block.blockUser.eq(blockUser); } + + private BooleanExpression blockUserEqOrBlockFromEq(Long userId) { + return blockFromEq(userId).or(blockUserEq(userId)); + } } diff --git a/Domain/src/main/java/allchive/server/domain/domains/block/service/BlockDomainService.java b/Domain/src/main/java/allchive/server/domain/domains/block/service/BlockDomainService.java index a38fb224..bfc7da06 100644 --- a/Domain/src/main/java/allchive/server/domain/domains/block/service/BlockDomainService.java +++ b/Domain/src/main/java/allchive/server/domain/domains/block/service/BlockDomainService.java @@ -18,4 +18,8 @@ public void save(Block block) { public void deleteByBlockFromAndBlockUser(Long blockFrom, Long blockUser) { blockAdaptor.deleteByBlockFromAndBlockUser(blockFrom, blockUser); } + + public void queryDeleteBlockByBlockFromOrBlockUser(Long userId) { + blockAdaptor.queryDeleteBlockByBlockFromOrBlockUser(userId); + } } diff --git a/Domain/src/main/java/allchive/server/domain/domains/content/adaptor/ContentAdaptor.java b/Domain/src/main/java/allchive/server/domain/domains/content/adaptor/ContentAdaptor.java index 7d789bed..b14cfdd7 100644 --- a/Domain/src/main/java/allchive/server/domain/domains/content/adaptor/ContentAdaptor.java +++ b/Domain/src/main/java/allchive/server/domain/domains/content/adaptor/ContentAdaptor.java @@ -52,4 +52,8 @@ public List findAllByArchivingIds(List archivingIds) { public boolean queryContentExistById(Long contentId) { return contentRepository.queryContentExistById(contentId); } + + public void deleteAllByArchivingIdIn(List archivingId) { + contentRepository.deleteAllByArchivingIdIn(archivingId); + } } diff --git a/Domain/src/main/java/allchive/server/domain/domains/content/adaptor/ContentTagGroupAdaptor.java b/Domain/src/main/java/allchive/server/domain/domains/content/adaptor/ContentTagGroupAdaptor.java index 2414717a..d2f4b492 100644 --- a/Domain/src/main/java/allchive/server/domain/domains/content/adaptor/ContentTagGroupAdaptor.java +++ b/Domain/src/main/java/allchive/server/domain/domains/content/adaptor/ContentTagGroupAdaptor.java @@ -33,4 +33,8 @@ public void saveAll(List contentTagGroupList) { public void deleteAllByContentIn(List contents) { contentTagGroupRepository.deleteAllByContentIn(contents); } + + public void deleteAllByTagIn(List tagList) { + contentTagGroupRepository.deleteAllByTagIn(tagList); + } } diff --git a/Domain/src/main/java/allchive/server/domain/domains/content/adaptor/TagAdaptor.java b/Domain/src/main/java/allchive/server/domain/domains/content/adaptor/TagAdaptor.java index 07f9a813..5a1df191 100644 --- a/Domain/src/main/java/allchive/server/domain/domains/content/adaptor/TagAdaptor.java +++ b/Domain/src/main/java/allchive/server/domain/domains/content/adaptor/TagAdaptor.java @@ -36,4 +36,12 @@ public void deleteById(Long tagId) { public List queryTagInTagIdList(List tagIds) { return tagRepository.queryTagInTagIdList(tagIds); } + + public List findAllByUserId(Long userId) { + return tagRepository.findAllByUserId(userId); + } + + public void deleteAll(List tagList) { + tagRepository.deleteAll(tagList); + } } diff --git a/Domain/src/main/java/allchive/server/domain/domains/content/repository/ContentRepository.java b/Domain/src/main/java/allchive/server/domain/domains/content/repository/ContentRepository.java index 79a39685..88540676 100644 --- a/Domain/src/main/java/allchive/server/domain/domains/content/repository/ContentRepository.java +++ b/Domain/src/main/java/allchive/server/domain/domains/content/repository/ContentRepository.java @@ -7,4 +7,6 @@ public interface ContentRepository extends JpaRepository, ContentCustomRepository { List findAllByIdIn(List contentIdList); + + void deleteAllByArchivingIdIn(List archivingId); } diff --git a/Domain/src/main/java/allchive/server/domain/domains/content/repository/ContentTagGroupRepository.java b/Domain/src/main/java/allchive/server/domain/domains/content/repository/ContentTagGroupRepository.java index a6babae0..f218bdae 100644 --- a/Domain/src/main/java/allchive/server/domain/domains/content/repository/ContentTagGroupRepository.java +++ b/Domain/src/main/java/allchive/server/domain/domains/content/repository/ContentTagGroupRepository.java @@ -14,4 +14,6 @@ public interface ContentTagGroupRepository void deleteByTag(Tag tag); void deleteAllByContentIn(List contents); + + void deleteAllByTagIn(List tagList); } diff --git a/Domain/src/main/java/allchive/server/domain/domains/content/repository/TagRepository.java b/Domain/src/main/java/allchive/server/domain/domains/content/repository/TagRepository.java index 0cfe5c5f..50911c53 100644 --- a/Domain/src/main/java/allchive/server/domain/domains/content/repository/TagRepository.java +++ b/Domain/src/main/java/allchive/server/domain/domains/content/repository/TagRepository.java @@ -7,4 +7,6 @@ public interface TagRepository extends JpaRepository, TagCustomRepository { List findAllByUserIdOrderByCreatedAtDesc(Long userId); + + List findAllByUserId(Long userId); } diff --git a/Domain/src/main/java/allchive/server/domain/domains/content/service/ContentDomainService.java b/Domain/src/main/java/allchive/server/domain/domains/content/service/ContentDomainService.java index 7f6c9f56..2b2fd708 100644 --- a/Domain/src/main/java/allchive/server/domain/domains/content/service/ContentDomainService.java +++ b/Domain/src/main/java/allchive/server/domain/domains/content/service/ContentDomainService.java @@ -31,4 +31,8 @@ public void restoreInIdList(List contentIds) { public void deleteAllById(List contentIds) { contentAdaptor.deleteAllById(contentIds); } + + public void deleteAllByArchivingIdIn(List archivingId) { + contentAdaptor.deleteAllByArchivingIdIn(archivingId); + } } diff --git a/Domain/src/main/java/allchive/server/domain/domains/content/service/ContentTagGroupDomainService.java b/Domain/src/main/java/allchive/server/domain/domains/content/service/ContentTagGroupDomainService.java index 9d162118..3f0dbf45 100644 --- a/Domain/src/main/java/allchive/server/domain/domains/content/service/ContentTagGroupDomainService.java +++ b/Domain/src/main/java/allchive/server/domain/domains/content/service/ContentTagGroupDomainService.java @@ -25,4 +25,8 @@ public void saveAll(List contentTagGroupList) { public void deleteByContentIn(List contents) { contentTagGroupAdaptor.deleteAllByContentIn(contents); } + + public void deleteAllByTagIn(List tagList) { + contentTagGroupAdaptor.deleteAllByTagIn(tagList); + } } diff --git a/Domain/src/main/java/allchive/server/domain/domains/content/service/TagDomainService.java b/Domain/src/main/java/allchive/server/domain/domains/content/service/TagDomainService.java index a9a75605..265d3158 100644 --- a/Domain/src/main/java/allchive/server/domain/domains/content/service/TagDomainService.java +++ b/Domain/src/main/java/allchive/server/domain/domains/content/service/TagDomainService.java @@ -6,6 +6,8 @@ import allchive.server.domain.domains.content.domain.Tag; import lombok.RequiredArgsConstructor; +import java.util.List; + @DomainService @RequiredArgsConstructor public class TagDomainService { @@ -24,4 +26,8 @@ public void updateTag(Long tagId, String name) { public void deleteById(Long tagId) { tagAdaptor.deleteById(tagId); } + + public void deleteAll(List tagList) { + tagAdaptor.deleteAll(tagList); + } } diff --git a/Domain/src/main/java/allchive/server/domain/domains/recycle/adaptor/RecycleAdaptor.java b/Domain/src/main/java/allchive/server/domain/domains/recycle/adaptor/RecycleAdaptor.java index eee460b6..b2055e21 100644 --- a/Domain/src/main/java/allchive/server/domain/domains/recycle/adaptor/RecycleAdaptor.java +++ b/Domain/src/main/java/allchive/server/domain/domains/recycle/adaptor/RecycleAdaptor.java @@ -34,4 +34,8 @@ public List findAllByUserId(Long userId) { public List findAllByDeletedAtBefore(LocalDateTime deleteStandard) { return recycleRepository.findAllByDeletedAtBefore(deleteStandard); } + + public void deleteAllByUserId(Long userId) { + recycleRepository.deleteAllByUserId(userId); + } } diff --git a/Domain/src/main/java/allchive/server/domain/domains/recycle/repository/RecycleRepository.java b/Domain/src/main/java/allchive/server/domain/domains/recycle/repository/RecycleRepository.java index a8dfb3b3..a94c960a 100644 --- a/Domain/src/main/java/allchive/server/domain/domains/recycle/repository/RecycleRepository.java +++ b/Domain/src/main/java/allchive/server/domain/domains/recycle/repository/RecycleRepository.java @@ -10,4 +10,6 @@ public interface RecycleRepository extends JpaRepository, Recycle List findAllByUserId(Long userId); List findAllByDeletedAtBefore(LocalDateTime time); + + void deleteAllByUserId(Long userId); } diff --git a/Domain/src/main/java/allchive/server/domain/domains/recycle/service/RecycleDomainService.java b/Domain/src/main/java/allchive/server/domain/domains/recycle/service/RecycleDomainService.java index 63531a58..9763eae5 100644 --- a/Domain/src/main/java/allchive/server/domain/domains/recycle/service/RecycleDomainService.java +++ b/Domain/src/main/java/allchive/server/domain/domains/recycle/service/RecycleDomainService.java @@ -27,4 +27,8 @@ public void deleteAllByUserIdAndArchivingIdOrUserIdAndContentId( public void deleteAll(List recycles) { recycleAdaptor.deleteAll(recycles); } + + public void deleteAllByUserId(Long userId) { + recycleAdaptor.deleteAllByUserId(userId); + } } diff --git a/Domain/src/main/java/allchive/server/domain/domains/report/adaptor/ReportAdaptor.java b/Domain/src/main/java/allchive/server/domain/domains/report/adaptor/ReportAdaptor.java index 95c1d405..16284ef0 100644 --- a/Domain/src/main/java/allchive/server/domain/domains/report/adaptor/ReportAdaptor.java +++ b/Domain/src/main/java/allchive/server/domain/domains/report/adaptor/ReportAdaptor.java @@ -22,4 +22,8 @@ public Boolean queryReportExistByUserIdAndContentId(Long userId, Long contentId) public Boolean queryReportExistByUserIdAndArchivingId(Long userId, Long archivingId) { return reportRepository.queryReportExistByUserIdAndArchivingId(userId, archivingId); } + + public void deleteAllByReportedUserId(Long userId) { + reportRepository.deleteAllByReportedUserId(userId); + } } diff --git a/Domain/src/main/java/allchive/server/domain/domains/report/domain/Report.java b/Domain/src/main/java/allchive/server/domain/domains/report/domain/Report.java index 693b4dc7..4d408633 100644 --- a/Domain/src/main/java/allchive/server/domain/domains/report/domain/Report.java +++ b/Domain/src/main/java/allchive/server/domain/domains/report/domain/Report.java @@ -30,6 +30,7 @@ public class Report extends BaseTimeEntity { private Long contentId; private Long archivingId; private Long userId; // 신고한 유저 + private Long reportedUserId; // 신고 당한 유저 id @Builder private Report( @@ -38,13 +39,15 @@ private Report( ReportedType reportedType, Long contentId, Long archivingId, - Long userId) { + Long userId, + Long reportedUserId) { this.reportObjectTypeType = reportObjectTypeType; this.reason = reason; this.reportedType = reportedType; this.contentId = contentId; this.archivingId = archivingId; this.userId = userId; + this.reportedUserId = reportedUserId; } public static Report of( @@ -53,7 +56,8 @@ public static Report of( ReportedType reportedType, Long contentId, Long archivingId, - Long userId) { + Long userId, + Long reportedUserId) { return Report.builder() .reportObjectTypeType(reportObjectTypeType) .reason(reason) @@ -61,6 +65,7 @@ public static Report of( .contentId(contentId) .archivingId(archivingId) .userId(userId) + .reportedUserId(reportedUserId) .build(); } } diff --git a/Domain/src/main/java/allchive/server/domain/domains/report/repository/ReportRepository.java b/Domain/src/main/java/allchive/server/domain/domains/report/repository/ReportRepository.java index c1bf33b6..763aa660 100644 --- a/Domain/src/main/java/allchive/server/domain/domains/report/repository/ReportRepository.java +++ b/Domain/src/main/java/allchive/server/domain/domains/report/repository/ReportRepository.java @@ -4,4 +4,6 @@ import allchive.server.domain.domains.report.domain.Report; import org.springframework.data.jpa.repository.JpaRepository; -public interface ReportRepository extends JpaRepository, ReportCustomRepository {} +public interface ReportRepository extends JpaRepository, ReportCustomRepository { + void deleteAllByReportedUserId(Long userId); +} diff --git a/Domain/src/main/java/allchive/server/domain/domains/report/service/ReportDomainService.java b/Domain/src/main/java/allchive/server/domain/domains/report/service/ReportDomainService.java index 6e24e2d6..00a0e4ad 100644 --- a/Domain/src/main/java/allchive/server/domain/domains/report/service/ReportDomainService.java +++ b/Domain/src/main/java/allchive/server/domain/domains/report/service/ReportDomainService.java @@ -14,4 +14,8 @@ public class ReportDomainService { public void save(Report report) { reportAdaptor.save(report); } + + public void deleteAllByReportedUserId(Long userId) { + reportAdaptor.deleteAllByReportedUserId(userId); + } } diff --git a/Domain/src/main/java/allchive/server/domain/domains/search/adaptor/LatestSearchAdaptor.java b/Domain/src/main/java/allchive/server/domain/domains/search/adaptor/LatestSearchAdaptor.java index bc354d21..c1087477 100644 --- a/Domain/src/main/java/allchive/server/domain/domains/search/adaptor/LatestSearchAdaptor.java +++ b/Domain/src/main/java/allchive/server/domain/domains/search/adaptor/LatestSearchAdaptor.java @@ -23,4 +23,8 @@ public void delete(LatestSearch latestSearch) { public void save(LatestSearch newSearch) { latestSearchRepository.save(newSearch); } + + public void deleteAllByUserId(Long userId) { + latestSearchRepository.deleteAllByUserId(userId); + } } diff --git a/Domain/src/main/java/allchive/server/domain/domains/search/repository/LatestSearchRepository.java b/Domain/src/main/java/allchive/server/domain/domains/search/repository/LatestSearchRepository.java index 782ea8b6..20ca1d86 100644 --- a/Domain/src/main/java/allchive/server/domain/domains/search/repository/LatestSearchRepository.java +++ b/Domain/src/main/java/allchive/server/domain/domains/search/repository/LatestSearchRepository.java @@ -7,4 +7,6 @@ public interface LatestSearchRepository extends JpaRepository { List findAllByUserIdOrderByCreatedAt(Long userId); + + void deleteAllByUserId(Long userId); } diff --git a/Domain/src/main/java/allchive/server/domain/domains/search/service/LatestSearchDomainService.java b/Domain/src/main/java/allchive/server/domain/domains/search/service/LatestSearchDomainService.java index 0d9e1407..533529ac 100644 --- a/Domain/src/main/java/allchive/server/domain/domains/search/service/LatestSearchDomainService.java +++ b/Domain/src/main/java/allchive/server/domain/domains/search/service/LatestSearchDomainService.java @@ -18,4 +18,8 @@ public void delete(LatestSearch latestSearch) { public void save(LatestSearch newSearch) { latestSearchAdaptor.save(newSearch); } + + public void deleteAllByUserId(Long userId) { + latestSearchAdaptor.deleteAllByUserId(userId); + } } diff --git a/Domain/src/main/java/allchive/server/domain/domains/user/adaptor/ScrapAdaptor.java b/Domain/src/main/java/allchive/server/domain/domains/user/adaptor/ScrapAdaptor.java index 82a84f9e..3b3942f9 100644 --- a/Domain/src/main/java/allchive/server/domain/domains/user/adaptor/ScrapAdaptor.java +++ b/Domain/src/main/java/allchive/server/domain/domains/user/adaptor/ScrapAdaptor.java @@ -33,4 +33,8 @@ public void save(Scrap scrap) { public void deleteAllByArchivingIdIn(List archivingIds) { scrapRepository.deleteAllByArchivingIdIn(archivingIds); } + + public void deleteAllByUser(User user) { + scrapRepository.deleteAllByUser(user); + } } diff --git a/Domain/src/main/java/allchive/server/domain/domains/user/adaptor/UserAdaptor.java b/Domain/src/main/java/allchive/server/domain/domains/user/adaptor/UserAdaptor.java index 976effb1..bdb3f7b4 100644 --- a/Domain/src/main/java/allchive/server/domain/domains/user/adaptor/UserAdaptor.java +++ b/Domain/src/main/java/allchive/server/domain/domains/user/adaptor/UserAdaptor.java @@ -28,7 +28,7 @@ public void save(User user) { userRepository.save(user); } - public User queryUserById(Long userId) { + public User findUserById(Long userId) { return userRepository.findById(userId).orElseThrow(() -> UserNotFoundException.EXCEPTION); } diff --git a/Domain/src/main/java/allchive/server/domain/domains/user/domain/User.java b/Domain/src/main/java/allchive/server/domain/domains/user/domain/User.java index 8d3c49c4..c5a87470 100644 --- a/Domain/src/main/java/allchive/server/domain/domains/user/domain/User.java +++ b/Domain/src/main/java/allchive/server/domain/domains/user/domain/User.java @@ -50,17 +50,27 @@ public class User extends BaseTimeEntity { private List categories = new ArrayList<>(); @Builder - private User(String nickname, String profileImgUrl, OauthInfo oauthInfo) { + private User( + String nickname, + String profileImgUrl, + List categoryList, + OauthInfo oauthInfo) { this.nickname = nickname; this.profileImgUrl = profileImgUrl; + this.categories = categoryList; this.oauthInfo = oauthInfo; this.lastLoginAt = LocalDateTime.now(); } - public static User of(String nickname, String profileImgUrl, OauthInfo oauthInfo) { + public static User of( + String nickname, + String profileImgUrl, + List categoryList, + OauthInfo oauthInfo) { return User.builder() .nickname(nickname) .profileImgUrl(profileImgUrl) + .categoryList(categoryList) .oauthInfo(oauthInfo) .build(); } diff --git a/Domain/src/main/java/allchive/server/domain/domains/user/repository/ScrapRepository.java b/Domain/src/main/java/allchive/server/domain/domains/user/repository/ScrapRepository.java index a6c06431..4ccfba30 100644 --- a/Domain/src/main/java/allchive/server/domain/domains/user/repository/ScrapRepository.java +++ b/Domain/src/main/java/allchive/server/domain/domains/user/repository/ScrapRepository.java @@ -13,4 +13,6 @@ public interface ScrapRepository extends JpaRepository { Optional findAllByUserAndArchivingId(User user, Long archivingId); void deleteAllByArchivingIdIn(List archivingId); + + void deleteAllByUser(User user); } diff --git a/Domain/src/main/java/allchive/server/domain/domains/user/service/ScrapDomainService.java b/Domain/src/main/java/allchive/server/domain/domains/user/service/ScrapDomainService.java index d994bb98..37440ece 100644 --- a/Domain/src/main/java/allchive/server/domain/domains/user/service/ScrapDomainService.java +++ b/Domain/src/main/java/allchive/server/domain/domains/user/service/ScrapDomainService.java @@ -30,4 +30,8 @@ public void save(Scrap scrap) { public void deleteAllByArchivingIdIn(List archivingIds) { scrapAdaptor.deleteAllByArchivingIdIn(archivingIds); } + + public void deleteAllByUser(User user) { + scrapAdaptor.deleteAllByUser(user); + } } diff --git a/Domain/src/main/java/allchive/server/domain/domains/user/service/UserDomainService.java b/Domain/src/main/java/allchive/server/domain/domains/user/service/UserDomainService.java index fb8acce1..997f9236 100644 --- a/Domain/src/main/java/allchive/server/domain/domains/user/service/UserDomainService.java +++ b/Domain/src/main/java/allchive/server/domain/domains/user/service/UserDomainService.java @@ -2,11 +2,13 @@ import allchive.server.core.annotation.DomainService; +import allchive.server.domain.domains.archiving.domain.enums.Category; import allchive.server.domain.domains.user.adaptor.UserAdaptor; import allchive.server.domain.domains.user.domain.User; import allchive.server.domain.domains.user.domain.enums.OauthInfo; import allchive.server.domain.domains.user.exception.exceptions.DuplicatedNicknameException; import allchive.server.domain.domains.user.validator.UserValidator; +import java.util.List; import lombok.RequiredArgsConstructor; import org.springframework.transaction.annotation.Transactional; @@ -21,9 +23,13 @@ public Boolean checkUserCanLogin(OauthInfo oauthInfo) { } @Transactional - public User registerUser(String nickname, String profileImgUrl, OauthInfo oauthInfo) { + public User registerUser( + String nickname, + String profileImgUrl, + List categoryList, + OauthInfo oauthInfo) { userValidator.validUserCanRegister(oauthInfo); - final User newUser = User.of(nickname, profileImgUrl, oauthInfo); + final User newUser = User.of(nickname, profileImgUrl, categoryList, oauthInfo); userAdaptor.save(newUser); return newUser; } @@ -37,13 +43,13 @@ public User loginUser(OauthInfo oauthInfo) { @Transactional public void deleteUserById(Long userId) { - User user = userAdaptor.queryUserById(userId); + User user = userAdaptor.findUserById(userId); user.withdrawUser(); } public void updateUserInfo( Long userId, String name, String email, String nickname, String imgUrl) { - User user = userAdaptor.queryUserById(userId); + User user = userAdaptor.findUserById(userId); user.updateInfo(name, email, nickname, imgUrl); } diff --git a/Domain/src/main/java/allchive/server/domain/domains/user/validator/UserValidator.java b/Domain/src/main/java/allchive/server/domain/domains/user/validator/UserValidator.java index 8a25182e..0a02dfb9 100644 --- a/Domain/src/main/java/allchive/server/domain/domains/user/validator/UserValidator.java +++ b/Domain/src/main/java/allchive/server/domain/domains/user/validator/UserValidator.java @@ -23,7 +23,7 @@ public Boolean checkUserCanRegister(OauthInfo oauthInfo) { } public void validateUserStatusNormal(Long userId) { - if (!userAdaptor.queryUserById(userId).getUserState().equals(UserState.NORMAL)) { + if (!userAdaptor.findUserById(userId).getUserState().equals(UserState.NORMAL)) { throw ForbiddenUserException.EXCEPTION; } }