diff --git a/backend/kirikiri/build.gradle b/backend/kirikiri/build.gradle index 7bd653e1d..0c94c0ac0 100644 --- a/backend/kirikiri/build.gradle +++ b/backend/kirikiri/build.gradle @@ -71,9 +71,10 @@ jacocoTestReport { classDirectories.setFrom( files(classDirectories.files.collect { fileTree(dir: it, excludes: [ - "co/kirikiri/persistence/QuerydslRepositorySupporter", - "co/kirikiri/domain/**", - "co/kirikiri/persistence/goalroom/dto/**", + "co/kirikiri/common/persistence/QuerydslRepositorySupporter", + "co/kirikiri/common/service/dto/**", + "co/kirikiri/**/domain/**", + "co/kirikiri/**/persistence/dto/**", "**/*Application*", "**/*Config*", "**/*Dto*", @@ -112,11 +113,12 @@ jacocoTestCoverageVerification { value = 'COVEREDRATIO' minimum = 0.80 } - + excludes = [ - "co.kirikiri.persistence.QuerydslRepositorySupporter", - "co.kirikiri.domain.**.**", - "co.kirikiri.persistence.goalroom.dto.**", + "co.kirikiri.common.persistence.QuerydslRepositorySupporter", + "co.kirikiri.common.service.dto.**", + "co.kirikiri.**.domain.**", + "co.kirikiri.**.persistence.dto.**", "**.*Application*", "**.*Config*", "**.*Dto*", diff --git a/backend/kirikiri/src/main/java/co/kirikiri/controller/AuthController.java b/backend/kirikiri/src/main/java/co/kirikiri/auth/controller/AuthController.java similarity index 84% rename from backend/kirikiri/src/main/java/co/kirikiri/controller/AuthController.java rename to backend/kirikiri/src/main/java/co/kirikiri/auth/controller/AuthController.java index dfbdd8620..694bdcfe0 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/controller/AuthController.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/auth/controller/AuthController.java @@ -1,11 +1,11 @@ -package co.kirikiri.controller; +package co.kirikiri.auth.controller; -import co.kirikiri.service.auth.AuthService; -import co.kirikiri.service.auth.NaverOauthService; -import co.kirikiri.service.dto.auth.OauthRedirectResponse; -import co.kirikiri.service.dto.auth.request.LoginRequest; -import co.kirikiri.service.dto.auth.request.ReissueTokenRequest; -import co.kirikiri.service.dto.auth.response.AuthenticationResponse; +import co.kirikiri.auth.service.AuthService; +import co.kirikiri.auth.service.NaverOauthService; +import co.kirikiri.auth.service.dto.request.LoginRequest; +import co.kirikiri.auth.service.dto.request.ReissueTokenRequest; +import co.kirikiri.auth.service.dto.response.AuthenticationResponse; +import co.kirikiri.auth.service.dto.response.OauthRedirectResponse; import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; diff --git a/backend/kirikiri/src/main/java/co/kirikiri/infra/NaverOauthNetworkService.java b/backend/kirikiri/src/main/java/co/kirikiri/auth/infra/NaverOauthNetworkService.java similarity index 96% rename from backend/kirikiri/src/main/java/co/kirikiri/infra/NaverOauthNetworkService.java rename to backend/kirikiri/src/main/java/co/kirikiri/auth/infra/NaverOauthNetworkService.java index 6cd0e7cd1..adc4eb647 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/infra/NaverOauthNetworkService.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/auth/infra/NaverOauthNetworkService.java @@ -1,6 +1,6 @@ -package co.kirikiri.infra; +package co.kirikiri.auth.infra; -import co.kirikiri.service.OauthNetworkService; +import co.kirikiri.auth.service.OauthNetworkService; import lombok.RequiredArgsConstructor; import org.springframework.core.env.Environment; import org.springframework.http.HttpEntity; diff --git a/backend/kirikiri/src/main/java/co/kirikiri/auth/interceptor/AuthInterceptorImpl.java b/backend/kirikiri/src/main/java/co/kirikiri/auth/interceptor/AuthInterceptorImpl.java new file mode 100644 index 000000000..279b934e6 --- /dev/null +++ b/backend/kirikiri/src/main/java/co/kirikiri/auth/interceptor/AuthInterceptorImpl.java @@ -0,0 +1,48 @@ +package co.kirikiri.auth.interceptor; + +import co.kirikiri.auth.service.AuthService; +import co.kirikiri.common.exception.AuthenticationException; +import co.kirikiri.common.interceptor.AuthInterceptor; +import co.kirikiri.common.interceptor.Authenticated; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpHeaders; +import org.springframework.stereotype.Component; +import org.springframework.web.method.HandlerMethod; + +@Component +@RequiredArgsConstructor +public class AuthInterceptorImpl implements AuthInterceptor { + + private static final String BEARER = "Bearer "; + + private final AuthService authService; + + @Override + public boolean preHandle(final HttpServletRequest request, final HttpServletResponse response, + final Object handler) { + if (!(handler instanceof final HandlerMethod handlerMethod)) { + return true; + } + if (handlerMethod.hasMethodAnnotation(Authenticated.class)) { + final String authorizationHeader = request.getHeader(HttpHeaders.AUTHORIZATION); + checkHeader(authorizationHeader); + final String token = authorizationHeader.substring(BEARER.length()); + checkTokenCertify(token); + } + return true; + } + + private void checkHeader(final String authorizationHeader) { + if (authorizationHeader == null || !authorizationHeader.startsWith(BEARER)) { + throw new AuthenticationException("인증 헤더가 적절하지 않습니다."); + } + } + + private void checkTokenCertify(final String token) { + if (!authService.isCertified(token)) { + throw new AuthenticationException("토큰이 유효하지 않습니다."); + } + } +} diff --git a/backend/kirikiri/src/main/java/co/kirikiri/persistence/auth/RefreshTokenRepository.java b/backend/kirikiri/src/main/java/co/kirikiri/auth/persistence/RefreshTokenRepository.java similarity index 85% rename from backend/kirikiri/src/main/java/co/kirikiri/persistence/auth/RefreshTokenRepository.java rename to backend/kirikiri/src/main/java/co/kirikiri/auth/persistence/RefreshTokenRepository.java index 18e789945..de96a27fb 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/persistence/auth/RefreshTokenRepository.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/auth/persistence/RefreshTokenRepository.java @@ -1,4 +1,4 @@ -package co.kirikiri.persistence.auth; +package co.kirikiri.auth.persistence; import java.util.Optional; diff --git a/backend/kirikiri/src/main/java/co/kirikiri/persistence/auth/RefreshTokenRepositoryImpl.java b/backend/kirikiri/src/main/java/co/kirikiri/auth/persistence/RefreshTokenRepositoryImpl.java similarity index 97% rename from backend/kirikiri/src/main/java/co/kirikiri/persistence/auth/RefreshTokenRepositoryImpl.java rename to backend/kirikiri/src/main/java/co/kirikiri/auth/persistence/RefreshTokenRepositoryImpl.java index 7ca0a5de2..97d97397c 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/persistence/auth/RefreshTokenRepositoryImpl.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/auth/persistence/RefreshTokenRepositoryImpl.java @@ -1,10 +1,10 @@ -package co.kirikiri.persistence.auth; +package co.kirikiri.auth.persistence; -import java.util.Optional; -import java.util.concurrent.TimeUnit; import org.springframework.beans.factory.annotation.Value; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Repository; +import java.util.Optional; +import java.util.concurrent.TimeUnit; @Repository public class RefreshTokenRepositoryImpl implements RefreshTokenRepository { diff --git a/backend/kirikiri/src/main/java/co/kirikiri/auth/resolver/MemberIdentifierArgumentResolverImpl.java b/backend/kirikiri/src/main/java/co/kirikiri/auth/resolver/MemberIdentifierArgumentResolverImpl.java new file mode 100644 index 000000000..9d9357ca3 --- /dev/null +++ b/backend/kirikiri/src/main/java/co/kirikiri/auth/resolver/MemberIdentifierArgumentResolverImpl.java @@ -0,0 +1,48 @@ +package co.kirikiri.auth.resolver; + +import co.kirikiri.auth.service.AuthService; +import co.kirikiri.common.exception.AuthenticationException; +import co.kirikiri.common.exception.ServerException; +import co.kirikiri.common.interceptor.Authenticated; +import co.kirikiri.common.resolver.MemberIdentifier; +import co.kirikiri.common.resolver.MemberIdentifierArgumentResolver; +import lombok.RequiredArgsConstructor; +import org.springframework.core.MethodParameter; +import org.springframework.http.HttpHeaders; +import org.springframework.stereotype.Component; +import org.springframework.web.bind.support.WebDataBinderFactory; +import org.springframework.web.context.request.NativeWebRequest; +import org.springframework.web.method.support.ModelAndViewContainer; + +@Component +@RequiredArgsConstructor +public class MemberIdentifierArgumentResolverImpl implements MemberIdentifierArgumentResolver { + + private static final String BEARER = "Bearer "; + + private final AuthService authService; + + @Override + public boolean supportsParameter(final MethodParameter parameter) { + if (!parameter.hasMethodAnnotation(Authenticated.class)) { + throw new ServerException("MemberIdentifier는 인증된 사용자만 사용 가능합니다. (@Authenticated)"); + } + return parameter.getParameterType().equals(String.class) + && parameter.hasParameterAnnotation(MemberIdentifier.class); + } + + @Override + public String resolveArgument(final MethodParameter parameter, final ModelAndViewContainer mavContainer, + final NativeWebRequest webRequest, final WebDataBinderFactory binderFactory) { + final String authorizationHeader = webRequest.getHeader(HttpHeaders.AUTHORIZATION); + checkHeader(authorizationHeader); + final String token = authorizationHeader.substring(BEARER.length()); + return authService.findIdentifierByToken(token); + } + + private void checkHeader(final String authorizationHeader) { + if (authorizationHeader == null || !authorizationHeader.startsWith(BEARER)) { + throw new AuthenticationException("인증 헤더가 적절하지 않습니다."); + } + } +} diff --git a/backend/kirikiri/src/main/java/co/kirikiri/service/auth/AuthService.java b/backend/kirikiri/src/main/java/co/kirikiri/auth/service/AuthService.java similarity index 86% rename from backend/kirikiri/src/main/java/co/kirikiri/service/auth/AuthService.java rename to backend/kirikiri/src/main/java/co/kirikiri/auth/service/AuthService.java index 9f72df0ea..1b75cd523 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/service/auth/AuthService.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/auth/service/AuthService.java @@ -1,21 +1,21 @@ -package co.kirikiri.service.auth; +package co.kirikiri.auth.service; +import co.kirikiri.auth.persistence.RefreshTokenRepository; +import co.kirikiri.auth.service.dto.LoginDto; +import co.kirikiri.auth.service.dto.request.LoginRequest; +import co.kirikiri.auth.service.dto.request.ReissueTokenRequest; +import co.kirikiri.auth.service.dto.response.AuthenticationResponse; +import co.kirikiri.auth.service.mapper.AuthMapper; import co.kirikiri.common.aop.ExceptionConvert; import co.kirikiri.common.exception.AuthenticationException; -import co.kirikiri.domain.member.Member; -import co.kirikiri.domain.member.vo.Identifier; -import co.kirikiri.domain.member.vo.Password; -import co.kirikiri.persistence.auth.RefreshTokenRepository; -import co.kirikiri.persistence.member.MemberRepository; -import co.kirikiri.service.dto.auth.LoginDto; -import co.kirikiri.service.dto.auth.request.LoginRequest; -import co.kirikiri.service.dto.auth.request.ReissueTokenRequest; -import co.kirikiri.service.dto.auth.response.AuthenticationResponse; -import co.kirikiri.service.mapper.AuthMapper; -import java.util.Map; +import co.kirikiri.member.domain.Member; +import co.kirikiri.member.domain.vo.Identifier; +import co.kirikiri.member.domain.vo.Password; +import co.kirikiri.member.persistence.MemberRepository; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.Map; @Service @Transactional(readOnly = true) diff --git a/backend/kirikiri/src/main/java/co/kirikiri/service/auth/JwtTokenProvider.java b/backend/kirikiri/src/main/java/co/kirikiri/auth/service/JwtTokenProvider.java similarity index 99% rename from backend/kirikiri/src/main/java/co/kirikiri/service/auth/JwtTokenProvider.java rename to backend/kirikiri/src/main/java/co/kirikiri/auth/service/JwtTokenProvider.java index dcfaeda37..bbef381b6 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/service/auth/JwtTokenProvider.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/auth/service/JwtTokenProvider.java @@ -1,4 +1,4 @@ -package co.kirikiri.service.auth; +package co.kirikiri.auth.service; import co.kirikiri.common.exception.AuthenticationException; import io.jsonwebtoken.Claims; @@ -7,6 +7,9 @@ import io.jsonwebtoken.JwtException; import io.jsonwebtoken.Jwts; import io.jsonwebtoken.security.Keys; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; +import javax.crypto.SecretKey; import java.nio.charset.StandardCharsets; import java.time.LocalDateTime; import java.time.ZoneId; @@ -14,9 +17,6 @@ import java.util.HashMap; import java.util.Map; import java.util.UUID; -import javax.crypto.SecretKey; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.stereotype.Component; @Component public class JwtTokenProvider implements TokenProvider { diff --git a/backend/kirikiri/src/main/java/co/kirikiri/service/auth/NaverOauthService.java b/backend/kirikiri/src/main/java/co/kirikiri/auth/service/NaverOauthService.java similarity index 72% rename from backend/kirikiri/src/main/java/co/kirikiri/service/auth/NaverOauthService.java rename to backend/kirikiri/src/main/java/co/kirikiri/auth/service/NaverOauthService.java index d0630697e..fe2c5811e 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/service/auth/NaverOauthService.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/auth/service/NaverOauthService.java @@ -1,26 +1,25 @@ -package co.kirikiri.service.auth; +package co.kirikiri.auth.service; -import co.kirikiri.domain.member.Member; -import co.kirikiri.persistence.member.MemberRepository; -import co.kirikiri.service.OauthNetworkService; -import co.kirikiri.service.dto.auth.NaverMemberProfileDto; -import co.kirikiri.service.dto.auth.NaverMemberProfileResponseDto; -import co.kirikiri.service.dto.auth.NaverOauthTokenDto; -import co.kirikiri.service.dto.auth.OauthRedirectResponse; -import co.kirikiri.service.dto.auth.response.AuthenticationResponse; -import co.kirikiri.service.dto.member.OauthMemberJoinDto; -import co.kirikiri.service.dto.member.request.GenderType; -import co.kirikiri.service.mapper.OauthMapper; -import co.kirikiri.service.member.MemberService; -import java.math.BigInteger; -import java.security.SecureRandom; -import java.util.Map; -import java.util.Optional; +import co.kirikiri.auth.service.dto.NaverMemberProfileDto; +import co.kirikiri.auth.service.dto.NaverMemberProfileResponseDto; +import co.kirikiri.auth.service.dto.NaverOauthTokenDto; +import co.kirikiri.auth.service.dto.response.AuthenticationResponse; +import co.kirikiri.auth.service.dto.response.OauthRedirectResponse; +import co.kirikiri.auth.service.mapper.OauthMapper; +import co.kirikiri.member.domain.Member; +import co.kirikiri.member.persistence.MemberRepository; +import co.kirikiri.member.service.MemberService; +import co.kirikiri.member.service.dto.OauthMemberJoinDto; +import co.kirikiri.member.service.dto.request.GenderType; import lombok.RequiredArgsConstructor; import org.springframework.core.env.Environment; import org.springframework.http.HttpHeaders; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.math.BigInteger; +import java.security.SecureRandom; +import java.util.Map; +import java.util.Optional; @Service @Transactional(readOnly = true) @@ -58,17 +57,19 @@ private String getProperty(final String property) { @Transactional public AuthenticationResponse login(final Map queryParams) { - final NaverOauthTokenDto naverOauthTokenDto = oauthNetworkService.requestToken(NaverOauthTokenDto.class, - queryParams).getBody(); + final NaverOauthTokenDto naverOauthTokenDto = oauthNetworkService.requestToken(NaverOauthTokenDto.class, queryParams) + .getBody(); final NaverMemberProfileDto naverMemberProfileDto = getNaverMemberProfileDto(naverOauthTokenDto.accessToken()); final NaverMemberProfileResponseDto naverMemberProfileResponseDto = naverMemberProfileDto.response(); final Optional optionalMember = memberRepository.findByOauthId(naverMemberProfileResponseDto.id()); - if (optionalMember.isPresent()) { - final Member member = optionalMember.get(); - return authService.oauthLogin(member); - } + final Member savedMember = optionalMember.orElseGet(() -> saveMember(naverMemberProfileResponseDto)); + return authService.oauthLogin(savedMember); + } + + private Member saveMember(final NaverMemberProfileResponseDto naverMemberProfileResponseDto) { return memberService.oauthJoin( - new OauthMemberJoinDto(naverMemberProfileResponseDto.id(), naverMemberProfileResponseDto.email(), + new OauthMemberJoinDto(naverMemberProfileResponseDto.id(), + naverMemberProfileResponseDto.email(), naverMemberProfileResponseDto.nickname(), GenderType.findByOauthType(naverMemberProfileResponseDto.gender()))); } diff --git a/backend/kirikiri/src/main/java/co/kirikiri/service/OauthNetworkService.java b/backend/kirikiri/src/main/java/co/kirikiri/auth/service/OauthNetworkService.java similarity index 90% rename from backend/kirikiri/src/main/java/co/kirikiri/service/OauthNetworkService.java rename to backend/kirikiri/src/main/java/co/kirikiri/auth/service/OauthNetworkService.java index ad5f67286..e013660d6 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/service/OauthNetworkService.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/auth/service/OauthNetworkService.java @@ -1,4 +1,4 @@ -package co.kirikiri.service; +package co.kirikiri.auth.service; import org.springframework.http.ResponseEntity; import java.util.Map; diff --git a/backend/kirikiri/src/main/java/co/kirikiri/service/auth/TokenProvider.java b/backend/kirikiri/src/main/java/co/kirikiri/auth/service/TokenProvider.java similarity index 92% rename from backend/kirikiri/src/main/java/co/kirikiri/service/auth/TokenProvider.java rename to backend/kirikiri/src/main/java/co/kirikiri/auth/service/TokenProvider.java index 3bed60faa..1d9ffd184 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/service/auth/TokenProvider.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/auth/service/TokenProvider.java @@ -1,4 +1,4 @@ -package co.kirikiri.service.auth; +package co.kirikiri.auth.service; import java.time.LocalDateTime; import java.util.Map; diff --git a/backend/kirikiri/src/main/java/co/kirikiri/auth/service/dto/LoginDto.java b/backend/kirikiri/src/main/java/co/kirikiri/auth/service/dto/LoginDto.java new file mode 100644 index 000000000..48c9f3ec6 --- /dev/null +++ b/backend/kirikiri/src/main/java/co/kirikiri/auth/service/dto/LoginDto.java @@ -0,0 +1,11 @@ +package co.kirikiri.auth.service.dto; + +import co.kirikiri.member.domain.vo.Identifier; +import co.kirikiri.member.domain.vo.Password; + +public record LoginDto( + Identifier identifier, + Password password +) { + +} diff --git a/backend/kirikiri/src/main/java/co/kirikiri/service/dto/auth/NaverMemberProfileDto.java b/backend/kirikiri/src/main/java/co/kirikiri/auth/service/dto/NaverMemberProfileDto.java similarity index 89% rename from backend/kirikiri/src/main/java/co/kirikiri/service/dto/auth/NaverMemberProfileDto.java rename to backend/kirikiri/src/main/java/co/kirikiri/auth/service/dto/NaverMemberProfileDto.java index 66218b592..854c6e909 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/service/dto/auth/NaverMemberProfileDto.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/auth/service/dto/NaverMemberProfileDto.java @@ -1,4 +1,4 @@ -package co.kirikiri.service.dto.auth; +package co.kirikiri.auth.service.dto; import com.fasterxml.jackson.databind.PropertyNamingStrategies; import com.fasterxml.jackson.databind.annotation.JsonNaming; diff --git a/backend/kirikiri/src/main/java/co/kirikiri/service/dto/auth/NaverMemberProfileResponseDto.java b/backend/kirikiri/src/main/java/co/kirikiri/auth/service/dto/NaverMemberProfileResponseDto.java similarity index 89% rename from backend/kirikiri/src/main/java/co/kirikiri/service/dto/auth/NaverMemberProfileResponseDto.java rename to backend/kirikiri/src/main/java/co/kirikiri/auth/service/dto/NaverMemberProfileResponseDto.java index c2e073300..e588d720c 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/service/dto/auth/NaverMemberProfileResponseDto.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/auth/service/dto/NaverMemberProfileResponseDto.java @@ -1,4 +1,4 @@ -package co.kirikiri.service.dto.auth; +package co.kirikiri.auth.service.dto; import com.fasterxml.jackson.databind.PropertyNamingStrategies; import com.fasterxml.jackson.databind.annotation.JsonNaming; diff --git a/backend/kirikiri/src/main/java/co/kirikiri/service/dto/auth/NaverOauthTokenDto.java b/backend/kirikiri/src/main/java/co/kirikiri/auth/service/dto/NaverOauthTokenDto.java similarity index 90% rename from backend/kirikiri/src/main/java/co/kirikiri/service/dto/auth/NaverOauthTokenDto.java rename to backend/kirikiri/src/main/java/co/kirikiri/auth/service/dto/NaverOauthTokenDto.java index eb3b782ea..e51b0e055 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/service/dto/auth/NaverOauthTokenDto.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/auth/service/dto/NaverOauthTokenDto.java @@ -1,4 +1,4 @@ -package co.kirikiri.service.dto.auth; +package co.kirikiri.auth.service.dto; import com.fasterxml.jackson.databind.PropertyNamingStrategies; import com.fasterxml.jackson.databind.annotation.JsonNaming; diff --git a/backend/kirikiri/src/main/java/co/kirikiri/service/dto/auth/request/LoginRequest.java b/backend/kirikiri/src/main/java/co/kirikiri/auth/service/dto/request/LoginRequest.java similarity index 86% rename from backend/kirikiri/src/main/java/co/kirikiri/service/dto/auth/request/LoginRequest.java rename to backend/kirikiri/src/main/java/co/kirikiri/auth/service/dto/request/LoginRequest.java index cc901cbdf..19c30276f 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/service/dto/auth/request/LoginRequest.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/auth/service/dto/request/LoginRequest.java @@ -1,4 +1,4 @@ -package co.kirikiri.service.dto.auth.request; +package co.kirikiri.auth.service.dto.request; import jakarta.validation.constraints.NotBlank; diff --git a/backend/kirikiri/src/main/java/co/kirikiri/service/dto/auth/request/ReissueTokenRequest.java b/backend/kirikiri/src/main/java/co/kirikiri/auth/service/dto/request/ReissueTokenRequest.java similarity index 81% rename from backend/kirikiri/src/main/java/co/kirikiri/service/dto/auth/request/ReissueTokenRequest.java rename to backend/kirikiri/src/main/java/co/kirikiri/auth/service/dto/request/ReissueTokenRequest.java index 68c220de0..16566c0c3 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/service/dto/auth/request/ReissueTokenRequest.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/auth/service/dto/request/ReissueTokenRequest.java @@ -1,4 +1,4 @@ -package co.kirikiri.service.dto.auth.request; +package co.kirikiri.auth.service.dto.request; import jakarta.validation.constraints.NotBlank; diff --git a/backend/kirikiri/src/main/java/co/kirikiri/service/dto/auth/response/AuthenticationResponse.java b/backend/kirikiri/src/main/java/co/kirikiri/auth/service/dto/response/AuthenticationResponse.java similarity index 68% rename from backend/kirikiri/src/main/java/co/kirikiri/service/dto/auth/response/AuthenticationResponse.java rename to backend/kirikiri/src/main/java/co/kirikiri/auth/service/dto/response/AuthenticationResponse.java index 5c71cf9d1..d7c9971dc 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/service/dto/auth/response/AuthenticationResponse.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/auth/service/dto/response/AuthenticationResponse.java @@ -1,4 +1,4 @@ -package co.kirikiri.service.dto.auth.response; +package co.kirikiri.auth.service.dto.response; public record AuthenticationResponse( String refreshToken, diff --git a/backend/kirikiri/src/main/java/co/kirikiri/service/dto/auth/OauthRedirectResponse.java b/backend/kirikiri/src/main/java/co/kirikiri/auth/service/dto/response/OauthRedirectResponse.java similarity index 64% rename from backend/kirikiri/src/main/java/co/kirikiri/service/dto/auth/OauthRedirectResponse.java rename to backend/kirikiri/src/main/java/co/kirikiri/auth/service/dto/response/OauthRedirectResponse.java index 983d60487..6041f63e4 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/service/dto/auth/OauthRedirectResponse.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/auth/service/dto/response/OauthRedirectResponse.java @@ -1,4 +1,4 @@ -package co.kirikiri.service.dto.auth; +package co.kirikiri.auth.service.dto.response; public record OauthRedirectResponse( String url, diff --git a/backend/kirikiri/src/main/java/co/kirikiri/service/mapper/AuthMapper.java b/backend/kirikiri/src/main/java/co/kirikiri/auth/service/mapper/AuthMapper.java similarity index 66% rename from backend/kirikiri/src/main/java/co/kirikiri/service/mapper/AuthMapper.java rename to backend/kirikiri/src/main/java/co/kirikiri/auth/service/mapper/AuthMapper.java index 4809ca258..a82e7b6cb 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/service/mapper/AuthMapper.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/auth/service/mapper/AuthMapper.java @@ -1,10 +1,10 @@ -package co.kirikiri.service.mapper; +package co.kirikiri.auth.service.mapper; -import co.kirikiri.domain.member.vo.Identifier; -import co.kirikiri.domain.member.vo.Password; -import co.kirikiri.service.dto.auth.LoginDto; -import co.kirikiri.service.dto.auth.request.LoginRequest; -import co.kirikiri.service.dto.auth.response.AuthenticationResponse; +import co.kirikiri.auth.service.dto.LoginDto; +import co.kirikiri.auth.service.dto.request.LoginRequest; +import co.kirikiri.auth.service.dto.response.AuthenticationResponse; +import co.kirikiri.member.domain.vo.Identifier; +import co.kirikiri.member.domain.vo.Password; import lombok.AccessLevel; import lombok.NoArgsConstructor; diff --git a/backend/kirikiri/src/main/java/co/kirikiri/service/mapper/OauthMapper.java b/backend/kirikiri/src/main/java/co/kirikiri/auth/service/mapper/OauthMapper.java similarity index 64% rename from backend/kirikiri/src/main/java/co/kirikiri/service/mapper/OauthMapper.java rename to backend/kirikiri/src/main/java/co/kirikiri/auth/service/mapper/OauthMapper.java index d302d2f00..df8cf4025 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/service/mapper/OauthMapper.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/auth/service/mapper/OauthMapper.java @@ -1,6 +1,6 @@ -package co.kirikiri.service.mapper; +package co.kirikiri.auth.service.mapper; -import co.kirikiri.service.dto.auth.OauthRedirectResponse; +import co.kirikiri.auth.service.dto.response.OauthRedirectResponse; public class OauthMapper { diff --git a/backend/kirikiri/src/main/java/co/kirikiri/checkfeed/service/GoalRoomCheckFeedService.java b/backend/kirikiri/src/main/java/co/kirikiri/checkfeed/service/GoalRoomCheckFeedService.java index 8c60ed483..eacf550c1 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/checkfeed/service/GoalRoomCheckFeedService.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/checkfeed/service/GoalRoomCheckFeedService.java @@ -18,14 +18,14 @@ import co.kirikiri.common.service.dto.FileInformation; import co.kirikiri.common.type.ImageContentType; import co.kirikiri.common.type.ImageDirType; -import co.kirikiri.domain.member.Member; -import co.kirikiri.domain.member.vo.Identifier; import co.kirikiri.goalroom.domain.GoalRoom; import co.kirikiri.goalroom.domain.GoalRoomMember; import co.kirikiri.goalroom.domain.GoalRoomRoadmapNode; import co.kirikiri.goalroom.persistence.GoalRoomMemberRepository; import co.kirikiri.goalroom.persistence.GoalRoomRepository; -import co.kirikiri.persistence.member.MemberRepository; +import co.kirikiri.member.domain.Member; +import co.kirikiri.member.domain.vo.Identifier; +import co.kirikiri.member.persistence.MemberRepository; import java.net.URL; import java.time.LocalDate; import java.time.LocalDateTime; diff --git a/backend/kirikiri/src/main/java/co/kirikiri/common/aop/ExceptionConvertAop.java b/backend/kirikiri/src/main/java/co/kirikiri/common/aop/ExceptionConvertAop.java index 75a043acd..00366e6bf 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/common/aop/ExceptionConvertAop.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/common/aop/ExceptionConvertAop.java @@ -1,9 +1,9 @@ package co.kirikiri.common.aop; import co.kirikiri.common.exception.BadRequestException; -import co.kirikiri.common.exception.DomainException; import co.kirikiri.common.exception.ServerException; -import co.kirikiri.common.exception.UnexpectedDomainException; +import co.kirikiri.common.exception.domain.DomainException; +import co.kirikiri.common.exception.domain.UnexpectedDomainException; import org.aspectj.lang.annotation.AfterThrowing; import org.aspectj.lang.annotation.Aspect; import org.springframework.stereotype.Component; diff --git a/backend/kirikiri/src/main/java/co/kirikiri/common/config/RedisConfig.java b/backend/kirikiri/src/main/java/co/kirikiri/common/config/RedisConfig.java index e49a413d9..ad4109bc5 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/common/config/RedisConfig.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/common/config/RedisConfig.java @@ -2,7 +2,6 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; -import java.time.Duration; import org.springframework.cache.CacheManager; import org.springframework.cache.annotation.EnableCaching; import org.springframework.context.annotation.Bean; @@ -16,6 +15,7 @@ import org.springframework.data.redis.serializer.RedisSerializationContext; import org.springframework.data.redis.serializer.RedisSerializer; import org.springframework.data.redis.serializer.StringRedisSerializer; +import java.time.Duration; @Configuration @EnableCaching diff --git a/backend/kirikiri/src/main/java/co/kirikiri/common/exception/DomainException.java b/backend/kirikiri/src/main/java/co/kirikiri/common/exception/DomainException.java index 6d458a6c9..e69de29bb 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/common/exception/DomainException.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/common/exception/DomainException.java @@ -1,8 +0,0 @@ -package co.kirikiri.common.exception; - -public class DomainException extends RuntimeException { - - public DomainException(final String message) { - super(message); - } -} diff --git a/backend/kirikiri/src/main/java/co/kirikiri/common/exception/domain/DomainException.java b/backend/kirikiri/src/main/java/co/kirikiri/common/exception/domain/DomainException.java new file mode 100644 index 000000000..4d53b691f --- /dev/null +++ b/backend/kirikiri/src/main/java/co/kirikiri/common/exception/domain/DomainException.java @@ -0,0 +1,8 @@ +package co.kirikiri.common.exception.domain; + +public class DomainException extends RuntimeException { + + public DomainException(final String message) { + super(message); + } +} diff --git a/backend/kirikiri/src/main/java/co/kirikiri/common/exception/ImageExtensionException.java b/backend/kirikiri/src/main/java/co/kirikiri/common/exception/domain/ImageExtensionException.java similarity index 77% rename from backend/kirikiri/src/main/java/co/kirikiri/common/exception/ImageExtensionException.java rename to backend/kirikiri/src/main/java/co/kirikiri/common/exception/domain/ImageExtensionException.java index 1643f0399..e60fff500 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/common/exception/ImageExtensionException.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/common/exception/domain/ImageExtensionException.java @@ -1,4 +1,4 @@ -package co.kirikiri.common.exception; +package co.kirikiri.common.exception.domain; public class ImageExtensionException extends DomainException { diff --git a/backend/kirikiri/src/main/java/co/kirikiri/common/exception/UnexpectedDomainException.java b/backend/kirikiri/src/main/java/co/kirikiri/common/exception/domain/UnexpectedDomainException.java similarity index 78% rename from backend/kirikiri/src/main/java/co/kirikiri/common/exception/UnexpectedDomainException.java rename to backend/kirikiri/src/main/java/co/kirikiri/common/exception/domain/UnexpectedDomainException.java index 510f3c6bc..067c0241a 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/common/exception/UnexpectedDomainException.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/common/exception/domain/UnexpectedDomainException.java @@ -1,4 +1,4 @@ -package co.kirikiri.common.exception; +package co.kirikiri.common.exception.domain; public class UnexpectedDomainException extends DomainException { diff --git a/backend/kirikiri/src/main/java/co/kirikiri/infra/AmazonS3FileService.java b/backend/kirikiri/src/main/java/co/kirikiri/common/infra/AmazonS3FileService.java similarity index 99% rename from backend/kirikiri/src/main/java/co/kirikiri/infra/AmazonS3FileService.java rename to backend/kirikiri/src/main/java/co/kirikiri/common/infra/AmazonS3FileService.java index 1eb92cced..e603b2d28 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/infra/AmazonS3FileService.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/common/infra/AmazonS3FileService.java @@ -1,4 +1,4 @@ -package co.kirikiri.infra; +package co.kirikiri.common.infra; import co.kirikiri.common.exception.ServerException; import co.kirikiri.common.service.FileService; diff --git a/backend/kirikiri/src/main/java/co/kirikiri/infra/CloudFrontService.java b/backend/kirikiri/src/main/java/co/kirikiri/common/infra/CloudFrontService.java similarity index 97% rename from backend/kirikiri/src/main/java/co/kirikiri/infra/CloudFrontService.java rename to backend/kirikiri/src/main/java/co/kirikiri/common/infra/CloudFrontService.java index 62db3821f..984a01ca6 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/infra/CloudFrontService.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/common/infra/CloudFrontService.java @@ -1,11 +1,11 @@ -package co.kirikiri.infra; +package co.kirikiri.common.infra; import co.kirikiri.common.exception.ServerException; -import java.net.MalformedURLException; -import java.net.URL; import lombok.RequiredArgsConstructor; import org.springframework.core.env.Environment; import org.springframework.stereotype.Service; +import java.net.MalformedURLException; +import java.net.URL; @Service @RequiredArgsConstructor diff --git a/backend/kirikiri/src/main/java/co/kirikiri/common/interceptor/AuthInterceptor.java b/backend/kirikiri/src/main/java/co/kirikiri/common/interceptor/AuthInterceptor.java index cca8b0608..6c48d09bd 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/common/interceptor/AuthInterceptor.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/common/interceptor/AuthInterceptor.java @@ -1,47 +1,6 @@ package co.kirikiri.common.interceptor; -import co.kirikiri.common.exception.AuthenticationException; -import co.kirikiri.service.auth.AuthService; -import jakarta.servlet.http.HttpServletRequest; -import jakarta.servlet.http.HttpServletResponse; -import lombok.RequiredArgsConstructor; -import org.springframework.http.HttpHeaders; -import org.springframework.stereotype.Component; -import org.springframework.web.method.HandlerMethod; import org.springframework.web.servlet.HandlerInterceptor; -@Component -@RequiredArgsConstructor -public class AuthInterceptor implements HandlerInterceptor { - - private static final String BEARER = "Bearer "; - - private final AuthService authService; - - @Override - public boolean preHandle(final HttpServletRequest request, final HttpServletResponse response, - final Object handler) { - if (!(handler instanceof final HandlerMethod handlerMethod)) { - return true; - } - if (handlerMethod.hasMethodAnnotation(Authenticated.class)) { - final String authorizationHeader = request.getHeader(HttpHeaders.AUTHORIZATION); - checkHeader(authorizationHeader); - final String token = authorizationHeader.substring(BEARER.length()); - checkTokenCertify(token); - } - return true; - } - - private void checkHeader(final String authorizationHeader) { - if (authorizationHeader == null || !authorizationHeader.startsWith(BEARER)) { - throw new AuthenticationException("인증 헤더가 적절하지 않습니다."); - } - } - - private void checkTokenCertify(final String token) { - if (!authService.isCertified(token)) { - throw new AuthenticationException("토큰이 유효하지 않습니다."); - } - } +public interface AuthInterceptor extends HandlerInterceptor { } diff --git a/backend/kirikiri/src/main/java/co/kirikiri/service/mapper/ScrollResponseMapper.java b/backend/kirikiri/src/main/java/co/kirikiri/common/mapper/ScrollResponseMapper.java similarity index 93% rename from backend/kirikiri/src/main/java/co/kirikiri/service/mapper/ScrollResponseMapper.java rename to backend/kirikiri/src/main/java/co/kirikiri/common/mapper/ScrollResponseMapper.java index c9d3b4c64..3bee95b34 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/service/mapper/ScrollResponseMapper.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/common/mapper/ScrollResponseMapper.java @@ -1,4 +1,4 @@ -package co.kirikiri.service.mapper; +package co.kirikiri.common.mapper; import lombok.AccessLevel; import lombok.NoArgsConstructor; diff --git a/backend/kirikiri/src/main/java/co/kirikiri/common/persistence/QuerydslRepositorySupporter.java b/backend/kirikiri/src/main/java/co/kirikiri/common/persistence/QuerydslRepositorySupporter.java index 6300ecd13..a5d6a7a3f 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/common/persistence/QuerydslRepositorySupporter.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/common/persistence/QuerydslRepositorySupporter.java @@ -9,7 +9,6 @@ import com.querydsl.jpa.impl.JPAQueryFactory; import jakarta.annotation.PostConstruct; import jakarta.persistence.EntityManager; -import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cglib.core.internal.Function; import org.springframework.data.domain.Page; @@ -17,6 +16,7 @@ import org.springframework.data.jpa.repository.support.Querydsl; import org.springframework.data.support.PageableExecutionUtils; import org.springframework.stereotype.Repository; +import java.util.List; @Repository public abstract class QuerydslRepositorySupporter { diff --git a/backend/kirikiri/src/main/java/co/kirikiri/common/resolver/MemberIdentifierArgumentResolver.java b/backend/kirikiri/src/main/java/co/kirikiri/common/resolver/MemberIdentifierArgumentResolver.java index 462c6654f..9e1d99241 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/common/resolver/MemberIdentifierArgumentResolver.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/common/resolver/MemberIdentifierArgumentResolver.java @@ -1,47 +1,6 @@ package co.kirikiri.common.resolver; -import co.kirikiri.common.exception.AuthenticationException; -import co.kirikiri.common.exception.ServerException; -import co.kirikiri.common.interceptor.Authenticated; -import co.kirikiri.service.auth.AuthService; -import lombok.RequiredArgsConstructor; -import org.springframework.core.MethodParameter; -import org.springframework.http.HttpHeaders; -import org.springframework.stereotype.Component; -import org.springframework.web.bind.support.WebDataBinderFactory; -import org.springframework.web.context.request.NativeWebRequest; import org.springframework.web.method.support.HandlerMethodArgumentResolver; -import org.springframework.web.method.support.ModelAndViewContainer; -@Component -@RequiredArgsConstructor -public class MemberIdentifierArgumentResolver implements HandlerMethodArgumentResolver { - - private static final String BEARER = "Bearer "; - - private final AuthService authService; - - @Override - public boolean supportsParameter(final MethodParameter parameter) { - if (!parameter.hasMethodAnnotation(Authenticated.class)) { - throw new ServerException("MemberIdentifier는 인증된 사용자만 사용 가능합니다. (@Authenticated)"); - } - return parameter.getParameterType().equals(String.class) - && parameter.hasParameterAnnotation(MemberIdentifier.class); - } - - @Override - public String resolveArgument(final MethodParameter parameter, final ModelAndViewContainer mavContainer, - final NativeWebRequest webRequest, final WebDataBinderFactory binderFactory) { - final String authorizationHeader = webRequest.getHeader(HttpHeaders.AUTHORIZATION); - checkHeader(authorizationHeader); - final String token = authorizationHeader.substring(BEARER.length()); - return authService.findIdentifierByToken(token); - } - - private void checkHeader(final String authorizationHeader) { - if (authorizationHeader == null || !authorizationHeader.startsWith(BEARER)) { - throw new AuthenticationException("인증 헤더가 적절하지 않습니다."); - } - } +public interface MemberIdentifierArgumentResolver extends HandlerMethodArgumentResolver { } diff --git a/backend/kirikiri/src/main/java/co/kirikiri/common/resolver/RoadmapSaveArgumentResolver.java b/backend/kirikiri/src/main/java/co/kirikiri/common/resolver/RoadmapSaveArgumentResolver.java index 8c668086b..7ad2b1c12 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/common/resolver/RoadmapSaveArgumentResolver.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/common/resolver/RoadmapSaveArgumentResolver.java @@ -1,98 +1,7 @@ package co.kirikiri.common.resolver; -import co.kirikiri.common.exception.BadRequestException; -import co.kirikiri.service.dto.roadmap.request.RoadmapNodeSaveRequest; -import co.kirikiri.service.dto.roadmap.request.RoadmapSaveRequest; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import jakarta.servlet.http.HttpServletRequest; -import java.util.List; -import lombok.RequiredArgsConstructor; -import org.springframework.core.MethodParameter; -import org.springframework.stereotype.Component; -import org.springframework.validation.DataBinder; -import org.springframework.validation.Validator; -import org.springframework.web.bind.MethodArgumentNotValidException; -import org.springframework.web.bind.support.WebDataBinderFactory; -import org.springframework.web.context.request.NativeWebRequest; import org.springframework.web.method.support.HandlerMethodArgumentResolver; -import org.springframework.web.method.support.ModelAndViewContainer; -import org.springframework.web.multipart.MultipartFile; -import org.springframework.web.multipart.MultipartHttpServletRequest; -import org.springframework.web.multipart.MultipartResolver; -import org.springframework.web.multipart.support.StandardServletMultipartResolver; -@Component -@RequiredArgsConstructor -public class RoadmapSaveArgumentResolver implements HandlerMethodArgumentResolver { +public interface RoadmapSaveArgumentResolver extends HandlerMethodArgumentResolver { - private final ObjectMapper objectMapper; - private final Validator validator; - - @Override - public boolean supportsParameter(final MethodParameter parameter) { - return parameter.getParameterType().equals(RoadmapSaveRequest.class); - } - - @Override - public Object resolveArgument(final MethodParameter parameter, final ModelAndViewContainer mavContainer, - final NativeWebRequest nativeWebRequest, final WebDataBinderFactory binderFactory) - throws MethodArgumentNotValidException { - final HttpServletRequest request = (HttpServletRequest) nativeWebRequest.getNativeRequest(); - checkMultipart(request); - final MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; - final RoadmapSaveRequest roadmapSaveRequestNotIncludeImage = makeRoadmapSaveRequestNotIncludeImage( - multipartRequest); - validateRequest(parameter, roadmapSaveRequestNotIncludeImage); - return makeRoadmapSaveRequestIncludeImage(roadmapSaveRequestNotIncludeImage, multipartRequest); - } - - private void checkMultipart(final HttpServletRequest request) { - final MultipartResolver multipartResolver = new StandardServletMultipartResolver(); - if (!multipartResolver.isMultipart(request)) { - throw new BadRequestException("multipart/form-data 형식으로 들어와야합니다."); - } - } - - private RoadmapSaveRequest makeRoadmapSaveRequestNotIncludeImage( - final MultipartHttpServletRequest multipartRequest) { - final String jsonData = getJsonData(multipartRequest); - return bindRoadmapSaveRequest(jsonData); - } - - private void validateRequest(final MethodParameter parameter, final RoadmapSaveRequest roadmapSaveRequest) - throws MethodArgumentNotValidException { - final DataBinder binder = new DataBinder(roadmapSaveRequest); - binder.setValidator(validator); - binder.validate(); - - if (binder.getBindingResult().hasErrors()) { - throw new MethodArgumentNotValidException(parameter, binder.getBindingResult()); - } - } - - private RoadmapSaveRequest makeRoadmapSaveRequestIncludeImage(final RoadmapSaveRequest roadmapSaveRequest, - final MultipartHttpServletRequest multipartRequest) { - for (final RoadmapNodeSaveRequest roadmapNode : roadmapSaveRequest.roadmapNodes()) { - final List images = multipartRequest.getFiles(roadmapNode.getTitle()); - roadmapNode.setImages(images); - } - return roadmapSaveRequest; - } - - private String getJsonData(final MultipartHttpServletRequest multipartRequest) { - final String jsonData = multipartRequest.getParameter("jsonData"); - if (jsonData == null) { - throw new BadRequestException("로드맵 생성 시 jsonData는 필수입니다."); - } - return multipartRequest.getParameter("jsonData"); - } - - private RoadmapSaveRequest bindRoadmapSaveRequest(final String jsonData) { - try { - return objectMapper.readValue(jsonData, RoadmapSaveRequest.class); - } catch (final JsonProcessingException exception) { - throw new BadRequestException("로드맵 생성 요청 형식이 틀렸습니다."); - } - } } diff --git a/backend/kirikiri/src/main/java/co/kirikiri/service/CacheKeyGenerator.java b/backend/kirikiri/src/main/java/co/kirikiri/common/service/CacheKeyGenerator.java similarity index 95% rename from backend/kirikiri/src/main/java/co/kirikiri/service/CacheKeyGenerator.java rename to backend/kirikiri/src/main/java/co/kirikiri/common/service/CacheKeyGenerator.java index 2a11fcd5d..79ffb2cfc 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/service/CacheKeyGenerator.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/common/service/CacheKeyGenerator.java @@ -1,10 +1,10 @@ -package co.kirikiri.service; +package co.kirikiri.common.service; +import org.springframework.cache.interceptor.KeyGenerator; +import org.springframework.stereotype.Component; import java.lang.reflect.Method; import java.util.Arrays; import java.util.stream.Collectors; -import org.springframework.cache.interceptor.KeyGenerator; -import org.springframework.stereotype.Component; @Component public class CacheKeyGenerator implements KeyGenerator { diff --git a/backend/kirikiri/src/main/java/co/kirikiri/service/NumberGenerator.java b/backend/kirikiri/src/main/java/co/kirikiri/common/service/NumberGenerator.java similarity index 62% rename from backend/kirikiri/src/main/java/co/kirikiri/service/NumberGenerator.java rename to backend/kirikiri/src/main/java/co/kirikiri/common/service/NumberGenerator.java index 2c289f458..8c48cc5c4 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/service/NumberGenerator.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/common/service/NumberGenerator.java @@ -1,4 +1,4 @@ -package co.kirikiri.service; +package co.kirikiri.common.service; public interface NumberGenerator { diff --git a/backend/kirikiri/src/main/java/co/kirikiri/service/UUIDFilePathGenerator.java b/backend/kirikiri/src/main/java/co/kirikiri/common/service/UUIDFilePathGenerator.java similarity index 95% rename from backend/kirikiri/src/main/java/co/kirikiri/service/UUIDFilePathGenerator.java rename to backend/kirikiri/src/main/java/co/kirikiri/common/service/UUIDFilePathGenerator.java index ebdf8ca81..0df4ecd3b 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/service/UUIDFilePathGenerator.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/common/service/UUIDFilePathGenerator.java @@ -1,7 +1,6 @@ -package co.kirikiri.service; +package co.kirikiri.common.service; import co.kirikiri.common.exception.BadRequestException; -import co.kirikiri.common.service.FilePathGenerator; import co.kirikiri.common.type.ImageDirType; import java.time.LocalDate; import java.time.format.DateTimeFormatter; diff --git a/backend/kirikiri/src/main/java/co/kirikiri/service/dto/CustomScrollRequest.java b/backend/kirikiri/src/main/java/co/kirikiri/common/service/dto/CustomScrollRequest.java similarity index 83% rename from backend/kirikiri/src/main/java/co/kirikiri/service/dto/CustomScrollRequest.java rename to backend/kirikiri/src/main/java/co/kirikiri/common/service/dto/CustomScrollRequest.java index f76ab1dd8..de8c7baec 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/service/dto/CustomScrollRequest.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/common/service/dto/CustomScrollRequest.java @@ -1,4 +1,4 @@ -package co.kirikiri.service.dto; +package co.kirikiri.common.service.dto; import jakarta.validation.constraints.NotNull; diff --git a/backend/kirikiri/src/main/java/co/kirikiri/common/type/ImageContentType.java b/backend/kirikiri/src/main/java/co/kirikiri/common/type/ImageContentType.java index faf34f204..4c86287a0 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/common/type/ImageContentType.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/common/type/ImageContentType.java @@ -1,6 +1,6 @@ package co.kirikiri.common.type; -import co.kirikiri.common.exception.ImageExtensionException; +import co.kirikiri.common.exception.domain.ImageExtensionException; import java.util.Arrays; public enum ImageContentType { diff --git a/backend/kirikiri/src/main/java/co/kirikiri/domain/roadmap/RoadmapContents.java b/backend/kirikiri/src/main/java/co/kirikiri/domain/roadmap/RoadmapContents.java deleted file mode 100644 index 4677640f2..000000000 --- a/backend/kirikiri/src/main/java/co/kirikiri/domain/roadmap/RoadmapContents.java +++ /dev/null @@ -1,42 +0,0 @@ -package co.kirikiri.domain.roadmap; - -import jakarta.persistence.CascadeType; -import jakarta.persistence.Column; -import jakarta.persistence.Embeddable; -import jakarta.persistence.FetchType; -import jakarta.persistence.OneToMany; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; -import java.util.ArrayList; -import java.util.List; -import java.util.Optional; - -@Embeddable -@NoArgsConstructor(access = AccessLevel.PROTECTED) -public class RoadmapContents { - - @OneToMany(fetch = FetchType.LAZY, - cascade = {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE}, - mappedBy = "roadmap") - @Column(nullable = false) - private final List values = new ArrayList<>(); - - public RoadmapContents(final List contents) { - this.values.addAll(contents); - } - - public void add(final RoadmapContent content) { - this.values.add(content); - } - - public Optional findLastRoadmapContent() { - if (values.isEmpty()) { - return Optional.empty(); - } - return Optional.of(values.get(values.size() - 1)); - } - - public List getValues() { - return values; - } -} diff --git a/backend/kirikiri/src/main/java/co/kirikiri/domain/roadmap/RoadmapReviews.java b/backend/kirikiri/src/main/java/co/kirikiri/domain/roadmap/RoadmapReviews.java deleted file mode 100644 index 706c14b6f..000000000 --- a/backend/kirikiri/src/main/java/co/kirikiri/domain/roadmap/RoadmapReviews.java +++ /dev/null @@ -1,24 +0,0 @@ -package co.kirikiri.domain.roadmap; - -import jakarta.persistence.CascadeType; -import jakarta.persistence.Embeddable; -import jakarta.persistence.FetchType; -import jakarta.persistence.OneToMany; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; -import java.util.ArrayList; -import java.util.List; - -@Embeddable -@NoArgsConstructor(access = AccessLevel.PROTECTED) -public class RoadmapReviews { - - @OneToMany(fetch = FetchType.LAZY, - cascade = {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE}, - orphanRemoval = true, mappedBy = "roadmap") - private List values = new ArrayList<>(); - - public void add(final RoadmapReview review) { - this.values.add(review); - } -} diff --git a/backend/kirikiri/src/main/java/co/kirikiri/goalroom/domain/BaseGoalRoomMember.java b/backend/kirikiri/src/main/java/co/kirikiri/goalroom/domain/BaseGoalRoomMember.java index be129f359..578c963ea 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/goalroom/domain/BaseGoalRoomMember.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/goalroom/domain/BaseGoalRoomMember.java @@ -8,12 +8,14 @@ import jakarta.persistence.ManyToOne; import jakarta.persistence.MappedSuperclass; import jakarta.persistence.PrePersist; -import java.time.LocalDateTime; -import java.time.format.DateTimeFormatter; -import java.util.Objects; import lombok.AccessLevel; import lombok.NoArgsConstructor; +import org.hibernate.annotations.OnDelete; +import org.hibernate.annotations.OnDeleteAction; import org.springframework.data.annotation.CreatedDate; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.util.Objects; @MappedSuperclass @NoArgsConstructor(access = AccessLevel.PROTECTED) @@ -29,6 +31,7 @@ public abstract class BaseGoalRoomMember extends BaseEntity { @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "goal_room_id", nullable = false) + @OnDelete(action = OnDeleteAction.CASCADE) protected GoalRoom goalRoom; protected Long memberId; diff --git a/backend/kirikiri/src/main/java/co/kirikiri/goalroom/domain/GoalRoomMembers.java b/backend/kirikiri/src/main/java/co/kirikiri/goalroom/domain/GoalRoomMembers.java index d3fbbfe3b..3d6f142bf 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/goalroom/domain/GoalRoomMembers.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/goalroom/domain/GoalRoomMembers.java @@ -1,6 +1,6 @@ package co.kirikiri.goalroom.domain; -import co.kirikiri.common.exception.UnexpectedDomainException; +import co.kirikiri.common.exception.domain.UnexpectedDomainException; import java.util.ArrayList; import java.util.Comparator; import java.util.List; diff --git a/backend/kirikiri/src/main/java/co/kirikiri/goalroom/domain/GoalRoomPendingMembers.java b/backend/kirikiri/src/main/java/co/kirikiri/goalroom/domain/GoalRoomPendingMembers.java index f8e42bc4b..f137495b8 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/goalroom/domain/GoalRoomPendingMembers.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/goalroom/domain/GoalRoomPendingMembers.java @@ -1,6 +1,6 @@ package co.kirikiri.goalroom.domain; -import co.kirikiri.common.exception.UnexpectedDomainException; +import co.kirikiri.common.exception.domain.UnexpectedDomainException; import java.util.ArrayList; import java.util.Comparator; import java.util.List; diff --git a/backend/kirikiri/src/main/java/co/kirikiri/goalroom/domain/GoalRoomRoadmapNodes.java b/backend/kirikiri/src/main/java/co/kirikiri/goalroom/domain/GoalRoomRoadmapNodes.java index f7458d21d..ba254eeb3 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/goalroom/domain/GoalRoomRoadmapNodes.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/goalroom/domain/GoalRoomRoadmapNodes.java @@ -6,6 +6,8 @@ import jakarta.persistence.FetchType; import jakarta.persistence.JoinColumn; import jakarta.persistence.OneToMany; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; import java.time.LocalDate; import java.time.temporal.ChronoUnit; import java.util.ArrayList; @@ -13,8 +15,6 @@ import java.util.List; import java.util.Optional; import java.util.stream.IntStream; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; @Embeddable @NoArgsConstructor(access = AccessLevel.PROTECTED) diff --git a/backend/kirikiri/src/main/java/co/kirikiri/goalroom/domain/exception/GoalRoomException.java b/backend/kirikiri/src/main/java/co/kirikiri/goalroom/domain/exception/GoalRoomException.java index e25c5dda5..1a3212a75 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/goalroom/domain/exception/GoalRoomException.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/goalroom/domain/exception/GoalRoomException.java @@ -1,6 +1,6 @@ package co.kirikiri.goalroom.domain.exception; -import co.kirikiri.common.exception.DomainException; +import co.kirikiri.common.exception.domain.DomainException; public class GoalRoomException extends DomainException { diff --git a/backend/kirikiri/src/main/java/co/kirikiri/goalroom/domain/vo/Period.java b/backend/kirikiri/src/main/java/co/kirikiri/goalroom/domain/vo/Period.java index eabaf447f..8426a34e2 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/goalroom/domain/vo/Period.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/goalroom/domain/vo/Period.java @@ -3,10 +3,10 @@ import co.kirikiri.goalroom.domain.exception.GoalRoomException; import jakarta.persistence.Column; import jakarta.persistence.Embeddable; -import java.time.LocalDate; -import java.time.temporal.ChronoUnit; import lombok.AccessLevel; import lombok.NoArgsConstructor; +import java.time.LocalDate; +import java.time.temporal.ChronoUnit; @Embeddable @NoArgsConstructor(access = AccessLevel.PROTECTED) diff --git a/backend/kirikiri/src/main/java/co/kirikiri/goalroom/persistence/GoalRoomMemberQueryRepository.java b/backend/kirikiri/src/main/java/co/kirikiri/goalroom/persistence/GoalRoomMemberQueryRepository.java index 42a931835..d41686713 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/goalroom/persistence/GoalRoomMemberQueryRepository.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/goalroom/persistence/GoalRoomMemberQueryRepository.java @@ -8,9 +8,9 @@ public interface GoalRoomMemberQueryRepository { - Optional findByRoadmapIdAndMemberIdentifierAndGoalRoomStatus(final Long roadmapId, - final Long memberId, - final GoalRoomStatus status); + Optional findByRoadmapIdAndMemberIdAndGoalRoomStatus(final Long roadmapId, + final Long memberId, + final GoalRoomStatus status); List findByGoalRoomIdOrderedBySortType(final Long goalRoomId, final GoalRoomMemberSortType sortType); diff --git a/backend/kirikiri/src/main/java/co/kirikiri/goalroom/persistence/GoalRoomMemberQueryRepositoryImpl.java b/backend/kirikiri/src/main/java/co/kirikiri/goalroom/persistence/GoalRoomMemberQueryRepositoryImpl.java index fd932e21c..446dbec8a 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/goalroom/persistence/GoalRoomMemberQueryRepositoryImpl.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/goalroom/persistence/GoalRoomMemberQueryRepositoryImpl.java @@ -22,9 +22,9 @@ public GoalRoomMemberQueryRepositoryImpl() { } @Override - public Optional findByRoadmapIdAndMemberIdentifierAndGoalRoomStatus(final Long roadmapId, - final Long memberId, - final GoalRoomStatus status) { + public Optional findByRoadmapIdAndMemberIdAndGoalRoomStatus(final Long roadmapId, + final Long memberId, + final GoalRoomStatus status) { return Optional.ofNullable(selectFrom(goalRoomMember) .innerJoin(goalRoomMember.goalRoom, goalRoom) .fetchJoin() diff --git a/backend/kirikiri/src/main/java/co/kirikiri/goalroom/service/GoalRoomCreateEventListener.java b/backend/kirikiri/src/main/java/co/kirikiri/goalroom/service/GoalRoomCreateEventListener.java index b960c8e28..49af35db0 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/goalroom/service/GoalRoomCreateEventListener.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/goalroom/service/GoalRoomCreateEventListener.java @@ -2,15 +2,15 @@ import co.kirikiri.common.aop.ExceptionConvert; import co.kirikiri.common.exception.NotFoundException; -import co.kirikiri.domain.member.Member; -import co.kirikiri.domain.member.vo.Identifier; import co.kirikiri.goalroom.domain.GoalRoom; import co.kirikiri.goalroom.domain.GoalRoomPendingMember; import co.kirikiri.goalroom.domain.GoalRoomRole; import co.kirikiri.goalroom.persistence.GoalRoomPendingMemberRepository; import co.kirikiri.goalroom.persistence.GoalRoomRepository; import co.kirikiri.goalroom.service.event.GoalRoomCreateEvent; -import co.kirikiri.persistence.member.MemberRepository; +import co.kirikiri.member.domain.Member; +import co.kirikiri.member.domain.vo.Identifier; +import co.kirikiri.member.persistence.MemberRepository; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; diff --git a/backend/kirikiri/src/main/java/co/kirikiri/goalroom/service/GoalRoomCreateService.java b/backend/kirikiri/src/main/java/co/kirikiri/goalroom/service/GoalRoomCreateService.java index 04c6fd0be..a4e9d84ed 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/goalroom/service/GoalRoomCreateService.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/goalroom/service/GoalRoomCreateService.java @@ -3,11 +3,6 @@ import co.kirikiri.common.aop.ExceptionConvert; import co.kirikiri.common.exception.BadRequestException; import co.kirikiri.common.exception.NotFoundException; -import co.kirikiri.domain.member.Member; -import co.kirikiri.domain.member.vo.Identifier; -import co.kirikiri.domain.roadmap.Roadmap; -import co.kirikiri.domain.roadmap.RoadmapContent; -import co.kirikiri.domain.roadmap.RoadmapNode; import co.kirikiri.goalroom.domain.GoalRoom; import co.kirikiri.goalroom.domain.GoalRoomMember; import co.kirikiri.goalroom.domain.GoalRoomMembers; @@ -26,8 +21,14 @@ import co.kirikiri.goalroom.service.event.GoalRoomCreateEvent; import co.kirikiri.goalroom.service.event.GoalRoomLeaveEvent; import co.kirikiri.goalroom.service.mapper.GoalRoomMapper; -import co.kirikiri.persistence.member.MemberRepository; -import co.kirikiri.persistence.roadmap.RoadmapContentRepository; +import co.kirikiri.member.domain.Member; +import co.kirikiri.member.domain.vo.Identifier; +import co.kirikiri.member.persistence.MemberRepository; +import co.kirikiri.roadmap.domain.Roadmap; +import co.kirikiri.roadmap.domain.RoadmapContent; +import co.kirikiri.roadmap.domain.RoadmapNode; +import co.kirikiri.roadmap.persistence.RoadmapContentRepository; +import co.kirikiri.roadmap.persistence.RoadmapRepository; import java.util.List; import lombok.RequiredArgsConstructor; import org.springframework.context.ApplicationEventPublisher; @@ -44,6 +45,7 @@ public class GoalRoomCreateService { private final GoalRoomPendingMemberRepository goalRoomPendingMemberRepository; private final GoalRoomMemberRepository goalRoomMemberRepository; private final RoadmapContentRepository roadmapContentRepository; + private final RoadmapRepository roadmapRepository; private final MemberRepository memberRepository; private final ApplicationEventPublisher applicationEventPublisher; @@ -61,17 +63,22 @@ public Long create(final GoalRoomCreateRequest goalRoomCreateRequest, final Stri } private RoadmapContent findRoadmapContentById(final Long roadmapContentId) { - return roadmapContentRepository.findByIdWithRoadmap(roadmapContentId) - .orElseThrow(() -> new NotFoundException("존재하지 않는 로드맵입니다.")); + return roadmapContentRepository.findById(roadmapContentId) + .orElseThrow(() -> new NotFoundException("존재하지 않는 로드맵 본문입니다.")); } private void validateDeletedRoadmap(final RoadmapContent roadmapContent) { - final Roadmap roadmap = roadmapContent.getRoadmap(); + final Roadmap roadmap = findRoadmapById(roadmapContent.getRoadmapId()); if (roadmap.isDeleted()) { throw new BadRequestException("삭제된 로드맵에 대해 골룸을 생성할 수 없습니다."); } } + private Roadmap findRoadmapById(final Long roadmapId) { + return roadmapRepository.findById(roadmapId) + .orElseThrow(() -> new NotFoundException("존재하지 않는 로드맵입니다.")); + } + private void validateNodeSizeEqual(final int roadmapNodesSize, final int goalRoomRoadmapNodeDtosSize) { if (roadmapNodesSize != goalRoomRoadmapNodeDtosSize) { throw new BadRequestException("모든 노드에 대해 기간이 설정돼야 합니다."); diff --git a/backend/kirikiri/src/main/java/co/kirikiri/goalroom/service/GoalRoomReadService.java b/backend/kirikiri/src/main/java/co/kirikiri/goalroom/service/GoalRoomReadService.java index ac872e475..24be54849 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/goalroom/service/GoalRoomReadService.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/goalroom/service/GoalRoomReadService.java @@ -4,11 +4,6 @@ import co.kirikiri.common.exception.ForbiddenException; import co.kirikiri.common.exception.NotFoundException; import co.kirikiri.common.service.FileService; -import co.kirikiri.domain.member.Member; -import co.kirikiri.domain.member.vo.Identifier; -import co.kirikiri.domain.roadmap.RoadmapContent; -import co.kirikiri.domain.roadmap.RoadmapNode; -import co.kirikiri.domain.roadmap.RoadmapNodes; import co.kirikiri.goalroom.domain.GoalRoom; import co.kirikiri.goalroom.domain.GoalRoomMember; import co.kirikiri.goalroom.domain.GoalRoomPendingMember; @@ -35,9 +30,13 @@ import co.kirikiri.goalroom.service.dto.response.MemberGoalRoomForListResponse; import co.kirikiri.goalroom.service.dto.response.MemberGoalRoomResponse; import co.kirikiri.goalroom.service.mapper.GoalRoomMapper; -import co.kirikiri.persistence.member.MemberRepository; -import co.kirikiri.persistence.roadmap.RoadmapContentRepository; -import co.kirikiri.persistence.roadmap.RoadmapNodeRepository; +import co.kirikiri.member.domain.Member; +import co.kirikiri.member.domain.vo.Identifier; +import co.kirikiri.member.persistence.MemberRepository; +import co.kirikiri.roadmap.domain.RoadmapContent; +import co.kirikiri.roadmap.domain.RoadmapNode; +import co.kirikiri.roadmap.persistence.RoadmapContentRepository; +import co.kirikiri.roadmap.persistence.RoadmapNodeRepository; import java.net.URL; import java.util.List; import lombok.RequiredArgsConstructor; @@ -63,12 +62,11 @@ public class GoalRoomReadService { public GoalRoomCertifiedResponse findGoalRoom(final String identifier, final Long goalRoomId) { final GoalRoom goalRoom = findGoalRoomWithRoadmapContentById(goalRoomId); - final RoadmapContent roadmapContent = findRoadmapContentById(goalRoom.getRoadmapContentId()); - final List roadmapNodes = roadmapNodeRepository.findAllByRoadmapContent(roadmapContent); + final RoadmapContent roadmapContent = findRoadmapContentByIdWithRoadmapNodes(goalRoom.getRoadmapContentId()); final boolean isJoined = isMemberGoalRoomJoin(new Identifier(identifier), goalRoom); return GoalRoomMapper.convertGoalRoomCertifiedResponse(goalRoom, getCurrentMemberCount(goalRoom), - new RoadmapNodes(roadmapNodes), isJoined); + roadmapContent.getNodes(), isJoined); } private GoalRoom findGoalRoomWithRoadmapContentById(final Long goalRoomId) { @@ -76,8 +74,8 @@ private GoalRoom findGoalRoomWithRoadmapContentById(final Long goalRoomId) { .orElseThrow(() -> new NotFoundException("골룸 정보가 존재하지 않습니다. goalRoomId = " + goalRoomId)); } - private RoadmapContent findRoadmapContentById(final Long roadmapContentId) { - return roadmapContentRepository.findById(roadmapContentId) + private RoadmapContent findRoadmapContentByIdWithRoadmapNodes(final Long roadmapContentId) { + return roadmapContentRepository.findByIdWithRoadmapNodes(roadmapContentId) .orElseThrow(() -> new NotFoundException( "존재하지 않는 로드맵 컨텐츠 아이디입니다. roadmapContentId = " + roadmapContentId)); } @@ -101,10 +99,9 @@ private int getCurrentMemberCount(final GoalRoom goalRoom) { public GoalRoomResponse findGoalRoom(final Long goalRoomId) { final GoalRoom goalRoom = findGoalRoomWithRoadmapContentById(goalRoomId); - final RoadmapContent roadmapContent = findRoadmapContentById(goalRoom.getRoadmapContentId()); - final List roadmapNodes = roadmapNodeRepository.findAllByRoadmapContent(roadmapContent); + final RoadmapContent roadmapContent = findRoadmapContentByIdWithRoadmapNodes(goalRoom.getRoadmapContentId()); return GoalRoomMapper.convertGoalRoomResponse(goalRoom, getCurrentMemberCount(goalRoom), - new RoadmapNodes(roadmapNodes)); + roadmapContent.getNodes()); } public List findGoalRoomMembers(final Long goalRoomId, @@ -170,14 +167,13 @@ public MemberGoalRoomResponse findMemberGoalRoom(final String identifier, final final Member member = findMemberByIdentifier(new Identifier(identifier)); validateMemberInGoalRoom(goalRoom, member.getId()); - final RoadmapContent roadmapContent = findRoadmapContentById(goalRoom.getRoadmapContentId()); - final List roadmapNodes = roadmapNodeRepository.findAllByRoadmapContent(roadmapContent); + final RoadmapContent roadmapContent = findRoadmapContentByIdWithRoadmapNodes(goalRoom.getRoadmapContentId()); final List checkFeeds = dashBoardCheckFeedService.findCheckFeedsByNodeAndGoalRoomStatus( goalRoom); final List checkedTodos = dashBoardToDoService.findMemberCheckedGoalRoomToDoIds( goalRoom, member.getId()); return GoalRoomMapper.convertToMemberGoalRoomResponse(goalRoom, findGoalRoomLeaderId(goalRoom), - getCurrentMemberCount(goalRoom), new RoadmapNodes(roadmapNodes), checkFeeds, checkedTodos); + getCurrentMemberCount(goalRoom), roadmapContent.getNodes(), checkFeeds, checkedTodos); } private GoalRoom findGoalRoomWithNodesById(final Long goalRoomId) { @@ -291,7 +287,7 @@ private GoalRoomRoadmapNodeDetailDto makeGoalRoomNodeDetailResponse(final GoalRo } private RoadmapNode findRoadmapNodeById(final Long roadmapNodeId) { - return roadmapNodeRepository.findById(roadmapNodeId) + return roadmapNodeRepository.findByIdWithRoadmapNodeImages(roadmapNodeId) .orElseThrow(() -> new NotFoundException("존재하지 않는 로드맵 노드입니다. roadmapNodeId = " + roadmapNodeId)); } diff --git a/backend/kirikiri/src/main/java/co/kirikiri/goalroom/service/RoadmapGoalRoomServiceImpl.java b/backend/kirikiri/src/main/java/co/kirikiri/goalroom/service/RoadmapGoalRoomServiceImpl.java new file mode 100644 index 000000000..9d969e439 --- /dev/null +++ b/backend/kirikiri/src/main/java/co/kirikiri/goalroom/service/RoadmapGoalRoomServiceImpl.java @@ -0,0 +1,157 @@ +package co.kirikiri.goalroom.service; + +import co.kirikiri.common.aop.ExceptionConvert; +import co.kirikiri.common.exception.BadRequestException; +import co.kirikiri.common.exception.NotFoundException; +import co.kirikiri.common.mapper.ScrollResponseMapper; +import co.kirikiri.common.service.FileService; +import co.kirikiri.common.service.dto.CustomScrollRequest; +import co.kirikiri.goalroom.domain.GoalRoom; +import co.kirikiri.goalroom.domain.GoalRoomRole; +import co.kirikiri.goalroom.domain.GoalRoomStatus; +import co.kirikiri.goalroom.persistence.GoalRoomMemberRepository; +import co.kirikiri.goalroom.persistence.GoalRoomPendingMemberRepository; +import co.kirikiri.goalroom.persistence.GoalRoomRepository; +import co.kirikiri.goalroom.persistence.dto.RoadmapGoalRoomsOrderType; +import co.kirikiri.goalroom.service.dto.MemberDto; +import co.kirikiri.goalroom.service.dto.RoadmapGoalRoomDto; +import co.kirikiri.goalroom.service.dto.RoadmapGoalRoomScrollDto; +import co.kirikiri.goalroom.service.mapper.GoalRoomMapper; +import co.kirikiri.member.domain.Member; +import co.kirikiri.member.domain.vo.Identifier; +import co.kirikiri.member.persistence.MemberRepository; +import co.kirikiri.roadmap.domain.Roadmap; +import co.kirikiri.roadmap.domain.RoadmapContent; +import co.kirikiri.roadmap.persistence.RoadmapContentRepository; +import co.kirikiri.roadmap.service.RoadmapGoalRoomService; +import co.kirikiri.roadmap.service.dto.RoadmapGoalRoomNumberDto; +import co.kirikiri.roadmap.service.dto.RoadmapGoalRoomsOrderTypeDto; +import co.kirikiri.roadmap.service.dto.response.RoadmapGoalRoomResponses; +import java.net.URL; +import java.util.List; +import lombok.RequiredArgsConstructor; +import org.springframework.http.HttpMethod; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@Transactional(readOnly = true) +@RequiredArgsConstructor +@ExceptionConvert +public class RoadmapGoalRoomServiceImpl implements RoadmapGoalRoomService { + + private static final int DELETE_AFTER_MONTH = 3; + + private final GoalRoomRepository goalRoomRepository; + private final GoalRoomMemberRepository goalRoomMemberRepository; + private final GoalRoomPendingMemberRepository goalRoomPendingMemberRepository; + private final RoadmapContentRepository roadmapContentRepository; + private final MemberRepository memberRepository; + private final FileService fileService; + + @Override + public Long findCompletedGoalRoomMemberId(final Long roadmapId, final String identifier) { + final Member member = findMemberByIdentifier(identifier); + return goalRoomMemberRepository.findByRoadmapIdAndMemberIdAndGoalRoomStatus(roadmapId, member.getId(), + GoalRoomStatus.COMPLETED) + .orElseThrow(() -> new BadRequestException( + "로드맵에 대해서 완료된 골룸이 존재하지 않습니다. roadmapId = " + roadmapId + " memberIdentifier = " + identifier)) + .getMemberId(); + } + + private Member findMemberByIdentifier(final String identifier) { + return memberRepository.findByIdentifier(new Identifier(identifier)) + .orElseThrow(() -> new NotFoundException("존재하지 않는 회원입니다.")); + } + + @Override + public boolean hasGoalRooms(final Long roadmapId) { + + return !findGoalRoomsByRoadmapId(roadmapId).isEmpty(); + } + + private List findGoalRoomsByRoadmapId(final Long roadmapId) { + final RoadmapContent roadmapContent = findRoadmapContentByRoadmapId(roadmapId); + return goalRoomRepository.findByRoadmapContentId(roadmapContent.getId()); + } + + private RoadmapContent findRoadmapContentByRoadmapId(final Long roadmapId) { + return roadmapContentRepository.findFirstByRoadmapIdOrderByCreatedAtDesc(roadmapId) + .orElseThrow(() -> new NotFoundException("로드맵 본문이 존재하지 않습니다.")); + } + + @Override + public RoadmapGoalRoomNumberDto findRoadmapGoalRoomsByRoadmap(final Roadmap roadmap) { + return GoalRoomMapper.convertRoadmapGoalRoomDto(findGoalRoomsByRoadmapId(roadmap.getId())); + } + + @Override + public RoadmapGoalRoomResponses makeRoadmapGoalRoomResponsesByOrderType(final Long roadmapId, + final RoadmapGoalRoomsOrderTypeDto orderTypeDto, + final CustomScrollRequest scrollRequest) { + final RoadmapGoalRoomsOrderType orderType = GoalRoomMapper.convertToGoalRoomOrderType(orderTypeDto); + final RoadmapContent roadmapContent = findRoadmapContentByRoadmapId(roadmapId); + final List roadmapGoalRoomDtos = goalRoomRepository.findGoalRoomsByRoadmapContentIdAndCond( + roadmapContent.getId(), orderType, scrollRequest.lastId(), scrollRequest.size()) + .stream() + .map(this::makeGoalRoomDto) + .toList(); + final List subDtos = ScrollResponseMapper.getSubResponses(roadmapGoalRoomDtos, + scrollRequest.size()); + final boolean hasNext = ScrollResponseMapper.hasNext(roadmapGoalRoomDtos.size(), scrollRequest.size()); + + return GoalRoomMapper.convertToRoadmapGoalRoomResponses(new RoadmapGoalRoomScrollDto(subDtos, hasNext)); + } + + private RoadmapGoalRoomDto makeGoalRoomDto(final GoalRoom goalRoom) { + final Long goalRoomLeaderId = findGoalRoomLeaderId(goalRoom); + return new RoadmapGoalRoomDto(goalRoom.getId(), goalRoom.getName().getValue(), goalRoom.getStatus(), + getCurrentMemberCount(goalRoom), goalRoom.getLimitedMemberCount().getValue(), + goalRoom.getCreatedAt(), goalRoom.getStartDate(), + goalRoom.getEndDate(), makeMemberDto(goalRoomLeaderId)); + } + + private Long findGoalRoomLeaderId(final GoalRoom goalRoom) { + if (goalRoom.isRecruiting()) { + return goalRoomPendingMemberRepository.findLeaderByGoalRoomAndRole(goalRoom, GoalRoomRole.LEADER) + .orElseThrow(() -> new NotFoundException("골룸의 리더가 존재하지 않습니다.")) + .getMemberId(); + } + return goalRoomMemberRepository.findLeaderByGoalRoomAndRole(goalRoom, GoalRoomRole.LEADER) + .orElseThrow(() -> new NotFoundException("골룸의 리더가 존재하지 않습니다.")) + .getMemberId(); + } + + private int getCurrentMemberCount(final GoalRoom goalRoom) { + if (goalRoom.isRecruiting()) { + return goalRoomPendingMemberRepository.findByGoalRoom(goalRoom) + .size(); + } + return goalRoomMemberRepository.findAllByGoalRoom(goalRoom) + .size(); + } + + private MemberDto makeMemberDto(final Long creatorId) { + final Member creator = findMemberById(creatorId); + final URL url = fileService.generateUrl(creator.getImage().getServerFilePath(), HttpMethod.GET); + return new MemberDto(creator.getId(), creator.getNickname().getValue(), url.toExternalForm()); + } + + private Member findMemberById(final Long creatorId) { + return memberRepository.findById(creatorId) + .orElseThrow(() -> new NotFoundException("존재하지 않는 회원입니다. memberId = " + creatorId)); + } + + @Override + @Transactional + public boolean canDeleteGoalRoomsInRoadmap(final Long roadmapId) { + final RoadmapContent roadmapContent = findRoadmapContentByRoadmapId(roadmapId); + final List goalRooms = goalRoomRepository.findByRoadmapContentId(roadmapContent.getId()); + return canDeleteRoadmapBasedOnGoalRooms(goalRooms); + } + + private boolean canDeleteRoadmapBasedOnGoalRooms(final List goalRooms) { + return goalRooms.stream() + .allMatch(goalRoom -> goalRoom.isCompleted() && goalRoom.isCompletedAfterMonths(DELETE_AFTER_MONTH)); + } +} diff --git a/backend/kirikiri/src/main/java/co/kirikiri/goalroom/service/mapper/GoalRoomMapper.java b/backend/kirikiri/src/main/java/co/kirikiri/goalroom/service/mapper/GoalRoomMapper.java index 1b2e72f6b..50e6ef0c7 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/goalroom/service/mapper/GoalRoomMapper.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/goalroom/service/mapper/GoalRoomMapper.java @@ -1,8 +1,6 @@ package co.kirikiri.goalroom.service.mapper; import co.kirikiri.common.exception.NotFoundException; -import co.kirikiri.domain.roadmap.RoadmapNode; -import co.kirikiri.domain.roadmap.RoadmapNodes; import co.kirikiri.goalroom.domain.GoalRoom; import co.kirikiri.goalroom.domain.GoalRoomRoadmapNode; import co.kirikiri.goalroom.domain.GoalRoomRoadmapNodes; @@ -34,10 +32,13 @@ import co.kirikiri.goalroom.service.dto.response.MemberGoalRoomForListResponse; import co.kirikiri.goalroom.service.dto.response.MemberGoalRoomResponse; import co.kirikiri.goalroom.service.dto.response.MemberResponse; -import co.kirikiri.goalroom.service.dto.response.RoadmapGoalRoomResponse; -import co.kirikiri.service.dto.roadmap.RoadmapGoalRoomNumberDto; -import co.kirikiri.service.dto.roadmap.RoadmapGoalRoomsOrderTypeDto; -import co.kirikiri.service.dto.roadmap.response.RoadmapGoalRoomResponses; +import co.kirikiri.roadmap.domain.RoadmapNode; +import co.kirikiri.roadmap.domain.RoadmapNodes; +import co.kirikiri.roadmap.service.dto.RoadmapGoalRoomNumberDto; +import co.kirikiri.roadmap.service.dto.RoadmapGoalRoomsOrderTypeDto; +import co.kirikiri.roadmap.service.dto.response.MemberRoadmapGoalRoomResponse; +import co.kirikiri.roadmap.service.dto.response.RoadmapGoalRoomResponse; +import co.kirikiri.roadmap.service.dto.response.RoadmapGoalRoomResponses; import java.time.LocalDate; import java.util.Collections; import java.util.List; @@ -146,14 +147,14 @@ public static RoadmapGoalRoomResponses convertToRoadmapGoalRoomResponses( private static RoadmapGoalRoomResponse convertToRoadmapGoalRoomResponse( final RoadmapGoalRoomDto roadmapGoalRoomDto) { return new RoadmapGoalRoomResponse(roadmapGoalRoomDto.goalRoomId(), roadmapGoalRoomDto.name(), - roadmapGoalRoomDto.status(), roadmapGoalRoomDto.currentMemberCount(), + roadmapGoalRoomDto.status().name(), roadmapGoalRoomDto.currentMemberCount(), roadmapGoalRoomDto.limitedMemberCount(), roadmapGoalRoomDto.createdAt(), roadmapGoalRoomDto.startDate(), roadmapGoalRoomDto.endDate(), convertToMemberResponse(roadmapGoalRoomDto.goalRoomLeader())); } - private static MemberResponse convertToMemberResponse(final MemberDto memberDto) { - return new MemberResponse(memberDto.id(), memberDto.name(), memberDto.imageUrl()); + private static MemberRoadmapGoalRoomResponse convertToMemberResponse(final MemberDto memberDto) { + return new MemberRoadmapGoalRoomResponse(memberDto.id(), memberDto.name(), memberDto.imageUrl()); } public static GoalRoomMemberSortType convertGoalRoomMemberSortType(final GoalRoomMemberSortTypeDto sortType) { diff --git a/backend/kirikiri/src/main/java/co/kirikiri/controller/MemberController.java b/backend/kirikiri/src/main/java/co/kirikiri/member/controller/MemberController.java similarity index 85% rename from backend/kirikiri/src/main/java/co/kirikiri/controller/MemberController.java rename to backend/kirikiri/src/main/java/co/kirikiri/member/controller/MemberController.java index 84c47dead..936c00bfc 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/controller/MemberController.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/member/controller/MemberController.java @@ -1,11 +1,11 @@ -package co.kirikiri.controller; +package co.kirikiri.member.controller; import co.kirikiri.common.interceptor.Authenticated; import co.kirikiri.common.resolver.MemberIdentifier; -import co.kirikiri.service.member.MemberService; -import co.kirikiri.service.dto.member.request.MemberJoinRequest; -import co.kirikiri.service.dto.member.response.MemberInformationForPublicResponse; -import co.kirikiri.service.dto.member.response.MemberInformationResponse; +import co.kirikiri.member.service.MemberService; +import co.kirikiri.member.service.dto.request.MemberJoinRequest; +import co.kirikiri.member.service.dto.response.MemberInformationForPublicResponse; +import co.kirikiri.member.service.dto.response.MemberInformationResponse; import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; import org.springframework.http.ResponseEntity; diff --git a/backend/kirikiri/src/main/java/co/kirikiri/domain/member/EncryptedPassword.java b/backend/kirikiri/src/main/java/co/kirikiri/member/domain/EncryptedPassword.java similarity index 93% rename from backend/kirikiri/src/main/java/co/kirikiri/domain/member/EncryptedPassword.java rename to backend/kirikiri/src/main/java/co/kirikiri/member/domain/EncryptedPassword.java index b06f2b651..266fb000b 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/domain/member/EncryptedPassword.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/member/domain/EncryptedPassword.java @@ -1,14 +1,14 @@ -package co.kirikiri.domain.member; +package co.kirikiri.member.domain; -import co.kirikiri.common.exception.UnexpectedDomainException; -import co.kirikiri.domain.member.vo.Password; +import co.kirikiri.common.exception.domain.UnexpectedDomainException; +import co.kirikiri.member.domain.vo.Password; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.security.SecureRandom; import java.util.Base64; import java.util.Objects; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; @NoArgsConstructor(access = AccessLevel.PROTECTED) public class EncryptedPassword { diff --git a/backend/kirikiri/src/main/java/co/kirikiri/domain/member/Gender.java b/backend/kirikiri/src/main/java/co/kirikiri/member/domain/Gender.java similarity index 63% rename from backend/kirikiri/src/main/java/co/kirikiri/domain/member/Gender.java rename to backend/kirikiri/src/main/java/co/kirikiri/member/domain/Gender.java index 238cb7cd5..f864b4f6c 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/domain/member/Gender.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/member/domain/Gender.java @@ -1,4 +1,4 @@ -package co.kirikiri.domain.member; +package co.kirikiri.member.domain; public enum Gender { diff --git a/backend/kirikiri/src/main/java/co/kirikiri/domain/member/Member.java b/backend/kirikiri/src/main/java/co/kirikiri/member/domain/Member.java similarity index 90% rename from backend/kirikiri/src/main/java/co/kirikiri/domain/member/Member.java rename to backend/kirikiri/src/main/java/co/kirikiri/member/domain/Member.java index fec71cf79..b9e242873 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/domain/member/Member.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/member/domain/Member.java @@ -1,9 +1,9 @@ -package co.kirikiri.domain.member; +package co.kirikiri.member.domain; import co.kirikiri.common.entity.BaseUpdatedTimeEntity; -import co.kirikiri.domain.member.vo.Identifier; -import co.kirikiri.domain.member.vo.Nickname; -import co.kirikiri.domain.member.vo.Password; +import co.kirikiri.member.domain.vo.Identifier; +import co.kirikiri.member.domain.vo.Nickname; +import co.kirikiri.member.domain.vo.Password; import jakarta.persistence.CascadeType; import jakarta.persistence.Embedded; import jakarta.persistence.Entity; @@ -50,8 +50,7 @@ public Member(final Identifier identifier, final String oauthId, final Nickname this(null, identifier, oauthId, null, nickname, image, memberProfile); } - public Member(final Long id, final Identifier identifier, final String oauthId, - final EncryptedPassword encryptedPassword, + public Member(final Long id, final Identifier identifier, final String oauthId, final EncryptedPassword encryptedPassword, final Nickname nickname, final MemberImage image, final MemberProfile memberProfile) { this.id = id; this.identifier = identifier; diff --git a/backend/kirikiri/src/main/java/co/kirikiri/domain/member/MemberImage.java b/backend/kirikiri/src/main/java/co/kirikiri/member/domain/MemberImage.java similarity index 95% rename from backend/kirikiri/src/main/java/co/kirikiri/domain/member/MemberImage.java rename to backend/kirikiri/src/main/java/co/kirikiri/member/domain/MemberImage.java index 8e0032a54..af59685b8 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/domain/member/MemberImage.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/member/domain/MemberImage.java @@ -1,4 +1,4 @@ -package co.kirikiri.domain.member; +package co.kirikiri.member.domain; import co.kirikiri.common.entity.BaseEntity; import co.kirikiri.common.type.ImageContentType; diff --git a/backend/kirikiri/src/main/java/co/kirikiri/domain/member/MemberProfile.java b/backend/kirikiri/src/main/java/co/kirikiri/member/domain/MemberProfile.java similarity index 95% rename from backend/kirikiri/src/main/java/co/kirikiri/domain/member/MemberProfile.java rename to backend/kirikiri/src/main/java/co/kirikiri/member/domain/MemberProfile.java index d8b6796ce..c360d4f88 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/domain/member/MemberProfile.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/member/domain/MemberProfile.java @@ -1,4 +1,4 @@ -package co.kirikiri.domain.member; +package co.kirikiri.member.domain; import co.kirikiri.common.entity.BaseUpdatedTimeEntity; import jakarta.persistence.Column; diff --git a/backend/kirikiri/src/main/java/co/kirikiri/domain/member/exception/MemberException.java b/backend/kirikiri/src/main/java/co/kirikiri/member/domain/exception/MemberException.java similarity index 57% rename from backend/kirikiri/src/main/java/co/kirikiri/domain/member/exception/MemberException.java rename to backend/kirikiri/src/main/java/co/kirikiri/member/domain/exception/MemberException.java index 2f2c42025..e8b62e619 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/domain/member/exception/MemberException.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/member/domain/exception/MemberException.java @@ -1,6 +1,6 @@ -package co.kirikiri.domain.member.exception; +package co.kirikiri.member.domain.exception; -import co.kirikiri.common.exception.DomainException; +import co.kirikiri.common.exception.domain.DomainException; public class MemberException extends DomainException { diff --git a/backend/kirikiri/src/main/java/co/kirikiri/domain/member/vo/Identifier.java b/backend/kirikiri/src/main/java/co/kirikiri/member/domain/vo/Identifier.java similarity index 92% rename from backend/kirikiri/src/main/java/co/kirikiri/domain/member/vo/Identifier.java rename to backend/kirikiri/src/main/java/co/kirikiri/member/domain/vo/Identifier.java index f3ee6e3c1..c16c2a1ba 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/domain/member/vo/Identifier.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/member/domain/vo/Identifier.java @@ -1,10 +1,10 @@ -package co.kirikiri.domain.member.vo; +package co.kirikiri.member.domain.vo; -import co.kirikiri.domain.member.exception.MemberException; +import co.kirikiri.member.domain.exception.MemberException; import jakarta.persistence.Column; -import java.util.Objects; import lombok.AccessLevel; import lombok.NoArgsConstructor; +import java.util.Objects; @NoArgsConstructor(access = AccessLevel.PROTECTED) public class Identifier { diff --git a/backend/kirikiri/src/main/java/co/kirikiri/domain/member/vo/Nickname.java b/backend/kirikiri/src/main/java/co/kirikiri/member/domain/vo/Nickname.java similarity index 92% rename from backend/kirikiri/src/main/java/co/kirikiri/domain/member/vo/Nickname.java rename to backend/kirikiri/src/main/java/co/kirikiri/member/domain/vo/Nickname.java index 3032a52a4..c65353bee 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/domain/member/vo/Nickname.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/member/domain/vo/Nickname.java @@ -1,9 +1,9 @@ -package co.kirikiri.domain.member.vo; +package co.kirikiri.member.domain.vo; -import co.kirikiri.domain.member.exception.MemberException; +import co.kirikiri.member.domain.exception.MemberException; import jakarta.persistence.Column; -import java.util.Objects; import lombok.NoArgsConstructor; +import java.util.Objects; @NoArgsConstructor public class Nickname { diff --git a/backend/kirikiri/src/main/java/co/kirikiri/domain/member/vo/Password.java b/backend/kirikiri/src/main/java/co/kirikiri/member/domain/vo/Password.java similarity index 90% rename from backend/kirikiri/src/main/java/co/kirikiri/domain/member/vo/Password.java rename to backend/kirikiri/src/main/java/co/kirikiri/member/domain/vo/Password.java index 10db63859..f0002b74c 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/domain/member/vo/Password.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/member/domain/vo/Password.java @@ -1,6 +1,6 @@ -package co.kirikiri.domain.member.vo; +package co.kirikiri.member.domain.vo; -import co.kirikiri.domain.member.exception.MemberException; +import co.kirikiri.member.domain.exception.MemberException; import lombok.Getter; @Getter diff --git a/backend/kirikiri/src/main/java/co/kirikiri/persistence/member/MemberQueryRepository.java b/backend/kirikiri/src/main/java/co/kirikiri/member/persistence/MemberQueryRepository.java similarity index 79% rename from backend/kirikiri/src/main/java/co/kirikiri/persistence/member/MemberQueryRepository.java rename to backend/kirikiri/src/main/java/co/kirikiri/member/persistence/MemberQueryRepository.java index 42c4224c1..8f35c60f3 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/persistence/member/MemberQueryRepository.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/member/persistence/MemberQueryRepository.java @@ -1,6 +1,6 @@ -package co.kirikiri.persistence.member; +package co.kirikiri.member.persistence; -import co.kirikiri.domain.member.Member; +import co.kirikiri.member.domain.Member; import java.util.Optional; public interface MemberQueryRepository { diff --git a/backend/kirikiri/src/main/java/co/kirikiri/persistence/member/MemberQueryRepositoryImpl.java b/backend/kirikiri/src/main/java/co/kirikiri/member/persistence/MemberQueryRepositoryImpl.java similarity index 84% rename from backend/kirikiri/src/main/java/co/kirikiri/persistence/member/MemberQueryRepositoryImpl.java rename to backend/kirikiri/src/main/java/co/kirikiri/member/persistence/MemberQueryRepositoryImpl.java index c00737d43..4e81c87b9 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/persistence/member/MemberQueryRepositoryImpl.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/member/persistence/MemberQueryRepositoryImpl.java @@ -1,11 +1,11 @@ -package co.kirikiri.persistence.member; +package co.kirikiri.member.persistence; -import static co.kirikiri.domain.member.QMember.member; -import static co.kirikiri.domain.member.QMemberImage.memberImage; -import static co.kirikiri.domain.member.QMemberProfile.memberProfile; +import static co.kirikiri.member.domain.QMember.member; +import static co.kirikiri.member.domain.QMemberImage.memberImage; +import static co.kirikiri.member.domain.QMemberProfile.memberProfile; import co.kirikiri.common.persistence.QuerydslRepositorySupporter; -import co.kirikiri.domain.member.Member; +import co.kirikiri.member.domain.Member; import java.util.Optional; public class MemberQueryRepositoryImpl extends QuerydslRepositorySupporter implements MemberQueryRepository { diff --git a/backend/kirikiri/src/main/java/co/kirikiri/persistence/member/MemberRepository.java b/backend/kirikiri/src/main/java/co/kirikiri/member/persistence/MemberRepository.java similarity index 68% rename from backend/kirikiri/src/main/java/co/kirikiri/persistence/member/MemberRepository.java rename to backend/kirikiri/src/main/java/co/kirikiri/member/persistence/MemberRepository.java index 4dd4e97ca..1f6b36390 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/persistence/member/MemberRepository.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/member/persistence/MemberRepository.java @@ -1,8 +1,8 @@ -package co.kirikiri.persistence.member; +package co.kirikiri.member.persistence; -import co.kirikiri.domain.member.Member; -import co.kirikiri.domain.member.vo.Identifier; -import co.kirikiri.domain.member.vo.Nickname; +import co.kirikiri.member.domain.Member; +import co.kirikiri.member.domain.vo.Identifier; +import co.kirikiri.member.domain.vo.Nickname; import org.springframework.data.jpa.repository.JpaRepository; import java.util.Optional; diff --git a/backend/kirikiri/src/main/java/co/kirikiri/service/member/MemberService.java b/backend/kirikiri/src/main/java/co/kirikiri/member/service/MemberService.java similarity index 73% rename from backend/kirikiri/src/main/java/co/kirikiri/service/member/MemberService.java rename to backend/kirikiri/src/main/java/co/kirikiri/member/service/MemberService.java index dc169c7f6..776876b82 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/service/member/MemberService.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/member/service/MemberService.java @@ -1,39 +1,34 @@ -package co.kirikiri.service.member; +package co.kirikiri.member.service; import co.kirikiri.common.aop.ExceptionConvert; import co.kirikiri.common.exception.ConflictException; import co.kirikiri.common.exception.NotFoundException; import co.kirikiri.common.service.FileService; +import co.kirikiri.common.service.NumberGenerator; import co.kirikiri.common.type.ImageContentType; -import co.kirikiri.domain.member.EncryptedPassword; -import co.kirikiri.domain.member.Gender; -import co.kirikiri.domain.member.Member; -import co.kirikiri.domain.member.MemberImage; -import co.kirikiri.domain.member.MemberProfile; -import co.kirikiri.domain.member.vo.Identifier; -import co.kirikiri.domain.member.vo.Nickname; -import co.kirikiri.persistence.auth.RefreshTokenRepository; -import co.kirikiri.persistence.member.MemberRepository; -import co.kirikiri.service.NumberGenerator; -import co.kirikiri.service.auth.TokenProvider; -import co.kirikiri.service.dto.auth.response.AuthenticationResponse; -import co.kirikiri.service.dto.member.MemberInformationDto; -import co.kirikiri.service.dto.member.MemberInformationForPublicDto; -import co.kirikiri.service.dto.member.MemberJoinDto; -import co.kirikiri.service.dto.member.OauthMemberJoinDto; -import co.kirikiri.service.dto.member.request.MemberJoinRequest; -import co.kirikiri.service.dto.member.response.MemberInformationForPublicResponse; -import co.kirikiri.service.dto.member.response.MemberInformationResponse; -import co.kirikiri.service.mapper.AuthMapper; -import co.kirikiri.service.mapper.MemberMapper; -import java.net.URL; -import java.util.Map; -import java.util.UUID; +import co.kirikiri.member.domain.EncryptedPassword; +import co.kirikiri.member.domain.Gender; +import co.kirikiri.member.domain.Member; +import co.kirikiri.member.domain.MemberImage; +import co.kirikiri.member.domain.MemberProfile; +import co.kirikiri.member.domain.vo.Identifier; +import co.kirikiri.member.domain.vo.Nickname; +import co.kirikiri.member.persistence.MemberRepository; +import co.kirikiri.member.service.dto.MemberInformationDto; +import co.kirikiri.member.service.dto.MemberInformationForPublicDto; +import co.kirikiri.member.service.dto.MemberJoinDto; +import co.kirikiri.member.service.dto.OauthMemberJoinDto; +import co.kirikiri.member.service.dto.request.MemberJoinRequest; +import co.kirikiri.member.service.dto.response.MemberInformationForPublicResponse; +import co.kirikiri.member.service.dto.response.MemberInformationResponse; +import co.kirikiri.member.service.mapper.MemberMapper; import lombok.RequiredArgsConstructor; import org.springframework.core.env.Environment; import org.springframework.http.HttpMethod; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.net.URL; +import java.util.UUID; @Service @Transactional(readOnly = true) @@ -50,9 +45,7 @@ public class MemberService { private final Environment environment; private final NumberGenerator numberGenerator; private final FileService fileService; - private final TokenProvider tokenProvider; private final MemberRepository memberRepository; - private final RefreshTokenRepository refreshTokenRepository; @Transactional public Long join(final MemberJoinRequest memberJoinRequest) { @@ -73,15 +66,14 @@ private void checkIdentifierDuplicate(final Identifier identifier) { } @Transactional - public AuthenticationResponse oauthJoin(final OauthMemberJoinDto oauthMemberJoinDto) { + public Member oauthJoin(final OauthMemberJoinDto oauthMemberJoinDto) { final MemberProfile memberProfile = new MemberProfile(Gender.valueOf(oauthMemberJoinDto.gender().name()), oauthMemberJoinDto.email()); final Identifier identifier = makeIdentifier(oauthMemberJoinDto); final Nickname nickname = new Nickname(oauthMemberJoinDto.nickname()); final Member member = new Member(identifier, oauthMemberJoinDto.oauthId(), nickname, findDefaultMemberImage(), memberProfile); - memberRepository.save(member); - return makeAuthenticationResponse(member); + return memberRepository.save(member); } private Identifier makeIdentifier(final OauthMemberJoinDto oauthMemberJoinDto) { @@ -95,17 +87,6 @@ private Identifier makeIdentifier(final OauthMemberJoinDto oauthMemberJoinDto) { return new Identifier(identifierWithUUID); } - private AuthenticationResponse makeAuthenticationResponse(final Member member) { - final String refreshToken = tokenProvider.createRefreshToken(member.getIdentifier().getValue(), Map.of()); - saveRefreshToken(refreshToken, member); - final String accessToken = tokenProvider.createAccessToken(member.getIdentifier().getValue(), Map.of()); - return AuthMapper.convertToAuthenticationResponse(refreshToken, accessToken); - } - - private void saveRefreshToken(final String refreshToken, final Member member) { - refreshTokenRepository.save(refreshToken, member.getIdentifier().getValue()); - } - private MemberImage findDefaultMemberImage() { final String defaultOriginalFileName = environment.getProperty(DEFAULT_ORIGINAL_FILE_NAME_PROPERTY); final String defaultServerFilePath = environment.getProperty(DEFAULT_SERVER_FILE_PATH_PROPERTY); @@ -123,7 +104,7 @@ public MemberInformationResponse findMemberInformation(final String identifier) return MemberMapper.convertToMemberInformationResponse(memberInformationDto); } - public MemberInformationDto makeMemberInformationDto(final Member member) { + private MemberInformationDto makeMemberInformationDto(final Member member) { final MemberImage memberImage = member.getImage(); final MemberProfile memberProfile = member.getMemberProfile(); final URL imageUrl = fileService.generateUrl(memberImage.getServerFilePath(), HttpMethod.GET); diff --git a/backend/kirikiri/src/main/java/co/kirikiri/service/RandomNumberGenerator.java b/backend/kirikiri/src/main/java/co/kirikiri/member/service/RandomNumberGenerator.java similarity index 81% rename from backend/kirikiri/src/main/java/co/kirikiri/service/RandomNumberGenerator.java rename to backend/kirikiri/src/main/java/co/kirikiri/member/service/RandomNumberGenerator.java index edc031a4b..17065b063 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/service/RandomNumberGenerator.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/member/service/RandomNumberGenerator.java @@ -1,7 +1,8 @@ -package co.kirikiri.service; +package co.kirikiri.member.service; -import org.springframework.stereotype.Component; +import co.kirikiri.common.service.NumberGenerator; import java.util.Random; +import org.springframework.stereotype.Component; @Component public class RandomNumberGenerator implements NumberGenerator { diff --git a/backend/kirikiri/src/main/java/co/kirikiri/service/dto/member/MemberDto.java b/backend/kirikiri/src/main/java/co/kirikiri/member/service/dto/MemberDto.java similarity index 70% rename from backend/kirikiri/src/main/java/co/kirikiri/service/dto/member/MemberDto.java rename to backend/kirikiri/src/main/java/co/kirikiri/member/service/dto/MemberDto.java index e687b3c6a..4a68d615d 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/service/dto/member/MemberDto.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/member/service/dto/MemberDto.java @@ -1,4 +1,4 @@ -package co.kirikiri.service.dto.member; +package co.kirikiri.member.service.dto; public record MemberDto( long id, diff --git a/backend/kirikiri/src/main/java/co/kirikiri/service/dto/member/MemberInformationDto.java b/backend/kirikiri/src/main/java/co/kirikiri/member/service/dto/MemberInformationDto.java similarity index 82% rename from backend/kirikiri/src/main/java/co/kirikiri/service/dto/member/MemberInformationDto.java rename to backend/kirikiri/src/main/java/co/kirikiri/member/service/dto/MemberInformationDto.java index c11785204..64022a8e9 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/service/dto/member/MemberInformationDto.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/member/service/dto/MemberInformationDto.java @@ -1,4 +1,4 @@ -package co.kirikiri.service.dto.member; +package co.kirikiri.member.service.dto; public record MemberInformationDto( Long id, diff --git a/backend/kirikiri/src/main/java/co/kirikiri/service/dto/member/MemberInformationForPublicDto.java b/backend/kirikiri/src/main/java/co/kirikiri/member/service/dto/MemberInformationForPublicDto.java similarity index 76% rename from backend/kirikiri/src/main/java/co/kirikiri/service/dto/member/MemberInformationForPublicDto.java rename to backend/kirikiri/src/main/java/co/kirikiri/member/service/dto/MemberInformationForPublicDto.java index d5438e4cb..9379c1f0b 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/service/dto/member/MemberInformationForPublicDto.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/member/service/dto/MemberInformationForPublicDto.java @@ -1,4 +1,4 @@ -package co.kirikiri.service.dto.member; +package co.kirikiri.member.service.dto; public record MemberInformationForPublicDto( String nickname, diff --git a/backend/kirikiri/src/main/java/co/kirikiri/member/service/dto/MemberJoinDto.java b/backend/kirikiri/src/main/java/co/kirikiri/member/service/dto/MemberJoinDto.java new file mode 100644 index 000000000..62db68555 --- /dev/null +++ b/backend/kirikiri/src/main/java/co/kirikiri/member/service/dto/MemberJoinDto.java @@ -0,0 +1,16 @@ +package co.kirikiri.member.service.dto; + +import co.kirikiri.member.domain.Gender; +import co.kirikiri.member.domain.vo.Identifier; +import co.kirikiri.member.domain.vo.Nickname; +import co.kirikiri.member.domain.vo.Password; + +public record MemberJoinDto( + Identifier identifier, + Password password, + Nickname nickname, + Gender gender, + String email +) { + +} diff --git a/backend/kirikiri/src/main/java/co/kirikiri/service/dto/member/OauthMemberJoinDto.java b/backend/kirikiri/src/main/java/co/kirikiri/member/service/dto/OauthMemberJoinDto.java similarity index 58% rename from backend/kirikiri/src/main/java/co/kirikiri/service/dto/member/OauthMemberJoinDto.java rename to backend/kirikiri/src/main/java/co/kirikiri/member/service/dto/OauthMemberJoinDto.java index 713493688..03011e88d 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/service/dto/member/OauthMemberJoinDto.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/member/service/dto/OauthMemberJoinDto.java @@ -1,6 +1,6 @@ -package co.kirikiri.service.dto.member; +package co.kirikiri.member.service.dto; -import co.kirikiri.service.dto.member.request.GenderType; +import co.kirikiri.member.service.dto.request.GenderType; public record OauthMemberJoinDto( String oauthId, diff --git a/backend/kirikiri/src/main/java/co/kirikiri/service/dto/member/request/GenderType.java b/backend/kirikiri/src/main/java/co/kirikiri/member/service/dto/request/GenderType.java similarity index 69% rename from backend/kirikiri/src/main/java/co/kirikiri/service/dto/member/request/GenderType.java rename to backend/kirikiri/src/main/java/co/kirikiri/member/service/dto/request/GenderType.java index 0af6e6334..6a5b6881a 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/service/dto/member/request/GenderType.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/member/service/dto/request/GenderType.java @@ -1,6 +1,6 @@ -package co.kirikiri.service.dto.member.request; +package co.kirikiri.member.service.dto.request; -import co.kirikiri.common.exception.BadRequestException; +import co.kirikiri.member.domain.exception.MemberException; import java.util.Arrays; public enum GenderType { @@ -19,6 +19,6 @@ public static GenderType findByOauthType(final String oauthGenderType) { return Arrays.stream(values()) .filter(it -> it.oauthGenderType.equals(oauthGenderType)) .findAny() - .orElseThrow(() -> new BadRequestException("존재하지 않는 성별 타입입니다.")); + .orElseThrow(() -> new MemberException("존재하지 않는 성별 타입입니다.")); } } diff --git a/backend/kirikiri/src/main/java/co/kirikiri/service/dto/member/request/MemberJoinRequest.java b/backend/kirikiri/src/main/java/co/kirikiri/member/service/dto/request/MemberJoinRequest.java similarity index 94% rename from backend/kirikiri/src/main/java/co/kirikiri/service/dto/member/request/MemberJoinRequest.java rename to backend/kirikiri/src/main/java/co/kirikiri/member/service/dto/request/MemberJoinRequest.java index 1aaf4f39b..99f145d71 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/service/dto/member/request/MemberJoinRequest.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/member/service/dto/request/MemberJoinRequest.java @@ -1,4 +1,4 @@ -package co.kirikiri.service.dto.member.request; +package co.kirikiri.member.service.dto.request; import jakarta.validation.constraints.Email; import jakarta.validation.constraints.NotBlank; diff --git a/backend/kirikiri/src/main/java/co/kirikiri/service/dto/member/response/MemberInformationForPublicResponse.java b/backend/kirikiri/src/main/java/co/kirikiri/member/service/dto/response/MemberInformationForPublicResponse.java similarity index 73% rename from backend/kirikiri/src/main/java/co/kirikiri/service/dto/member/response/MemberInformationForPublicResponse.java rename to backend/kirikiri/src/main/java/co/kirikiri/member/service/dto/response/MemberInformationForPublicResponse.java index b533d7e73..80ff0d761 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/service/dto/member/response/MemberInformationForPublicResponse.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/member/service/dto/response/MemberInformationForPublicResponse.java @@ -1,4 +1,4 @@ -package co.kirikiri.service.dto.member.response; +package co.kirikiri.member.service.dto.response; public record MemberInformationForPublicResponse( String nickname, diff --git a/backend/kirikiri/src/main/java/co/kirikiri/service/dto/member/response/MemberInformationResponse.java b/backend/kirikiri/src/main/java/co/kirikiri/member/service/dto/response/MemberInformationResponse.java similarity index 79% rename from backend/kirikiri/src/main/java/co/kirikiri/service/dto/member/response/MemberInformationResponse.java rename to backend/kirikiri/src/main/java/co/kirikiri/member/service/dto/response/MemberInformationResponse.java index 1be4e1933..9c9fc69f3 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/service/dto/member/response/MemberInformationResponse.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/member/service/dto/response/MemberInformationResponse.java @@ -1,4 +1,4 @@ -package co.kirikiri.service.dto.member.response; +package co.kirikiri.member.service.dto.response; public record MemberInformationResponse( Long id, diff --git a/backend/kirikiri/src/main/java/co/kirikiri/service/dto/member/response/MemberResponse.java b/backend/kirikiri/src/main/java/co/kirikiri/member/service/dto/response/MemberResponse.java similarity index 67% rename from backend/kirikiri/src/main/java/co/kirikiri/service/dto/member/response/MemberResponse.java rename to backend/kirikiri/src/main/java/co/kirikiri/member/service/dto/response/MemberResponse.java index 26b1e7b23..c90f24be6 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/service/dto/member/response/MemberResponse.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/member/service/dto/response/MemberResponse.java @@ -1,4 +1,4 @@ -package co.kirikiri.service.dto.member.response; +package co.kirikiri.member.service.dto.response; public record MemberResponse( long id, diff --git a/backend/kirikiri/src/main/java/co/kirikiri/service/mapper/MemberMapper.java b/backend/kirikiri/src/main/java/co/kirikiri/member/service/mapper/MemberMapper.java similarity index 71% rename from backend/kirikiri/src/main/java/co/kirikiri/service/mapper/MemberMapper.java rename to backend/kirikiri/src/main/java/co/kirikiri/member/service/mapper/MemberMapper.java index 409e662ee..495755911 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/service/mapper/MemberMapper.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/member/service/mapper/MemberMapper.java @@ -1,15 +1,15 @@ -package co.kirikiri.service.mapper; +package co.kirikiri.member.service.mapper; -import co.kirikiri.domain.member.Gender; -import co.kirikiri.domain.member.vo.Identifier; -import co.kirikiri.domain.member.vo.Nickname; -import co.kirikiri.domain.member.vo.Password; -import co.kirikiri.service.dto.member.MemberInformationDto; -import co.kirikiri.service.dto.member.MemberInformationForPublicDto; -import co.kirikiri.service.dto.member.MemberJoinDto; -import co.kirikiri.service.dto.member.request.MemberJoinRequest; -import co.kirikiri.service.dto.member.response.MemberInformationForPublicResponse; -import co.kirikiri.service.dto.member.response.MemberInformationResponse; +import co.kirikiri.member.domain.Gender; +import co.kirikiri.member.domain.vo.Identifier; +import co.kirikiri.member.domain.vo.Nickname; +import co.kirikiri.member.domain.vo.Password; +import co.kirikiri.member.service.dto.MemberInformationDto; +import co.kirikiri.member.service.dto.MemberInformationForPublicDto; +import co.kirikiri.member.service.dto.MemberJoinDto; +import co.kirikiri.member.service.dto.request.MemberJoinRequest; +import co.kirikiri.member.service.dto.response.MemberInformationForPublicResponse; +import co.kirikiri.member.service.dto.response.MemberInformationResponse; import lombok.AccessLevel; import lombok.NoArgsConstructor; diff --git a/backend/kirikiri/src/main/java/co/kirikiri/persistence/roadmap/RoadmapContentRepository.java b/backend/kirikiri/src/main/java/co/kirikiri/persistence/roadmap/RoadmapContentRepository.java deleted file mode 100644 index 3e75c3103..000000000 --- a/backend/kirikiri/src/main/java/co/kirikiri/persistence/roadmap/RoadmapContentRepository.java +++ /dev/null @@ -1,20 +0,0 @@ -package co.kirikiri.persistence.roadmap; - -import co.kirikiri.domain.roadmap.Roadmap; -import co.kirikiri.domain.roadmap.RoadmapContent; -import java.util.Optional; -import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Query; -import org.springframework.data.repository.query.Param; - -public interface RoadmapContentRepository extends JpaRepository { - - Optional findFirstByRoadmapOrderByCreatedAtDesc(final Roadmap roadmap); - - @Query("select rc from RoadmapContent rc " - + "join fetch rc.roadmap r " - + "where rc.id = :roadmapContentId") - Optional findByIdWithRoadmap(@Param("roadmapContentId") final Long roadmapContentId); - - Optional findByRoadmap(@Param("roadmap") final Roadmap roadmap); -} diff --git a/backend/kirikiri/src/main/java/co/kirikiri/persistence/roadmap/RoadmapNodeRepository.java b/backend/kirikiri/src/main/java/co/kirikiri/persistence/roadmap/RoadmapNodeRepository.java deleted file mode 100644 index cbe15b11b..000000000 --- a/backend/kirikiri/src/main/java/co/kirikiri/persistence/roadmap/RoadmapNodeRepository.java +++ /dev/null @@ -1,11 +0,0 @@ -package co.kirikiri.persistence.roadmap; - -import co.kirikiri.domain.roadmap.RoadmapContent; -import co.kirikiri.domain.roadmap.RoadmapNode; -import org.springframework.data.jpa.repository.JpaRepository; -import java.util.List; - -public interface RoadmapNodeRepository extends JpaRepository { - - List findAllByRoadmapContent(final RoadmapContent roadmapContent); -} diff --git a/backend/kirikiri/src/main/java/co/kirikiri/persistence/roadmap/RoadmapRepository.java b/backend/kirikiri/src/main/java/co/kirikiri/persistence/roadmap/RoadmapRepository.java deleted file mode 100644 index 6df4b1ba4..000000000 --- a/backend/kirikiri/src/main/java/co/kirikiri/persistence/roadmap/RoadmapRepository.java +++ /dev/null @@ -1,8 +0,0 @@ -package co.kirikiri.persistence.roadmap; - -import co.kirikiri.domain.roadmap.Roadmap; -import org.springframework.data.jpa.repository.JpaRepository; - -public interface RoadmapRepository extends JpaRepository, RoadmapQueryRepository { - -} diff --git a/backend/kirikiri/src/main/java/co/kirikiri/persistence/roadmap/RoadmapReviewQueryRepository.java b/backend/kirikiri/src/main/java/co/kirikiri/persistence/roadmap/RoadmapReviewQueryRepository.java deleted file mode 100644 index 84a779636..000000000 --- a/backend/kirikiri/src/main/java/co/kirikiri/persistence/roadmap/RoadmapReviewQueryRepository.java +++ /dev/null @@ -1,12 +0,0 @@ -package co.kirikiri.persistence.roadmap; - -import co.kirikiri.domain.roadmap.Roadmap; -import co.kirikiri.domain.roadmap.RoadmapReview; -import java.util.List; - -public interface RoadmapReviewQueryRepository { - - List findRoadmapReviewWithMemberByRoadmapOrderByLatest(final Roadmap roadmap, - final Long lastId, - final int pageSize); -} diff --git a/backend/kirikiri/src/main/java/co/kirikiri/persistence/roadmap/RoadmapReviewRepository.java b/backend/kirikiri/src/main/java/co/kirikiri/persistence/roadmap/RoadmapReviewRepository.java deleted file mode 100644 index b83bb24f2..000000000 --- a/backend/kirikiri/src/main/java/co/kirikiri/persistence/roadmap/RoadmapReviewRepository.java +++ /dev/null @@ -1,12 +0,0 @@ -package co.kirikiri.persistence.roadmap; - -import co.kirikiri.domain.member.Member; -import co.kirikiri.domain.roadmap.Roadmap; -import co.kirikiri.domain.roadmap.RoadmapReview; -import org.springframework.data.jpa.repository.JpaRepository; -import java.util.Optional; - -public interface RoadmapReviewRepository extends JpaRepository, RoadmapReviewQueryRepository { - - Optional findByRoadmapAndMember(final Roadmap roadmap, final Member member); -} diff --git a/backend/kirikiri/src/main/java/co/kirikiri/controller/RoadmapController.java b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/controller/RoadmapController.java similarity index 85% rename from backend/kirikiri/src/main/java/co/kirikiri/controller/RoadmapController.java rename to backend/kirikiri/src/main/java/co/kirikiri/roadmap/controller/RoadmapController.java index 21abca873..a7750d410 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/controller/RoadmapController.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/controller/RoadmapController.java @@ -1,22 +1,22 @@ -package co.kirikiri.controller; +package co.kirikiri.roadmap.controller; import co.kirikiri.common.interceptor.Authenticated; import co.kirikiri.common.resolver.MemberIdentifier; -import co.kirikiri.service.dto.CustomScrollRequest; -import co.kirikiri.service.dto.roadmap.RoadmapGoalRoomsOrderTypeDto; -import co.kirikiri.service.dto.roadmap.request.RoadmapCategorySaveRequest; -import co.kirikiri.service.dto.roadmap.request.RoadmapOrderTypeRequest; -import co.kirikiri.service.dto.roadmap.request.RoadmapReviewSaveRequest; -import co.kirikiri.service.dto.roadmap.request.RoadmapSaveRequest; -import co.kirikiri.service.dto.roadmap.request.RoadmapSearchRequest; -import co.kirikiri.service.dto.roadmap.response.MemberRoadmapResponses; -import co.kirikiri.service.dto.roadmap.response.RoadmapCategoryResponse; -import co.kirikiri.service.dto.roadmap.response.RoadmapForListResponses; -import co.kirikiri.service.dto.roadmap.response.RoadmapGoalRoomResponses; -import co.kirikiri.service.dto.roadmap.response.RoadmapResponse; -import co.kirikiri.service.dto.roadmap.response.RoadmapReviewResponse; -import co.kirikiri.service.roadmap.RoadmapCreateService; -import co.kirikiri.service.roadmap.RoadmapReadService; +import co.kirikiri.common.service.dto.CustomScrollRequest; +import co.kirikiri.roadmap.service.RoadmapCreateService; +import co.kirikiri.roadmap.service.RoadmapReadService; +import co.kirikiri.roadmap.service.dto.RoadmapGoalRoomsOrderTypeDto; +import co.kirikiri.roadmap.service.dto.request.RoadmapCategorySaveRequest; +import co.kirikiri.roadmap.service.dto.request.RoadmapOrderTypeRequest; +import co.kirikiri.roadmap.service.dto.request.RoadmapReviewSaveRequest; +import co.kirikiri.roadmap.service.dto.request.RoadmapSaveRequest; +import co.kirikiri.roadmap.service.dto.request.RoadmapSearchRequest; +import co.kirikiri.roadmap.service.dto.response.MemberRoadmapResponses; +import co.kirikiri.roadmap.service.dto.response.RoadmapCategoryResponse; +import co.kirikiri.roadmap.service.dto.response.RoadmapForListResponses; +import co.kirikiri.roadmap.service.dto.response.RoadmapGoalRoomResponses; +import co.kirikiri.roadmap.service.dto.response.RoadmapResponse; +import co.kirikiri.roadmap.service.dto.response.RoadmapReviewResponse; import jakarta.validation.Valid; import java.net.URI; import java.util.List; diff --git a/backend/kirikiri/src/main/java/co/kirikiri/domain/roadmap/Roadmap.java b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/domain/Roadmap.java similarity index 65% rename from backend/kirikiri/src/main/java/co/kirikiri/domain/roadmap/Roadmap.java rename to backend/kirikiri/src/main/java/co/kirikiri/roadmap/domain/Roadmap.java index ac45f02c4..99ba766af 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/domain/roadmap/Roadmap.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/domain/Roadmap.java @@ -1,8 +1,7 @@ -package co.kirikiri.domain.roadmap; +package co.kirikiri.roadmap.domain; import co.kirikiri.common.entity.BaseCreatedTimeEntity; -import co.kirikiri.domain.member.Member; -import co.kirikiri.domain.roadmap.exception.RoadmapException; +import co.kirikiri.roadmap.domain.exception.RoadmapException; import jakarta.persistence.Column; import jakarta.persistence.Embedded; import jakarta.persistence.Entity; @@ -11,11 +10,10 @@ import jakarta.persistence.FetchType; import jakarta.persistence.JoinColumn; import jakarta.persistence.ManyToOne; -import java.util.Objects; -import java.util.Optional; import lombok.AccessLevel; import lombok.AllArgsConstructor; import lombok.NoArgsConstructor; +import java.util.Objects; @Entity @NoArgsConstructor(access = AccessLevel.PROTECTED) @@ -46,42 +44,23 @@ public class Roadmap extends BaseCreatedTimeEntity { @Column(length = 10, nullable = false) private RoadmapStatus status = RoadmapStatus.CREATED; - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "member_id", nullable = false, updatable = false) - private Member creator; + private Long creatorId; @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "category_id", nullable = false) private RoadmapCategory category; - @Embedded - private RoadmapContents contents = new RoadmapContents(); - @Embedded private RoadmapTags tags = new RoadmapTags(); - @Embedded - private RoadmapReviews reviews = new RoadmapReviews(); - - public Roadmap(final String title, final String introduction, final int requiredPeriod, - final RoadmapDifficulty difficulty, final Member creator, final RoadmapCategory category) { - this(null, title, introduction, requiredPeriod, difficulty, RoadmapStatus.CREATED, creator, category); - } - - public Roadmap(final String title, final String introduction, final Integer requiredPeriod, - final RoadmapDifficulty difficulty, final RoadmapStatus status, final Member creator, - final RoadmapCategory category) { - this(null, title, introduction, requiredPeriod, difficulty, status, creator, category); - } - - public Roadmap(final Long id, final String title, final String introduction, final Integer requiredPeriod, - final RoadmapDifficulty difficulty, final Member creator, final RoadmapCategory category) { - this(id, title, introduction, requiredPeriod, difficulty, RoadmapStatus.CREATED, creator, category); + public Roadmap(final String title, final String introduction, final int requiredPeriod, final RoadmapDifficulty difficulty, + final Long creatorId, final RoadmapCategory category, final RoadmapTags tags) { + this(null, title, introduction, requiredPeriod, difficulty, RoadmapStatus.CREATED, creatorId, category, tags); } public Roadmap(final Long id, final String title, final String introduction, final Integer requiredPeriod, - final RoadmapDifficulty difficulty, final RoadmapStatus status, final Member creator, - final RoadmapCategory category) { + final RoadmapDifficulty difficulty, final RoadmapStatus status, final Long creatorId, + final RoadmapCategory category, final RoadmapTags tags) { validate(title, introduction, requiredPeriod); this.id = id; this.title = title; @@ -89,8 +68,9 @@ public Roadmap(final Long id, final String title, final String introduction, fin this.requiredPeriod = requiredPeriod; this.difficulty = difficulty; this.status = status; - this.creator = creator; + this.creatorId = creatorId; this.category = category; + this.tags = tags; } private void validate(final String title, final String introduction, final int requiredPeriod) { @@ -125,42 +105,20 @@ private void validateRequiredPeriod(final int requiredPeriod) { } } - public void addContent(final RoadmapContent content) { - contents.add(content); - if (content.isNotSameRoadmap(this)) { - content.updateRoadmap(this); - } - } - - public void addTags(final RoadmapTags tags) { - this.tags.addAll(tags); - } - - public boolean isCreator(final Member member) { - return Objects.equals(creator.getId(), member.getId()); - } - - public void addReview(final RoadmapReview review) { - reviews.add(review); - if (review.isNotSameRoadmap(this)) { - review.updateRoadmap(this); - } + public boolean isCreator(final Long memberId) { + return Objects.equals(creatorId, memberId); } public void delete() { this.status = RoadmapStatus.DELETED; } - public Optional findLastRoadmapContent() { - return this.contents.findLastRoadmapContent(); - } - public boolean isDeleted() { return status == RoadmapStatus.DELETED; } - public Member getCreator() { - return creator; + public Long getCreatorId() { + return creatorId; } public String getTitle() { @@ -171,10 +129,6 @@ public RoadmapCategory getCategory() { return category; } - public RoadmapContents getContents() { - return contents; - } - public String getIntroduction() { return introduction; } diff --git a/backend/kirikiri/src/main/java/co/kirikiri/domain/roadmap/RoadmapCategory.java b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/domain/RoadmapCategory.java similarity index 91% rename from backend/kirikiri/src/main/java/co/kirikiri/domain/roadmap/RoadmapCategory.java rename to backend/kirikiri/src/main/java/co/kirikiri/roadmap/domain/RoadmapCategory.java index a71fcfb19..552c6d78e 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/domain/roadmap/RoadmapCategory.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/domain/RoadmapCategory.java @@ -1,7 +1,7 @@ -package co.kirikiri.domain.roadmap; +package co.kirikiri.roadmap.domain; import co.kirikiri.common.entity.BaseEntity; -import co.kirikiri.domain.roadmap.exception.RoadmapException; +import co.kirikiri.roadmap.domain.exception.RoadmapException; import jakarta.persistence.Column; import jakarta.persistence.Entity; import lombok.AccessLevel; diff --git a/backend/kirikiri/src/main/java/co/kirikiri/domain/roadmap/RoadmapContent.java b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/domain/RoadmapContent.java similarity index 59% rename from backend/kirikiri/src/main/java/co/kirikiri/domain/roadmap/RoadmapContent.java rename to backend/kirikiri/src/main/java/co/kirikiri/roadmap/domain/RoadmapContent.java index e982cfdf9..2233732f5 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/domain/roadmap/RoadmapContent.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/domain/RoadmapContent.java @@ -1,17 +1,14 @@ -package co.kirikiri.domain.roadmap; +package co.kirikiri.roadmap.domain; import co.kirikiri.common.entity.BaseUpdatedTimeEntity; -import co.kirikiri.domain.roadmap.exception.RoadmapException; +import co.kirikiri.roadmap.domain.exception.RoadmapException; import jakarta.persistence.Column; import jakarta.persistence.Embedded; import jakarta.persistence.Entity; -import jakarta.persistence.FetchType; -import jakarta.persistence.JoinColumn; -import jakarta.persistence.ManyToOne; -import java.util.Optional; import lombok.AccessLevel; import lombok.Getter; import lombok.NoArgsConstructor; +import java.util.Optional; @Entity @NoArgsConstructor(access = AccessLevel.PROTECTED) @@ -23,21 +20,21 @@ public class RoadmapContent extends BaseUpdatedTimeEntity { @Column(length = 2200) private String content; - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "roadmap_id", nullable = false) - private Roadmap roadmap; + private Long roadmapId; @Embedded - private final RoadmapNodes nodes = new RoadmapNodes(); + private RoadmapNodes nodes; - public RoadmapContent(final String content) { - this(null, content); + public RoadmapContent(final String content, final Long roadmapId, final RoadmapNodes nodes) { + this(null, content, roadmapId, nodes); } - public RoadmapContent(final Long id, final String content) { + public RoadmapContent(final Long id, final String content, final Long roadmapId, final RoadmapNodes nodes) { validate(content); this.id = id; this.content = content; + this.roadmapId = roadmapId; + this.nodes = nodes; } private void validate(final String content) { @@ -53,21 +50,6 @@ private void validateContentLength(final String content) { } } - public void addNodes(final RoadmapNodes nodes) { - this.nodes.addAll(nodes); - nodes.updateAllRoadmapContent(this); - } - - public boolean isNotSameRoadmap(final Roadmap roadmap) { - return this.roadmap == null || !this.roadmap.equals(roadmap); - } - - public void updateRoadmap(final Roadmap roadmap) { - if (this.roadmap == null) { - this.roadmap = roadmap; - } - } - public int nodesSize() { return nodes.size(); } @@ -84,11 +66,11 @@ public String getContent() { return content; } - public RoadmapNodes getNodes() { - return nodes; + public Long getRoadmapId() { + return roadmapId; } - public Roadmap getRoadmap() { - return roadmap; + public RoadmapNodes getNodes() { + return nodes; } } diff --git a/backend/kirikiri/src/main/java/co/kirikiri/domain/roadmap/RoadmapDifficulty.java b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/domain/RoadmapDifficulty.java similarity index 74% rename from backend/kirikiri/src/main/java/co/kirikiri/domain/roadmap/RoadmapDifficulty.java rename to backend/kirikiri/src/main/java/co/kirikiri/roadmap/domain/RoadmapDifficulty.java index f8379da50..1a4969ced 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/domain/roadmap/RoadmapDifficulty.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/domain/RoadmapDifficulty.java @@ -1,4 +1,4 @@ -package co.kirikiri.domain.roadmap; +package co.kirikiri.roadmap.domain; public enum RoadmapDifficulty { diff --git a/backend/kirikiri/src/main/java/co/kirikiri/domain/roadmap/RoadmapNode.java b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/domain/RoadmapNode.java similarity index 74% rename from backend/kirikiri/src/main/java/co/kirikiri/domain/roadmap/RoadmapNode.java rename to backend/kirikiri/src/main/java/co/kirikiri/roadmap/domain/RoadmapNode.java index 0e82f470d..4308f0440 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/domain/roadmap/RoadmapNode.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/domain/RoadmapNode.java @@ -1,13 +1,10 @@ -package co.kirikiri.domain.roadmap; +package co.kirikiri.roadmap.domain; import co.kirikiri.common.entity.BaseEntity; -import co.kirikiri.domain.roadmap.exception.RoadmapException; +import co.kirikiri.roadmap.domain.exception.RoadmapException; import jakarta.persistence.Column; import jakarta.persistence.Embedded; import jakarta.persistence.Entity; -import jakarta.persistence.FetchType; -import jakarta.persistence.JoinColumn; -import jakarta.persistence.ManyToOne; import lombok.AccessLevel; import lombok.NoArgsConstructor; @@ -19,20 +16,13 @@ public class RoadmapNode extends BaseEntity { private static final int TITLE_MAX_LENGTH = 40; private static final int CONTENT_MIN_LENGTH = 1; private static final int CONTENT_MAX_LENGTH = 2000; - + @Embedded + private final RoadmapNodeImages roadmapNodeImages = new RoadmapNodeImages(); @Column(length = 50, nullable = false) private String title; - @Column(length = 2200, nullable = false) private String content; - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "roadmap_content_id", nullable = false) - private RoadmapContent roadmapContent; - - @Embedded - private final RoadmapNodeImages roadmapNodeImages = new RoadmapNodeImages(); - public RoadmapNode(final String title, final String content) { this(null, title, content); } @@ -67,16 +57,6 @@ public void addImages(final RoadmapNodeImages roadmapNodeImages) { this.roadmapNodeImages.addAll(roadmapNodeImages); } - public boolean isNotSameRoadmapContent(final RoadmapContent roadmapContent) { - return this.roadmapContent == null || !this.roadmapContent.equals(roadmapContent); - } - - public void updateRoadmapContent(final RoadmapContent roadmapContent) { - if (this.roadmapContent == null) { - this.roadmapContent = roadmapContent; - } - } - public String getTitle() { return title; } @@ -85,10 +65,6 @@ public String getContent() { return content; } - public RoadmapContent getRoadmapContent() { - return roadmapContent; - } - public RoadmapNodeImages getRoadmapNodeImages() { return roadmapNodeImages; } diff --git a/backend/kirikiri/src/main/java/co/kirikiri/domain/roadmap/RoadmapNodeImage.java b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/domain/RoadmapNodeImage.java similarity index 97% rename from backend/kirikiri/src/main/java/co/kirikiri/domain/roadmap/RoadmapNodeImage.java rename to backend/kirikiri/src/main/java/co/kirikiri/roadmap/domain/RoadmapNodeImage.java index 4713f04a2..2e8a68d1c 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/domain/roadmap/RoadmapNodeImage.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/domain/RoadmapNodeImage.java @@ -1,4 +1,4 @@ -package co.kirikiri.domain.roadmap; +package co.kirikiri.roadmap.domain; import co.kirikiri.common.entity.BaseEntity; import co.kirikiri.common.type.ImageContentType; diff --git a/backend/kirikiri/src/main/java/co/kirikiri/domain/roadmap/RoadmapNodeImages.java b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/domain/RoadmapNodeImages.java similarity index 93% rename from backend/kirikiri/src/main/java/co/kirikiri/domain/roadmap/RoadmapNodeImages.java rename to backend/kirikiri/src/main/java/co/kirikiri/roadmap/domain/RoadmapNodeImages.java index 8d33922dc..d939b4f5d 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/domain/roadmap/RoadmapNodeImages.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/domain/RoadmapNodeImages.java @@ -1,14 +1,14 @@ -package co.kirikiri.domain.roadmap; +package co.kirikiri.roadmap.domain; -import co.kirikiri.domain.roadmap.exception.RoadmapException; +import co.kirikiri.roadmap.domain.exception.RoadmapException; import jakarta.persistence.CascadeType; import jakarta.persistence.Embeddable; import jakarta.persistence.FetchType; import jakarta.persistence.JoinColumn; import jakarta.persistence.OneToMany; +import lombok.NoArgsConstructor; import java.util.ArrayList; import java.util.List; -import lombok.NoArgsConstructor; @Embeddable @NoArgsConstructor diff --git a/backend/kirikiri/src/main/java/co/kirikiri/domain/roadmap/RoadmapNodes.java b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/domain/RoadmapNodes.java similarity index 78% rename from backend/kirikiri/src/main/java/co/kirikiri/domain/roadmap/RoadmapNodes.java rename to backend/kirikiri/src/main/java/co/kirikiri/roadmap/domain/RoadmapNodes.java index 728d15b6f..2e6ab937b 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/domain/roadmap/RoadmapNodes.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/domain/RoadmapNodes.java @@ -1,16 +1,17 @@ -package co.kirikiri.domain.roadmap; +package co.kirikiri.roadmap.domain; -import co.kirikiri.domain.roadmap.exception.RoadmapException; +import co.kirikiri.roadmap.domain.exception.RoadmapException; import jakarta.persistence.CascadeType; import jakarta.persistence.Embeddable; import jakarta.persistence.FetchType; +import jakarta.persistence.JoinColumn; import jakarta.persistence.OneToMany; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; import java.util.ArrayList; import java.util.List; import java.util.Optional; import java.util.stream.Collectors; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; @Embeddable @NoArgsConstructor(access = AccessLevel.PROTECTED) @@ -18,7 +19,8 @@ public class RoadmapNodes { @OneToMany(fetch = FetchType.LAZY, cascade = {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE}, - mappedBy = "roadmapContent") + orphanRemoval = true) + @JoinColumn(name = "roadmap_content_id", nullable = false) private final List values = new ArrayList<>(); public RoadmapNodes(final List roadmapNodes) { @@ -46,18 +48,6 @@ public void addAll(final RoadmapNodes roadmapNodes) { validateTitleDistinct(values); } - public void updateAllRoadmapContent(final RoadmapContent content) { - for (final RoadmapNode roadmapNode : values) { - updateRoadmapContent(roadmapNode, content); - } - } - - private void updateRoadmapContent(final RoadmapNode roadmapNode, final RoadmapContent content) { - if (roadmapNode.isNotSameRoadmapContent(content)) { - roadmapNode.updateRoadmapContent(content); - } - } - public Optional findById(final Long roadmapNodeId) { return values.stream() .filter(it -> it.getId().equals(roadmapNodeId)) diff --git a/backend/kirikiri/src/main/java/co/kirikiri/domain/roadmap/RoadmapReview.java b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/domain/RoadmapReview.java similarity index 69% rename from backend/kirikiri/src/main/java/co/kirikiri/domain/roadmap/RoadmapReview.java rename to backend/kirikiri/src/main/java/co/kirikiri/roadmap/domain/RoadmapReview.java index bd65ed753..f13644b4e 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/domain/roadmap/RoadmapReview.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/domain/RoadmapReview.java @@ -1,16 +1,12 @@ -package co.kirikiri.domain.roadmap; +package co.kirikiri.roadmap.domain; import co.kirikiri.common.entity.BaseUpdatedTimeEntity; -import co.kirikiri.domain.member.Member; -import co.kirikiri.domain.roadmap.exception.RoadmapException; +import co.kirikiri.roadmap.domain.exception.RoadmapException; import jakarta.persistence.Column; import jakarta.persistence.Entity; -import jakarta.persistence.FetchType; -import jakarta.persistence.JoinColumn; -import jakarta.persistence.ManyToOne; -import java.util.regex.Pattern; import lombok.AccessLevel; import lombok.NoArgsConstructor; +import java.util.regex.Pattern; @Entity @NoArgsConstructor(access = AccessLevel.PROTECTED) @@ -29,21 +25,18 @@ public class RoadmapReview extends BaseUpdatedTimeEntity { @Column(nullable = false) private Double rate = 0.0; - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "member_id") - private Member member; + private Long memberId; - @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "roadmap_id") - private Roadmap roadmap; + private Long roadmapId; - public RoadmapReview(final String content, final Double rate, final Member member) { + public RoadmapReview(final String content, final Double rate, final Long memberId, final Long roadmapId) { if (content != null) { validate(content, rate); } this.content = content; this.rate = rate; - this.member = member; + this.memberId = memberId; + this.roadmapId = roadmapId; } private void validate(final String content, final Double rate) { @@ -64,16 +57,6 @@ private void validateRate(final Double rate) { } } - public void updateRoadmap(final Roadmap roadmap) { - if (this.roadmap == null) { - this.roadmap = roadmap; - } - } - - public boolean isNotSameRoadmap(final Roadmap roadmap) { - return this.roadmap == null || !this.roadmap.equals(roadmap); - } - public String getContent() { return content; } @@ -82,7 +65,11 @@ public Double getRate() { return rate; } - public Member getMember() { - return member; + public Long getMemberId() { + return memberId; + } + + public Long getRoadmapId() { + return roadmapId; } } diff --git a/backend/kirikiri/src/main/java/co/kirikiri/domain/roadmap/RoadmapStatus.java b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/domain/RoadmapStatus.java similarity index 61% rename from backend/kirikiri/src/main/java/co/kirikiri/domain/roadmap/RoadmapStatus.java rename to backend/kirikiri/src/main/java/co/kirikiri/roadmap/domain/RoadmapStatus.java index 2e24fc540..e730beb56 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/domain/roadmap/RoadmapStatus.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/domain/RoadmapStatus.java @@ -1,4 +1,4 @@ -package co.kirikiri.domain.roadmap; +package co.kirikiri.roadmap.domain; public enum RoadmapStatus { diff --git a/backend/kirikiri/src/main/java/co/kirikiri/domain/roadmap/RoadmapTag.java b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/domain/RoadmapTag.java similarity index 93% rename from backend/kirikiri/src/main/java/co/kirikiri/domain/roadmap/RoadmapTag.java rename to backend/kirikiri/src/main/java/co/kirikiri/roadmap/domain/RoadmapTag.java index 6ffb3283a..ec2feeebb 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/domain/roadmap/RoadmapTag.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/domain/RoadmapTag.java @@ -1,12 +1,12 @@ -package co.kirikiri.domain.roadmap; +package co.kirikiri.roadmap.domain; import co.kirikiri.common.entity.BaseEntity; -import co.kirikiri.domain.roadmap.vo.RoadmapTagName; +import co.kirikiri.roadmap.domain.vo.RoadmapTagName; import jakarta.persistence.Embedded; import jakarta.persistence.Entity; -import java.util.Objects; import lombok.AccessLevel; import lombok.NoArgsConstructor; +import java.util.Objects; @Entity @NoArgsConstructor(access = AccessLevel.PROTECTED) diff --git a/backend/kirikiri/src/main/java/co/kirikiri/domain/roadmap/RoadmapTags.java b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/domain/RoadmapTags.java similarity index 93% rename from backend/kirikiri/src/main/java/co/kirikiri/domain/roadmap/RoadmapTags.java rename to backend/kirikiri/src/main/java/co/kirikiri/roadmap/domain/RoadmapTags.java index 763c920cb..7f863adf7 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/domain/roadmap/RoadmapTags.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/domain/RoadmapTags.java @@ -1,19 +1,19 @@ -package co.kirikiri.domain.roadmap; +package co.kirikiri.roadmap.domain; -import co.kirikiri.domain.roadmap.exception.RoadmapException; -import co.kirikiri.domain.roadmap.vo.RoadmapTagName; +import co.kirikiri.roadmap.domain.exception.RoadmapException; +import co.kirikiri.roadmap.domain.vo.RoadmapTagName; import jakarta.persistence.CascadeType; import jakarta.persistence.Embeddable; import jakarta.persistence.FetchType; import jakarta.persistence.JoinColumn; import jakarta.persistence.OneToMany; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; +import org.hibernate.annotations.BatchSize; import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.stream.Collectors; -import lombok.AccessLevel; -import lombok.NoArgsConstructor; -import org.hibernate.annotations.BatchSize; @Embeddable @NoArgsConstructor(access = AccessLevel.PROTECTED) diff --git a/backend/kirikiri/src/main/java/co/kirikiri/domain/roadmap/exception/RoadmapException.java b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/domain/exception/RoadmapException.java similarity index 57% rename from backend/kirikiri/src/main/java/co/kirikiri/domain/roadmap/exception/RoadmapException.java rename to backend/kirikiri/src/main/java/co/kirikiri/roadmap/domain/exception/RoadmapException.java index d178b24d2..94c568120 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/domain/roadmap/exception/RoadmapException.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/domain/exception/RoadmapException.java @@ -1,6 +1,6 @@ -package co.kirikiri.domain.roadmap.exception; +package co.kirikiri.roadmap.domain.exception; -import co.kirikiri.common.exception.DomainException; +import co.kirikiri.common.exception.domain.DomainException; public class RoadmapException extends DomainException { diff --git a/backend/kirikiri/src/main/java/co/kirikiri/domain/roadmap/vo/RoadmapTagName.java b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/domain/vo/RoadmapTagName.java similarity index 88% rename from backend/kirikiri/src/main/java/co/kirikiri/domain/roadmap/vo/RoadmapTagName.java rename to backend/kirikiri/src/main/java/co/kirikiri/roadmap/domain/vo/RoadmapTagName.java index 711208319..9b568e2fe 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/domain/roadmap/vo/RoadmapTagName.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/domain/vo/RoadmapTagName.java @@ -1,10 +1,10 @@ -package co.kirikiri.domain.roadmap.vo; +package co.kirikiri.roadmap.domain.vo; -import co.kirikiri.domain.roadmap.exception.RoadmapException; +import co.kirikiri.roadmap.domain.exception.RoadmapException; import jakarta.persistence.Column; -import java.util.Objects; import lombok.AccessLevel; import lombok.NoArgsConstructor; +import java.util.Objects; @NoArgsConstructor(access = AccessLevel.PROTECTED) public class RoadmapTagName { @@ -16,7 +16,7 @@ public class RoadmapTagName { private String value; public RoadmapTagName(final String value) { - final String removedSpaceValue = value.replaceAll(" ", ""); + final String removedSpaceValue = value.replace(" ", ""); validate(removedSpaceValue); this.value = removedSpaceValue; } diff --git a/backend/kirikiri/src/main/java/co/kirikiri/persistence/roadmap/RoadmapCategoryRepository.java b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/persistence/RoadmapCategoryRepository.java similarity index 72% rename from backend/kirikiri/src/main/java/co/kirikiri/persistence/roadmap/RoadmapCategoryRepository.java rename to backend/kirikiri/src/main/java/co/kirikiri/roadmap/persistence/RoadmapCategoryRepository.java index 37d52022b..a7250e476 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/persistence/roadmap/RoadmapCategoryRepository.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/persistence/RoadmapCategoryRepository.java @@ -1,6 +1,6 @@ -package co.kirikiri.persistence.roadmap; +package co.kirikiri.roadmap.persistence; -import co.kirikiri.domain.roadmap.RoadmapCategory; +import co.kirikiri.roadmap.domain.RoadmapCategory; import org.springframework.data.jpa.repository.JpaRepository; import java.util.Optional; diff --git a/backend/kirikiri/src/main/java/co/kirikiri/roadmap/persistence/RoadmapContentQueryRepository.java b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/persistence/RoadmapContentQueryRepository.java new file mode 100644 index 000000000..a743d8e9b --- /dev/null +++ b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/persistence/RoadmapContentQueryRepository.java @@ -0,0 +1,9 @@ +package co.kirikiri.roadmap.persistence; + +import co.kirikiri.roadmap.domain.RoadmapContent; +import java.util.Optional; + +public interface RoadmapContentQueryRepository { + + Optional findByIdWithRoadmapNodes(final Long id); +} diff --git a/backend/kirikiri/src/main/java/co/kirikiri/roadmap/persistence/RoadmapContentQueryRepositoryImpl.java b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/persistence/RoadmapContentQueryRepositoryImpl.java new file mode 100644 index 000000000..afd29d68d --- /dev/null +++ b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/persistence/RoadmapContentQueryRepositoryImpl.java @@ -0,0 +1,25 @@ +package co.kirikiri.roadmap.persistence; + +import static co.kirikiri.roadmap.domain.QRoadmapContent.roadmapContent; +import static co.kirikiri.roadmap.domain.QRoadmapNode.roadmapNode; + +import co.kirikiri.common.persistence.QuerydslRepositorySupporter; +import co.kirikiri.roadmap.domain.RoadmapContent; +import java.util.Optional; + +public class RoadmapContentQueryRepositoryImpl extends QuerydslRepositorySupporter implements + RoadmapContentQueryRepository { + + public RoadmapContentQueryRepositoryImpl() { + super(RoadmapContent.class); + } + + @Override + public Optional findByIdWithRoadmapNodes(final Long id) { + return Optional.ofNullable(selectFrom(roadmapContent) + .innerJoin(roadmapContent.nodes.values, roadmapNode) + .fetchJoin() + .where(roadmapContent.id.eq(id)) + .fetchOne()); + } +} diff --git a/backend/kirikiri/src/main/java/co/kirikiri/roadmap/persistence/RoadmapContentRepository.java b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/persistence/RoadmapContentRepository.java new file mode 100644 index 000000000..2ce268041 --- /dev/null +++ b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/persistence/RoadmapContentRepository.java @@ -0,0 +1,15 @@ +package co.kirikiri.roadmap.persistence; + +import co.kirikiri.roadmap.domain.RoadmapContent; +import java.util.List; +import java.util.Optional; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface RoadmapContentRepository extends JpaRepository, RoadmapContentQueryRepository { + + Optional findFirstByRoadmapIdOrderByCreatedAtDesc(final Long roadmapId); + + List findAllByRoadmapId(final Long roadmapId); + + void deleteAllByRoadmapId(final Long roadmapId); +} diff --git a/backend/kirikiri/src/main/java/co/kirikiri/roadmap/persistence/RoadmapNodeQueryRepository.java b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/persistence/RoadmapNodeQueryRepository.java new file mode 100644 index 000000000..f787caff8 --- /dev/null +++ b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/persistence/RoadmapNodeQueryRepository.java @@ -0,0 +1,9 @@ +package co.kirikiri.roadmap.persistence; + +import co.kirikiri.roadmap.domain.RoadmapNode; +import java.util.Optional; + +public interface RoadmapNodeQueryRepository { + + Optional findByIdWithRoadmapNodeImages(final Long id); +} diff --git a/backend/kirikiri/src/main/java/co/kirikiri/roadmap/persistence/RoadmapNodeQueryRepositoryImpl.java b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/persistence/RoadmapNodeQueryRepositoryImpl.java new file mode 100644 index 000000000..79b1895f3 --- /dev/null +++ b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/persistence/RoadmapNodeQueryRepositoryImpl.java @@ -0,0 +1,25 @@ +package co.kirikiri.roadmap.persistence; + +import static co.kirikiri.roadmap.domain.QRoadmapNode.roadmapNode; +import static co.kirikiri.roadmap.domain.QRoadmapNodeImage.roadmapNodeImage; + +import co.kirikiri.common.persistence.QuerydslRepositorySupporter; +import co.kirikiri.roadmap.domain.RoadmapNode; +import java.util.Optional; + +public class RoadmapNodeQueryRepositoryImpl extends QuerydslRepositorySupporter implements + RoadmapNodeQueryRepository { + + public RoadmapNodeQueryRepositoryImpl() { + super(RoadmapNode.class); + } + + @Override + public Optional findByIdWithRoadmapNodeImages(final Long id) { + return Optional.ofNullable(selectFrom(roadmapNode) + .innerJoin(roadmapNode.roadmapNodeImages.values, roadmapNodeImage) + .fetchJoin() + .where(roadmapNode.id.eq(id)) + .fetchOne()); + } +} diff --git a/backend/kirikiri/src/main/java/co/kirikiri/roadmap/persistence/RoadmapNodeRepository.java b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/persistence/RoadmapNodeRepository.java new file mode 100644 index 000000000..37013e7f0 --- /dev/null +++ b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/persistence/RoadmapNodeRepository.java @@ -0,0 +1,8 @@ +package co.kirikiri.roadmap.persistence; + +import co.kirikiri.roadmap.domain.RoadmapNode; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface RoadmapNodeRepository extends JpaRepository, RoadmapNodeQueryRepository { + +} diff --git a/backend/kirikiri/src/main/java/co/kirikiri/persistence/roadmap/RoadmapQueryRepository.java b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/persistence/RoadmapQueryRepository.java similarity index 63% rename from backend/kirikiri/src/main/java/co/kirikiri/persistence/roadmap/RoadmapQueryRepository.java rename to backend/kirikiri/src/main/java/co/kirikiri/roadmap/persistence/RoadmapQueryRepository.java index 05a9d838e..c583aace7 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/persistence/roadmap/RoadmapQueryRepository.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/persistence/RoadmapQueryRepository.java @@ -1,11 +1,9 @@ -package co.kirikiri.persistence.roadmap; +package co.kirikiri.roadmap.persistence; -import co.kirikiri.domain.member.Member; -import co.kirikiri.domain.roadmap.Roadmap; -import co.kirikiri.domain.roadmap.RoadmapCategory; -import co.kirikiri.domain.roadmap.RoadmapStatus; -import co.kirikiri.persistence.dto.RoadmapOrderType; -import co.kirikiri.persistence.dto.RoadmapSearchDto; +import co.kirikiri.roadmap.domain.Roadmap; +import co.kirikiri.roadmap.domain.RoadmapCategory; +import co.kirikiri.roadmap.persistence.dto.RoadmapOrderType; +import co.kirikiri.roadmap.persistence.dto.RoadmapSearchDto; import java.util.List; import java.util.Optional; @@ -23,11 +21,9 @@ List findRoadmapsByCond(final RoadmapSearchDto searchRequest, final Long lastId, final int pageSize); - List findRoadmapsWithCategoryByMemberOrderByLatest(final Member member, - final Long lastId, - final int pageSize); + List findRoadmapsWithCategoryByMemberIdOrderByLatest(final Long memberId, + final Long lastId, + final int pageSize); Optional findByIdAndMemberIdentifier(final Long roadmapId, final String identifier); - - List findWithRoadmapContentByStatus(final RoadmapStatus status); } diff --git a/backend/kirikiri/src/main/java/co/kirikiri/persistence/roadmap/RoadmapQueryRepositoryImpl.java b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/persistence/RoadmapQueryRepositoryImpl.java similarity index 64% rename from backend/kirikiri/src/main/java/co/kirikiri/persistence/roadmap/RoadmapQueryRepositoryImpl.java rename to backend/kirikiri/src/main/java/co/kirikiri/roadmap/persistence/RoadmapQueryRepositoryImpl.java index c1b854df1..92a04755d 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/persistence/roadmap/RoadmapQueryRepositoryImpl.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/persistence/RoadmapQueryRepositoryImpl.java @@ -1,25 +1,24 @@ -package co.kirikiri.persistence.roadmap; - -import static co.kirikiri.domain.member.QMember.member; -import static co.kirikiri.domain.roadmap.QRoadmap.roadmap; -import static co.kirikiri.domain.roadmap.QRoadmapCategory.roadmapCategory; -import static co.kirikiri.domain.roadmap.QRoadmapContent.roadmapContent; -import static co.kirikiri.domain.roadmap.QRoadmapReview.roadmapReview; -import static co.kirikiri.domain.roadmap.QRoadmapTag.roadmapTag; +package co.kirikiri.roadmap.persistence; + import static co.kirikiri.goalroom.domain.QGoalRoom.goalRoom; import static co.kirikiri.goalroom.domain.QGoalRoomMember.goalRoomMember; +import static co.kirikiri.member.domain.QMember.member; +import static co.kirikiri.roadmap.domain.QRoadmap.roadmap; +import static co.kirikiri.roadmap.domain.QRoadmapCategory.roadmapCategory; +import static co.kirikiri.roadmap.domain.QRoadmapContent.roadmapContent; +import static co.kirikiri.roadmap.domain.QRoadmapReview.roadmapReview; +import static co.kirikiri.roadmap.domain.QRoadmapTag.roadmapTag; import co.kirikiri.common.persistence.QuerydslRepositorySupporter; -import co.kirikiri.domain.member.Member; -import co.kirikiri.domain.member.vo.Identifier; -import co.kirikiri.domain.roadmap.Roadmap; -import co.kirikiri.domain.roadmap.RoadmapCategory; -import co.kirikiri.domain.roadmap.RoadmapStatus; -import co.kirikiri.persistence.dto.RoadmapOrderType; -import co.kirikiri.persistence.dto.RoadmapSearchCreatorNickname; -import co.kirikiri.persistence.dto.RoadmapSearchDto; -import co.kirikiri.persistence.dto.RoadmapSearchTagName; -import co.kirikiri.persistence.dto.RoadmapSearchTitle; +import co.kirikiri.member.domain.vo.Identifier; +import co.kirikiri.roadmap.domain.Roadmap; +import co.kirikiri.roadmap.domain.RoadmapCategory; +import co.kirikiri.roadmap.domain.RoadmapStatus; +import co.kirikiri.roadmap.persistence.dto.RoadmapOrderType; +import co.kirikiri.roadmap.persistence.dto.RoadmapSearchCreatorNickname; +import co.kirikiri.roadmap.persistence.dto.RoadmapSearchDto; +import co.kirikiri.roadmap.persistence.dto.RoadmapSearchTagName; +import co.kirikiri.roadmap.persistence.dto.RoadmapSearchTitle; import com.querydsl.core.types.Order; import com.querydsl.core.types.OrderSpecifier; import com.querydsl.core.types.dsl.BooleanExpression; @@ -41,8 +40,6 @@ public RoadmapQueryRepositoryImpl() { @Override public Optional findRoadmapById(final Long roadmapId) { return Optional.ofNullable(selectFrom(roadmap) - .innerJoin(roadmap.creator, member) - .fetchJoin() .innerJoin(roadmap.category, roadmapCategory) .fetchJoin() .leftJoin(roadmap.tags.values, roadmapTag) @@ -57,8 +54,6 @@ public List findRoadmapsByCategory(final RoadmapCategory category, fina return selectFrom(roadmap) .innerJoin(roadmap.category, roadmapCategory) .fetchJoin() - .innerJoin(roadmap.creator, member) - .fetchJoin() .where( lessThanLastId(lastId, orderType), statusCond(RoadmapStatus.CREATED), @@ -74,8 +69,6 @@ public List findRoadmapsByCond(final RoadmapSearchDto searchRequest, fi return selectFrom(roadmap) .innerJoin(roadmap.category, roadmapCategory) .fetchJoin() - .innerJoin(roadmap.creator, member) - .fetchJoin() .where( lessThanLastId(lastId, orderType), statusCond(RoadmapStatus.CREATED), @@ -88,15 +81,15 @@ public List findRoadmapsByCond(final RoadmapSearchDto searchRequest, fi } @Override - public List findRoadmapsWithCategoryByMemberOrderByLatest(final Member member, - final Long lastId, - final int pageSize) { + public List findRoadmapsWithCategoryByMemberIdOrderByLatest(final Long memberId, + final Long lastId, + final int pageSize) { final RoadmapOrderType orderType = RoadmapOrderType.LATEST; return selectFrom(roadmap) .innerJoin(roadmap.category, roadmapCategory) .fetchJoin() .where( - creatorIdCond(member.getId()), + creatorIdCond(memberId), lessThanLastId(lastId, orderType)) .limit(pageSize + LIMIT_OFFSET) .orderBy(sortCond(orderType)) @@ -111,15 +104,6 @@ public Optional findByIdAndMemberIdentifier(final Long roadmapId, final .fetchOne()); } - @Override - public List findWithRoadmapContentByStatus(final RoadmapStatus status) { - return selectFrom(roadmap) - .innerJoin(roadmap.contents.values, roadmapContent) - .fetchJoin() - .where(statusCond(status)) - .fetch(); - } - private BooleanExpression roadmapCond(final Long roadmapId) { return roadmap.id.eq(roadmapId); } @@ -150,14 +134,17 @@ private BooleanExpression creatorIdCond(final Long creatorId) { if (creatorId == null) { return null; } - return roadmap.creator.id.eq(creatorId); + return roadmap.creatorId.eq(creatorId); } private BooleanExpression creatorNicknameCond(final RoadmapSearchCreatorNickname creatorName) { if (creatorName == null) { return null; } - return roadmap.creator.nickname.value.eq(creatorName.value()); + return roadmap.creatorId + .eq(select(member.id) + .from(member) + .where(member.nickname.value.eq(creatorName.value()))); } private BooleanExpression tagCond(final RoadmapSearchTagName tagName) { @@ -171,22 +158,24 @@ private BooleanExpression tagCond(final RoadmapSearchTagName tagName) { } private OrderSpecifier sortCond(final RoadmapOrderType orderType) { -// if (orderType == RoadmapOrderType.GOAL_ROOM_COUNT) { -// return new OrderSpecifier<>( -// Order.DESC, -// goalRoomCountCond(goalRoom.roadmapContent.roadmap.eq(roadmap)) -// ); -// } -// if (orderType == RoadmapOrderType.PARTICIPANT_COUNT) { -// return new OrderSpecifier<>( -// Order.DESC, -// participantCountCond(goalRoomMember.goalRoom.roadmapContent.roadmap.eq(roadmap)) -// ); -// } + if (orderType == RoadmapOrderType.GOAL_ROOM_COUNT) { + return new OrderSpecifier<>( + Order.DESC, + goalRoomCountCond(goalRoom.roadmapContentId.eq(getLatestRoadmapContentIdByRoadmap(roadmap.id))) + ); + } + if (orderType == RoadmapOrderType.PARTICIPANT_COUNT) { + return new OrderSpecifier<>( + Order.DESC, + participantCountCond( + goalRoomMember.goalRoom.roadmapContentId.eq(getLatestRoadmapContentIdByRoadmap(roadmap.id)) + ) + ); + } if (orderType == RoadmapOrderType.REVIEW_RATE) { return new OrderSpecifier<>( Order.DESC, - reviewRateCond(roadmapReview.roadmap.eq(roadmap)) + reviewRateCond(roadmapReview.roadmapId.eq(roadmap.id)) ); } return roadmap.createdAt.desc(); @@ -210,22 +199,38 @@ private JPAQuery reviewRateCond(final BooleanExpression isSatisfiedRoadm .where(isSatisfiedRoadmap); } + private JPAQuery getLatestRoadmapContentIdByRoadmap(final NumberPath id) { + return select(roadmapContent.id) + .from(roadmapContent) + .where(roadmapContent.roadmapId.eq(id)) + .orderBy(roadmapContent.createdAt.desc()); + } + + private JPAQuery getLatestRoadmapContentIdByRoadmap(final Long id) { + return select(roadmapContent.id) + .from(roadmapContent) + .where(roadmapContent.roadmapId.eq(id)) + .orderBy(roadmapContent.createdAt.desc()); + } + private BooleanExpression lessThanLastId(final Long lastId, final RoadmapOrderType orderType) { if (lastId == null) { return null; } -// if (orderType == RoadmapOrderType.GOAL_ROOM_COUNT) { -// final NumberPath goalRoomRoadmapId = goalRoom.roadmapContent.roadmap.id; -// return goalRoomCountCond(goalRoomRoadmapId.eq(roadmap.id)) -// .lt(goalRoomCountCond(goalRoomRoadmapId.eq(lastId))); -// } -// if (orderType == RoadmapOrderType.PARTICIPANT_COUNT) { -// final NumberPath goalRoomMemberRoadmapId = goalRoomMember.goalRoom.roadmapContent.roadmap.id; -// return participantCountCond(goalRoomMemberRoadmapId.eq(roadmap.id)) -// .lt(participantCountCond(goalRoomMemberRoadmapId.eq(lastId))); -// } + if (orderType == RoadmapOrderType.GOAL_ROOM_COUNT) { + final NumberPath goalRoomRoadmapContentId = goalRoom.roadmapContentId; + return goalRoomCountCond(goalRoomRoadmapContentId.eq(getLatestRoadmapContentIdByRoadmap(roadmap.id))) + .lt(goalRoomCountCond(goalRoomRoadmapContentId.eq(getLatestRoadmapContentIdByRoadmap(lastId)))); + } + if (orderType == RoadmapOrderType.PARTICIPANT_COUNT) { + final NumberPath goalRoomMemberRoadmapContentId = goalRoomMember.goalRoom.roadmapContentId; + return participantCountCond( + goalRoomMemberRoadmapContentId.eq(getLatestRoadmapContentIdByRoadmap(roadmap.id))) + .lt(participantCountCond( + goalRoomMemberRoadmapContentId.eq(getLatestRoadmapContentIdByRoadmap(lastId)))); + } if (orderType == RoadmapOrderType.REVIEW_RATE) { - final NumberPath roadmapReviewRoadmapId = roadmapReview.roadmap.id; + final NumberPath roadmapReviewRoadmapId = roadmapReview.roadmapId; return reviewRateCond(roadmapReviewRoadmapId.eq(roadmap.id)) .lt(reviewRateCond(roadmapReviewRoadmapId.eq(lastId))); } @@ -238,6 +243,9 @@ private BooleanExpression lessThanLastId(final Long lastId, final RoadmapOrderTy private BooleanExpression creatorIdentifierCond(final String identifier) { final Identifier creatorIdentifier = new Identifier(identifier); - return roadmap.creator.identifier.eq(creatorIdentifier); + return roadmap.creatorId + .eq(select(member.id) + .from(member) + .where(member.identifier.eq(creatorIdentifier))); } } diff --git a/backend/kirikiri/src/main/java/co/kirikiri/roadmap/persistence/RoadmapRepository.java b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/persistence/RoadmapRepository.java new file mode 100644 index 000000000..a022ac304 --- /dev/null +++ b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/persistence/RoadmapRepository.java @@ -0,0 +1,11 @@ +package co.kirikiri.roadmap.persistence; + +import co.kirikiri.roadmap.domain.Roadmap; +import co.kirikiri.roadmap.domain.RoadmapStatus; +import org.springframework.data.jpa.repository.JpaRepository; +import java.util.List; + +public interface RoadmapRepository extends JpaRepository, RoadmapQueryRepository { + + List findByStatus(final RoadmapStatus status); +} diff --git a/backend/kirikiri/src/main/java/co/kirikiri/roadmap/persistence/RoadmapReviewQueryRepository.java b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/persistence/RoadmapReviewQueryRepository.java new file mode 100644 index 000000000..3cd7c1f08 --- /dev/null +++ b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/persistence/RoadmapReviewQueryRepository.java @@ -0,0 +1,11 @@ +package co.kirikiri.roadmap.persistence; + +import co.kirikiri.roadmap.domain.RoadmapReview; +import java.util.List; + +public interface RoadmapReviewQueryRepository { + + List findRoadmapReviewByRoadmapIdOrderByLatest(final Long roadmapId, + final Long lastId, + final int pageSize); +} diff --git a/backend/kirikiri/src/main/java/co/kirikiri/persistence/roadmap/RoadmapReviewQueryRepositoryImpl.java b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/persistence/RoadmapReviewQueryRepositoryImpl.java similarity index 62% rename from backend/kirikiri/src/main/java/co/kirikiri/persistence/roadmap/RoadmapReviewQueryRepositoryImpl.java rename to backend/kirikiri/src/main/java/co/kirikiri/roadmap/persistence/RoadmapReviewQueryRepositoryImpl.java index 894983742..c39898a9a 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/persistence/roadmap/RoadmapReviewQueryRepositoryImpl.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/persistence/RoadmapReviewQueryRepositoryImpl.java @@ -1,11 +1,9 @@ -package co.kirikiri.persistence.roadmap; +package co.kirikiri.roadmap.persistence; -import static co.kirikiri.domain.member.QMember.member; -import static co.kirikiri.domain.roadmap.QRoadmapReview.roadmapReview; +import static co.kirikiri.roadmap.domain.QRoadmapReview.roadmapReview; import co.kirikiri.common.persistence.QuerydslRepositorySupporter; -import co.kirikiri.domain.roadmap.Roadmap; -import co.kirikiri.domain.roadmap.RoadmapReview; +import co.kirikiri.roadmap.domain.RoadmapReview; import com.querydsl.core.types.OrderSpecifier; import com.querydsl.core.types.dsl.BooleanExpression; import java.time.LocalDateTime; @@ -19,20 +17,18 @@ public RoadmapReviewQueryRepositoryImpl() { } @Override - public List findRoadmapReviewWithMemberByRoadmapOrderByLatest(final Roadmap roadmap, - final Long lastId, - final int pageSize) { + public List findRoadmapReviewByRoadmapIdOrderByLatest(final Long roadmapId, + final Long lastId, + final int pageSize) { return selectFrom(roadmapReview) - .innerJoin(roadmapReview.member, member) - .fetchJoin() - .where(roadmapCond(roadmap), lessThanLastId(lastId)) + .where(roadmapCond(roadmapId), lessThanLastId(lastId)) .limit(pageSize) .orderBy(orderByCreatedAtDesc()) .fetch(); } - private BooleanExpression roadmapCond(final Roadmap roadmap) { - return roadmapReview.roadmap.eq(roadmap); + private BooleanExpression roadmapCond(final Long roadmapId) { + return roadmapReview.roadmapId.eq(roadmapId); } private BooleanExpression lessThanLastId(final Long lastId) { diff --git a/backend/kirikiri/src/main/java/co/kirikiri/roadmap/persistence/RoadmapReviewRepository.java b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/persistence/RoadmapReviewRepository.java new file mode 100644 index 000000000..f9f6731f3 --- /dev/null +++ b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/persistence/RoadmapReviewRepository.java @@ -0,0 +1,12 @@ +package co.kirikiri.roadmap.persistence; + +import co.kirikiri.roadmap.domain.RoadmapReview; +import org.springframework.data.jpa.repository.JpaRepository; +import java.util.Optional; + +public interface RoadmapReviewRepository extends JpaRepository, RoadmapReviewQueryRepository { + + Optional findByRoadmapIdAndMemberId(final Long roadmapId, final Long memberId); + + void deleteAllByRoadmapId(final Long roadmapId); +} diff --git a/backend/kirikiri/src/main/java/co/kirikiri/persistence/dto/RoadmapOrderType.java b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/persistence/dto/RoadmapOrderType.java similarity index 67% rename from backend/kirikiri/src/main/java/co/kirikiri/persistence/dto/RoadmapOrderType.java rename to backend/kirikiri/src/main/java/co/kirikiri/roadmap/persistence/dto/RoadmapOrderType.java index fb4ccb0b6..bafb11c4c 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/persistence/dto/RoadmapOrderType.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/persistence/dto/RoadmapOrderType.java @@ -1,4 +1,4 @@ -package co.kirikiri.persistence.dto; +package co.kirikiri.roadmap.persistence.dto; public enum RoadmapOrderType { LATEST, GOAL_ROOM_COUNT, PARTICIPANT_COUNT, REVIEW_RATE diff --git a/backend/kirikiri/src/main/java/co/kirikiri/persistence/dto/RoadmapSearchCreatorNickname.java b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/persistence/dto/RoadmapSearchCreatorNickname.java similarity index 85% rename from backend/kirikiri/src/main/java/co/kirikiri/persistence/dto/RoadmapSearchCreatorNickname.java rename to backend/kirikiri/src/main/java/co/kirikiri/roadmap/persistence/dto/RoadmapSearchCreatorNickname.java index 70ab96d1d..34d7d650b 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/persistence/dto/RoadmapSearchCreatorNickname.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/persistence/dto/RoadmapSearchCreatorNickname.java @@ -1,4 +1,4 @@ -package co.kirikiri.persistence.dto; +package co.kirikiri.roadmap.persistence.dto; public record RoadmapSearchCreatorNickname( String value diff --git a/backend/kirikiri/src/main/java/co/kirikiri/persistence/dto/RoadmapSearchDto.java b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/persistence/dto/RoadmapSearchDto.java similarity index 95% rename from backend/kirikiri/src/main/java/co/kirikiri/persistence/dto/RoadmapSearchDto.java rename to backend/kirikiri/src/main/java/co/kirikiri/roadmap/persistence/dto/RoadmapSearchDto.java index adde60018..92b34371d 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/persistence/dto/RoadmapSearchDto.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/persistence/dto/RoadmapSearchDto.java @@ -1,4 +1,4 @@ -package co.kirikiri.persistence.dto; +package co.kirikiri.roadmap.persistence.dto; import lombok.AccessLevel; import lombok.AllArgsConstructor; diff --git a/backend/kirikiri/src/main/java/co/kirikiri/persistence/dto/RoadmapSearchTagName.java b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/persistence/dto/RoadmapSearchTagName.java similarity index 80% rename from backend/kirikiri/src/main/java/co/kirikiri/persistence/dto/RoadmapSearchTagName.java rename to backend/kirikiri/src/main/java/co/kirikiri/roadmap/persistence/dto/RoadmapSearchTagName.java index 3ed402e18..85b2649e2 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/persistence/dto/RoadmapSearchTagName.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/persistence/dto/RoadmapSearchTagName.java @@ -1,6 +1,6 @@ -package co.kirikiri.persistence.dto; +package co.kirikiri.roadmap.persistence.dto; -import co.kirikiri.common.exception.BadRequestException; +import co.kirikiri.roadmap.domain.exception.RoadmapException; public record RoadmapSearchTagName( String value @@ -20,7 +20,7 @@ private String removeBlank(final String name) { private void validateLength(final String name) { if (name.length() < MIN_LENGTH) { - throw new BadRequestException( + throw new RoadmapException( String.format("검색어는 최소 %d자부터 가능합니다.", MIN_LENGTH)); } } diff --git a/backend/kirikiri/src/main/java/co/kirikiri/persistence/dto/RoadmapSearchTitle.java b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/persistence/dto/RoadmapSearchTitle.java similarity index 81% rename from backend/kirikiri/src/main/java/co/kirikiri/persistence/dto/RoadmapSearchTitle.java rename to backend/kirikiri/src/main/java/co/kirikiri/roadmap/persistence/dto/RoadmapSearchTitle.java index 743e78444..9b7b139ad 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/persistence/dto/RoadmapSearchTitle.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/persistence/dto/RoadmapSearchTitle.java @@ -1,6 +1,6 @@ -package co.kirikiri.persistence.dto; +package co.kirikiri.roadmap.persistence.dto; -import co.kirikiri.common.exception.BadRequestException; +import co.kirikiri.roadmap.domain.exception.RoadmapException; public record RoadmapSearchTitle( String value @@ -20,7 +20,7 @@ private String removeBlank(final String title) { private void validateLength(final String title) { if (title.length() < MIN_LENGTH) { - throw new BadRequestException( + throw new RoadmapException( String.format("검색어는 최소 %d자부터 가능합니다.", MIN_LENGTH)); } } diff --git a/backend/kirikiri/src/main/java/co/kirikiri/roadmap/resolver/RoadmapSaveArgumentResolverImpl.java b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/resolver/RoadmapSaveArgumentResolverImpl.java new file mode 100644 index 000000000..5b53544c8 --- /dev/null +++ b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/resolver/RoadmapSaveArgumentResolverImpl.java @@ -0,0 +1,98 @@ +package co.kirikiri.roadmap.resolver; + +import co.kirikiri.common.exception.BadRequestException; +import co.kirikiri.common.resolver.RoadmapSaveArgumentResolver; +import co.kirikiri.roadmap.service.dto.request.RoadmapNodeSaveRequest; +import co.kirikiri.roadmap.service.dto.request.RoadmapSaveRequest; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import jakarta.servlet.http.HttpServletRequest; +import java.util.List; +import lombok.RequiredArgsConstructor; +import org.springframework.core.MethodParameter; +import org.springframework.stereotype.Component; +import org.springframework.validation.DataBinder; +import org.springframework.validation.Validator; +import org.springframework.web.bind.MethodArgumentNotValidException; +import org.springframework.web.bind.support.WebDataBinderFactory; +import org.springframework.web.context.request.NativeWebRequest; +import org.springframework.web.method.support.ModelAndViewContainer; +import org.springframework.web.multipart.MultipartFile; +import org.springframework.web.multipart.MultipartHttpServletRequest; +import org.springframework.web.multipart.MultipartResolver; +import org.springframework.web.multipart.support.StandardServletMultipartResolver; + +@Component +@RequiredArgsConstructor +public class RoadmapSaveArgumentResolverImpl implements RoadmapSaveArgumentResolver { + + private final ObjectMapper objectMapper; + private final Validator validator; + + @Override + public boolean supportsParameter(final MethodParameter parameter) { + return parameter.getParameterType().equals(RoadmapSaveRequest.class); + } + + @Override + public Object resolveArgument(final MethodParameter parameter, final ModelAndViewContainer mavContainer, + final NativeWebRequest nativeWebRequest, final WebDataBinderFactory binderFactory) + throws MethodArgumentNotValidException { + final HttpServletRequest request = (HttpServletRequest) nativeWebRequest.getNativeRequest(); + checkMultipart(request); + final MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request; + final RoadmapSaveRequest roadmapSaveRequestNotIncludeImage = makeRoadmapSaveRequestNotIncludeImage( + multipartRequest); + validateRequest(parameter, roadmapSaveRequestNotIncludeImage); + return makeRoadmapSaveRequestIncludeImage(roadmapSaveRequestNotIncludeImage, multipartRequest); + } + + private void checkMultipart(final HttpServletRequest request) { + final MultipartResolver multipartResolver = new StandardServletMultipartResolver(); + if (!multipartResolver.isMultipart(request)) { + throw new BadRequestException("multipart/form-data 형식으로 들어와야합니다."); + } + } + + private RoadmapSaveRequest makeRoadmapSaveRequestNotIncludeImage( + final MultipartHttpServletRequest multipartRequest) { + final String jsonData = getJsonData(multipartRequest); + return bindRoadmapSaveRequest(jsonData); + } + + private void validateRequest(final MethodParameter parameter, final RoadmapSaveRequest roadmapSaveRequest) + throws MethodArgumentNotValidException { + final DataBinder binder = new DataBinder(roadmapSaveRequest); + binder.setValidator(validator); + binder.validate(); + + if (binder.getBindingResult().hasErrors()) { + throw new MethodArgumentNotValidException(parameter, binder.getBindingResult()); + } + } + + private RoadmapSaveRequest makeRoadmapSaveRequestIncludeImage(final RoadmapSaveRequest roadmapSaveRequest, + final MultipartHttpServletRequest multipartRequest) { + for (final RoadmapNodeSaveRequest roadmapNode : roadmapSaveRequest.roadmapNodes()) { + final List images = multipartRequest.getFiles(roadmapNode.getTitle()); + roadmapNode.setImages(images); + } + return roadmapSaveRequest; + } + + private String getJsonData(final MultipartHttpServletRequest multipartRequest) { + final String jsonData = multipartRequest.getParameter("jsonData"); + if (jsonData == null) { + throw new BadRequestException("로드맵 생성 시 jsonData는 필수입니다."); + } + return multipartRequest.getParameter("jsonData"); + } + + private RoadmapSaveRequest bindRoadmapSaveRequest(final String jsonData) { + try { + return objectMapper.readValue(jsonData, RoadmapSaveRequest.class); + } catch (final JsonProcessingException exception) { + throw new BadRequestException("로드맵 생성 요청 형식이 틀렸습니다."); + } + } +} diff --git a/backend/kirikiri/src/main/java/co/kirikiri/service/roadmap/RoadmapCreateEventListener.java b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/service/RoadmapCreateEventListener.java similarity index 81% rename from backend/kirikiri/src/main/java/co/kirikiri/service/roadmap/RoadmapCreateEventListener.java rename to backend/kirikiri/src/main/java/co/kirikiri/roadmap/service/RoadmapCreateEventListener.java index c70e02070..e9d69380f 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/service/roadmap/RoadmapCreateEventListener.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/service/RoadmapCreateEventListener.java @@ -1,4 +1,4 @@ -package co.kirikiri.service.roadmap; +package co.kirikiri.roadmap.service; import co.kirikiri.common.aop.ExceptionConvert; import co.kirikiri.common.exception.BadRequestException; @@ -8,16 +8,16 @@ import co.kirikiri.common.service.dto.FileInformation; import co.kirikiri.common.type.ImageContentType; import co.kirikiri.common.type.ImageDirType; -import co.kirikiri.domain.roadmap.Roadmap; -import co.kirikiri.domain.roadmap.RoadmapContent; -import co.kirikiri.domain.roadmap.RoadmapNode; -import co.kirikiri.domain.roadmap.RoadmapNodeImage; -import co.kirikiri.domain.roadmap.RoadmapNodeImages; -import co.kirikiri.persistence.roadmap.RoadmapContentRepository; -import co.kirikiri.service.dto.roadmap.RoadmapNodeSaveDto; -import co.kirikiri.service.event.RoadmapCreateEvent; +import co.kirikiri.roadmap.domain.RoadmapContent; +import co.kirikiri.roadmap.domain.RoadmapNode; +import co.kirikiri.roadmap.domain.RoadmapNodeImage; +import co.kirikiri.roadmap.domain.RoadmapNodeImages; +import co.kirikiri.roadmap.persistence.RoadmapContentRepository; +import co.kirikiri.roadmap.service.dto.RoadmapNodeSaveDto; +import co.kirikiri.roadmap.service.event.RoadmapCreateEvent; import java.util.List; import lombok.RequiredArgsConstructor; +import org.springframework.cache.annotation.CacheEvict; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -35,12 +35,13 @@ public class RoadmapCreateEventListener { @Async @TransactionalEventListener @Transactional + @CacheEvict(value = "roadmapList", allEntries = true) public void handleRoadmapCreate(final RoadmapCreateEvent roadmapCreateEvent) { saveRoadmapNodeImage(roadmapCreateEvent); } private void saveRoadmapNodeImage(final RoadmapCreateEvent roadmapCreateEvent) { - final RoadmapContent lastRoadmapContent = findLastRoadmapContent(roadmapCreateEvent.roadmap()); + final RoadmapContent lastRoadmapContent = findLastRoadmapContent(roadmapCreateEvent.roadmapId()); for (final RoadmapNodeSaveDto roadmapNodeSaveDto : roadmapCreateEvent.roadmapSaveDto().roadmapNodes()) { final RoadmapNode roadmapNode = findRoadmapNodeByTitle(lastRoadmapContent, roadmapNodeSaveDto); final RoadmapNodeImages roadmapNodeImages = makeRoadmapNodeImages(roadmapNodeSaveDto, roadmapNode); @@ -49,8 +50,8 @@ private void saveRoadmapNodeImage(final RoadmapCreateEvent roadmapCreateEvent) { roadmapContentRepository.save(lastRoadmapContent); } - private RoadmapContent findLastRoadmapContent(final Roadmap roadmap) { - return roadmap.findLastRoadmapContent() + private RoadmapContent findLastRoadmapContent(final Long roadmapId) { + return roadmapContentRepository.findFirstByRoadmapIdOrderByCreatedAtDesc(roadmapId) .orElseThrow(() -> new ServerException("로드맵 컨텐츠가 존재하지 않습니다.")); } @@ -58,7 +59,7 @@ private RoadmapNode findRoadmapNodeByTitle(final RoadmapContent lastRoadmapConte final RoadmapNodeSaveDto roadmapNodeSaveDto) { return lastRoadmapContent.findRoadmapNodeByTitle(roadmapNodeSaveDto.title()) .orElseThrow(() -> new BadRequestException( - "해당 제목을 가지고있는 로드맵 노드가 없습니다. title = " + roadmapNodeSaveDto.title())); + "해당 제목을 가지고 있는 로드맵 노드가 없습니다. title = " + roadmapNodeSaveDto.title())); } private RoadmapNodeImages makeRoadmapNodeImages(final RoadmapNodeSaveDto roadmapNodeSaveDto, diff --git a/backend/kirikiri/src/main/java/co/kirikiri/service/roadmap/RoadmapCreateService.java b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/service/RoadmapCreateService.java similarity index 51% rename from backend/kirikiri/src/main/java/co/kirikiri/service/roadmap/RoadmapCreateService.java rename to backend/kirikiri/src/main/java/co/kirikiri/roadmap/service/RoadmapCreateService.java index 7f4785bb6..479c2cd80 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/service/roadmap/RoadmapCreateService.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/service/RoadmapCreateService.java @@ -1,4 +1,4 @@ -package co.kirikiri.service.roadmap; +package co.kirikiri.roadmap.service; import co.kirikiri.common.aop.ExceptionConvert; import co.kirikiri.common.exception.AuthenticationException; @@ -6,37 +6,33 @@ import co.kirikiri.common.exception.ConflictException; import co.kirikiri.common.exception.ForbiddenException; import co.kirikiri.common.exception.NotFoundException; -import co.kirikiri.domain.member.Member; -import co.kirikiri.domain.member.vo.Identifier; -import co.kirikiri.domain.roadmap.Roadmap; -import co.kirikiri.domain.roadmap.RoadmapCategory; -import co.kirikiri.domain.roadmap.RoadmapContent; -import co.kirikiri.domain.roadmap.RoadmapDifficulty; -import co.kirikiri.domain.roadmap.RoadmapNode; -import co.kirikiri.domain.roadmap.RoadmapNodes; -import co.kirikiri.domain.roadmap.RoadmapReview; -import co.kirikiri.domain.roadmap.RoadmapTag; -import co.kirikiri.domain.roadmap.RoadmapTags; -import co.kirikiri.domain.roadmap.vo.RoadmapTagName; -import co.kirikiri.goalroom.domain.GoalRoom; -import co.kirikiri.goalroom.domain.GoalRoomMember; -import co.kirikiri.goalroom.domain.GoalRoomStatus; -import co.kirikiri.goalroom.persistence.GoalRoomMemberRepository; -import co.kirikiri.goalroom.persistence.GoalRoomRepository; -import co.kirikiri.persistence.member.MemberRepository; -import co.kirikiri.persistence.roadmap.RoadmapCategoryRepository; -import co.kirikiri.persistence.roadmap.RoadmapContentRepository; -import co.kirikiri.persistence.roadmap.RoadmapRepository; -import co.kirikiri.persistence.roadmap.RoadmapReviewRepository; -import co.kirikiri.service.dto.roadmap.RoadmapNodeSaveDto; -import co.kirikiri.service.dto.roadmap.RoadmapReviewDto; -import co.kirikiri.service.dto.roadmap.RoadmapSaveDto; -import co.kirikiri.service.dto.roadmap.RoadmapTagSaveDto; -import co.kirikiri.service.dto.roadmap.request.RoadmapCategorySaveRequest; -import co.kirikiri.service.dto.roadmap.request.RoadmapReviewSaveRequest; -import co.kirikiri.service.dto.roadmap.request.RoadmapSaveRequest; -import co.kirikiri.service.event.RoadmapCreateEvent; -import co.kirikiri.service.mapper.RoadmapMapper; +import co.kirikiri.member.domain.Member; +import co.kirikiri.member.domain.vo.Identifier; +import co.kirikiri.member.persistence.MemberRepository; +import co.kirikiri.roadmap.domain.Roadmap; +import co.kirikiri.roadmap.domain.RoadmapCategory; +import co.kirikiri.roadmap.domain.RoadmapContent; +import co.kirikiri.roadmap.domain.RoadmapDifficulty; +import co.kirikiri.roadmap.domain.RoadmapNode; +import co.kirikiri.roadmap.domain.RoadmapNodes; +import co.kirikiri.roadmap.domain.RoadmapReview; +import co.kirikiri.roadmap.domain.RoadmapTag; +import co.kirikiri.roadmap.domain.RoadmapTags; +import co.kirikiri.roadmap.domain.vo.RoadmapTagName; +import co.kirikiri.roadmap.persistence.RoadmapCategoryRepository; +import co.kirikiri.roadmap.persistence.RoadmapContentRepository; +import co.kirikiri.roadmap.persistence.RoadmapRepository; +import co.kirikiri.roadmap.persistence.RoadmapReviewRepository; +import co.kirikiri.roadmap.service.dto.RoadmapNodeSaveDto; +import co.kirikiri.roadmap.service.dto.RoadmapReviewDto; +import co.kirikiri.roadmap.service.dto.RoadmapSaveDto; +import co.kirikiri.roadmap.service.dto.RoadmapTagSaveDto; +import co.kirikiri.roadmap.service.dto.request.RoadmapCategorySaveRequest; +import co.kirikiri.roadmap.service.dto.request.RoadmapReviewSaveRequest; +import co.kirikiri.roadmap.service.dto.request.RoadmapSaveRequest; +import co.kirikiri.roadmap.service.event.RoadmapCreateEvent; +import co.kirikiri.roadmap.service.event.RoadmapDeleteEvent; +import co.kirikiri.roadmap.service.mapper.RoadmapMapper; import java.util.List; import lombok.RequiredArgsConstructor; import org.springframework.cache.annotation.CacheEvict; @@ -54,9 +50,8 @@ public class RoadmapCreateService { private final RoadmapRepository roadmapRepository; private final RoadmapContentRepository roadmapContentRepository; private final RoadmapReviewRepository roadmapReviewRepository; - private final GoalRoomRepository goalRoomRepository; - private final GoalRoomMemberRepository goalRoomMemberRepository; private final RoadmapCategoryRepository roadmapCategoryRepository; + private final RoadmapGoalRoomService roadmapGoalRoomService; private final ApplicationEventPublisher applicationEventPublisher; @CacheEvict(value = "roadmapList", allEntries = true) @@ -64,10 +59,14 @@ public Long create(final RoadmapSaveRequest request, final String identifier) { final Member member = findMemberByIdentifier(identifier); final RoadmapCategory roadmapCategory = findRoadmapCategoryById(request.categoryId()); final RoadmapSaveDto roadmapSaveDto = RoadmapMapper.convertToRoadmapSaveDto(request); - final Roadmap roadmap = createRoadmap(member, roadmapSaveDto, roadmapCategory); + + final Roadmap roadmap = makeRoadmap(member.getId(), roadmapSaveDto, roadmapCategory); final Roadmap savedRoadmap = roadmapRepository.save(roadmap); - applicationEventPublisher.publishEvent(new RoadmapCreateEvent(savedRoadmap, roadmapSaveDto)); + final RoadmapContent roadmapContent = makeRoadmapContent(roadmapSaveDto, savedRoadmap.getId()); + roadmapContentRepository.save(roadmapContent); + + applicationEventPublisher.publishEvent(new RoadmapCreateEvent(savedRoadmap.getId(), roadmapSaveDto)); return savedRoadmap.getId(); } @@ -82,29 +81,13 @@ private RoadmapCategory findRoadmapCategoryById(final Long categoryId) { .orElseThrow(() -> new NotFoundException("존재하지 않는 카테고리입니다. categoryId = " + categoryId)); } - private Roadmap createRoadmap(final Member member, final RoadmapSaveDto roadmapSaveDto, - final RoadmapCategory roadmapCategory) { - final RoadmapNodes roadmapNodes = makeRoadmapNodes(roadmapSaveDto.roadmapNodes()); - final RoadmapContent roadmapContent = makeRoadmapContent(roadmapSaveDto, roadmapNodes); + private Roadmap makeRoadmap(final Long memberId, final RoadmapSaveDto roadmapSaveDto, + final RoadmapCategory roadmapCategory) { final RoadmapTags roadmapTags = makeRoadmapTags(roadmapSaveDto.tags()); - final Roadmap roadmap = makeRoadmap(member, roadmapSaveDto, roadmapCategory); - roadmap.addContent(roadmapContent); - roadmap.addTags(roadmapTags); - return roadmap; - } - - private RoadmapNodes makeRoadmapNodes(final List roadmapNodeSaveDtos) { - return new RoadmapNodes( - roadmapNodeSaveDtos.stream() - .map(node -> new RoadmapNode(node.title(), node.content())) - .toList() - ); - } - - private RoadmapContent makeRoadmapContent(final RoadmapSaveDto roadmapSaveDto, final RoadmapNodes roadmapNodes) { - final RoadmapContent roadmapContent = new RoadmapContent(roadmapSaveDto.content()); - roadmapContent.addNodes(roadmapNodes); - return roadmapContent; + return new Roadmap(roadmapSaveDto.title(), roadmapSaveDto.introduction(), + roadmapSaveDto.requiredPeriod(), RoadmapDifficulty.valueOf(roadmapSaveDto.difficulty().name()), + memberId, + roadmapCategory, roadmapTags); } private RoadmapTags makeRoadmapTags(final List roadmapTagSaveDto) { @@ -115,25 +98,29 @@ private RoadmapTags makeRoadmapTags(final List roadmapTagSave ); } - private Roadmap makeRoadmap(final Member member, final RoadmapSaveDto roadmapSaveDto, - final RoadmapCategory roadmapCategory) { - return new Roadmap(roadmapSaveDto.title(), roadmapSaveDto.introduction(), - roadmapSaveDto.requiredPeriod(), RoadmapDifficulty.valueOf(roadmapSaveDto.difficulty().name()), member, - roadmapCategory); + private RoadmapContent makeRoadmapContent(final RoadmapSaveDto roadmapSaveDto, final Long roadmapId) { + final RoadmapNodes nodes = makeRoadmapNodes(roadmapSaveDto.roadmapNodes()); + return new RoadmapContent(roadmapSaveDto.content(), roadmapId, nodes); + } + + private RoadmapNodes makeRoadmapNodes(final List roadmapNodeSaveDtos) { + return new RoadmapNodes( + roadmapNodeSaveDtos.stream() + .map(node -> new RoadmapNode(node.title(), node.content())) + .toList() + ); } public void createReview(final Long roadmapId, final String identifier, final RoadmapReviewSaveRequest request) { final Roadmap roadmap = findRoadmapById(roadmapId); - final Member member = findMemberByIdentifier(identifier); - final GoalRoomMember goalRoomMember = findCompletedGoalRoomMember(roadmapId, member.getId()); -// final Long memberId = goalRoomMember.getMemberId(); -// final Member member = findMemberById(memberId); - final RoadmapReviewDto roadmapReviewDto = RoadmapMapper.convertRoadmapReviewDto(request, member); - validateReviewQualification(roadmap, member); - validateReviewCount(roadmap, member); + final Long memberId = roadmapGoalRoomService.findCompletedGoalRoomMemberId(roadmapId, identifier); + + validateReviewQualification(roadmap, memberId); + validateReviewCount(roadmapId, memberId); + final RoadmapReviewDto roadmapReviewDto = RoadmapMapper.convertRoadmapReviewDto(request, memberId); final RoadmapReview roadmapReview = new RoadmapReview(roadmapReviewDto.content(), roadmapReviewDto.rate(), - roadmapReviewDto.member()); - roadmap.addReview(roadmapReview); + memberId, roadmapId); + roadmapReviewRepository.save(roadmapReview); } private Roadmap findRoadmapById(final Long id) { @@ -141,29 +128,17 @@ private Roadmap findRoadmapById(final Long id) { .orElseThrow(() -> new NotFoundException("존재하지 않는 로드맵입니다. roadmapId = " + id)); } - private GoalRoomMember findCompletedGoalRoomMember(final Long roadmapId, final Long memberId) { - return goalRoomMemberRepository.findByRoadmapIdAndMemberIdentifierAndGoalRoomStatus(roadmapId, memberId, - GoalRoomStatus.COMPLETED) - .orElseThrow(() -> new BadRequestException( - "로드맵에 대해서 완료된 골룸이 존재하지 않습니다. roadmapId = " + roadmapId + " memberId = " + memberId)); - } - - private Member findMemberById(final Long memberId) { - return memberRepository.findById(memberId) - .orElseThrow(() -> new NotFoundException("존재하지 않는 회원입니다. memberId = " + memberId)); - } - - private void validateReviewQualification(final Roadmap roadmap, final Member member) { - if (roadmap.isCreator(member)) { + private void validateReviewQualification(final Roadmap roadmap, final Long memberId) { + if (roadmap.isCreator(memberId)) { throw new BadRequestException( - "로드맵 생성자는 리뷰를 달 수 없습니다. roadmapId = " + roadmap.getId() + " memberId = " + member.getId()); + "로드맵 생성자는 리뷰를 달 수 없습니다. roadmapId = " + roadmap.getId() + " memberId = " + memberId); } } - private void validateReviewCount(final Roadmap roadmap, final Member member) { - if (roadmapReviewRepository.findByRoadmapAndMember(roadmap, member).isPresent()) { + private void validateReviewCount(final Long roadmapId, final Long memberId) { + if (roadmapReviewRepository.findByRoadmapIdAndMemberId(roadmapId, memberId).isPresent()) { throw new BadRequestException( - "이미 작성한 리뷰가 존재합니다. roadmapId = " + roadmap.getId() + " memberId = " + member.getId()); + "이미 작성한 리뷰가 존재합니다. roadmapId = " + roadmapId + " memberId = " + memberId); } } @@ -171,23 +146,19 @@ private void validateReviewCount(final Roadmap roadmap, final Member member) { public void deleteRoadmap(final String identifier, final Long roadmapId) { final Roadmap roadmap = findRoadmapById(roadmapId); validateRoadmapCreator(roadmapId, identifier); - final RoadmapContent roadmapContent = findRecentContent(roadmap); - final List goalRooms = goalRoomRepository.findByRoadmapContentId(roadmapContent.getId()); - if (goalRooms.isEmpty()) { + if (!roadmapGoalRoomService.hasGoalRooms(roadmapId)) { + applicationEventPublisher.publishEvent(new RoadmapDeleteEvent(roadmap.getId(), "Review")); + roadmapContentRepository.deleteAllByRoadmapId(roadmapId); roadmapRepository.delete(roadmap); return; } roadmap.delete(); } - private RoadmapContent findRecentContent(final Roadmap roadmap) { - return roadmapContentRepository.findFirstByRoadmapOrderByCreatedAtDesc(roadmap) - .orElseThrow(() -> new NotFoundException("로드맵에 컨텐츠가 존재하지 않습니다.")); - } - private void validateRoadmapCreator(final Long roadmapId, final String identifier) { - roadmapRepository.findByIdAndMemberIdentifier(roadmapId, identifier) - .orElseThrow(() -> new ForbiddenException("해당 로드맵을 생성한 사용자가 아닙니다.")); + if (roadmapRepository.findByIdAndMemberIdentifier(roadmapId, identifier).isEmpty()) { + throw new ForbiddenException("해당 로드맵을 생성한 사용자가 아닙니다."); + } } @CacheEvict(value = "categoryList", allEntries = true) diff --git a/backend/kirikiri/src/main/java/co/kirikiri/roadmap/service/RoadmapGoalRoomService.java b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/service/RoadmapGoalRoomService.java new file mode 100644 index 000000000..2e3f9b142 --- /dev/null +++ b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/service/RoadmapGoalRoomService.java @@ -0,0 +1,22 @@ +package co.kirikiri.roadmap.service; + +import co.kirikiri.common.service.dto.CustomScrollRequest; +import co.kirikiri.roadmap.domain.Roadmap; +import co.kirikiri.roadmap.service.dto.RoadmapGoalRoomNumberDto; +import co.kirikiri.roadmap.service.dto.RoadmapGoalRoomsOrderTypeDto; +import co.kirikiri.roadmap.service.dto.response.RoadmapGoalRoomResponses; + +public interface RoadmapGoalRoomService { + + Long findCompletedGoalRoomMemberId(final Long roadmapId, final String identifier); + + boolean hasGoalRooms(final Long roadmapId); + + RoadmapGoalRoomNumberDto findRoadmapGoalRoomsByRoadmap(final Roadmap roadmap); + + RoadmapGoalRoomResponses makeRoadmapGoalRoomResponsesByOrderType(final Long roadmapId, + final RoadmapGoalRoomsOrderTypeDto orderTypeDto, + final CustomScrollRequest scrollRequest); + + boolean canDeleteGoalRoomsInRoadmap(final Long roadmapId); +} diff --git a/backend/kirikiri/src/main/java/co/kirikiri/service/roadmap/RoadmapReadService.java b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/service/RoadmapReadService.java similarity index 59% rename from backend/kirikiri/src/main/java/co/kirikiri/service/roadmap/RoadmapReadService.java rename to backend/kirikiri/src/main/java/co/kirikiri/roadmap/service/RoadmapReadService.java index 95a59da8d..de1320744 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/service/roadmap/RoadmapReadService.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/service/RoadmapReadService.java @@ -1,55 +1,46 @@ -package co.kirikiri.service.roadmap; +package co.kirikiri.roadmap.service; import co.kirikiri.common.aop.ExceptionConvert; import co.kirikiri.common.exception.NotFoundException; +import co.kirikiri.common.mapper.ScrollResponseMapper; import co.kirikiri.common.service.FileService; -import co.kirikiri.domain.member.Member; -import co.kirikiri.domain.member.vo.Identifier; -import co.kirikiri.domain.roadmap.Roadmap; -import co.kirikiri.domain.roadmap.RoadmapCategory; -import co.kirikiri.domain.roadmap.RoadmapContent; -import co.kirikiri.domain.roadmap.RoadmapNode; -import co.kirikiri.domain.roadmap.RoadmapNodes; -import co.kirikiri.domain.roadmap.RoadmapReview; -import co.kirikiri.domain.roadmap.RoadmapTags; -import co.kirikiri.goalroom.domain.GoalRoom; -import co.kirikiri.goalroom.domain.GoalRoomRole; -import co.kirikiri.goalroom.persistence.GoalRoomMemberRepository; -import co.kirikiri.goalroom.persistence.GoalRoomPendingMemberRepository; -import co.kirikiri.goalroom.persistence.GoalRoomRepository; -import co.kirikiri.goalroom.persistence.dto.RoadmapGoalRoomsOrderType; -import co.kirikiri.goalroom.service.dto.RoadmapGoalRoomDto; -import co.kirikiri.goalroom.service.dto.RoadmapGoalRoomScrollDto; -import co.kirikiri.goalroom.service.mapper.GoalRoomMapper; -import co.kirikiri.persistence.dto.RoadmapOrderType; -import co.kirikiri.persistence.dto.RoadmapSearchDto; -import co.kirikiri.persistence.member.MemberRepository; -import co.kirikiri.persistence.roadmap.RoadmapCategoryRepository; -import co.kirikiri.persistence.roadmap.RoadmapContentRepository; -import co.kirikiri.persistence.roadmap.RoadmapRepository; -import co.kirikiri.persistence.roadmap.RoadmapReviewRepository; -import co.kirikiri.service.dto.CustomScrollRequest; -import co.kirikiri.service.dto.member.MemberDto; -import co.kirikiri.service.dto.roadmap.RoadmapCategoryDto; -import co.kirikiri.service.dto.roadmap.RoadmapContentDto; -import co.kirikiri.service.dto.roadmap.RoadmapDto; -import co.kirikiri.service.dto.roadmap.RoadmapForListDto; -import co.kirikiri.service.dto.roadmap.RoadmapForListScrollDto; -import co.kirikiri.service.dto.roadmap.RoadmapGoalRoomNumberDto; -import co.kirikiri.service.dto.roadmap.RoadmapGoalRoomsOrderTypeDto; -import co.kirikiri.service.dto.roadmap.RoadmapNodeDto; -import co.kirikiri.service.dto.roadmap.RoadmapReviewReadDto; -import co.kirikiri.service.dto.roadmap.RoadmapTagDto; -import co.kirikiri.service.dto.roadmap.request.RoadmapOrderTypeRequest; -import co.kirikiri.service.dto.roadmap.request.RoadmapSearchRequest; -import co.kirikiri.service.dto.roadmap.response.MemberRoadmapResponses; -import co.kirikiri.service.dto.roadmap.response.RoadmapCategoryResponse; -import co.kirikiri.service.dto.roadmap.response.RoadmapForListResponses; -import co.kirikiri.service.dto.roadmap.response.RoadmapGoalRoomResponses; -import co.kirikiri.service.dto.roadmap.response.RoadmapResponse; -import co.kirikiri.service.dto.roadmap.response.RoadmapReviewResponse; -import co.kirikiri.service.mapper.RoadmapMapper; -import co.kirikiri.service.mapper.ScrollResponseMapper; +import co.kirikiri.common.service.dto.CustomScrollRequest; +import co.kirikiri.member.domain.Member; +import co.kirikiri.member.domain.vo.Identifier; +import co.kirikiri.member.persistence.MemberRepository; +import co.kirikiri.member.service.dto.MemberDto; +import co.kirikiri.roadmap.domain.Roadmap; +import co.kirikiri.roadmap.domain.RoadmapCategory; +import co.kirikiri.roadmap.domain.RoadmapContent; +import co.kirikiri.roadmap.domain.RoadmapNode; +import co.kirikiri.roadmap.domain.RoadmapNodes; +import co.kirikiri.roadmap.domain.RoadmapReview; +import co.kirikiri.roadmap.domain.RoadmapTags; +import co.kirikiri.roadmap.persistence.RoadmapCategoryRepository; +import co.kirikiri.roadmap.persistence.RoadmapContentRepository; +import co.kirikiri.roadmap.persistence.RoadmapRepository; +import co.kirikiri.roadmap.persistence.RoadmapReviewRepository; +import co.kirikiri.roadmap.persistence.dto.RoadmapOrderType; +import co.kirikiri.roadmap.persistence.dto.RoadmapSearchDto; +import co.kirikiri.roadmap.service.dto.RoadmapCategoryDto; +import co.kirikiri.roadmap.service.dto.RoadmapContentDto; +import co.kirikiri.roadmap.service.dto.RoadmapDto; +import co.kirikiri.roadmap.service.dto.RoadmapForListDto; +import co.kirikiri.roadmap.service.dto.RoadmapForListScrollDto; +import co.kirikiri.roadmap.service.dto.RoadmapGoalRoomNumberDto; +import co.kirikiri.roadmap.service.dto.RoadmapGoalRoomsOrderTypeDto; +import co.kirikiri.roadmap.service.dto.RoadmapNodeDto; +import co.kirikiri.roadmap.service.dto.RoadmapReviewReadDto; +import co.kirikiri.roadmap.service.dto.RoadmapTagDto; +import co.kirikiri.roadmap.service.dto.request.RoadmapOrderTypeRequest; +import co.kirikiri.roadmap.service.dto.request.RoadmapSearchRequest; +import co.kirikiri.roadmap.service.dto.response.MemberRoadmapResponses; +import co.kirikiri.roadmap.service.dto.response.RoadmapCategoryResponse; +import co.kirikiri.roadmap.service.dto.response.RoadmapForListResponses; +import co.kirikiri.roadmap.service.dto.response.RoadmapGoalRoomResponses; +import co.kirikiri.roadmap.service.dto.response.RoadmapResponse; +import co.kirikiri.roadmap.service.dto.response.RoadmapReviewResponse; +import co.kirikiri.roadmap.service.mapper.RoadmapMapper; import java.net.URL; import java.util.List; import lombok.RequiredArgsConstructor; @@ -68,25 +59,33 @@ public class RoadmapReadService { private final RoadmapCategoryRepository roadmapCategoryRepository; private final RoadmapContentRepository roadmapContentRepository; private final RoadmapReviewRepository roadmapReviewRepository; - private final GoalRoomRepository goalRoomRepository; - private final GoalRoomMemberRepository goalRoomMemberRepository; - private final GoalRoomPendingMemberRepository goalRoomPendingMemberRepository; + private final RoadmapGoalRoomService roadmapGoalRoomService; private final MemberRepository memberRepository; private final FileService fileService; @Cacheable(value = "roadmap", keyGenerator = "cacheKeyGenerator", cacheManager = "redisCacheManager") - public RoadmapResponse findRoadmap(final Long id) { - final Roadmap roadmap = findRoadmapById(id); - final RoadmapContent recentRoadmapContent = findRecentContent(roadmap); - final List goalRooms = goalRoomRepository.findByRoadmapContentId(recentRoadmapContent.getId()); - final RoadmapGoalRoomNumberDto roadmapGoalRoomNumberDto = GoalRoomMapper.convertRoadmapGoalRoomDto(goalRooms); + public RoadmapResponse findRoadmap(final Long roadmapId) { + final Roadmap roadmap = findRoadmapById(roadmapId); + final RoadmapContent recentRoadmapContent = findRecentContent(roadmapId); + final RoadmapGoalRoomNumberDto roadmapGoalRoomNumberDto = roadmapGoalRoomService.findRoadmapGoalRoomsByRoadmap( + roadmap); final RoadmapDto roadmapDto = makeRoadmapDto(roadmap, recentRoadmapContent); return RoadmapMapper.convertToRoadmapResponse(roadmapDto, roadmapGoalRoomNumberDto); } + private Roadmap findRoadmapById(final Long id) { + return roadmapRepository.findById(id) + .orElseThrow(() -> new NotFoundException("존재하지 않는 로드맵입니다. roadmapId = " + id)); + } + + private RoadmapContent findRecentContent(final Long roadmapId) { + return roadmapContentRepository.findFirstByRoadmapIdOrderByCreatedAtDesc(roadmapId) + .orElseThrow(() -> new NotFoundException("로드맵에 컨텐츠가 존재하지 않습니다.")); + } + private RoadmapDto makeRoadmapDto(final Roadmap roadmap, final RoadmapContent roadmapContent) { final RoadmapCategory category = roadmap.getCategory(); - final Member creator = roadmap.getCreator(); + final Member creator = findMemberById(roadmap.getCreatorId()); final RoadmapContentDto roadmapContentDto = new RoadmapContentDto( roadmapContent.getId(), roadmapContent.getContent(), @@ -97,6 +96,11 @@ private RoadmapDto makeRoadmapDto(final Roadmap roadmap, final RoadmapContent ro roadmap.getCreatedAt(), makeRoadmapTagDtos(roadmap.getTags())); } + private Member findMemberById(final Long memberId) { + return memberRepository.findWithMemberProfileAndImageById(memberId) + .orElseThrow(() -> new NotFoundException("존재하지 않는 회원입니다.")); + } + private MemberDto makeMemberDto(final Member creator) { final URL url = fileService.generateUrl(creator.getImage().getServerFilePath(), HttpMethod.GET); return new MemberDto(creator.getId(), creator.getNickname().getValue(), url.toExternalForm()); @@ -125,16 +129,6 @@ private List makeRoadmapTagDtos(final RoadmapTags roadmapTags) { .toList(); } - private Roadmap findRoadmapById(final Long id) { - return roadmapRepository.findRoadmapById(id) - .orElseThrow(() -> new NotFoundException("존재하지 않는 로드맵입니다. roadmapId = " + id)); - } - - private RoadmapContent findRecentContent(final Roadmap roadmap) { - return roadmapContentRepository.findFirstByRoadmapOrderByCreatedAtDesc(roadmap) - .orElseThrow(() -> new NotFoundException("로드맵에 컨텐츠가 존재하지 않습니다.")); - } - @Cacheable(value = "roadmapList", keyGenerator = "cacheKeyGenerator", cacheManager = "redisCacheManager") public RoadmapForListResponses findRoadmapsByOrderType(final Long categoryId, final RoadmapOrderTypeRequest orderTypeRequest, @@ -169,7 +163,7 @@ private RoadmapForListDto makeRoadmapForListDto(final Roadmap roadmap) { final RoadmapCategory category = roadmap.getCategory(); final RoadmapCategoryDto roadmapCategoryDto = new RoadmapCategoryDto(category.getId(), category.getName()); - final Member creator = roadmap.getCreator(); + final Member creator = findMemberById(roadmap.getCreatorId()); final URL creatorImageUrl = fileService.generateUrl(creator.getImage().getServerFilePath(), HttpMethod.GET); final MemberDto memberDto = new MemberDto(creator.getId(), creator.getNickname().getValue(), creatorImageUrl.toExternalForm()); @@ -217,7 +211,7 @@ public List findAllRoadmapCategories() { public MemberRoadmapResponses findAllMemberRoadmaps(final String identifier, final CustomScrollRequest scrollRequest) { final Member member = findMemberByIdentifier(identifier); - final List roadmaps = roadmapRepository.findRoadmapsWithCategoryByMemberOrderByLatest(member, + final List roadmaps = roadmapRepository.findRoadmapsWithCategoryByMemberIdOrderByLatest(member.getId(), scrollRequest.lastId(), scrollRequest.size()); return RoadmapMapper.convertMemberRoadmapResponses(roadmaps, scrollRequest.size()); } @@ -231,74 +225,15 @@ public RoadmapGoalRoomResponses findRoadmapGoalRoomsByOrderType(final Long roadm final RoadmapGoalRoomsOrderTypeDto orderTypeDto, final CustomScrollRequest scrollRequest) { final Roadmap roadmap = findRoadmapById(roadmapId); - final RoadmapGoalRoomsOrderType orderType = GoalRoomMapper.convertToGoalRoomOrderType(orderTypeDto); - final RoadmapContent roadmapContent = findRecentContent(roadmap); - final List goalRooms = goalRoomRepository.findGoalRoomsByRoadmapContentIdAndCond( - roadmapContent.getId(), orderType, scrollRequest.lastId(), scrollRequest.size()); - final RoadmapGoalRoomScrollDto roadmapGoalRoomScrollDto = makeGoalRoomDtos(goalRooms, scrollRequest.size()); - return GoalRoomMapper.convertToRoadmapGoalRoomResponses(roadmapGoalRoomScrollDto); - } - -// private RoadmapContent findRoadmapContentByRoadmap(final Roadmap roadmap) { -// return roadmapContentRepository.findByRoadmap(roadmap) -// .orElseThrow(() -> new NotFoundException("존재하지 않는 로드맵 컨텐츠입니다.")); -// } - - private RoadmapGoalRoomScrollDto makeGoalRoomDtos(final List goalRooms, - final int requestSize) { - final List roadmapGoalRoomDtos = goalRooms.stream() - .map(this::makeGoalRoomDto) - .toList(); - final List subDtos = ScrollResponseMapper.getSubResponses(roadmapGoalRoomDtos, requestSize); - final boolean hasNext = ScrollResponseMapper.hasNext(roadmapGoalRoomDtos.size(), requestSize); - return new RoadmapGoalRoomScrollDto(subDtos, hasNext); - } - - private RoadmapGoalRoomDto makeGoalRoomDto(final GoalRoom goalRoom) { - final Long goalRoomLeaderId = findGoalRoomLeaderId(goalRoom); - return new RoadmapGoalRoomDto(goalRoom.getId(), goalRoom.getName().getValue(), goalRoom.getStatus(), - getCurrentMemberCount(goalRoom), goalRoom.getLimitedMemberCount().getValue(), - goalRoom.getCreatedAt(), goalRoom.getStartDate(), goalRoom.getEndDate(), - makeMemberDto(goalRoomLeaderId)); - } - - private Long findGoalRoomLeaderId(final GoalRoom goalRoom) { - if (goalRoom.isRecruiting()) { - return goalRoomPendingMemberRepository.findLeaderByGoalRoomAndRole(goalRoom, GoalRoomRole.LEADER) - .orElseThrow(() -> new NotFoundException("골룸의 리더가 존재하지 않습니다.")) - .getMemberId(); - } - return goalRoomMemberRepository.findLeaderByGoalRoomAndRole(goalRoom, GoalRoomRole.LEADER) - .orElseThrow(() -> new NotFoundException("골룸의 리더가 존재하지 않습니다.")) - .getMemberId(); - } - - private int getCurrentMemberCount(final GoalRoom goalRoom) { - if (goalRoom.isRecruiting()) { - return goalRoomPendingMemberRepository.findByGoalRoom(goalRoom) - .size(); - } - return goalRoomMemberRepository.findAllByGoalRoom(goalRoom) - .size(); - } - - private co.kirikiri.goalroom.service.dto.MemberDto makeMemberDto(final Long creatorId) { - final Member creator = findMemberById(creatorId); - final URL url = fileService.generateUrl(creator.getImage().getServerFilePath(), HttpMethod.GET); - return new co.kirikiri.goalroom.service.dto.MemberDto(creator.getId(), creator.getNickname().getValue(), - url.toExternalForm()); - } - - private Member findMemberById(final Long creatorId) { - return memberRepository.findById(creatorId) - .orElseThrow(() -> new NotFoundException("존재하지 않는 회원입니다. memberId = " + creatorId)); + return roadmapGoalRoomService.makeRoadmapGoalRoomResponsesByOrderType(roadmap.getId(), orderTypeDto, + scrollRequest); } public List findRoadmapReviews(final Long roadmapId, final CustomScrollRequest scrollRequest) { final Roadmap roadmap = findRoadmapById(roadmapId); - final List roadmapReviews = roadmapReviewRepository.findRoadmapReviewWithMemberByRoadmapOrderByLatest( - roadmap, scrollRequest.lastId(), scrollRequest.size()); + final List roadmapReviews = roadmapReviewRepository.findRoadmapReviewByRoadmapIdOrderByLatest( + roadmap.getId(), scrollRequest.lastId(), scrollRequest.size()); final List roadmapReviewReadDtos = makeRoadmapReviewReadDtos(roadmapReviews); return RoadmapMapper.convertToRoadmapReviewResponses(roadmapReviewReadDtos); } @@ -310,7 +245,7 @@ public List makeRoadmapReviewReadDtos(final List convertRoadmapCategoryResponses( } public static RoadmapReviewDto convertRoadmapReviewDto(final RoadmapReviewSaveRequest request, - final Member member) { - return new RoadmapReviewDto(request.content(), request.rate(), member); + final Long memberId) { + return new RoadmapReviewDto(request.content(), request.rate(), memberId); } public static MemberRoadmapResponses convertMemberRoadmapResponses(final List roadmaps, diff --git a/backend/kirikiri/src/main/java/co/kirikiri/roadmap/service/scheduler/RoadmapScheduler.java b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/service/scheduler/RoadmapScheduler.java new file mode 100644 index 000000000..d47a8b156 --- /dev/null +++ b/backend/kirikiri/src/main/java/co/kirikiri/roadmap/service/scheduler/RoadmapScheduler.java @@ -0,0 +1,46 @@ +package co.kirikiri.roadmap.service.scheduler; + +import co.kirikiri.common.aop.ExceptionConvert; +import co.kirikiri.roadmap.domain.Roadmap; +import co.kirikiri.roadmap.domain.RoadmapStatus; +import co.kirikiri.roadmap.persistence.RoadmapContentRepository; +import co.kirikiri.roadmap.persistence.RoadmapRepository; +import co.kirikiri.roadmap.service.RoadmapGoalRoomService; +import co.kirikiri.roadmap.service.event.RoadmapDeleteEvent; +import lombok.RequiredArgsConstructor; +import org.springframework.context.ApplicationEventPublisher; +import org.springframework.scheduling.annotation.Scheduled; +import org.springframework.stereotype.Component; +import org.springframework.transaction.annotation.Transactional; +import java.util.List; + +@Component +@Transactional +@RequiredArgsConstructor +@ExceptionConvert +public class RoadmapScheduler { + + private final RoadmapRepository roadmapRepository; + private final RoadmapContentRepository roadmapContentRepository; + private final RoadmapGoalRoomService roadmapGoalRoomService; + private final ApplicationEventPublisher applicationEventPublisher; + + @Scheduled(cron = "0 0 4 * * *") + public void deleteRoadmaps() { + final RoadmapStatus status = RoadmapStatus.DELETED; + final List deletedStatusRoadmaps = roadmapRepository.findByStatus(status); + for (final Roadmap roadmap : deletedStatusRoadmaps) { + delete(roadmap); + } + } + + private void delete(final Roadmap roadmap) { + final boolean canDelete = roadmapGoalRoomService.canDeleteGoalRoomsInRoadmap(roadmap.getId()); + // TODO : GoalRoom 내부의 Roadmap 직접 의존 제거 시 로드맵에 포함된 GoalRoom 따로 제거해주기 (이벤트 활용) + if (canDelete) { + applicationEventPublisher.publishEvent(new RoadmapDeleteEvent(roadmap.getId(), "Review")); + roadmapContentRepository.deleteAllByRoadmapId(roadmap.getId()); + roadmapRepository.delete(roadmap); + } + } +} diff --git a/backend/kirikiri/src/main/java/co/kirikiri/service/dto/auth/AuthenticationTokenDto.java b/backend/kirikiri/src/main/java/co/kirikiri/service/dto/auth/AuthenticationTokenDto.java deleted file mode 100644 index 8e56708f4..000000000 --- a/backend/kirikiri/src/main/java/co/kirikiri/service/dto/auth/AuthenticationTokenDto.java +++ /dev/null @@ -1,7 +0,0 @@ -package co.kirikiri.service.dto.auth; - -public record AuthenticationTokenDto( - String accessToken, - String refreshToken -) { -} diff --git a/backend/kirikiri/src/main/java/co/kirikiri/service/dto/auth/LoginDto.java b/backend/kirikiri/src/main/java/co/kirikiri/service/dto/auth/LoginDto.java deleted file mode 100644 index 1224c1d5c..000000000 --- a/backend/kirikiri/src/main/java/co/kirikiri/service/dto/auth/LoginDto.java +++ /dev/null @@ -1,11 +0,0 @@ -package co.kirikiri.service.dto.auth; - -import co.kirikiri.domain.member.vo.Identifier; -import co.kirikiri.domain.member.vo.Password; - -public record LoginDto( - Identifier identifier, - Password password -) { - -} diff --git a/backend/kirikiri/src/main/java/co/kirikiri/service/dto/member/MemberJoinDto.java b/backend/kirikiri/src/main/java/co/kirikiri/service/dto/member/MemberJoinDto.java deleted file mode 100644 index fadfda7b1..000000000 --- a/backend/kirikiri/src/main/java/co/kirikiri/service/dto/member/MemberJoinDto.java +++ /dev/null @@ -1,16 +0,0 @@ -package co.kirikiri.service.dto.member; - -import co.kirikiri.domain.member.Gender; -import co.kirikiri.domain.member.vo.Identifier; -import co.kirikiri.domain.member.vo.Nickname; -import co.kirikiri.domain.member.vo.Password; - -public record MemberJoinDto( - Identifier identifier, - Password password, - Nickname nickname, - Gender gender, - String email -) { - -} diff --git a/backend/kirikiri/src/main/java/co/kirikiri/service/dto/roadmap/RoadmapReviewDto.java b/backend/kirikiri/src/main/java/co/kirikiri/service/dto/roadmap/RoadmapReviewDto.java deleted file mode 100644 index 89ef43983..000000000 --- a/backend/kirikiri/src/main/java/co/kirikiri/service/dto/roadmap/RoadmapReviewDto.java +++ /dev/null @@ -1,11 +0,0 @@ -package co.kirikiri.service.dto.roadmap; - -import co.kirikiri.domain.member.Member; - -public record RoadmapReviewDto( - String content, - Double rate, - Member member -) { - -} diff --git a/backend/kirikiri/src/main/java/co/kirikiri/service/event/RoadmapCreateEvent.java b/backend/kirikiri/src/main/java/co/kirikiri/service/event/RoadmapCreateEvent.java deleted file mode 100644 index d0e3d129c..000000000 --- a/backend/kirikiri/src/main/java/co/kirikiri/service/event/RoadmapCreateEvent.java +++ /dev/null @@ -1,11 +0,0 @@ -package co.kirikiri.service.event; - -import co.kirikiri.domain.roadmap.Roadmap; -import co.kirikiri.service.dto.roadmap.RoadmapSaveDto; - -public record RoadmapCreateEvent( - Roadmap roadmap, - RoadmapSaveDto roadmapSaveDto -) { - -} diff --git a/backend/kirikiri/src/main/java/co/kirikiri/service/scheduler/RoadmapScheduler.java b/backend/kirikiri/src/main/java/co/kirikiri/service/scheduler/RoadmapScheduler.java deleted file mode 100644 index eb640aa57..000000000 --- a/backend/kirikiri/src/main/java/co/kirikiri/service/scheduler/RoadmapScheduler.java +++ /dev/null @@ -1,66 +0,0 @@ -package co.kirikiri.service.scheduler; - -import co.kirikiri.common.aop.ExceptionConvert; -import co.kirikiri.common.exception.NotFoundException; -import co.kirikiri.domain.roadmap.Roadmap; -import co.kirikiri.domain.roadmap.RoadmapContent; -import co.kirikiri.domain.roadmap.RoadmapStatus; -import co.kirikiri.goalroom.domain.GoalRoom; -import co.kirikiri.goalroom.persistence.GoalRoomRepository; -import co.kirikiri.persistence.roadmap.RoadmapContentRepository; -import co.kirikiri.persistence.roadmap.RoadmapRepository; -import java.util.List; -import lombok.RequiredArgsConstructor; -import org.springframework.scheduling.annotation.Scheduled; -import org.springframework.stereotype.Component; -import org.springframework.transaction.annotation.Transactional; - -@Component -@Transactional -@RequiredArgsConstructor -@ExceptionConvert -public class RoadmapScheduler { - - private static final int DELETE_AFTER_MONTH = 3; - - private final RoadmapRepository roadmapRepository; - private final RoadmapContentRepository roadmapContentRepository; - private final GoalRoomRepository goalRoomRepository; - - @Scheduled(cron = "0 0 4 * * *") - public void deleteRoadmaps() { - final RoadmapStatus status = RoadmapStatus.DELETED; - final List deletedStatusRoadmaps = roadmapRepository.findWithRoadmapContentByStatus(status); - for (final Roadmap roadmap : deletedStatusRoadmaps) { - final RoadmapContent roadmapContent = findRecentContent(roadmap); - delete(roadmap, roadmapContent); - } - } - - private RoadmapContent findRecentContent(final Roadmap roadmap) { - return roadmapContentRepository.findFirstByRoadmapOrderByCreatedAtDesc(roadmap) - .orElseThrow(() -> new NotFoundException("로드맵에 컨텐츠가 존재하지 않습니다.")); - } - - private void delete(final Roadmap roadmap, final RoadmapContent roadmapContent) { - final List goalRooms = goalRoomRepository.findByRoadmapContentId(roadmapContent.getId()); - final boolean canDelete = canDeleteRoadmapBasedOnGoalRooms(goalRooms); - if (canDelete) { - deleteGoalRooms(goalRooms); - deleteRoadmap(roadmap); - } - } - - private boolean canDeleteRoadmapBasedOnGoalRooms(final List goalRooms) { - return goalRooms.stream() - .allMatch(goalRoom -> goalRoom.isCompleted() && goalRoom.isCompletedAfterMonths(DELETE_AFTER_MONTH)); - } - - private void deleteGoalRooms(final List goalRooms) { - goalRoomRepository.deleteAll(goalRooms); - } - - private void deleteRoadmap(final Roadmap roadmap) { - roadmapRepository.delete(roadmap); - } -} diff --git a/backend/kirikiri/src/main/java/co/kirikiri/todo/domain/exception/GoalRoomToDoException.java b/backend/kirikiri/src/main/java/co/kirikiri/todo/domain/exception/GoalRoomToDoException.java index 68673c292..5f7ac3426 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/todo/domain/exception/GoalRoomToDoException.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/todo/domain/exception/GoalRoomToDoException.java @@ -1,9 +1,9 @@ package co.kirikiri.todo.domain.exception; -import co.kirikiri.common.exception.DomainException; +import co.kirikiri.common.exception.domain.DomainException; public class GoalRoomToDoException extends DomainException { - + public GoalRoomToDoException(final String message) { super(message); } diff --git a/backend/kirikiri/src/main/java/co/kirikiri/todo/service/GoalRoomToDoService.java b/backend/kirikiri/src/main/java/co/kirikiri/todo/service/GoalRoomToDoService.java index 5e00a218d..b6245268d 100644 --- a/backend/kirikiri/src/main/java/co/kirikiri/todo/service/GoalRoomToDoService.java +++ b/backend/kirikiri/src/main/java/co/kirikiri/todo/service/GoalRoomToDoService.java @@ -4,14 +4,14 @@ import co.kirikiri.common.exception.BadRequestException; import co.kirikiri.common.exception.ForbiddenException; import co.kirikiri.common.exception.NotFoundException; -import co.kirikiri.domain.member.Member; -import co.kirikiri.domain.member.vo.Identifier; import co.kirikiri.goalroom.domain.GoalRoom; import co.kirikiri.goalroom.domain.GoalRoomMember; import co.kirikiri.goalroom.domain.GoalRoomMembers; import co.kirikiri.goalroom.persistence.GoalRoomMemberRepository; import co.kirikiri.goalroom.persistence.GoalRoomRepository; -import co.kirikiri.persistence.member.MemberRepository; +import co.kirikiri.member.domain.Member; +import co.kirikiri.member.domain.vo.Identifier; +import co.kirikiri.member.persistence.MemberRepository; import co.kirikiri.todo.domain.GoalRoomToDo; import co.kirikiri.todo.domain.GoalRoomToDoCheck; import co.kirikiri.todo.domain.GoalRoomToDos; diff --git a/backend/kirikiri/src/test/java/co/kirikiri/controller/AuthCreateApiTest.java b/backend/kirikiri/src/test/java/co/kirikiri/auth/controller/AuthCreateApiTest.java similarity index 97% rename from backend/kirikiri/src/test/java/co/kirikiri/controller/AuthCreateApiTest.java rename to backend/kirikiri/src/test/java/co/kirikiri/auth/controller/AuthCreateApiTest.java index dad0e21f3..2cd666391 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/controller/AuthCreateApiTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/auth/controller/AuthCreateApiTest.java @@ -1,4 +1,4 @@ -package co.kirikiri.controller; +package co.kirikiri.auth.controller; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; @@ -12,16 +12,16 @@ import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import co.kirikiri.auth.service.AuthService; +import co.kirikiri.auth.service.NaverOauthService; +import co.kirikiri.auth.service.dto.request.LoginRequest; +import co.kirikiri.auth.service.dto.request.ReissueTokenRequest; +import co.kirikiri.auth.service.dto.response.AuthenticationResponse; +import co.kirikiri.auth.service.dto.response.OauthRedirectResponse; import co.kirikiri.common.exception.AuthenticationException; import co.kirikiri.common.helper.ControllerTestHelper; -import co.kirikiri.common.service.dto.ErrorResponse; import co.kirikiri.common.helper.FieldDescriptionHelper.FieldDescription; -import co.kirikiri.service.auth.AuthService; -import co.kirikiri.service.auth.NaverOauthService; -import co.kirikiri.service.dto.auth.OauthRedirectResponse; -import co.kirikiri.service.dto.auth.request.LoginRequest; -import co.kirikiri.service.dto.auth.request.ReissueTokenRequest; -import co.kirikiri.service.dto.auth.response.AuthenticationResponse; +import co.kirikiri.common.service.dto.ErrorResponse; import com.fasterxml.jackson.core.type.TypeReference; import java.util.List; import org.junit.jupiter.api.Test; diff --git a/backend/kirikiri/src/test/java/co/kirikiri/common/interceptor/AuthInterceptorTest.java b/backend/kirikiri/src/test/java/co/kirikiri/auth/interceptor/AuthInterceptorImplTest.java similarity index 95% rename from backend/kirikiri/src/test/java/co/kirikiri/common/interceptor/AuthInterceptorTest.java rename to backend/kirikiri/src/test/java/co/kirikiri/auth/interceptor/AuthInterceptorImplTest.java index 19ac403e2..4d085dc17 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/common/interceptor/AuthInterceptorTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/auth/interceptor/AuthInterceptorImplTest.java @@ -1,4 +1,4 @@ -package co.kirikiri.common.interceptor; +package co.kirikiri.auth.interceptor; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; @@ -6,8 +6,8 @@ import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.when; +import co.kirikiri.auth.service.AuthService; import co.kirikiri.common.exception.AuthenticationException; -import co.kirikiri.service.auth.AuthService; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -20,7 +20,7 @@ import org.springframework.web.method.HandlerMethod; @ExtendWith(MockitoExtension.class) -class AuthInterceptorTest { +class AuthInterceptorImplTest { private MockHttpServletRequest request; private MockHttpServletResponse response; @@ -32,7 +32,7 @@ class AuthInterceptorTest { private HandlerMethod handlerMethod; @InjectMocks - private AuthInterceptor authInterceptor; + private AuthInterceptorImpl authInterceptor; @BeforeEach void setUp() { diff --git a/backend/kirikiri/src/test/java/co/kirikiri/persistence/auth/RefreshTokenRepositoryTest.java b/backend/kirikiri/src/test/java/co/kirikiri/auth/persistence/RefreshTokenRepositoryTest.java similarity index 87% rename from backend/kirikiri/src/test/java/co/kirikiri/persistence/auth/RefreshTokenRepositoryTest.java rename to backend/kirikiri/src/test/java/co/kirikiri/auth/persistence/RefreshTokenRepositoryTest.java index d31e6d075..dd9190e8f 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/persistence/auth/RefreshTokenRepositoryTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/auth/persistence/RefreshTokenRepositoryTest.java @@ -1,17 +1,16 @@ -package co.kirikiri.persistence.auth; +package co.kirikiri.auth.persistence; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.mockito.Mockito.when; -import co.kirikiri.domain.member.EncryptedPassword; -import co.kirikiri.domain.member.Gender; -import co.kirikiri.domain.member.Member; -import co.kirikiri.domain.member.MemberProfile; -import co.kirikiri.domain.member.vo.Identifier; -import co.kirikiri.domain.member.vo.Nickname; -import co.kirikiri.domain.member.vo.Password; -import java.util.Optional; +import co.kirikiri.member.domain.EncryptedPassword; +import co.kirikiri.member.domain.Gender; +import co.kirikiri.member.domain.Member; +import co.kirikiri.member.domain.MemberProfile; +import co.kirikiri.member.domain.vo.Identifier; +import co.kirikiri.member.domain.vo.Nickname; +import co.kirikiri.member.domain.vo.Password; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -20,6 +19,7 @@ import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.ValueOperations; +import java.util.Optional; @ExtendWith(MockitoExtension.class) class RefreshTokenRepositoryTest { @@ -34,15 +34,7 @@ class RefreshTokenRepositoryTest { @Mock private ValueOperations valueOperations; - private RefreshTokenRepositoryImpl refreshTokenRepository; - - @BeforeEach - void init() { - when(redisTemplate.opsForValue()) - .thenReturn(valueOperations); - refreshTokenRepository = new RefreshTokenRepositoryImpl(redisTemplate, refreshTokenValidityInSeconds); - } - + private RefreshTokenRepository refreshTokenRepository; @BeforeAll static void setUp() { @@ -55,6 +47,13 @@ static void setUp() { member = new Member(identifier, encryptedPassword, nickname, null, memberProfile); } + @BeforeEach + void init() { + when(redisTemplate.opsForValue()) + .thenReturn(valueOperations); + refreshTokenRepository = new RefreshTokenRepositoryImpl(redisTemplate, refreshTokenValidityInSeconds); + } + @Test void 정상적으로_리프레시_토큰을_저장한다() { //given diff --git a/backend/kirikiri/src/test/java/co/kirikiri/common/resolver/MemberIdentifierArgumentResolverTest.java b/backend/kirikiri/src/test/java/co/kirikiri/auth/resolver/MemberIdentifierArgumentResolverImplTest.java similarity index 95% rename from backend/kirikiri/src/test/java/co/kirikiri/common/resolver/MemberIdentifierArgumentResolverTest.java rename to backend/kirikiri/src/test/java/co/kirikiri/auth/resolver/MemberIdentifierArgumentResolverImplTest.java index 5063ba103..633942adc 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/common/resolver/MemberIdentifierArgumentResolverTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/auth/resolver/MemberIdentifierArgumentResolverImplTest.java @@ -1,15 +1,15 @@ -package co.kirikiri.common.resolver; +package co.kirikiri.auth.resolver; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.when; +import co.kirikiri.auth.service.AuthService; import co.kirikiri.common.exception.AuthenticationException; import co.kirikiri.common.exception.ServerException; import co.kirikiri.common.interceptor.Authenticated; -import co.kirikiri.service.auth.AuthService; -import java.util.List; +import co.kirikiri.common.resolver.MemberIdentifier; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; @@ -21,9 +21,10 @@ import org.springframework.web.bind.support.WebDataBinderFactory; import org.springframework.web.context.request.NativeWebRequest; import org.springframework.web.method.support.ModelAndViewContainer; +import java.util.List; @ExtendWith(MockitoExtension.class) -class MemberIdentifierArgumentResolverTest { +class MemberIdentifierArgumentResolverImplTest { private static final String BEARER = "Bearer "; @@ -43,7 +44,7 @@ class MemberIdentifierArgumentResolverTest { private WebDataBinderFactory binderFactory; @InjectMocks - private MemberIdentifierArgumentResolver memberIdentifierArgumentResolver; + private MemberIdentifierArgumentResolverImpl memberIdentifierArgumentResolver; @Test void 정상적으로_String_타입이고_MemberIdentifier이_붙은_인자인_경우() { diff --git a/backend/kirikiri/src/test/java/co/kirikiri/service/AuthServiceTest.java b/backend/kirikiri/src/test/java/co/kirikiri/auth/service/AuthServiceTest.java similarity index 89% rename from backend/kirikiri/src/test/java/co/kirikiri/service/AuthServiceTest.java rename to backend/kirikiri/src/test/java/co/kirikiri/auth/service/AuthServiceTest.java index 8851cbf56..5fb6f8cae 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/service/AuthServiceTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/auth/service/AuthServiceTest.java @@ -1,32 +1,30 @@ -package co.kirikiri.service; +package co.kirikiri.auth.service; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; +import co.kirikiri.auth.persistence.RefreshTokenRepository; +import co.kirikiri.auth.service.dto.request.LoginRequest; +import co.kirikiri.auth.service.dto.request.ReissueTokenRequest; +import co.kirikiri.auth.service.dto.response.AuthenticationResponse; import co.kirikiri.common.exception.AuthenticationException; -import co.kirikiri.domain.member.EncryptedPassword; -import co.kirikiri.domain.member.Gender; -import co.kirikiri.domain.member.Member; -import co.kirikiri.domain.member.MemberProfile; -import co.kirikiri.domain.member.vo.Identifier; -import co.kirikiri.domain.member.vo.Nickname; -import co.kirikiri.domain.member.vo.Password; -import co.kirikiri.persistence.auth.RefreshTokenRepository; -import co.kirikiri.persistence.member.MemberRepository; -import co.kirikiri.service.auth.AuthService; -import co.kirikiri.service.auth.TokenProvider; -import co.kirikiri.service.dto.auth.request.LoginRequest; -import co.kirikiri.service.dto.auth.request.ReissueTokenRequest; -import co.kirikiri.service.dto.auth.response.AuthenticationResponse; -import java.util.Optional; +import co.kirikiri.member.domain.EncryptedPassword; +import co.kirikiri.member.domain.Gender; +import co.kirikiri.member.domain.Member; +import co.kirikiri.member.domain.MemberProfile; +import co.kirikiri.member.domain.vo.Identifier; +import co.kirikiri.member.domain.vo.Nickname; +import co.kirikiri.member.domain.vo.Password; +import co.kirikiri.member.persistence.MemberRepository; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; +import java.util.Optional; @ExtendWith(MockitoExtension.class) class AuthServiceTest { diff --git a/backend/kirikiri/src/test/java/co/kirikiri/service/JwtTokenProviderTest.java b/backend/kirikiri/src/test/java/co/kirikiri/auth/service/JwtTokenProviderTest.java similarity index 97% rename from backend/kirikiri/src/test/java/co/kirikiri/service/JwtTokenProviderTest.java rename to backend/kirikiri/src/test/java/co/kirikiri/auth/service/JwtTokenProviderTest.java index b91457c58..d64a2a8b0 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/service/JwtTokenProviderTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/auth/service/JwtTokenProviderTest.java @@ -1,23 +1,22 @@ -package co.kirikiri.service; +package co.kirikiri.auth.service; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import co.kirikiri.common.exception.AuthenticationException; -import co.kirikiri.service.auth.JwtTokenProvider; -import co.kirikiri.service.auth.TokenProvider; import io.jsonwebtoken.Claims; import io.jsonwebtoken.Jwts; import io.jsonwebtoken.security.Keys; +import org.junit.jupiter.api.Test; import java.time.LocalDateTime; import java.util.HashMap; import java.util.Map; -import org.junit.jupiter.api.Test; class JwtTokenProviderTest { private static final String secretKey = "9zrOjg1kDd2gUp6KBbElGJj5GHP5BnneDs3nXEhdztHAUjKBX7l69JXUErBovPLn7TVWV0UCfejYZyxIjIMC5KPfSvBzo9C1gJ2"; + TokenProvider tokenProvider = new JwtTokenProvider(secretKey, 1_800_000L, 86_400_000L); @Test diff --git a/backend/kirikiri/src/test/java/co/kirikiri/infra/NaverOauthNetworkServiceTest.java b/backend/kirikiri/src/test/java/co/kirikiri/auth/service/NaverOauthNetworkServiceTest.java similarity index 90% rename from backend/kirikiri/src/test/java/co/kirikiri/infra/NaverOauthNetworkServiceTest.java rename to backend/kirikiri/src/test/java/co/kirikiri/auth/service/NaverOauthNetworkServiceTest.java index bdcfe98c2..34352b613 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/infra/NaverOauthNetworkServiceTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/auth/service/NaverOauthNetworkServiceTest.java @@ -1,15 +1,12 @@ -package co.kirikiri.infra; +package co.kirikiri.auth.service; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.ArgumentMatchers.*; import static org.mockito.Mockito.when; -import co.kirikiri.service.dto.auth.NaverOauthTokenDto; -import co.kirikiri.service.dto.auth.response.AuthenticationResponse; -import java.util.Map; -import java.util.Optional; +import co.kirikiri.auth.infra.NaverOauthNetworkService; +import co.kirikiri.auth.service.dto.NaverOauthTokenDto; +import co.kirikiri.auth.service.dto.response.AuthenticationResponse; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; @@ -19,6 +16,8 @@ import org.springframework.http.HttpHeaders; import org.springframework.http.ResponseEntity; import org.springframework.web.client.RestTemplate; +import java.util.Map; +import java.util.Optional; @ExtendWith(MockitoExtension.class) class NaverOauthNetworkServiceTest { diff --git a/backend/kirikiri/src/test/java/co/kirikiri/service/NaverOauthServiceTest.java b/backend/kirikiri/src/test/java/co/kirikiri/auth/service/NaverOauthServiceTest.java similarity index 83% rename from backend/kirikiri/src/test/java/co/kirikiri/service/NaverOauthServiceTest.java rename to backend/kirikiri/src/test/java/co/kirikiri/auth/service/NaverOauthServiceTest.java index 2b0a06491..e1f021d8f 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/service/NaverOauthServiceTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/auth/service/NaverOauthServiceTest.java @@ -1,20 +1,22 @@ -package co.kirikiri.service; +package co.kirikiri.auth.service; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.when; -import co.kirikiri.domain.member.Member; -import co.kirikiri.persistence.member.MemberRepository; -import co.kirikiri.service.auth.AuthService; -import co.kirikiri.service.auth.NaverOauthService; -import co.kirikiri.service.dto.auth.NaverMemberProfileDto; -import co.kirikiri.service.dto.auth.NaverMemberProfileResponseDto; -import co.kirikiri.service.dto.auth.NaverOauthTokenDto; -import co.kirikiri.service.dto.auth.OauthRedirectResponse; -import co.kirikiri.service.dto.auth.response.AuthenticationResponse; -import co.kirikiri.service.member.MemberService; +import co.kirikiri.auth.service.dto.NaverMemberProfileDto; +import co.kirikiri.auth.service.dto.NaverMemberProfileResponseDto; +import co.kirikiri.auth.service.dto.NaverOauthTokenDto; +import co.kirikiri.auth.service.dto.response.AuthenticationResponse; +import co.kirikiri.auth.service.dto.response.OauthRedirectResponse; +import co.kirikiri.member.domain.Gender; +import co.kirikiri.member.domain.Member; +import co.kirikiri.member.domain.MemberProfile; +import co.kirikiri.member.domain.vo.Identifier; +import co.kirikiri.member.domain.vo.Nickname; +import co.kirikiri.member.persistence.MemberRepository; +import co.kirikiri.member.service.MemberService; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; @@ -112,8 +114,14 @@ class NaverOauthServiceTest { when(memberRepository.findByOauthId(anyString())) .thenReturn(Optional.empty()); - final AuthenticationResponse authenticationResponse = new AuthenticationResponse("refreshToken", "accessToken"); + final MemberProfile memberProfile = new MemberProfile(Gender.MALE, naverMemberProfileResponseDto.email()); + final Member member = new Member(new Identifier("identifier"), naverMemberProfileResponseDto.id(), + new Nickname(naverMemberProfileResponseDto.nickname()), null, memberProfile); when(memberService.oauthJoin(any())) + .thenReturn(member); + + final AuthenticationResponse authenticationResponse = new AuthenticationResponse("refreshToken", "accessToken"); + when(authService.oauthLogin(member)) .thenReturn(authenticationResponse); //when diff --git a/backend/kirikiri/src/test/java/co/kirikiri/checkfeed/persistence/CheckFeedRepositoryTest.java b/backend/kirikiri/src/test/java/co/kirikiri/checkfeed/persistence/CheckFeedRepositoryTest.java index 60ec4012f..48f2eb854 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/checkfeed/persistence/CheckFeedRepositoryTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/checkfeed/persistence/CheckFeedRepositoryTest.java @@ -6,23 +6,6 @@ import co.kirikiri.checkfeed.domain.CheckFeed; import co.kirikiri.common.helper.RepositoryTest; import co.kirikiri.common.type.ImageContentType; -import co.kirikiri.domain.member.EncryptedPassword; -import co.kirikiri.domain.member.Gender; -import co.kirikiri.domain.member.Member; -import co.kirikiri.domain.member.MemberImage; -import co.kirikiri.domain.member.MemberProfile; -import co.kirikiri.domain.member.vo.Identifier; -import co.kirikiri.domain.member.vo.Nickname; -import co.kirikiri.domain.member.vo.Password; -import co.kirikiri.domain.roadmap.Roadmap; -import co.kirikiri.domain.roadmap.RoadmapCategory; -import co.kirikiri.domain.roadmap.RoadmapContent; -import co.kirikiri.domain.roadmap.RoadmapContents; -import co.kirikiri.domain.roadmap.RoadmapDifficulty; -import co.kirikiri.domain.roadmap.RoadmapNode; -import co.kirikiri.domain.roadmap.RoadmapNodeImage; -import co.kirikiri.domain.roadmap.RoadmapNodeImages; -import co.kirikiri.domain.roadmap.RoadmapNodes; import co.kirikiri.goalroom.domain.GoalRoom; import co.kirikiri.goalroom.domain.GoalRoomMember; import co.kirikiri.goalroom.domain.GoalRoomRoadmapNode; @@ -33,13 +16,32 @@ import co.kirikiri.goalroom.domain.vo.Period; import co.kirikiri.goalroom.persistence.GoalRoomMemberRepository; import co.kirikiri.goalroom.persistence.GoalRoomRepository; -import co.kirikiri.persistence.member.MemberRepository; -import co.kirikiri.persistence.roadmap.RoadmapCategoryRepository; -import co.kirikiri.persistence.roadmap.RoadmapRepository; +import co.kirikiri.member.domain.EncryptedPassword; +import co.kirikiri.member.domain.Gender; +import co.kirikiri.member.domain.Member; +import co.kirikiri.member.domain.MemberImage; +import co.kirikiri.member.domain.MemberProfile; +import co.kirikiri.member.domain.vo.Identifier; +import co.kirikiri.member.domain.vo.Nickname; +import co.kirikiri.member.domain.vo.Password; +import co.kirikiri.member.persistence.MemberRepository; +import co.kirikiri.roadmap.domain.Roadmap; +import co.kirikiri.roadmap.domain.RoadmapCategory; +import co.kirikiri.roadmap.domain.RoadmapContent; +import co.kirikiri.roadmap.domain.RoadmapDifficulty; +import co.kirikiri.roadmap.domain.RoadmapNode; +import co.kirikiri.roadmap.domain.RoadmapNodeImage; +import co.kirikiri.roadmap.domain.RoadmapNodeImages; +import co.kirikiri.roadmap.domain.RoadmapNodes; +import co.kirikiri.roadmap.domain.RoadmapTags; +import co.kirikiri.roadmap.persistence.RoadmapCategoryRepository; +import co.kirikiri.roadmap.persistence.RoadmapContentRepository; +import co.kirikiri.roadmap.persistence.RoadmapRepository; +import org.junit.jupiter.api.Test; import java.time.LocalDate; import java.time.LocalDateTime; +import java.util.ArrayList; import java.util.List; -import org.junit.jupiter.api.Test; @RepositoryTest class CheckFeedRepositoryTest { @@ -55,6 +57,7 @@ class CheckFeedRepositoryTest { private final MemberRepository memberRepository; private final RoadmapCategoryRepository roadmapCategoryRepository; private final RoadmapRepository roadmapRepository; + private final RoadmapContentRepository roadmapContentRepository; private final GoalRoomRepository goalRoomRepository; private final GoalRoomMemberRepository goalRoomMemberRepository; private final CheckFeedRepository checkFeedRepository; @@ -62,12 +65,14 @@ class CheckFeedRepositoryTest { public CheckFeedRepositoryTest(final MemberRepository memberRepository, final RoadmapCategoryRepository roadmapCategoryRepository, final RoadmapRepository roadmapRepository, + final RoadmapContentRepository roadmapContentRepository, final GoalRoomRepository goalRoomRepository, final GoalRoomMemberRepository goalRoomMemberRepository, final CheckFeedRepository checkFeedRepository) { this.memberRepository = memberRepository; this.roadmapCategoryRepository = roadmapCategoryRepository; this.roadmapRepository = roadmapRepository; + this.roadmapContentRepository = roadmapContentRepository; this.goalRoomRepository = goalRoomRepository; this.goalRoomMemberRepository = goalRoomMemberRepository; this.checkFeedRepository = checkFeedRepository; @@ -77,13 +82,11 @@ public CheckFeedRepositoryTest(final MemberRepository memberRepository, void 사용자가_해당_골룸에서_오늘_올린_피드의_존재유무를_확인한다() { //given final Member creator = 사용자를_저장한다("cokiri", "코끼리"); - final RoadmapCategory category = 카테고리를_저장한다("여가"); - final Roadmap roadmap = 로드맵을_저장한다(creator, category); - - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); final Member member = 사용자를_저장한다("participant", "참여자"); - final GoalRoom goalRoom = 골룸을_저장한다(targetRoadmapContent, member); + final RoadmapCategory category = 카테고리를_생성한다("여행"); + final Roadmap roadmap = 로드맵을_저장한다("title", creator, category); + final RoadmapContent roadmapContent = 로드맵_본문을_저장한다(roadmap.getId()); + final GoalRoom goalRoom = 골룸을_저장한다(roadmapContent, creator); final GoalRoomMember leader = new GoalRoomMember(GoalRoomRole.LEADER, LocalDateTime.now(), goalRoom, creator.getId()); @@ -113,13 +116,11 @@ public CheckFeedRepositoryTest(final MemberRepository memberRepository, void 사용자가_현재_진행중인_노드에서_인증한_횟수를_확인한다() { //given final Member creator = 사용자를_저장한다("cokiri", "코끼리"); - final RoadmapCategory category = 카테고리를_저장한다("여가"); - final Roadmap roadmap = 로드맵을_저장한다(creator, category); - - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); final Member member = 사용자를_저장한다("participant", "참여자"); - final GoalRoom goalRoom = 골룸을_저장한다(targetRoadmapContent, member); + final RoadmapCategory category = 카테고리를_생성한다("여행"); + final Roadmap roadmap = 로드맵을_저장한다("title", creator, category); + final RoadmapContent roadmapContent = 로드맵_본문을_저장한다(roadmap.getId()); + final GoalRoom goalRoom = 골룸을_저장한다(roadmapContent, creator); final GoalRoomMember leader = new GoalRoomMember(GoalRoomRole.LEADER, LocalDateTime.now(), goalRoom, creator.getId()); @@ -146,14 +147,12 @@ public CheckFeedRepositoryTest(final MemberRepository memberRepository, void 특정_골룸에서_등록된_모든_인증_피드들을_조회한다() { //given final Member creator = 사용자를_저장한다("cokiri", "코끼리"); - final RoadmapCategory category = 카테고리를_저장한다("여가"); - final Roadmap roadmap = 로드맵을_저장한다(creator, category); - - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); final Member member = 사용자를_저장한다("participant", "참여자"); - final GoalRoom goalRoom1 = 골룸을_저장한다(targetRoadmapContent, creator); - final GoalRoom goalRoom2 = 골룸을_저장한다(targetRoadmapContent, creator); + final RoadmapCategory category = 카테고리를_생성한다("여행"); + final Roadmap roadmap = 로드맵을_저장한다("title", creator, category); + final RoadmapContent roadmapContent = 로드맵_본문을_저장한다(roadmap.getId()); + final GoalRoom goalRoom1 = 골룸을_저장한다(roadmapContent, creator); + final GoalRoom goalRoom2 = 골룸을_저장한다(roadmapContent, creator); final GoalRoomMember leader = new GoalRoomMember(GoalRoomRole.LEADER, LocalDateTime.now(), goalRoom1, creator.getId()); @@ -190,13 +189,11 @@ public CheckFeedRepositoryTest(final MemberRepository memberRepository, void 골룸이_완료됐을_때는_특정한_노드_동안이_아닌_모든_기간_동안_등록된_인증_피드들을_조회한다() { //given final Member creator = 사용자를_저장한다("cokiri", "코끼리"); - final RoadmapCategory category = 카테고리를_저장한다("여가"); - final Roadmap roadmap = 로드맵을_저장한다(creator, category); - - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); final Member member = 사용자를_저장한다("participant", "참여자"); - final GoalRoom goalRoom = 골룸을_저장한다(targetRoadmapContent, member); + final RoadmapCategory category = 카테고리를_생성한다("여행"); + final Roadmap roadmap = 로드맵을_저장한다("title", creator, category); + final RoadmapContent roadmapContent = 로드맵_본문을_저장한다(roadmap.getId()); + final GoalRoom goalRoom = 골룸을_저장한다(roadmapContent, creator); final GoalRoomMember leader = new GoalRoomMember(GoalRoomRole.LEADER, LocalDateTime.now(), goalRoom, creator.getId()); @@ -227,13 +224,11 @@ public CheckFeedRepositoryTest(final MemberRepository memberRepository, void 골룸이_진행중일_때_특정_노드_동안_등록된_인증_피드들을_조회한다() { //given final Member creator = 사용자를_저장한다("cokiri", "코끼리"); - final RoadmapCategory category = 카테고리를_저장한다("여가"); - final Roadmap roadmap = 로드맵을_저장한다(creator, category); - - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); final Member member = 사용자를_저장한다("participant", "참여자"); - final GoalRoom goalRoom = 골룸을_저장한다(targetRoadmapContent, member); + final RoadmapCategory category = 카테고리를_생성한다("여행"); + final Roadmap roadmap = 로드맵을_저장한다("title", creator, category); + final RoadmapContent roadmapContent = 로드맵_본문을_저장한다(roadmap.getId()); + final GoalRoom goalRoom = 골룸을_저장한다(roadmapContent, creator); final GoalRoomMember leader = new GoalRoomMember(GoalRoomRole.LEADER, LocalDateTime.now(), goalRoom, creator.getId()); @@ -272,13 +267,11 @@ public CheckFeedRepositoryTest(final MemberRepository memberRepository, void 진행중인_골룸에서_특정_노드_기간이_아니면_빈_인증_피드들_반환한다() { //given final Member creator = 사용자를_저장한다("cokiri", "코끼리"); - final RoadmapCategory category = 카테고리를_저장한다("여가"); - final Roadmap roadmap = 로드맵을_저장한다(creator, category); - - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); final Member member = 사용자를_저장한다("participant", "참여자"); - final GoalRoom goalRoom = 골룸을_저장한다(targetRoadmapContent, member); + final RoadmapCategory category = 카테고리를_생성한다("여행"); + final Roadmap roadmap = 로드맵을_저장한다("title", creator, category); + final RoadmapContent roadmapContent = 로드맵_본문을_저장한다(roadmap.getId()); + final GoalRoom goalRoom = 골룸을_저장한다(roadmapContent, creator); final GoalRoomMember leader = new GoalRoomMember(GoalRoomRole.LEADER, LocalDateTime.now(), goalRoom, creator.getId()); @@ -322,19 +315,22 @@ public CheckFeedRepositoryTest(final MemberRepository memberRepository, return memberRepository.save(creator); } - private RoadmapCategory 카테고리를_저장한다(final String name) { + private RoadmapCategory 카테고리를_생성한다(final String name) { final RoadmapCategory roadmapCategory = new RoadmapCategory(name); return roadmapCategoryRepository.save(roadmapCategory); } - private Roadmap 로드맵을_저장한다(final Member creator, final RoadmapCategory category) { - final List roadmapNodes = 로드맵_노드들을_생성한다(); - final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmapNodes); - final Roadmap roadmap = new Roadmap("로드맵 제목", "로드맵 소개글", 10, RoadmapDifficulty.NORMAL, creator, category); - roadmap.addContent(roadmapContent); + private Roadmap 로드맵을_저장한다(final String title, final Member creator, final RoadmapCategory category) { + final Roadmap roadmap = new Roadmap(title, "로드맵 소개글", 10, RoadmapDifficulty.NORMAL, creator.getId(), category, new RoadmapTags(new ArrayList<>())); return roadmapRepository.save(roadmap); } + private RoadmapContent 로드맵_본문을_저장한다(final Long roadmapId) { + final List roadmapNodes = 로드맵_노드들을_생성한다(); + final RoadmapContent roadmapContent = new RoadmapContent("로드맵 본문", roadmapId, new RoadmapNodes(roadmapNodes)); + return roadmapContentRepository.save(roadmapContent); + } + private List 로드맵_노드들을_생성한다() { final RoadmapNode roadmapNode1 = new RoadmapNode("로드맵 1주차", "로드맵 1주차 내용"); roadmapNode1.addImages(new RoadmapNodeImages(노드_이미지들을_생성한다())); @@ -342,12 +338,6 @@ public CheckFeedRepositoryTest(final MemberRepository memberRepository, return List.of(roadmapNode1, roadmapNode2); } - private RoadmapContent 로드맵_본문을_생성한다(final List roadmapNodes) { - final RoadmapContent roadmapContent = new RoadmapContent("로드맵 본문"); - roadmapContent.addNodes(new RoadmapNodes(roadmapNodes)); - return roadmapContent; - } - private List 노드_이미지들을_생성한다() { return List.of( new RoadmapNodeImage("node-image1.png", "node-image1-save-path", ImageContentType.PNG), diff --git a/backend/kirikiri/src/test/java/co/kirikiri/checkfeed/service/CheckFeedCreateEventListenerTest.java b/backend/kirikiri/src/test/java/co/kirikiri/checkfeed/service/CheckFeedCreateEventListenerTest.java index 320bc2d6a..457020469 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/checkfeed/service/CheckFeedCreateEventListenerTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/checkfeed/service/CheckFeedCreateEventListenerTest.java @@ -10,13 +10,6 @@ import co.kirikiri.checkfeed.service.event.CheckFeedCreateEvent; import co.kirikiri.common.exception.NotFoundException; import co.kirikiri.common.type.ImageContentType; -import co.kirikiri.domain.member.EncryptedPassword; -import co.kirikiri.domain.member.Gender; -import co.kirikiri.domain.member.Member; -import co.kirikiri.domain.member.MemberProfile; -import co.kirikiri.domain.member.vo.Identifier; -import co.kirikiri.domain.member.vo.Nickname; -import co.kirikiri.domain.member.vo.Password; import co.kirikiri.goalroom.domain.GoalRoom; import co.kirikiri.goalroom.domain.GoalRoomMember; import co.kirikiri.goalroom.domain.GoalRoomRoadmapNode; @@ -27,6 +20,13 @@ import co.kirikiri.goalroom.domain.vo.Period; import co.kirikiri.goalroom.persistence.GoalRoomMemberRepository; import co.kirikiri.goalroom.persistence.GoalRoomRepository; +import co.kirikiri.member.domain.EncryptedPassword; +import co.kirikiri.member.domain.Gender; +import co.kirikiri.member.domain.Member; +import co.kirikiri.member.domain.MemberProfile; +import co.kirikiri.member.domain.vo.Identifier; +import co.kirikiri.member.domain.vo.Nickname; +import co.kirikiri.member.domain.vo.Password; import java.time.LocalDate; import java.time.LocalDateTime; import java.util.List; diff --git a/backend/kirikiri/src/test/java/co/kirikiri/checkfeed/service/GoalRoomCheckFeedServiceTest.java b/backend/kirikiri/src/test/java/co/kirikiri/checkfeed/service/GoalRoomCheckFeedServiceTest.java index 39a7fddd9..598f141b1 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/checkfeed/service/GoalRoomCheckFeedServiceTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/checkfeed/service/GoalRoomCheckFeedServiceTest.java @@ -16,28 +16,11 @@ import co.kirikiri.checkfeed.service.dto.response.GoalRoomCheckFeedResponse; import co.kirikiri.common.exception.BadRequestException; import co.kirikiri.common.exception.ForbiddenException; -import co.kirikiri.common.exception.ImageExtensionException; import co.kirikiri.common.exception.NotFoundException; +import co.kirikiri.common.exception.domain.ImageExtensionException; import co.kirikiri.common.service.FilePathGenerator; import co.kirikiri.common.service.FileService; import co.kirikiri.common.type.ImageContentType; -import co.kirikiri.domain.member.EncryptedPassword; -import co.kirikiri.domain.member.Gender; -import co.kirikiri.domain.member.Member; -import co.kirikiri.domain.member.MemberImage; -import co.kirikiri.domain.member.MemberProfile; -import co.kirikiri.domain.member.vo.Identifier; -import co.kirikiri.domain.member.vo.Nickname; -import co.kirikiri.domain.member.vo.Password; -import co.kirikiri.domain.roadmap.Roadmap; -import co.kirikiri.domain.roadmap.RoadmapCategory; -import co.kirikiri.domain.roadmap.RoadmapContent; -import co.kirikiri.domain.roadmap.RoadmapContents; -import co.kirikiri.domain.roadmap.RoadmapDifficulty; -import co.kirikiri.domain.roadmap.RoadmapNode; -import co.kirikiri.domain.roadmap.RoadmapNodeImage; -import co.kirikiri.domain.roadmap.RoadmapNodeImages; -import co.kirikiri.domain.roadmap.RoadmapNodes; import co.kirikiri.goalroom.domain.GoalRoom; import co.kirikiri.goalroom.domain.GoalRoomMember; import co.kirikiri.goalroom.domain.GoalRoomRoadmapNode; @@ -48,7 +31,23 @@ import co.kirikiri.goalroom.domain.vo.Period; import co.kirikiri.goalroom.persistence.GoalRoomMemberRepository; import co.kirikiri.goalroom.persistence.GoalRoomRepository; -import co.kirikiri.persistence.member.MemberRepository; +import co.kirikiri.member.domain.EncryptedPassword; +import co.kirikiri.member.domain.Gender; +import co.kirikiri.member.domain.Member; +import co.kirikiri.member.domain.MemberImage; +import co.kirikiri.member.domain.MemberProfile; +import co.kirikiri.member.domain.vo.Identifier; +import co.kirikiri.member.domain.vo.Nickname; +import co.kirikiri.member.domain.vo.Password; +import co.kirikiri.member.persistence.MemberRepository; +import co.kirikiri.roadmap.domain.Roadmap; +import co.kirikiri.roadmap.domain.RoadmapCategory; +import co.kirikiri.roadmap.domain.RoadmapContent; +import co.kirikiri.roadmap.domain.RoadmapDifficulty; +import co.kirikiri.roadmap.domain.RoadmapNode; +import co.kirikiri.roadmap.domain.RoadmapNodeImage; +import co.kirikiri.roadmap.domain.RoadmapNodeImages; +import co.kirikiri.roadmap.domain.RoadmapNodes; import java.net.MalformedURLException; import java.net.URL; import java.time.LocalDate; @@ -102,11 +101,11 @@ class GoalRoomCheckFeedServiceTest { final CheckFeedRequest request = 인증_피드_요청_DTO를_생성한다("image/jpeg"); final Member creator = 사용자를_생성한다(1L, "cokirikiri", "password1!", "코끼리", "kirikiri1@email"); + final List roadmapNodes = 로드맵_노드들을_생성한다(); final Roadmap roadmap = 로드맵을_생성한다(creator); + final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmap.getId(), roadmapNodes); - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); - final GoalRoom goalRoom = 골룸을_생성한다(1L, creator, targetRoadmapContent, 20); + final GoalRoom goalRoom = 골룸을_생성한다(1L, creator, roadmapContent, 20); final GoalRoomMember goalRoomLeader = new GoalRoomMember(GoalRoomRole.LEADER, LocalDateTime.now(), goalRoom, creator.getId()); goalRoomMemberRepository.save(goalRoomLeader); @@ -143,11 +142,11 @@ class GoalRoomCheckFeedServiceTest { final CheckFeedRequest request = 인증_피드_요청_DTO를_생성한다("image/jpeg"); final Member creator = 사용자를_생성한다(1L, "cokirikiri", "password1!", "코끼리", "kirikiri1@email"); + final List roadmapNodes = 로드맵_노드들을_생성한다(); final Roadmap roadmap = 로드맵을_생성한다(creator); + final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmap.getId(), roadmapNodes); - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); - final GoalRoom goalRoom = 시작_날짜가_미래인_골룸을_생성한다(1L, creator, targetRoadmapContent, 20); + final GoalRoom goalRoom = 시작_날짜가_미래인_골룸을_생성한다(1L, creator, roadmapContent, 20); final GoalRoomMember goalRoomLeader = new GoalRoomMember(GoalRoomRole.LEADER, LocalDateTime.now(), goalRoom, creator.getId()); goalRoomMemberRepository.save(goalRoomLeader); @@ -172,11 +171,11 @@ class GoalRoomCheckFeedServiceTest { final CheckFeedRequest request = 인증_피드_요청_DTO를_생성한다("image/jpeg"); final Member creator = 사용자를_생성한다(1L, "cokirikiri", "password1!", "코끼리", "kirikiri1@email"); + final List roadmapNodes = 로드맵_노드들을_생성한다(); final Roadmap roadmap = 로드맵을_생성한다(creator); + final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmap.getId(), roadmapNodes); - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); - final GoalRoom goalRoom = 골룸을_생성한다(1L, creator, targetRoadmapContent, 20); + final GoalRoom goalRoom = 골룸을_생성한다(1L, creator, roadmapContent, 20); final GoalRoomMember goalRoomLeader = new GoalRoomMember(GoalRoomRole.LEADER, LocalDateTime.now(), goalRoom, creator.getId()); goalRoomMemberRepository.save(goalRoomLeader); @@ -205,11 +204,11 @@ class GoalRoomCheckFeedServiceTest { final CheckFeedRequest request = 인증_피드_요청_DTO를_생성한다("image/jpeg"); final Member creator = 사용자를_생성한다(1L, "cokirikiri", "password1!", "코끼리", "kirikiri1@email"); + final List roadmapNodes = 로드맵_노드들을_생성한다(); final Roadmap roadmap = 로드맵을_생성한다(creator); + final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmap.getId(), roadmapNodes); - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); - final GoalRoom goalRoom = 골룸을_생성한다(1L, creator, targetRoadmapContent, 20); + final GoalRoom goalRoom = 골룸을_생성한다(1L, creator, roadmapContent, 20); final GoalRoomMember goalRoomLeader = new GoalRoomMember(GoalRoomRole.LEADER, LocalDateTime.now(), goalRoom, creator.getId()); goalRoomMemberRepository.save(goalRoomLeader); @@ -237,11 +236,11 @@ class GoalRoomCheckFeedServiceTest { final CheckFeedRequest request = 인증_피드_요청_DTO를_생성한다("image/gif"); final Member creator = 사용자를_생성한다(1L, "cokirikiri", "password1!", "코끼리", "kirikiri1@email"); + final List roadmapNodes = 로드맵_노드들을_생성한다(); final Roadmap roadmap = 로드맵을_생성한다(creator); + final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmap.getId(), roadmapNodes); - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); - final GoalRoom goalRoom = 골룸을_생성한다(1L, creator, targetRoadmapContent, 20); + final GoalRoom goalRoom = 골룸을_생성한다(1L, creator, roadmapContent, 20); final GoalRoomMember goalRoomLeader = new GoalRoomMember(GoalRoomRole.LEADER, LocalDateTime.now(), goalRoom, creator.getId()); goalRoomMemberRepository.save(goalRoomLeader); @@ -267,10 +266,10 @@ class GoalRoomCheckFeedServiceTest { final CheckFeedRequest request = 인증_피드_요청_DTO를_생성한다("image/jpeg"); final Member creator = 사용자를_생성한다(1L, "cokirikiri", "password1!", "코끼리", "kirikiri1@email"); + final List roadmapNodes = 로드맵_노드들을_생성한다(); final Roadmap roadmap = 로드맵을_생성한다(creator); - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); - final GoalRoom goalRoom = 골룸을_생성한다(1L, creator, targetRoadmapContent, 20); + final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmap.getId(), roadmapNodes); + final GoalRoom goalRoom = 골룸을_생성한다(1L, creator, roadmapContent, 20); final GoalRoomMember goalRoomLeader = new GoalRoomMember(GoalRoomRole.LEADER, LocalDateTime.now(), goalRoom, creator.getId()); goalRoomMemberRepository.save(goalRoomLeader); @@ -291,10 +290,10 @@ class GoalRoomCheckFeedServiceTest { final CheckFeedRequest request = 인증_피드_요청_DTO를_생성한다("image/jpeg"); final Member creator = 사용자를_생성한다(1L, "cokirikiri", "password1!", "코끼리", "kirikiri1@email"); + final List roadmapNodes = 로드맵_노드들을_생성한다(); final Roadmap roadmap = 로드맵을_생성한다(creator); - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); - final GoalRoom goalRoom = 골룸을_생성한다(1L, creator, targetRoadmapContent, 20); + final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmap.getId(), roadmapNodes); + final GoalRoom goalRoom = 골룸을_생성한다(1L, creator, roadmapContent, 20); final GoalRoomMember goalRoomLeader = new GoalRoomMember(GoalRoomRole.LEADER, LocalDateTime.now(), goalRoom, creator.getId()); @@ -319,11 +318,11 @@ class GoalRoomCheckFeedServiceTest { // given final Member creator = 사용자를_생성한다(1L, "cokirikiri1", "password1!", "코끼리1", "kirikiri1@email"); final Member follower = 사용자를_생성한다(2L, "cokirikiri2", "password2!", "코끼리2", "kirikiri2@email"); + final List roadmapNodes = 로드맵_노드들을_생성한다(); final Roadmap roadmap = 로드맵을_생성한다(creator); - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); + final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmap.getId(), roadmapNodes); - final GoalRoom goalRoom = 골룸을_생성한다(1L, creator, targetRoadmapContent, 20); + final GoalRoom goalRoom = 골룸을_생성한다(1L, creator, roadmapContent, 20); goalRoom.start(); final GoalRoomMember goalRoomMember1 = new GoalRoomMember(1L, GoalRoomRole.LEADER, LocalDateTime.now(), @@ -384,11 +383,11 @@ class GoalRoomCheckFeedServiceTest { void 모집중인_골룸의_인증피드를_조회시_빈_값을_반환한다() { // given final Member creator = 사용자를_생성한다(1L, "cokirikiri1", "password1!", "코끼리1", "kirikiri1@email"); + final List roadmapNodes = 로드맵_노드들을_생성한다(); final Roadmap roadmap = 로드맵을_생성한다(creator); - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); + final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmap.getId(), roadmapNodes); - final GoalRoom goalRoom = 골룸을_생성한다(1L, creator, targetRoadmapContent, 20); + final GoalRoom goalRoom = 골룸을_생성한다(1L, creator, roadmapContent, 20); final GoalRoomMember goalRoomMember = new GoalRoomMember(GoalRoomRole.LEADER, LocalDateTime.now(), goalRoom, creator.getId()); @@ -414,11 +413,11 @@ class GoalRoomCheckFeedServiceTest { // given final Member creator = 사용자를_생성한다(1L, "cokirikiri1", "password1!", "코끼리1", "kirikiri1@email"); final Member follower = 사용자를_생성한다(2L, "cokirikiri2", "password2!", "코끼리2", "kirikiri2@email"); + final List roadmapNodes = 로드맵_노드들을_생성한다(); final Roadmap roadmap = 로드맵을_생성한다(creator); - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); + final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmap.getId(), roadmapNodes); - final GoalRoom goalRoom = 골룸을_생성한다(1L, creator, targetRoadmapContent, 20); + final GoalRoom goalRoom = 골룸을_생성한다(1L, creator, roadmapContent, 20); goalRoom.complete(); final GoalRoomMember goalRoomMember1 = new GoalRoomMember(1L, GoalRoomRole.LEADER, LocalDateTime.now(), @@ -482,11 +481,11 @@ class GoalRoomCheckFeedServiceTest { // given final Member creator = 사용자를_생성한다(1L, "cokirikiri1", "password1!", "코끼리1", "kirikiri1@email"); final Member follower = 사용자를_생성한다(2L, "cokirikiri2", "password2!", "코끼리2", "kirikiri2@email"); + final List roadmapNodes = 로드맵_노드들을_생성한다(); final Roadmap roadmap = 로드맵을_생성한다(creator); - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); + final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmap.getId(), roadmapNodes); - final GoalRoom goalRoom = 진행중인_노드가_없는_골룸을_생성한다(creator, roadmap.getContents().getValues().get(0)); + final GoalRoom goalRoom = 진행중인_노드가_없는_골룸을_생성한다(creator, roadmapContent); final GoalRoomMember goalRoomMember1 = new GoalRoomMember(GoalRoomRole.LEADER, LocalDateTime.now(), goalRoom, creator.getId()); final GoalRoomMember goalRoomMember2 = new GoalRoomMember(GoalRoomRole.FOLLOWER, LocalDateTime.now(), goalRoom, @@ -528,11 +527,11 @@ class GoalRoomCheckFeedServiceTest { void 골룸의_인증피드를_전체_조회할_때_골룸에_참여하지_않은_회원이면_예외가_발생한다() { // given final Member creator = 사용자를_생성한다(1L, "cokirikiri1", "password1!", "코끼리1", "kirikiri1@email"); + final List roadmapNodes = 로드맵_노드들을_생성한다(); final Roadmap roadmap = 로드맵을_생성한다(creator); - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); + final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmap.getId(), roadmapNodes); - final GoalRoom goalRoom = 골룸을_생성한다(1L, creator, targetRoadmapContent, 20); + final GoalRoom goalRoom = 골룸을_생성한다(1L, creator, roadmapContent, 20); when(goalRoomRepository.findByIdWithNodes(anyLong())) .thenReturn(Optional.of(goalRoom)); @@ -555,23 +554,21 @@ class GoalRoomCheckFeedServiceTest { private Roadmap 로드맵을_생성한다(final Member creator) { final RoadmapCategory category = new RoadmapCategory("게임"); - final List roadmapNodes = 로드맵_노드들을_생성한다(); - final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmapNodes); - final Roadmap roadmap = new Roadmap("로드맵 제목", "로드맵 소개글", 10, RoadmapDifficulty.NORMAL, creator, category); - roadmap.addContent(roadmapContent); + final Roadmap roadmap = new Roadmap("로드맵 제목", "로드맵 소개글", 10, RoadmapDifficulty.NORMAL, creator.getId(), + category, null); return roadmap; } private List 로드맵_노드들을_생성한다() { - final RoadmapNode roadmapNode1 = new RoadmapNode("로드맵 1주차", "로드맵 1주차 내용"); - roadmapNode1.addImages(new RoadmapNodeImages(노드_이미지들을_생성한다())); - final RoadmapNode roadmapNode2 = new RoadmapNode("로드맵 2주차", "로드맵 2주차 내용"); + final RoadmapNode roadmapNode1 = new RoadmapNode(1L, "로드맵 1주차", "로드맵 1주차 내용"); + roadmapNode1.addImages(new RoadmapNodeImages(Collections.emptyList())); + final RoadmapNode roadmapNode2 = new RoadmapNode(2L, "로드맵 2주차", "로드맵 2주차 내용"); return List.of(roadmapNode1, roadmapNode2); } - private RoadmapContent 로드맵_본문을_생성한다(final List roadmapNodes) { - final RoadmapContent roadmapContent = new RoadmapContent("로드맵 본문"); - roadmapContent.addNodes(new RoadmapNodes(roadmapNodes)); + private RoadmapContent 로드맵_본문을_생성한다(final Long roadmapId, final List roadmapNodes) { + final RoadmapContent roadmapContent = new RoadmapContent(1L, "로드맵 본문", roadmapId, + new RoadmapNodes(roadmapNodes)); return roadmapContent; } diff --git a/backend/kirikiri/src/test/java/co/kirikiri/common/helper/ControllerTestHelper.java b/backend/kirikiri/src/test/java/co/kirikiri/common/helper/ControllerTestHelper.java index c5d6046fd..1555732bb 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/common/helper/ControllerTestHelper.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/common/helper/ControllerTestHelper.java @@ -23,7 +23,7 @@ public class ControllerTestHelper extends RestDocsHelper { private MemberIdentifierArgumentResolver memberIdentifierArgumentResolver; @BeforeEach - void setUp() { + void setUp() throws Exception { when(authInterceptor.preHandle(any(), any(), any())) .thenReturn(true); when(memberIdentifierArgumentResolver.resolveArgument(any(), any(), any(), any())) diff --git a/backend/kirikiri/src/test/java/co/kirikiri/common/helper/RepositoryTest.java b/backend/kirikiri/src/test/java/co/kirikiri/common/helper/RepositoryTest.java index aec6345c0..b6c2b84a6 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/common/helper/RepositoryTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/common/helper/RepositoryTest.java @@ -1,13 +1,13 @@ package co.kirikiri.common.helper; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.TestConstructor; import org.springframework.test.context.TestConstructor.AutowireMode; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; @DataJpaTest @ActiveProfiles("test") diff --git a/backend/kirikiri/src/test/java/co/kirikiri/service/CacheKeyGeneratorTest.java b/backend/kirikiri/src/test/java/co/kirikiri/common/service/CacheKeyGeneratorTest.java similarity index 96% rename from backend/kirikiri/src/test/java/co/kirikiri/service/CacheKeyGeneratorTest.java rename to backend/kirikiri/src/test/java/co/kirikiri/common/service/CacheKeyGeneratorTest.java index 08fea3baf..292e07f35 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/service/CacheKeyGeneratorTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/common/service/CacheKeyGeneratorTest.java @@ -1,9 +1,9 @@ -package co.kirikiri.service; +package co.kirikiri.common.service; import static org.assertj.core.api.Assertions.assertThat; -import java.lang.reflect.Method; import org.junit.jupiter.api.Test; +import java.lang.reflect.Method; class CacheKeyGeneratorTest { diff --git a/backend/kirikiri/src/test/java/co/kirikiri/service/UUIDFilePathGeneratorTest.java b/backend/kirikiri/src/test/java/co/kirikiri/common/service/UUIDFilePathGeneratorTest.java similarity index 96% rename from backend/kirikiri/src/test/java/co/kirikiri/service/UUIDFilePathGeneratorTest.java rename to backend/kirikiri/src/test/java/co/kirikiri/common/service/UUIDFilePathGeneratorTest.java index 44e2319f6..03edc31cd 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/service/UUIDFilePathGeneratorTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/common/service/UUIDFilePathGeneratorTest.java @@ -1,10 +1,9 @@ -package co.kirikiri.service; +package co.kirikiri.common.service; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.jupiter.api.Assertions.assertTrue; import co.kirikiri.common.exception.BadRequestException; -import co.kirikiri.common.service.FilePathGenerator; import co.kirikiri.common.type.ImageDirType; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; diff --git a/backend/kirikiri/src/test/java/co/kirikiri/domain/roadmap/RoadmapContentTest.java b/backend/kirikiri/src/test/java/co/kirikiri/domain/roadmap/RoadmapContentTest.java deleted file mode 100644 index 4a663ac40..000000000 --- a/backend/kirikiri/src/test/java/co/kirikiri/domain/roadmap/RoadmapContentTest.java +++ /dev/null @@ -1,89 +0,0 @@ -package co.kirikiri.domain.roadmap; - -import static co.kirikiri.domain.roadmap.RoadmapDifficulty.DIFFICULT; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.jupiter.api.Assertions.assertAll; -import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; - -import co.kirikiri.domain.member.EncryptedPassword; -import co.kirikiri.domain.member.Gender; -import co.kirikiri.domain.member.Member; -import co.kirikiri.domain.member.MemberProfile; -import co.kirikiri.domain.member.vo.Identifier; -import co.kirikiri.domain.member.vo.Nickname; -import co.kirikiri.domain.member.vo.Password; -import co.kirikiri.domain.roadmap.exception.RoadmapException; -import java.util.List; -import org.junit.jupiter.api.Test; - -class RoadmapContentTest { - - @Test - void 로드맵_본문의_길이가_2000보다_크면_예외가_발생한다() { - // given - final String content = "a".repeat(2001); - - // expect - assertThatThrownBy(() -> new RoadmapContent(content)) - .isInstanceOf(RoadmapException.class); - } - - @Test - void 로드맵_본문은_null값을_허용한다() { - // given - final String content = null; - - // expect - assertDoesNotThrow(() -> new RoadmapContent(content)); - } - - @Test - void 로드맵_본문에_노드들을_추가한다() { - // given - final RoadmapContent content = new RoadmapContent("content"); - - // when - content.addNodes( - new RoadmapNodes( - List.of(new RoadmapNode("title1", "content1"), new RoadmapNode("title2", "content1")))); - - // then - final RoadmapNodes nodes = content.getNodes(); - assertAll( - () -> assertThat(nodes.getValues()).hasSize(2), - () -> assertThat(nodes.getValues().get(0).getRoadmapContent()).isEqualTo(content), - () -> assertThat(nodes.getValues().get(1).getRoadmapContent()).isEqualTo(content) - ); - } - - @Test - void 로드맵_본문에_노드를_추가할때_이름이_겹치면_예외를_던진다() { - // given - final RoadmapContent content = new RoadmapContent("content"); - - // when - // then - final String title = "title"; - assertThatThrownBy(() -> content.addNodes( - new RoadmapNodes( - List.of(new RoadmapNode(title, "content1"), new RoadmapNode(title, "content1"))))); - } - - @Test - void 로드맵_본문의_로드맵인_경우_false를_반환한다() { - // given - final RoadmapContent content = new RoadmapContent("content"); - final MemberProfile profile = new MemberProfile(Gender.FEMALE, "kirikiri1@email.com"); - final Member creator = new Member(new Identifier("creator"), - new EncryptedPassword(new Password("password1")), new Nickname("nickname"), null, profile); - final RoadmapCategory category = new RoadmapCategory(1L, "여가"); - final Roadmap roadmap = new Roadmap("로드맵 제목", "로드맵 소개글", 30, DIFFICULT, creator, category); - - // when - roadmap.addContent(content); - - // then - assertThat(content.isNotSameRoadmap(roadmap)).isFalse(); - } -} diff --git a/backend/kirikiri/src/test/java/co/kirikiri/domain/roadmap/RoadmapContentsTest.java b/backend/kirikiri/src/test/java/co/kirikiri/domain/roadmap/RoadmapContentsTest.java deleted file mode 100644 index a9e9113f9..000000000 --- a/backend/kirikiri/src/test/java/co/kirikiri/domain/roadmap/RoadmapContentsTest.java +++ /dev/null @@ -1,27 +0,0 @@ -package co.kirikiri.domain.roadmap; - -import static org.assertj.core.api.Assertions.assertThat; - -import org.junit.jupiter.api.Test; -import java.util.List; - -class RoadmapContentsTest { - - @Test - void 로드맵_본문을_추가한다() { - // given - final RoadmapNodes roadmapNodes = new RoadmapNodes(List.of(new RoadmapNode("로드맵 노드 제목", "로드맵 노드 내용"))); - final RoadmapContent roadmapContent = new RoadmapContent("로드맵 본문"); - roadmapContent.addNodes(roadmapNodes); - final RoadmapContents roadmapContents = new RoadmapContents(List.of(roadmapContent)); - final RoadmapContent updatedRoadmapContent = new RoadmapContent("로드맵 본문 수정본"); - updatedRoadmapContent.addNodes(roadmapNodes); - - // when - roadmapContents.add(updatedRoadmapContent); - - // then - assertThat(roadmapContents.getValues()).usingRecursiveComparison() - .isEqualTo(List.of(roadmapContent, updatedRoadmapContent)); - } -} diff --git a/backend/kirikiri/src/test/java/co/kirikiri/domain/roadmap/RoadmapNodesTest.java b/backend/kirikiri/src/test/java/co/kirikiri/domain/roadmap/RoadmapNodesTest.java deleted file mode 100644 index e8c06eecc..000000000 --- a/backend/kirikiri/src/test/java/co/kirikiri/domain/roadmap/RoadmapNodesTest.java +++ /dev/null @@ -1,41 +0,0 @@ -package co.kirikiri.domain.roadmap; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertAll; - -import org.junit.jupiter.api.Test; -import java.util.List; - -class RoadmapNodesTest { - - @Test - void 로드맵_노드를_추가한다() { - // given - final RoadmapNodes roadmapNodes = new RoadmapNodes(List.of(new RoadmapNode("로드맵 노드 제목1", "로드맵 노드 내용"))); - - // when - roadmapNodes.add(new RoadmapNode("로드맵 노드 제목2", "로드맵 노드 내용")); - - // then - assertThat(roadmapNodes.getValues()).hasSize(2); - } - - @Test - void 로드맵_노드들의_로드맵_본문을_업데이트한다() { - // given - final RoadmapNodes roadmapNodes = new RoadmapNodes( - List.of(new RoadmapNode("로드맵 노드 제목1", "로드맵 노드 내용1"), new RoadmapNode("로드맵 노드 제목2", "로드맵 노드 내용2"))); - final RoadmapContent roadmapContent = new RoadmapContent("로드맵 본문"); - - // when - roadmapNodes.updateAllRoadmapContent(roadmapContent); - - // then - final List nodes = roadmapNodes.getValues(); - assertAll( - () -> assertThat(nodes.get(0).getRoadmapContent()).isEqualTo(roadmapContent), - () -> assertThat(nodes.get(1).getRoadmapContent()).isEqualTo(roadmapContent) - ); - } - -} diff --git a/backend/kirikiri/src/test/java/co/kirikiri/domain/roadmap/RoadmapTest.java b/backend/kirikiri/src/test/java/co/kirikiri/domain/roadmap/RoadmapTest.java deleted file mode 100644 index cea624848..000000000 --- a/backend/kirikiri/src/test/java/co/kirikiri/domain/roadmap/RoadmapTest.java +++ /dev/null @@ -1,99 +0,0 @@ -package co.kirikiri.domain.roadmap; - -import static co.kirikiri.domain.roadmap.RoadmapDifficulty.DIFFICULT; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; - -import co.kirikiri.domain.member.EncryptedPassword; -import co.kirikiri.domain.member.Gender; -import co.kirikiri.domain.member.Member; -import co.kirikiri.domain.member.MemberProfile; -import co.kirikiri.domain.member.vo.Identifier; -import co.kirikiri.domain.member.vo.Nickname; -import co.kirikiri.domain.member.vo.Password; -import co.kirikiri.domain.roadmap.exception.RoadmapException; -import java.util.List; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.ValueSource; - -class RoadmapTest { - - private final Member creator = 크리에이터를_생성한다(); - private final RoadmapCategory category = 카테고리를_생성한다(); - private final List roadmapNodes = 로드맵_노드들을_생성한다(); - private final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmapNodes); - - @Test - void 로드맵이_성공적으로_생성된다() { - // expect - assertDoesNotThrow(() -> new Roadmap("로드맵 제목", "로드맵 소개글", 30, DIFFICULT, - creator, category)); - } - - @Test - void 로드맵에_본문을_추가한다() { - // given - final Roadmap roadmap = new Roadmap("로드맵 제목", "로드맵 소개글", 30, DIFFICULT, creator, category); - - // when - roadmap.addContent(roadmapContent); - - // then - final RoadmapContents contents = roadmap.getContents(); - assertThat(contents.getValues()).hasSize(1); - } - - @ParameterizedTest - @ValueSource(ints = {0, 41}) - void 로드맵_제목의_길이가_1보다_작거나_40보다_크면_예외가_발생한다(final int titleLength) { - // given - final String title = "a".repeat(titleLength); - - // expect - assertThatThrownBy(() -> new Roadmap(title, "로드맵 소개글", 30, DIFFICULT, creator, category)) - .isInstanceOf(RoadmapException.class); - } - - @ParameterizedTest - @ValueSource(ints = {0, 151}) - void 로드맵_소개글의_길이가_1보다_작거나_150보다_크면_예외가_발생한다(final int introductionLength) { - // given - final String introduction = "a".repeat(introductionLength); - - // expect - assertThatThrownBy(() -> new Roadmap("로드맵 제목", introduction, 30, DIFFICULT, creator, category)) - .isInstanceOf(RoadmapException.class); - } - - @ParameterizedTest - @ValueSource(ints = {-1, 1001}) - void 로드맵_추천_소요_기간이_0보다_작고_1000보다_크면_예외가_발생한다(final int requiredPeriod) { - // expect - assertThatThrownBy(() -> new Roadmap("로드맵 제목", "로드맵 소개글", requiredPeriod, DIFFICULT, creator, category)) - .isInstanceOf(RoadmapException.class); - } - - private Member 크리에이터를_생성한다() { - final MemberProfile profile = new MemberProfile(Gender.FEMALE, "kirikiri1@email.com"); - - return new Member(new Identifier("creator"), new EncryptedPassword(new Password("password1")), - new Nickname("nickname"), null, profile); - } - - private RoadmapCategory 카테고리를_생성한다() { - return new RoadmapCategory(1L, "여가"); - } - - private List 로드맵_노드들을_생성한다() { - return List.of(new RoadmapNode("로드맵 1주차", "로드맵 1주차 내용"), - new RoadmapNode("로드맵 2주차", "로드맵 2주차 내용")); - } - - private RoadmapContent 로드맵_본문을_생성한다(final List roadmapNodes) { - final RoadmapContent roadmapContent = new RoadmapContent("로드맵 본문"); - roadmapContent.addNodes(new RoadmapNodes(roadmapNodes)); - return roadmapContent; - } -} diff --git a/backend/kirikiri/src/test/java/co/kirikiri/goalroom/domain/GoalRoomPendingMembersTest.java b/backend/kirikiri/src/test/java/co/kirikiri/goalroom/domain/GoalRoomPendingMembersTest.java index 009766c83..3292cf6b5 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/goalroom/domain/GoalRoomPendingMembersTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/goalroom/domain/GoalRoomPendingMembersTest.java @@ -3,7 +3,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import co.kirikiri.common.exception.UnexpectedDomainException; +import co.kirikiri.common.exception.domain.UnexpectedDomainException; import co.kirikiri.goalroom.domain.vo.GoalRoomName; import co.kirikiri.goalroom.domain.vo.LimitedMemberCount; import co.kirikiri.goalroom.domain.vo.Period; diff --git a/backend/kirikiri/src/test/java/co/kirikiri/goalroom/domain/GoalRoomTest.java b/backend/kirikiri/src/test/java/co/kirikiri/goalroom/domain/GoalRoomTest.java index f558bcd8f..90a52ea2c 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/goalroom/domain/GoalRoomTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/goalroom/domain/GoalRoomTest.java @@ -2,24 +2,23 @@ import static org.assertj.core.api.Assertions.assertThat; -import co.kirikiri.domain.member.EncryptedPassword; -import co.kirikiri.domain.member.Gender; -import co.kirikiri.domain.member.Member; -import co.kirikiri.domain.member.MemberProfile; -import co.kirikiri.domain.member.vo.Identifier; -import co.kirikiri.domain.member.vo.Nickname; -import co.kirikiri.domain.member.vo.Password; -import co.kirikiri.domain.roadmap.Roadmap; -import co.kirikiri.domain.roadmap.RoadmapCategory; -import co.kirikiri.domain.roadmap.RoadmapContent; -import co.kirikiri.domain.roadmap.RoadmapContents; -import co.kirikiri.domain.roadmap.RoadmapDifficulty; -import co.kirikiri.domain.roadmap.RoadmapNode; -import co.kirikiri.domain.roadmap.RoadmapNodeImages; -import co.kirikiri.domain.roadmap.RoadmapNodes; import co.kirikiri.goalroom.domain.vo.GoalRoomName; import co.kirikiri.goalroom.domain.vo.LimitedMemberCount; import co.kirikiri.goalroom.domain.vo.Period; +import co.kirikiri.member.domain.EncryptedPassword; +import co.kirikiri.member.domain.Gender; +import co.kirikiri.member.domain.Member; +import co.kirikiri.member.domain.MemberProfile; +import co.kirikiri.member.domain.vo.Identifier; +import co.kirikiri.member.domain.vo.Nickname; +import co.kirikiri.member.domain.vo.Password; +import co.kirikiri.roadmap.domain.Roadmap; +import co.kirikiri.roadmap.domain.RoadmapCategory; +import co.kirikiri.roadmap.domain.RoadmapContent; +import co.kirikiri.roadmap.domain.RoadmapDifficulty; +import co.kirikiri.roadmap.domain.RoadmapNode; +import co.kirikiri.roadmap.domain.RoadmapNodeImages; +import co.kirikiri.roadmap.domain.RoadmapNodes; import java.time.LocalDate; import java.util.Collections; import java.util.List; @@ -37,11 +36,11 @@ class GoalRoomTest { void 골룸의_총_기간을_계산한다() { // given final Member creator = 크리에이터를_생성한다(); + final List roadmapNodes = 로드맵_노드들을_생성한다(); final Roadmap roadmap = 로드맵을_생성한다(creator); + final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmap.getId(), roadmapNodes); - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); - final GoalRoom goalRoom = 골룸을_생성한다(targetRoadmapContent, creator); + final GoalRoom goalRoom = 골룸을_생성한다(roadmapContent, creator); // when final int totalPeriod = goalRoom.calculateTotalPeriod(); @@ -54,11 +53,11 @@ class GoalRoomTest { void 골룸의_총_인증_횟수를_구한다() { //given final Member creator = 크리에이터를_생성한다(); + final List roadmapNodes = 로드맵_노드들을_생성한다(); final Roadmap roadmap = 로드맵을_생성한다(creator); + final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmap.getId(), roadmapNodes); - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); - final GoalRoom goalRoom = 골룸을_생성한다(targetRoadmapContent, creator); + final GoalRoom goalRoom = 골룸을_생성한다(roadmapContent, creator); //expect assertThat(goalRoom.getAllCheckCount()).isEqualTo(20); @@ -68,11 +67,11 @@ class GoalRoomTest { void 골룸이_종료된지_3개월_이상_지나지_않으면_false를_반환한다() { //given final Member creator = 크리에이터를_생성한다(); + final List roadmapNodes = 로드맵_노드들을_생성한다(); final Roadmap roadmap = 로드맵을_생성한다(creator); + final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmap.getId(), roadmapNodes); - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); - final GoalRoom goalRoom = 골룸을_생성한다(targetRoadmapContent, creator); + final GoalRoom goalRoom = 골룸을_생성한다(roadmapContent, creator); // when final boolean result = goalRoom.isCompletedAfterMonths(3); @@ -89,10 +88,8 @@ class GoalRoomTest { private Roadmap 로드맵을_생성한다(final Member creator) { final RoadmapCategory category = new RoadmapCategory("게임"); - final List roadmapNodes = 로드맵_노드들을_생성한다(); - final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmapNodes); - final Roadmap roadmap = new Roadmap("로드맵 제목", "로드맵 소개글", 10, RoadmapDifficulty.NORMAL, creator, category); - roadmap.addContent(roadmapContent); + final Roadmap roadmap = new Roadmap("로드맵 제목", "로드맵 소개글", 10, RoadmapDifficulty.NORMAL, creator.getId(), + category, null); return roadmap; } @@ -103,9 +100,9 @@ class GoalRoomTest { return List.of(roadmapNode1, roadmapNode2); } - private RoadmapContent 로드맵_본문을_생성한다(final List roadmapNodes) { - final RoadmapContent roadmapContent = new RoadmapContent(1L, "로드맵 본문"); - roadmapContent.addNodes(new RoadmapNodes(roadmapNodes)); + private RoadmapContent 로드맵_본문을_생성한다(final Long roadmapId, final List roadmapNodes) { + final RoadmapContent roadmapContent = new RoadmapContent(1L, "로드맵 본문", roadmapId, + new RoadmapNodes(roadmapNodes)); return roadmapContent; } @@ -126,10 +123,4 @@ class GoalRoomTest { return new GoalRoom(new GoalRoomName("골룸"), new LimitedMemberCount(10), roadmapContent.getId(), goalRoomRoadmapNodes); } - - private GoalRoomRoadmapNodes 골룸_로드맵_노드들을_생성한다() { - return new GoalRoomRoadmapNodes(List.of( - new GoalRoomRoadmapNode(new Period(TODAY, TEN_DAY_LATER), 5, 1L)) - ); - } } diff --git a/backend/kirikiri/src/test/java/co/kirikiri/goalroom/persistence/GoalRoomMemberRepositoryTest.java b/backend/kirikiri/src/test/java/co/kirikiri/goalroom/persistence/GoalRoomMemberRepositoryTest.java index 71496e6ce..b10f5a655 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/goalroom/persistence/GoalRoomMemberRepositoryTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/goalroom/persistence/GoalRoomMemberRepositoryTest.java @@ -4,23 +4,6 @@ import co.kirikiri.common.helper.RepositoryTest; import co.kirikiri.common.type.ImageContentType; -import co.kirikiri.domain.member.EncryptedPassword; -import co.kirikiri.domain.member.Gender; -import co.kirikiri.domain.member.Member; -import co.kirikiri.domain.member.MemberImage; -import co.kirikiri.domain.member.MemberProfile; -import co.kirikiri.domain.member.vo.Identifier; -import co.kirikiri.domain.member.vo.Nickname; -import co.kirikiri.domain.member.vo.Password; -import co.kirikiri.domain.roadmap.Roadmap; -import co.kirikiri.domain.roadmap.RoadmapCategory; -import co.kirikiri.domain.roadmap.RoadmapContent; -import co.kirikiri.domain.roadmap.RoadmapContents; -import co.kirikiri.domain.roadmap.RoadmapDifficulty; -import co.kirikiri.domain.roadmap.RoadmapNode; -import co.kirikiri.domain.roadmap.RoadmapNodeImage; -import co.kirikiri.domain.roadmap.RoadmapNodeImages; -import co.kirikiri.domain.roadmap.RoadmapNodes; import co.kirikiri.goalroom.domain.GoalRoom; import co.kirikiri.goalroom.domain.GoalRoomMember; import co.kirikiri.goalroom.domain.GoalRoomRoadmapNode; @@ -30,15 +13,34 @@ import co.kirikiri.goalroom.domain.vo.LimitedMemberCount; import co.kirikiri.goalroom.domain.vo.Period; import co.kirikiri.goalroom.persistence.dto.GoalRoomMemberSortType; -import co.kirikiri.persistence.member.MemberRepository; -import co.kirikiri.persistence.roadmap.RoadmapCategoryRepository; -import co.kirikiri.persistence.roadmap.RoadmapRepository; +import co.kirikiri.member.domain.EncryptedPassword; +import co.kirikiri.member.domain.Gender; +import co.kirikiri.member.domain.Member; +import co.kirikiri.member.domain.MemberImage; +import co.kirikiri.member.domain.MemberProfile; +import co.kirikiri.member.domain.vo.Identifier; +import co.kirikiri.member.domain.vo.Nickname; +import co.kirikiri.member.domain.vo.Password; +import co.kirikiri.member.persistence.MemberRepository; +import co.kirikiri.roadmap.domain.Roadmap; +import co.kirikiri.roadmap.domain.RoadmapCategory; +import co.kirikiri.roadmap.domain.RoadmapContent; +import co.kirikiri.roadmap.domain.RoadmapDifficulty; +import co.kirikiri.roadmap.domain.RoadmapNode; +import co.kirikiri.roadmap.domain.RoadmapNodeImage; +import co.kirikiri.roadmap.domain.RoadmapNodeImages; +import co.kirikiri.roadmap.domain.RoadmapNodes; +import co.kirikiri.roadmap.domain.RoadmapTags; +import co.kirikiri.roadmap.persistence.RoadmapCategoryRepository; +import co.kirikiri.roadmap.persistence.RoadmapContentRepository; +import co.kirikiri.roadmap.persistence.RoadmapRepository; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.Test; import java.time.LocalDate; import java.time.LocalDateTime; +import java.util.ArrayList; import java.util.List; import java.util.Optional; -import org.assertj.core.api.Assertions; -import org.junit.jupiter.api.Test; @RepositoryTest class GoalRoomMemberRepositoryTest { @@ -49,20 +51,23 @@ class GoalRoomMemberRepositoryTest { private static final LocalDate THIRTY_DAY_LATER = TODAY.plusDays(30); private final MemberRepository memberRepository; + private final RoadmapCategoryRepository roadmapCategoryRepository; private final RoadmapRepository roadmapRepository; + private final RoadmapContentRepository roadmapContentRepository; private final GoalRoomRepository goalRoomRepository; - private final RoadmapCategoryRepository roadmapCategoryRepository; private final GoalRoomMemberRepository goalRoomMemberRepository; public GoalRoomMemberRepositoryTest(final MemberRepository memberRepository, + final RoadmapCategoryRepository roadmapCategoryRepository, final RoadmapRepository roadmapRepository, + final RoadmapContentRepository roadmapContentRepository, final GoalRoomRepository goalRoomRepository, - final RoadmapCategoryRepository roadmapCategoryRepository, final GoalRoomMemberRepository goalRoomMemberRepository) { this.memberRepository = memberRepository; + this.roadmapCategoryRepository = roadmapCategoryRepository; this.roadmapRepository = roadmapRepository; + this.roadmapContentRepository = roadmapContentRepository; this.goalRoomRepository = goalRoomRepository; - this.roadmapCategoryRepository = roadmapCategoryRepository; this.goalRoomMemberRepository = goalRoomMemberRepository; } @@ -70,22 +75,18 @@ public GoalRoomMemberRepositoryTest(final MemberRepository memberRepository, void 골룸과_사용자_아이디로_골룸_사용자_목록을_조회한다() { // given final Member creator = 크리에이터를_저장한다(); - final RoadmapCategory category = 카테고리를_저장한다("게임"); - final Roadmap roadmap = 로드맵을_저장한다(creator, category); - - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); - - final GoalRoom goalRoom = 골룸을_생성한다(targetRoadmapContent, creator); - final GoalRoom savedGoalRoom = goalRoomRepository.save(goalRoom); + final RoadmapCategory category = 카테고리를_생성한다("여행"); + final Roadmap roadmap = 로드맵을_저장한다("title", creator, category); + final RoadmapContent roadmapContent = 로드맵_본문을_저장한다(roadmap.getId()); + final GoalRoom goalRoom = 골룸을_저장한다(roadmapContent, creator); final GoalRoomMember goalRoomMember = new GoalRoomMember(GoalRoomRole.LEADER, - LocalDateTime.of(2023, 7, 19, 12, 0, 0), savedGoalRoom, creator.getId()); + LocalDateTime.of(2023, 7, 19, 12, 0, 0), goalRoom, creator.getId()); final GoalRoomMember expected = goalRoomMemberRepository.save(goalRoomMember); // when final Optional findGoalRoomMember = goalRoomMemberRepository.findByGoalRoomAndMemberId( - savedGoalRoom, creator.getId()); + goalRoom, creator.getId()); // then assertThat(findGoalRoomMember.get()) @@ -98,18 +99,14 @@ public GoalRoomMemberRepositoryTest(final MemberRepository memberRepository, void 골룸과_사용자_아이디로_골룸_사용자_목록_조회시_없으면_빈값을_반환한다() { // given final Member creator = 크리에이터를_저장한다(); - final RoadmapCategory category = 카테고리를_저장한다("게임"); - final Roadmap roadmap = 로드맵을_저장한다(creator, category); - - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); - - final GoalRoom goalRoom = 골룸을_생성한다(targetRoadmapContent, creator); - final GoalRoom savedGoalRoom = goalRoomRepository.save(goalRoom); + final RoadmapCategory category = 카테고리를_생성한다("여행"); + final Roadmap roadmap = 로드맵을_저장한다("title", creator, category); + final RoadmapContent roadmapContent = 로드맵_본문을_저장한다(roadmap.getId()); + final GoalRoom goalRoom = 골룸을_저장한다(roadmapContent, creator); // when final Optional findGoalRoomMember = goalRoomMemberRepository.findByGoalRoomAndMemberId( - savedGoalRoom, 2L); + goalRoom, 2L); // then assertThat(findGoalRoomMember) @@ -120,25 +117,21 @@ public GoalRoomMemberRepositoryTest(final MemberRepository memberRepository, void 골룸으로_사용자_목록과_멤버를_함께_조회한다() { // given final Member creator = 크리에이터를_저장한다(); - final RoadmapCategory category = 카테고리를_저장한다("게임"); - final Roadmap roadmap = 로드맵을_저장한다(creator, category); - - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); - - final GoalRoom goalRoom = 골룸을_생성한다(targetRoadmapContent, creator); - final GoalRoom savedGoalRoom = goalRoomRepository.save(goalRoom); + final RoadmapCategory category = 카테고리를_생성한다("여행"); + final Roadmap roadmap = 로드맵을_저장한다("title", creator, category); + final RoadmapContent roadmapContent = 로드맵_본문을_저장한다(roadmap.getId()); + final GoalRoom goalRoom = 골룸을_저장한다(roadmapContent, creator); final Member member1 = 사용자를_생성한다("identifier1", "password2!", "name1", "kirikiri1@email.com"); final Member member2 = 사용자를_생성한다("identifier2", "password3!", "name2", "kirikiri1@email.com"); final Member member3 = 사용자를_생성한다("identifier3", "password4!", "name3", "kirikiri1@email.com"); final GoalRoomMember goalRoomMember1 = new GoalRoomMember(GoalRoomRole.LEADER, - LocalDateTime.of(2023, 7, 19, 12, 0, 0), savedGoalRoom, member1.getId()); + LocalDateTime.of(2023, 7, 19, 12, 0, 0), goalRoom, member1.getId()); final GoalRoomMember goalRoomMember2 = new GoalRoomMember(GoalRoomRole.FOLLOWER, - LocalDateTime.of(2023, 7, 20, 12, 0, 0), savedGoalRoom, member2.getId()); + LocalDateTime.of(2023, 7, 20, 12, 0, 0), goalRoom, member2.getId()); final GoalRoomMember goalRoomMember3 = new GoalRoomMember(GoalRoomRole.FOLLOWER, - LocalDateTime.of(2023, 7, 21, 12, 0, 0), savedGoalRoom, member3.getId()); + LocalDateTime.of(2023, 7, 21, 12, 0, 0), goalRoom, member3.getId()); final List expected = goalRoomMemberRepository.saveAll( List.of(goalRoomMember1, goalRoomMember2, goalRoomMember3)); @@ -155,21 +148,16 @@ public GoalRoomMemberRepositoryTest(final MemberRepository memberRepository, void 골룸의_리더를_찾는다() { // given final Member creator = 크리에이터를_저장한다(); - final RoadmapCategory category = 카테고리를_저장한다("게임"); - final Roadmap roadmap = 로드맵을_저장한다(creator, category); - - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); - - final GoalRoom goalRoom = 골룸을_생성한다(targetRoadmapContent, creator); - final GoalRoom savedGoalRoom = goalRoomRepository.save(goalRoom); - + final RoadmapCategory category = 카테고리를_생성한다("여행"); + final Roadmap roadmap = 로드맵을_저장한다("title", creator, category); + final RoadmapContent roadmapContent = 로드맵_본문을_저장한다(roadmap.getId()); + final GoalRoom goalRoom = 골룸을_저장한다(roadmapContent, creator); final Member member1 = 사용자를_생성한다("identifier1", "password2!", "name1", "kirikiri1@email.com"); final GoalRoomMember goalRoomMember1 = new GoalRoomMember(GoalRoomRole.LEADER, - LocalDateTime.of(2023, 7, 19, 12, 0, 0), savedGoalRoom, creator.getId()); + LocalDateTime.of(2023, 7, 19, 12, 0, 0), goalRoom, creator.getId()); final GoalRoomMember goalRoomMember2 = new GoalRoomMember(GoalRoomRole.FOLLOWER, - LocalDateTime.of(2023, 7, 20, 12, 0, 0), savedGoalRoom, member1.getId()); + LocalDateTime.of(2023, 7, 20, 12, 0, 0), goalRoom, member1.getId()); final List expected = goalRoomMemberRepository.saveAll( List.of(goalRoomMember1, goalRoomMember2)); @@ -186,31 +174,27 @@ public GoalRoomMemberRepositoryTest(final MemberRepository memberRepository, void 골룸_아이디로_골룸_사용자를_조회하고_들어온지_오래된_순서대로_정렬한다() { // given final Member creator = 크리에이터를_저장한다(); - final RoadmapCategory category = 카테고리를_저장한다("게임"); - final Roadmap roadmap = 로드맵을_저장한다(creator, category); - - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); - - final GoalRoom goalRoom = 골룸을_생성한다(targetRoadmapContent, creator); - final GoalRoom savedGoalRoom = goalRoomRepository.save(goalRoom); + final RoadmapCategory category = 카테고리를_생성한다("여행"); + final Roadmap roadmap = 로드맵을_저장한다("title", creator, category); + final RoadmapContent roadmapContent = 로드맵_본문을_저장한다(roadmap.getId()); + final GoalRoom goalRoom = 골룸을_저장한다(roadmapContent, creator); final Member member1 = 사용자를_생성한다("identifier1", "password2!", "name1", "kirikiri1@email.com"); final Member member2 = 사용자를_생성한다("identifier2", "password3!", "name2", "kirikiri1@email.com"); final Member member3 = 사용자를_생성한다("identifier3", "password4!", "name3", "kirikiri1@email.com"); final GoalRoomMember goalRoomMember1 = new GoalRoomMember(GoalRoomRole.LEADER, - LocalDateTime.of(2023, 7, 19, 12, 0, 0), savedGoalRoom, member1.getId()); + LocalDateTime.of(2023, 7, 19, 12, 0, 0), goalRoom, member1.getId()); final GoalRoomMember goalRoomMember2 = new GoalRoomMember(GoalRoomRole.FOLLOWER, - LocalDateTime.of(2023, 7, 20, 12, 0, 0), savedGoalRoom, member2.getId()); + LocalDateTime.of(2023, 7, 20, 12, 0, 0), goalRoom, member2.getId()); final GoalRoomMember goalRoomMember3 = new GoalRoomMember(GoalRoomRole.FOLLOWER, - LocalDateTime.of(2023, 7, 21, 12, 0, 0), savedGoalRoom, member3.getId()); + LocalDateTime.of(2023, 7, 21, 12, 0, 0), goalRoom, member3.getId()); final List expected = goalRoomMemberRepository.saveAll( List.of(goalRoomMember1, goalRoomMember2, goalRoomMember3)); // when final List goalRoomMembers = goalRoomMemberRepository.findByGoalRoomIdOrderedBySortType( - savedGoalRoom.getId(), GoalRoomMemberSortType.JOINED_ASC); + goalRoom.getId(), GoalRoomMemberSortType.JOINED_ASC); // then assertThat(goalRoomMembers) @@ -221,32 +205,28 @@ public GoalRoomMemberRepositoryTest(final MemberRepository memberRepository, void 골룸_아이디로_골룸_사용자를_조회하고_마지막으로_들어온_순서대로_정렬한다() { // given final Member creator = 크리에이터를_저장한다(); - final RoadmapCategory category = 카테고리를_저장한다("게임"); - final Roadmap roadmap = 로드맵을_저장한다(creator, category); - - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); - - final GoalRoom goalRoom = 골룸을_생성한다(targetRoadmapContent, creator); - final GoalRoom savedGoalRoom = goalRoomRepository.save(goalRoom); + final RoadmapCategory category = 카테고리를_생성한다("여행"); + final Roadmap roadmap = 로드맵을_저장한다("title", creator, category); + final RoadmapContent roadmapContent = 로드맵_본문을_저장한다(roadmap.getId()); + final GoalRoom goalRoom = 골룸을_저장한다(roadmapContent, creator); final Member member1 = 사용자를_생성한다("identifier1", "password2!", "name1", "kirikiri1@email.com"); final Member member2 = 사용자를_생성한다("identifier2", "password3!", "name2", "kirikiri1@email.com"); final Member member3 = 사용자를_생성한다("identifier3", "password4!", "name3", "kirikiri1@email.com"); final GoalRoomMember goalRoomMember1 = new GoalRoomMember(GoalRoomRole.LEADER, - LocalDateTime.of(2023, 7, 19, 12, 0, 0), savedGoalRoom, member1.getId()); + LocalDateTime.of(2023, 7, 19, 12, 0, 0), goalRoom, member1.getId()); final GoalRoomMember goalRoomMember2 = new GoalRoomMember(GoalRoomRole.FOLLOWER, - LocalDateTime.of(2023, 7, 20, 12, 0, 0), savedGoalRoom, member2.getId()); + LocalDateTime.of(2023, 7, 20, 12, 0, 0), goalRoom, member2.getId()); final GoalRoomMember goalRoomMember3 = new GoalRoomMember(GoalRoomRole.FOLLOWER, - LocalDateTime.of(2023, 7, 21, 12, 0, 0), savedGoalRoom, member3.getId()); + LocalDateTime.of(2023, 7, 21, 12, 0, 0), goalRoom, member3.getId()); final GoalRoomMember savedGoalRoomMember1 = goalRoomMemberRepository.save(goalRoomMember1); final GoalRoomMember savedGoalRoomMember2 = goalRoomMemberRepository.save(goalRoomMember2); final GoalRoomMember savedGoalRoomMember3 = goalRoomMemberRepository.save(goalRoomMember3); // when final List goalRoomMembers = goalRoomMemberRepository.findByGoalRoomIdOrderedBySortType( - savedGoalRoom.getId(), GoalRoomMemberSortType.JOINED_DESC); + goalRoom.getId(), GoalRoomMemberSortType.JOINED_DESC); // then assertThat(goalRoomMembers) @@ -257,36 +237,32 @@ public GoalRoomMemberRepositoryTest(final MemberRepository memberRepository, void 골룸_아이디로_골룸_사용자를_조회하고_달성률이_높은_순대로_정렬한다() { // given final Member creator = 크리에이터를_저장한다(); - final RoadmapCategory category = 카테고리를_저장한다("게임"); - final Roadmap roadmap = 로드맵을_저장한다(creator, category); - - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); - - final GoalRoom goalRoom = 골룸을_생성한다(targetRoadmapContent, creator); - final GoalRoom savedGoalRoom = goalRoomRepository.save(goalRoom); + final RoadmapCategory category = 카테고리를_생성한다("여행"); + final Roadmap roadmap = 로드맵을_저장한다("title", creator, category); + final RoadmapContent roadmapContent = 로드맵_본문을_저장한다(roadmap.getId()); + final GoalRoom goalRoom = 골룸을_저장한다(roadmapContent, creator); final Member member1 = 사용자를_생성한다("identifier1", "password2!", "name1", "kirikiri1@email.com"); final Member member2 = 사용자를_생성한다("identifier2", "password3!", "name2", "kirikiri1@email.com"); final Member member3 = 사용자를_생성한다("identifier3", "password4!", "name3", "kirikiri1@email.com"); final GoalRoomMember goalRoomMember1 = new GoalRoomMember(GoalRoomRole.LEADER, - LocalDateTime.of(2023, 7, 19, 12, 0, 0), savedGoalRoom, member1.getId()); + LocalDateTime.of(2023, 7, 19, 12, 0, 0), goalRoom, member1.getId()); goalRoomMember1.updateAccomplishmentRate(30.0); final GoalRoomMember goalRoomMember2 = new GoalRoomMember(GoalRoomRole.FOLLOWER, - LocalDateTime.of(2023, 7, 20, 12, 0, 0), savedGoalRoom, member2.getId()); + LocalDateTime.of(2023, 7, 20, 12, 0, 0), goalRoom, member2.getId()); goalRoomMember2.updateAccomplishmentRate(70.0); final GoalRoomMember goalRoomMember3 = new GoalRoomMember(GoalRoomRole.FOLLOWER, - LocalDateTime.of(2023, 7, 21, 12, 0, 0), savedGoalRoom, member3.getId()); + LocalDateTime.of(2023, 7, 21, 12, 0, 0), goalRoom, member3.getId()); goalRoomMember3.updateAccomplishmentRate(10.0); final List expected = goalRoomMemberRepository.saveAll( List.of(goalRoomMember2, goalRoomMember1, goalRoomMember3)); // when final List goalRoomMembers1 = goalRoomMemberRepository.findByGoalRoomIdOrderedBySortType( - savedGoalRoom.getId(), GoalRoomMemberSortType.ACCOMPLISHMENT_RATE); + goalRoom.getId(), GoalRoomMemberSortType.ACCOMPLISHMENT_RATE); final List goalRoomMembers2 = goalRoomMemberRepository.findByGoalRoomIdOrderedBySortType( - savedGoalRoom.getId(), null); + goalRoom.getId(), null); // then assertThat(goalRoomMembers1) @@ -298,15 +274,11 @@ public GoalRoomMemberRepositoryTest(final MemberRepository memberRepository, @Test void 골룸_아이디와_사용자_아이디로_골룸_멤버를_조회한다() { // given - final Member creator = 사용자를_생성한다("identifier1", "password!1", "name1", "kirikiri1@email.com"); - final RoadmapCategory category = 카테고리를_저장한다("여가"); - final Roadmap roadmap = 로드맵을_저장한다(creator, category); - - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); - - final GoalRoom goalRoom = 골룸을_생성한다(targetRoadmapContent, creator); - goalRoomRepository.save(goalRoom); + final Member creator = 크리에이터를_저장한다(); + final RoadmapCategory category = 카테고리를_생성한다("여행"); + final Roadmap roadmap = 로드맵을_저장한다("title", creator, category); + final RoadmapContent roadmapContent = 로드맵_본문을_저장한다(roadmap.getId()); + final GoalRoom goalRoom = 골룸을_저장한다(roadmapContent, creator); final GoalRoomMember goalRoomMember = new GoalRoomMember( GoalRoomRole.LEADER, LocalDateTime.now(), goalRoom, creator.getId() @@ -341,11 +313,22 @@ public GoalRoomMemberRepositoryTest(final MemberRepository memberRepository, return memberRepository.save(member); } - private RoadmapCategory 카테고리를_저장한다(final String name) { + private RoadmapCategory 카테고리를_생성한다(final String name) { final RoadmapCategory roadmapCategory = new RoadmapCategory(name); return roadmapCategoryRepository.save(roadmapCategory); } + private Roadmap 로드맵을_저장한다(final String title, final Member creator, final RoadmapCategory category) { + final Roadmap roadmap = new Roadmap(title, "로드맵 소개글", 10, RoadmapDifficulty.NORMAL, creator.getId(), category, new RoadmapTags(new ArrayList<>())); + return roadmapRepository.save(roadmap); + } + + private RoadmapContent 로드맵_본문을_저장한다(final Long roadmapId) { + final List roadmapNodes = 로드맵_노드들을_생성한다(); + final RoadmapContent roadmapContent = new RoadmapContent("로드맵 본문", roadmapId, new RoadmapNodes(roadmapNodes)); + return roadmapContentRepository.save(roadmapContent); + } + private List 로드맵_노드들을_생성한다() { final RoadmapNode roadmapNode1 = new RoadmapNode("로드맵 1주차", "로드맵 1주차 내용"); roadmapNode1.addImages(new RoadmapNodeImages(노드_이미지들을_생성한다())); @@ -353,12 +336,6 @@ public GoalRoomMemberRepositoryTest(final MemberRepository memberRepository, return List.of(roadmapNode1, roadmapNode2); } - private RoadmapContent 로드맵_본문을_생성한다(final List roadmapNodes) { - final RoadmapContent roadmapContent = new RoadmapContent("로드맵 본문"); - roadmapContent.addNodes(new RoadmapNodes(roadmapNodes)); - return roadmapContent; - } - private List 노드_이미지들을_생성한다() { return List.of( new RoadmapNodeImage("node-image1.png", "node-image1-save-path", ImageContentType.PNG), @@ -366,15 +343,7 @@ public GoalRoomMemberRepositoryTest(final MemberRepository memberRepository, ); } - private Roadmap 로드맵을_저장한다(final Member creator, final RoadmapCategory category) { - final List roadmapNodes = 로드맵_노드들을_생성한다(); - final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmapNodes); - final Roadmap roadmap = new Roadmap("로드맵 제목", "로드맵 소개글", 10, RoadmapDifficulty.NORMAL, creator, category); - roadmap.addContent(roadmapContent); - return roadmapRepository.save(roadmap); - } - - private GoalRoom 골룸을_생성한다(final RoadmapContent roadmapContent, final Member member) { + private GoalRoom 골룸을_저장한다(final RoadmapContent roadmapContent, final Member member) { final List roadmapNodes = roadmapContent.getNodes().getValues(); final RoadmapNode firstRoadmapNode = roadmapNodes.get(0); @@ -389,7 +358,8 @@ public GoalRoomMemberRepositoryTest(final MemberRepository memberRepository, final GoalRoomRoadmapNodes goalRoomRoadmapNodes = new GoalRoomRoadmapNodes( List.of(firstGoalRoomRoadmapNode, secondGoalRoomRoadmapNode)); - return new GoalRoom(new GoalRoomName("골룸"), new LimitedMemberCount(10), roadmapContent.getId(), + final GoalRoom goalRoom = new GoalRoom(new GoalRoomName("골룸"), new LimitedMemberCount(10), roadmapContent.getId(), goalRoomRoadmapNodes); + return goalRoomRepository.save(goalRoom); } } diff --git a/backend/kirikiri/src/test/java/co/kirikiri/goalroom/persistence/GoalRoomPendingMemberRepositoryTest.java b/backend/kirikiri/src/test/java/co/kirikiri/goalroom/persistence/GoalRoomPendingMemberRepositoryTest.java index 64cfc1eaa..99ec97e97 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/goalroom/persistence/GoalRoomPendingMemberRepositoryTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/goalroom/persistence/GoalRoomPendingMemberRepositoryTest.java @@ -4,23 +4,6 @@ import co.kirikiri.common.helper.RepositoryTest; import co.kirikiri.common.type.ImageContentType; -import co.kirikiri.domain.member.EncryptedPassword; -import co.kirikiri.domain.member.Gender; -import co.kirikiri.domain.member.Member; -import co.kirikiri.domain.member.MemberImage; -import co.kirikiri.domain.member.MemberProfile; -import co.kirikiri.domain.member.vo.Identifier; -import co.kirikiri.domain.member.vo.Nickname; -import co.kirikiri.domain.member.vo.Password; -import co.kirikiri.domain.roadmap.Roadmap; -import co.kirikiri.domain.roadmap.RoadmapCategory; -import co.kirikiri.domain.roadmap.RoadmapContent; -import co.kirikiri.domain.roadmap.RoadmapContents; -import co.kirikiri.domain.roadmap.RoadmapDifficulty; -import co.kirikiri.domain.roadmap.RoadmapNode; -import co.kirikiri.domain.roadmap.RoadmapNodeImage; -import co.kirikiri.domain.roadmap.RoadmapNodeImages; -import co.kirikiri.domain.roadmap.RoadmapNodes; import co.kirikiri.goalroom.domain.GoalRoom; import co.kirikiri.goalroom.domain.GoalRoomPendingMember; import co.kirikiri.goalroom.domain.GoalRoomRoadmapNode; @@ -30,11 +13,30 @@ import co.kirikiri.goalroom.domain.vo.LimitedMemberCount; import co.kirikiri.goalroom.domain.vo.Period; import co.kirikiri.goalroom.persistence.dto.GoalRoomMemberSortType; -import co.kirikiri.persistence.member.MemberRepository; -import co.kirikiri.persistence.roadmap.RoadmapCategoryRepository; -import co.kirikiri.persistence.roadmap.RoadmapRepository; +import co.kirikiri.member.domain.EncryptedPassword; +import co.kirikiri.member.domain.Gender; +import co.kirikiri.member.domain.Member; +import co.kirikiri.member.domain.MemberImage; +import co.kirikiri.member.domain.MemberProfile; +import co.kirikiri.member.domain.vo.Identifier; +import co.kirikiri.member.domain.vo.Nickname; +import co.kirikiri.member.domain.vo.Password; +import co.kirikiri.member.persistence.MemberRepository; +import co.kirikiri.roadmap.domain.Roadmap; +import co.kirikiri.roadmap.domain.RoadmapCategory; +import co.kirikiri.roadmap.domain.RoadmapContent; +import co.kirikiri.roadmap.domain.RoadmapDifficulty; +import co.kirikiri.roadmap.domain.RoadmapNode; +import co.kirikiri.roadmap.domain.RoadmapNodeImage; +import co.kirikiri.roadmap.domain.RoadmapNodeImages; +import co.kirikiri.roadmap.domain.RoadmapNodes; +import co.kirikiri.roadmap.domain.RoadmapTags; +import co.kirikiri.roadmap.persistence.RoadmapCategoryRepository; +import co.kirikiri.roadmap.persistence.RoadmapContentRepository; +import co.kirikiri.roadmap.persistence.RoadmapRepository; import java.time.LocalDate; import java.time.LocalDateTime; +import java.util.ArrayList; import java.util.List; import java.util.Optional; import org.junit.jupiter.api.Assertions; @@ -49,19 +51,22 @@ class GoalRoomPendingMemberRepositoryTest { private static final LocalDate THIRTY_DAY_LATER = TODAY.plusDays(30); private final MemberRepository memberRepository; + private final RoadmapCategoryRepository roadmapCategoryRepository; private final RoadmapRepository roadmapRepository; + private final RoadmapContentRepository roadmapContentRepository; private final GoalRoomRepository goalRoomRepository; - private final RoadmapCategoryRepository roadmapCategoryRepository; private final GoalRoomPendingMemberRepository goalRoomPendingMemberRepository; public GoalRoomPendingMemberRepositoryTest(final MemberRepository memberRepository, final RoadmapCategoryRepository roadmapCategoryRepository, final RoadmapRepository roadmapRepository, + final RoadmapContentRepository roadmapContentRepository, final GoalRoomRepository goalRoomRepository, final GoalRoomPendingMemberRepository goalRoomPendingMemberRepository) { this.memberRepository = memberRepository; this.roadmapCategoryRepository = roadmapCategoryRepository; this.roadmapRepository = roadmapRepository; + this.roadmapContentRepository = roadmapContentRepository; this.goalRoomRepository = goalRoomRepository; this.goalRoomPendingMemberRepository = goalRoomPendingMemberRepository; } @@ -70,22 +75,18 @@ public GoalRoomPendingMemberRepositoryTest(final MemberRepository memberReposito void 골룸과_사용자_아이디로_골룸_사용자_대기_목록을_조회한다() { // given final Member creator = 크리에이터를_저장한다(); - final RoadmapCategory category = 카테고리를_저장한다("게임"); - final Roadmap roadmap = 로드맵을_저장한다(creator, category); - - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); - - final GoalRoom goalRoom = 골룸을_생성한다(targetRoadmapContent, creator); - final GoalRoom savedGoalRoom = goalRoomRepository.save(goalRoom); + final RoadmapCategory category = 카테고리를_생성한다("여행"); + final Roadmap roadmap = 로드맵을_저장한다("title", creator, category); + final RoadmapContent roadmapContent = 로드맵_본문을_저장한다(roadmap.getId()); + final GoalRoom goalRoom = 골룸을_저장한다(roadmapContent, creator); final GoalRoomPendingMember goalRoomPendingMember = new GoalRoomPendingMember(1L, GoalRoomRole.LEADER, - LocalDateTime.of(2023, 7, 19, 12, 0, 0), savedGoalRoom, creator.getId()); + LocalDateTime.of(2023, 7, 19, 12, 0, 0), goalRoom, creator.getId()); goalRoomPendingMemberRepository.save(goalRoomPendingMember); // when final Optional findGoalRoomPendingMember = goalRoomPendingMemberRepository.findByGoalRoomAndMemberId( - savedGoalRoom, creator.getId()); + goalRoom, creator.getId()); // then assertThat(findGoalRoomPendingMember.get()) @@ -98,18 +99,14 @@ public GoalRoomPendingMemberRepositoryTest(final MemberRepository memberReposito void 골룸과_사용자_아이디로_골룸_사용자_대기_목록_조회시_없으면_빈값을_반환한다() { // given final Member creator = 크리에이터를_저장한다(); - final RoadmapCategory category = 카테고리를_저장한다("게임"); - final Roadmap roadmap = 로드맵을_저장한다(creator, category); - - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); - - final GoalRoom goalRoom = 골룸을_생성한다(targetRoadmapContent, creator); - final GoalRoom savedGoalRoom = goalRoomRepository.save(goalRoom); + final RoadmapCategory category = 카테고리를_생성한다("여행"); + final Roadmap roadmap = 로드맵을_저장한다("title", creator, category); + final RoadmapContent roadmapContent = 로드맵_본문을_저장한다(roadmap.getId()); + final GoalRoom goalRoom = 골룸을_저장한다(roadmapContent, creator); // when final Optional findGoalRoomPendingMember = goalRoomPendingMemberRepository.findByGoalRoomAndMemberId( - savedGoalRoom, 2L); + goalRoom, 2L); // then assertThat(findGoalRoomPendingMember) @@ -120,27 +117,23 @@ public GoalRoomPendingMemberRepositoryTest(final MemberRepository memberReposito void 골룸으로_사용자_대기_목록과_멤버를_함께_조회한다() { // given final Member creator = 크리에이터를_저장한다(); - final RoadmapCategory category = 카테고리를_저장한다("게임"); - final Roadmap roadmap = 로드맵을_저장한다(creator, category); - - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); - - final GoalRoom goalRoom = 골룸을_생성한다(targetRoadmapContent, creator); - final GoalRoom savedGoalRoom = goalRoomRepository.save(goalRoom); + final RoadmapCategory category = 카테고리를_생성한다("여행"); + final Roadmap roadmap = 로드맵을_저장한다("title", creator, category); + final RoadmapContent roadmapContent = 로드맵_본문을_저장한다(roadmap.getId()); + final GoalRoom goalRoom = 골룸을_저장한다(roadmapContent, creator); final Member member1 = 사용자를_생성한다("identifier1", "password2!", "name1", "kirikiri1@email.com"); final Member member2 = 사용자를_생성한다("identifier2", "password3!", "name2", "kirikiri1@email.com"); final Member member3 = 사용자를_생성한다("identifier3", "password4!", "name3", "kirikiri1@email.com"); final GoalRoomPendingMember goalRoomPendingMember = new GoalRoomPendingMember(null, GoalRoomRole.LEADER, - LocalDateTime.now(), savedGoalRoom, creator.getId()); + LocalDateTime.now(), goalRoom, creator.getId()); final GoalRoomPendingMember goalRoomPendingMember1 = new GoalRoomPendingMember(null, GoalRoomRole.FOLLOWER, - LocalDateTime.now(), savedGoalRoom, member1.getId()); + LocalDateTime.now(), goalRoom, member1.getId()); final GoalRoomPendingMember goalRoomPendingMember2 = new GoalRoomPendingMember(null, GoalRoomRole.FOLLOWER, - LocalDateTime.now(), savedGoalRoom, member2.getId()); + LocalDateTime.now(), goalRoom, member2.getId()); final GoalRoomPendingMember goalRoomPendingMember3 = new GoalRoomPendingMember(null, GoalRoomRole.FOLLOWER, - LocalDateTime.now(), savedGoalRoom, member3.getId()); + LocalDateTime.now(), goalRoom, member3.getId()); goalRoomPendingMemberRepository.saveAll( List.of(goalRoomPendingMember, goalRoomPendingMember1, goalRoomPendingMember2, goalRoomPendingMember3)); @@ -162,21 +155,21 @@ public GoalRoomPendingMemberRepositoryTest(final MemberRepository memberReposito void 골룸에_참가한다() { //given final Member creator = 크리에이터를_저장한다(); - final RoadmapCategory category = 카테고리를_저장한다("게임"); - final Roadmap roadmap = 로드맵을_저장한다(creator, category); - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); - final GoalRoom goalRoom = 골룸을_생성한다(targetRoadmapContent, creator); - final GoalRoom savedGoalRoom = goalRoomRepository.save(goalRoom); - goalRoomPendingMemberRepository.save( - new GoalRoomPendingMember(GoalRoomRole.LEADER, savedGoalRoom, creator.getId())); + final RoadmapCategory category = 카테고리를_생성한다("여행"); + final Roadmap roadmap = 로드맵을_저장한다("title", creator, category); + final RoadmapContent roadmapContent = 로드맵_본문을_저장한다(roadmap.getId()); + final GoalRoom goalRoom = 골룸을_저장한다(roadmapContent, creator); + final GoalRoomPendingMember goalRoomPendingMember1 = new GoalRoomPendingMember(GoalRoomRole.LEADER, + goalRoom, creator.getId()); + goalRoomPendingMemberRepository.save(goalRoomPendingMember1); final Member follower = 사용자를_생성한다("identifier2", "password!2", "name", "kirikiri1@email.com"); - final GoalRoomPendingMember goalRoomPendingMember = new GoalRoomPendingMember(GoalRoomRole.FOLLOWER, - savedGoalRoom, follower.getId()); + final GoalRoomPendingMember goalRoomPendingMember2 = new GoalRoomPendingMember(GoalRoomRole.FOLLOWER, + goalRoom, follower.getId()); //when - goalRoomPendingMemberRepository.save(goalRoomPendingMember); + goalRoomPendingMemberRepository.save(goalRoomPendingMember1); + goalRoomPendingMemberRepository.save(goalRoomPendingMember2); //then final List goalRoomPendingMembers = goalRoomPendingMemberRepository.findByGoalRoom( @@ -196,19 +189,17 @@ public GoalRoomPendingMemberRepositoryTest(final MemberRepository memberReposito void 골룸의_리더를_찾는다() { //given final Member creator = 크리에이터를_저장한다(); - final RoadmapCategory category = 카테고리를_저장한다("게임"); - final Roadmap roadmap = 로드맵을_저장한다(creator, category); - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); - final GoalRoom goalRoom = 골룸을_생성한다(targetRoadmapContent, creator); - final GoalRoom savedGoalRoom = goalRoomRepository.save(goalRoom); + final RoadmapCategory category = 카테고리를_생성한다("여행"); + final Roadmap roadmap = 로드맵을_저장한다("title", creator, category); + final RoadmapContent roadmapContent = 로드맵_본문을_저장한다(roadmap.getId()); + final GoalRoom goalRoom = 골룸을_저장한다(roadmapContent, creator); final GoalRoomPendingMember goalRoomPendingMember1 = new GoalRoomPendingMember(GoalRoomRole.LEADER, - savedGoalRoom, creator.getId()); + goalRoom, creator.getId()); goalRoomPendingMemberRepository.save(goalRoomPendingMember1); final Member follower = 사용자를_생성한다("identifier2", "password!2", "name", "kirikiri1@email.com"); final GoalRoomPendingMember goalRoomPendingMember2 = new GoalRoomPendingMember(GoalRoomRole.FOLLOWER, - savedGoalRoom, follower.getId()); + goalRoom, follower.getId()); goalRoomPendingMemberRepository.save(goalRoomPendingMember2); //when @@ -223,27 +214,23 @@ public GoalRoomPendingMemberRepositoryTest(final MemberRepository memberReposito void 골룸_아이디로_골룸_사용자를_조회하고_들어온지_오래된_순서대로_정렬한다() { // given final Member creator = 크리에이터를_저장한다(); - final RoadmapCategory category = 카테고리를_저장한다("게임"); - final Roadmap roadmap = 로드맵을_저장한다(creator, category); - - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); - - final GoalRoom goalRoom = 골룸을_생성한다(targetRoadmapContent, creator); - final GoalRoom savedGoalRoom = goalRoomRepository.save(goalRoom); + final RoadmapCategory category = 카테고리를_생성한다("여행"); + final Roadmap roadmap = 로드맵을_저장한다("title", creator, category); + final RoadmapContent roadmapContent = 로드맵_본문을_저장한다(roadmap.getId()); + final GoalRoom goalRoom = 골룸을_저장한다(roadmapContent, creator); final Member member1 = 사용자를_생성한다("identifier1", "password2!", "name1", "kirikiri1@email.com"); final Member member2 = 사용자를_생성한다("identifier2", "password3!", "name2", "kirikiri1@email.com"); final Member member3 = 사용자를_생성한다("identifier3", "password4!", "name3", "kirikiri1@email.com"); final GoalRoomPendingMember goalRoomPendingMember0 = new GoalRoomPendingMember(null, GoalRoomRole.LEADER, - LocalDateTime.now(), savedGoalRoom, creator.getId()); + LocalDateTime.now(), goalRoom, creator.getId()); final GoalRoomPendingMember goalRoomPendingMember1 = new GoalRoomPendingMember(null, GoalRoomRole.FOLLOWER, - LocalDateTime.now(), savedGoalRoom, member1.getId()); + LocalDateTime.now(), goalRoom, member1.getId()); final GoalRoomPendingMember goalRoomPendingMember2 = new GoalRoomPendingMember(null, GoalRoomRole.FOLLOWER, - LocalDateTime.now(), savedGoalRoom, member2.getId()); + LocalDateTime.now(), goalRoom, member2.getId()); final GoalRoomPendingMember goalRoomPendingMember3 = new GoalRoomPendingMember(null, GoalRoomRole.FOLLOWER, - LocalDateTime.now(), savedGoalRoom, member3.getId()); + LocalDateTime.now(), goalRoom, member3.getId()); goalRoomPendingMemberRepository.saveAll( List.of(goalRoomPendingMember0, goalRoomPendingMember1, goalRoomPendingMember2, goalRoomPendingMember3)); @@ -252,7 +239,7 @@ public GoalRoomPendingMemberRepositoryTest(final MemberRepository memberReposito // when final List goalRoomPendingMembers = goalRoomPendingMemberRepository.findByGoalRoomIdOrderedBySortType( - savedGoalRoom.getId(), GoalRoomMemberSortType.JOINED_ASC); + goalRoom.getId(), GoalRoomMemberSortType.JOINED_ASC); // then assertThat(goalRoomPendingMembers) @@ -265,27 +252,23 @@ public GoalRoomPendingMemberRepositoryTest(final MemberRepository memberReposito void 골룸_아이디로_골룸_사용자를_조회하고_마지막으로_들어온_순서대로_정렬한다() { // given final Member creator = 크리에이터를_저장한다(); - final RoadmapCategory category = 카테고리를_저장한다("게임"); - final Roadmap roadmap = 로드맵을_저장한다(creator, category); - - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); - - final GoalRoom goalRoom = 골룸을_생성한다(targetRoadmapContent, creator); - final GoalRoom savedGoalRoom = goalRoomRepository.save(goalRoom); + final RoadmapCategory category = 카테고리를_생성한다("여행"); + final Roadmap roadmap = 로드맵을_저장한다("title", creator, category); + final RoadmapContent roadmapContent = 로드맵_본문을_저장한다(roadmap.getId()); + final GoalRoom goalRoom = 골룸을_저장한다(roadmapContent, creator); final Member member1 = 사용자를_생성한다("identifier1", "password2!", "name1", "kirikiri1@email.com"); final Member member2 = 사용자를_생성한다("identifier2", "password3!", "name2", "kirikiri1@email.com"); final Member member3 = 사용자를_생성한다("identifier3", "password4!", "name3", "kirikiri1@email.com"); final GoalRoomPendingMember goalRoomPendingMember0 = new GoalRoomPendingMember(null, GoalRoomRole.LEADER, - LocalDateTime.now(), savedGoalRoom, creator.getId()); + LocalDateTime.now(), goalRoom, creator.getId()); final GoalRoomPendingMember goalRoomPendingMember1 = new GoalRoomPendingMember(null, GoalRoomRole.FOLLOWER, - LocalDateTime.now(), savedGoalRoom, member1.getId()); + LocalDateTime.now(), goalRoom, member1.getId()); final GoalRoomPendingMember goalRoomPendingMember2 = new GoalRoomPendingMember(null, GoalRoomRole.FOLLOWER, - LocalDateTime.now(), savedGoalRoom, member2.getId()); + LocalDateTime.now(), goalRoom, member2.getId()); final GoalRoomPendingMember goalRoomPendingMember3 = new GoalRoomPendingMember(null, GoalRoomRole.FOLLOWER, - LocalDateTime.now(), savedGoalRoom, member3.getId()); + LocalDateTime.now(), goalRoom, member3.getId()); final GoalRoomPendingMember savedGoalRoomPendingMember0 = goalRoomPendingMemberRepository.save( goalRoomPendingMember0); final GoalRoomPendingMember savedGoalRoomPendingMember1 = goalRoomPendingMemberRepository.save( @@ -299,7 +282,7 @@ public GoalRoomPendingMemberRepositoryTest(final MemberRepository memberReposito // when final List goalRoomPendingMembers = goalRoomPendingMemberRepository.findByGoalRoomIdOrderedBySortType( - savedGoalRoom.getId(), GoalRoomMemberSortType.JOINED_DESC); + goalRoom.getId(), GoalRoomMemberSortType.JOINED_DESC); // then assertThat(goalRoomPendingMembers) @@ -310,27 +293,23 @@ public GoalRoomPendingMemberRepositoryTest(final MemberRepository memberReposito void 골룸_아이디로_골룸_사용자를_조회하고_정렬조건을_달성률순_또는_입력하지_않은경우_참여한순으로_정렬한다() { // given final Member creator = 크리에이터를_저장한다(); - final RoadmapCategory category = 카테고리를_저장한다("게임"); - final Roadmap roadmap = 로드맵을_저장한다(creator, category); - - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); - - final GoalRoom goalRoom = 골룸을_생성한다(targetRoadmapContent, creator); - final GoalRoom savedGoalRoom = goalRoomRepository.save(goalRoom); + final RoadmapCategory category = 카테고리를_생성한다("여행"); + final Roadmap roadmap = 로드맵을_저장한다("title", creator, category); + final RoadmapContent roadmapContent = 로드맵_본문을_저장한다(roadmap.getId()); + final GoalRoom goalRoom = 골룸을_저장한다(roadmapContent, creator); final Member member1 = 사용자를_생성한다("identifier1", "password2!", "name1", "kirikiri1@email.com"); final Member member2 = 사용자를_생성한다("identifier2", "password3!", "name2", "kirikiri1@email.com"); final Member member3 = 사용자를_생성한다("identifier3", "password4!", "name3", "kirikiri1@email.com"); final GoalRoomPendingMember goalRoomPendingMember0 = new GoalRoomPendingMember(null, GoalRoomRole.LEADER, - LocalDateTime.now(), savedGoalRoom, creator.getId()); + LocalDateTime.now(), goalRoom, creator.getId()); final GoalRoomPendingMember goalRoomPendingMember1 = new GoalRoomPendingMember(null, GoalRoomRole.FOLLOWER, - LocalDateTime.now(), savedGoalRoom, member1.getId()); + LocalDateTime.now(), goalRoom, member1.getId()); final GoalRoomPendingMember goalRoomPendingMember2 = new GoalRoomPendingMember(null, GoalRoomRole.FOLLOWER, - LocalDateTime.now(), savedGoalRoom, member2.getId()); + LocalDateTime.now(), goalRoom, member2.getId()); final GoalRoomPendingMember goalRoomPendingMember3 = new GoalRoomPendingMember(null, GoalRoomRole.FOLLOWER, - LocalDateTime.now(), savedGoalRoom, member3.getId()); + LocalDateTime.now(), goalRoom, member3.getId()); goalRoomPendingMemberRepository.saveAll( List.of(goalRoomPendingMember0, goalRoomPendingMember1, goalRoomPendingMember2, goalRoomPendingMember3)); @@ -339,9 +318,9 @@ public GoalRoomPendingMemberRepositoryTest(final MemberRepository memberReposito // when final List goalRoomPendingMembers1 = goalRoomPendingMemberRepository.findByGoalRoomIdOrderedBySortType( - savedGoalRoom.getId(), GoalRoomMemberSortType.ACCOMPLISHMENT_RATE); + goalRoom.getId(), GoalRoomMemberSortType.ACCOMPLISHMENT_RATE); final List goalRoomPendingMembers2 = goalRoomPendingMemberRepository.findByGoalRoomIdOrderedBySortType( - savedGoalRoom.getId(), null); + goalRoom.getId(), null); // then assertThat(goalRoomPendingMembers1) @@ -371,19 +350,23 @@ public GoalRoomPendingMemberRepositoryTest(final MemberRepository memberReposito return memberRepository.save(member); } - private RoadmapCategory 카테고리를_저장한다(final String name) { + private RoadmapCategory 카테고리를_생성한다(final String name) { final RoadmapCategory roadmapCategory = new RoadmapCategory(name); return roadmapCategoryRepository.save(roadmapCategory); } - private Roadmap 로드맵을_저장한다(final Member creator, final RoadmapCategory category) { - final List roadmapNodes = 로드맵_노드들을_생성한다(); - final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmapNodes); - final Roadmap roadmap = new Roadmap("로드맵 제목", "로드맵 소개글", 10, RoadmapDifficulty.NORMAL, creator, category); - roadmap.addContent(roadmapContent); + private Roadmap 로드맵을_저장한다(final String title, final Member creator, final RoadmapCategory category) { + final Roadmap roadmap = new Roadmap(title, "로드맵 소개글", 10, RoadmapDifficulty.NORMAL, creator.getId(), category, + new RoadmapTags(new ArrayList<>())); return roadmapRepository.save(roadmap); } + private RoadmapContent 로드맵_본문을_저장한다(final Long roadmapId) { + final List roadmapNodes = 로드맵_노드들을_생성한다(); + final RoadmapContent roadmapContent = new RoadmapContent("로드맵 본문", roadmapId, new RoadmapNodes(roadmapNodes)); + return roadmapContentRepository.save(roadmapContent); + } + private List 로드맵_노드들을_생성한다() { final RoadmapNode roadmapNode1 = new RoadmapNode("로드맵 1주차", "로드맵 1주차 내용"); roadmapNode1.addImages(new RoadmapNodeImages(노드_이미지들을_생성한다())); @@ -391,12 +374,6 @@ public GoalRoomPendingMemberRepositoryTest(final MemberRepository memberReposito return List.of(roadmapNode1, roadmapNode2); } - private RoadmapContent 로드맵_본문을_생성한다(final List roadmapNodes) { - final RoadmapContent roadmapContent = new RoadmapContent("로드맵 본문"); - roadmapContent.addNodes(new RoadmapNodes(roadmapNodes)); - return roadmapContent; - } - private List 노드_이미지들을_생성한다() { return List.of( new RoadmapNodeImage("node-image1.png", "node-image1-save-path", ImageContentType.PNG), @@ -404,7 +381,7 @@ public GoalRoomPendingMemberRepositoryTest(final MemberRepository memberReposito ); } - private GoalRoom 골룸을_생성한다(final RoadmapContent roadmapContent, final Member member) { + private GoalRoom 골룸을_저장한다(final RoadmapContent roadmapContent, final Member member) { final List roadmapNodes = roadmapContent.getNodes().getValues(); final RoadmapNode firstRoadmapNode = roadmapNodes.get(0); @@ -420,7 +397,9 @@ public GoalRoomPendingMemberRepositoryTest(final MemberRepository memberReposito final GoalRoomRoadmapNodes goalRoomRoadmapNodes = new GoalRoomRoadmapNodes( List.of(firstGoalRoomRoadmapNode, secondGoalRoomRoadmapNode)); - return new GoalRoom(new GoalRoomName("골룸"), new LimitedMemberCount(10), roadmapContent.getId(), + final GoalRoom goalRoom = new GoalRoom(new GoalRoomName("골룸"), new LimitedMemberCount(10), + roadmapContent.getId(), goalRoomRoadmapNodes); + return goalRoomRepository.save(goalRoom); } } diff --git a/backend/kirikiri/src/test/java/co/kirikiri/goalroom/persistence/GoalRoomRepositoryTest.java b/backend/kirikiri/src/test/java/co/kirikiri/goalroom/persistence/GoalRoomRepositoryTest.java index 9898ba6e1..6a257de5e 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/goalroom/persistence/GoalRoomRepositoryTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/goalroom/persistence/GoalRoomRepositoryTest.java @@ -4,19 +4,6 @@ import static org.junit.jupiter.api.Assertions.assertAll; import co.kirikiri.common.helper.RepositoryTest; -import co.kirikiri.domain.member.EncryptedPassword; -import co.kirikiri.domain.member.Gender; -import co.kirikiri.domain.member.Member; -import co.kirikiri.domain.member.MemberProfile; -import co.kirikiri.domain.member.vo.Identifier; -import co.kirikiri.domain.member.vo.Nickname; -import co.kirikiri.domain.member.vo.Password; -import co.kirikiri.domain.roadmap.Roadmap; -import co.kirikiri.domain.roadmap.RoadmapCategory; -import co.kirikiri.domain.roadmap.RoadmapContent; -import co.kirikiri.domain.roadmap.RoadmapDifficulty; -import co.kirikiri.domain.roadmap.RoadmapNode; -import co.kirikiri.domain.roadmap.RoadmapNodes; import co.kirikiri.goalroom.domain.GoalRoom; import co.kirikiri.goalroom.domain.GoalRoomMember; import co.kirikiri.goalroom.domain.GoalRoomPendingMember; @@ -28,13 +15,29 @@ import co.kirikiri.goalroom.domain.vo.LimitedMemberCount; import co.kirikiri.goalroom.domain.vo.Period; import co.kirikiri.goalroom.persistence.dto.RoadmapGoalRoomsOrderType; -import co.kirikiri.persistence.member.MemberRepository; -import co.kirikiri.persistence.roadmap.RoadmapCategoryRepository; -import co.kirikiri.persistence.roadmap.RoadmapRepository; +import co.kirikiri.member.domain.EncryptedPassword; +import co.kirikiri.member.domain.Gender; +import co.kirikiri.member.domain.Member; +import co.kirikiri.member.domain.MemberProfile; +import co.kirikiri.member.domain.vo.Identifier; +import co.kirikiri.member.domain.vo.Nickname; +import co.kirikiri.member.domain.vo.Password; +import co.kirikiri.member.persistence.MemberRepository; +import co.kirikiri.roadmap.domain.Roadmap; +import co.kirikiri.roadmap.domain.RoadmapCategory; +import co.kirikiri.roadmap.domain.RoadmapContent; +import co.kirikiri.roadmap.domain.RoadmapDifficulty; +import co.kirikiri.roadmap.domain.RoadmapNode; +import co.kirikiri.roadmap.domain.RoadmapNodes; +import co.kirikiri.roadmap.domain.RoadmapTags; +import co.kirikiri.roadmap.persistence.RoadmapCategoryRepository; +import co.kirikiri.roadmap.persistence.RoadmapContentRepository; +import co.kirikiri.roadmap.persistence.RoadmapRepository; +import org.junit.jupiter.api.Test; import java.time.LocalDate; import java.time.LocalDateTime; +import java.util.ArrayList; import java.util.List; -import org.junit.jupiter.api.Test; @RepositoryTest class GoalRoomRepositoryTest { @@ -45,24 +48,27 @@ class GoalRoomRepositoryTest { private static final LocalDate THIRTY_DAY_LATER = TODAY.plusDays(30); private final MemberRepository memberRepository; + private final RoadmapCategoryRepository roadmapCategoryRepository; private final RoadmapRepository roadmapRepository; + private final RoadmapContentRepository roadmapContentRepository; private final GoalRoomRepository goalRoomRepository; private final GoalRoomPendingMemberRepository goalRoomPendingMemberRepository; private final GoalRoomMemberRepository goalRoomMemberRepository; - private final RoadmapCategoryRepository roadmapCategoryRepository; public GoalRoomRepositoryTest(final MemberRepository memberRepository, + final RoadmapCategoryRepository roadmapCategoryRepository, final RoadmapRepository roadmapRepository, final GoalRoomRepository goalRoomRepository, final GoalRoomPendingMemberRepository goalRoomPendingMemberRepository, final GoalRoomMemberRepository goalRoomMemberRepository, - final RoadmapCategoryRepository roadmapCategoryRepository) { + final RoadmapContentRepository roadmapContentRepository) { this.memberRepository = memberRepository; + this.roadmapCategoryRepository = roadmapCategoryRepository; this.roadmapRepository = roadmapRepository; + this.roadmapContentRepository = roadmapContentRepository; this.goalRoomRepository = goalRoomRepository; this.goalRoomPendingMemberRepository = goalRoomPendingMemberRepository; this.goalRoomMemberRepository = goalRoomMemberRepository; - this.roadmapCategoryRepository = roadmapCategoryRepository; } @Test @@ -70,10 +76,11 @@ public GoalRoomRepositoryTest(final MemberRepository memberRepository, //given final Member creator = 사용자를_생성한다("name1", "kirikiri@email.com", "identifier1", "password!1"); final RoadmapCategory category = 카테고리를_저장한다("여가"); + final Roadmap roadmap = 로드맵을_저장한다(creator, category); + final RoadmapNode roadmapNode1 = 로드맵_노드를_생성한다("로드맵 1주차", "로드맵 1주차 내용"); final RoadmapNode roadmapNode2 = 로드맵_노드를_생성한다("로드맵 2주차", "로드맵 2주차 내용"); - final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(List.of(roadmapNode1, roadmapNode2)); - 로드맵을_생성한다(creator, category, roadmapContent); + final RoadmapContent roadmapContent = 로드맵_본문을_저장한다(List.of(roadmapNode1, roadmapNode2), roadmap.getId()); final GoalRoomRoadmapNode goalRoomRoadmapNode1 = 골룸_로드맵_노드를_생성한다(TODAY, TODAY.plusDays(10), roadmapNode1); @@ -100,10 +107,11 @@ public GoalRoomRepositoryTest(final MemberRepository memberRepository, //given final Member creator = 사용자를_생성한다("name1", "kirikiri@email.com", "identifier1", "password!1"); final RoadmapCategory category = 카테고리를_저장한다("여가"); + final Roadmap roadmap = 로드맵을_저장한다(creator, category); + final RoadmapNode roadmapNode1 = 로드맵_노드를_생성한다("로드맵 1주차", "로드맵 1주차 내용"); final RoadmapNode roadmapNode2 = 로드맵_노드를_생성한다("로드맵 2주차", "로드맵 2주차 내용"); - final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(List.of(roadmapNode1, roadmapNode2)); - final Roadmap roadmap = 로드맵을_생성한다(creator, category, roadmapContent); + final RoadmapContent roadmapContent = 로드맵_본문을_저장한다(List.of(roadmapNode1, roadmapNode2), roadmap.getId()); final GoalRoomRoadmapNode goalRoomRoadmapNode1 = 골룸_로드맵_노드를_생성한다(TODAY, TODAY.plusDays(10), roadmapNode1); @@ -142,10 +150,11 @@ public GoalRoomRepositoryTest(final MemberRepository memberRepository, //given final Member creator = 사용자를_생성한다("name1", "kirikiri@email.com", "identifier1", "password!1"); final RoadmapCategory category = 카테고리를_저장한다("여가"); + final Roadmap roadmap = 로드맵을_저장한다(creator, category); + final RoadmapNode roadmapNode1 = 로드맵_노드를_생성한다("로드맵 1주차", "로드맵 1주차 내용"); final RoadmapNode roadmapNode2 = 로드맵_노드를_생성한다("로드맵 2주차", "로드맵 2주차 내용"); - final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(List.of(roadmapNode1, roadmapNode2)); - final Roadmap roadmap = 로드맵을_생성한다(creator, category, roadmapContent); + final RoadmapContent roadmapContent = 로드맵_본문을_저장한다(List.of(roadmapNode1, roadmapNode2), roadmap.getId()); final GoalRoomRoadmapNode goalRoomRoadmapNode1 = 골룸_로드맵_노드를_생성한다(TODAY, TODAY.plusDays(10), roadmapNode1); final GoalRoomRoadmapNode goalRoomRoadmapNode2 = 골룸_로드맵_노드를_생성한다(TODAY.plusDays(11), TODAY.plusDays(20), @@ -182,9 +191,10 @@ public GoalRoomRepositoryTest(final MemberRepository memberRepository, //given final Member creator = 크리에이터를_저장한다(); final RoadmapCategory category = 카테고리를_저장한다("게임"); + final Roadmap roadmap = 로드맵을_저장한다(creator, category); + final RoadmapNode roadmapNode1 = 로드맵_노드를_생성한다("로드맵 1주차", "로드맵 1주차 내용"); - final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(List.of(roadmapNode1)); - 로드맵을_생성한다(creator, category, roadmapContent); + final RoadmapContent roadmapContent = 로드맵_본문을_저장한다(List.of(roadmapNode1), roadmap.getId()); final GoalRoomRoadmapNode goalRoomRoadmapNode1 = 골룸_로드맵_노드를_생성한다(TODAY, TODAY.plusDays(10), roadmapNode1); @@ -201,8 +211,8 @@ public GoalRoomRepositoryTest(final MemberRepository memberRepository, new GoalRoomRoadmapNodes(List.of(goalRoomRoadmapNode2)), creator); final GoalRoom goalRoom3 = 골룸을_생성한다("goalroom3", 20, roadmapContent, new GoalRoomRoadmapNodes(List.of(goalRoomRoadmapNode3)), creator); - final GoalRoom goalRoom4 = 골룸을_생성한다("goalroom3", 20, roadmapContent, - new GoalRoomRoadmapNodes(List.of(goalRoomRoadmapNode3)), creator); + final GoalRoom goalRoom4 = 골룸을_생성한다("goalroom4", 20, roadmapContent, + new GoalRoomRoadmapNodes(List.of(goalRoomRoadmapNode4)), creator); final Member member = 사용자를_생성한다("팔로워", "010-111-1111", "identifier2", "password2@"); final Long memberId = member.getId(); @@ -251,9 +261,10 @@ public GoalRoomRepositoryTest(final MemberRepository memberRepository, //given final Member creator = 크리에이터를_저장한다(); final RoadmapCategory category = 카테고리를_저장한다("게임"); + final Roadmap roadmap = 로드맵을_저장한다(creator, category); + final RoadmapNode roadmapNode1 = 로드맵_노드를_생성한다("로드맵 1주차", "로드맵 1주차 내용"); - final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(List.of(roadmapNode1)); - 로드맵을_생성한다(creator, category, roadmapContent); + final RoadmapContent roadmapContent = 로드맵_본문을_저장한다(List.of(roadmapNode1), roadmap.getId()); final GoalRoomRoadmapNode goalRoomRoadmapNode1 = 골룸_로드맵_노드를_생성한다(TODAY, TODAY.plusDays(10), roadmapNode1); @@ -270,8 +281,8 @@ public GoalRoomRepositoryTest(final MemberRepository memberRepository, new GoalRoomRoadmapNodes(List.of(goalRoomRoadmapNode2)), creator); final GoalRoom goalRoom3 = 골룸을_생성한다("goalroom3", 20, roadmapContent, new GoalRoomRoadmapNodes(List.of(goalRoomRoadmapNode3)), creator); - final GoalRoom goalRoom4 = 골룸을_생성한다("goalroom3", 20, roadmapContent, - new GoalRoomRoadmapNodes(List.of(goalRoomRoadmapNode3)), creator); + final GoalRoom goalRoom4 = 골룸을_생성한다("goalroom4", 20, roadmapContent, + new GoalRoomRoadmapNodes(List.of(goalRoomRoadmapNode4)), creator); final Member member = 사용자를_생성한다("팔로워", "010-111-1111", "identifier2", "password2@"); final Long memberId = member.getId(); @@ -298,7 +309,7 @@ public GoalRoomRepositoryTest(final MemberRepository memberRepository, new GoalRoomMember(GoalRoomRole.FOLLOWER, LocalDateTime.now(), goalRoom3, memberId)); goalRoomPendingMemberRepository.save( new GoalRoomPendingMember(GoalRoomRole.FOLLOWER, goalRoom4, memberId)); - + goalRoom2.start(); goalRoom3.complete(); @@ -328,10 +339,11 @@ public GoalRoomRepositoryTest(final MemberRepository memberRepository, void 노드와_함께_골룸을_조회한다() { final Member creator = 사용자를_생성한다("name1", "kirikiri@email.com", "identifier1", "password!1"); final RoadmapCategory category = 카테고리를_저장한다("여가"); + final Roadmap roadmap = 로드맵을_저장한다(creator, category); + final RoadmapNode roadmapNode1 = 로드맵_노드를_생성한다("로드맵 1주차", "로드맵 1주차 내용"); final RoadmapNode roadmapNode2 = 로드맵_노드를_생성한다("로드맵 2주차", "로드맵 2주차 내용"); - final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(List.of(roadmapNode1, roadmapNode2)); - 로드맵을_생성한다(creator, category, roadmapContent); + final RoadmapContent roadmapContent = 로드맵_본문을_저장한다(List.of(roadmapNode1, roadmapNode2), roadmap.getId()); final GoalRoomRoadmapNode goalRoomRoadmapNode1 = 골룸_로드맵_노드를_생성한다(TODAY, TODAY.plusDays(10), roadmapNode1); @@ -357,9 +369,10 @@ public GoalRoomRepositoryTest(final MemberRepository memberRepository, //given final Member creator = 크리에이터를_저장한다(); final RoadmapCategory category = 카테고리를_저장한다("게임"); + final Roadmap roadmap = 로드맵을_저장한다(creator, category); + final RoadmapNode roadmapNode = 로드맵_노드를_생성한다("로드맵 1주차", "로드맵 1주차 내용"); - final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(List.of(roadmapNode)); - final Roadmap roadmap = 로드맵을_생성한다(creator, category, roadmapContent); + final RoadmapContent roadmapContent = 로드맵_본문을_저장한다(List.of(roadmapNode), roadmap.getId()); final GoalRoomRoadmapNode goalRoomRoadmapNode1 = 골룸_로드맵_노드를_생성한다(TODAY, TEN_DAY_LATER, roadmapNode); @@ -389,17 +402,16 @@ public GoalRoomRepositoryTest(final MemberRepository memberRepository, // given final Member creator = 사용자를_생성한다("name1", "kirikiri@email.com", "identifier1", "password!1"); final RoadmapCategory category = 카테고리를_저장한다("여가"); + + final Roadmap roadmap1 = 로드맵을_저장한다(creator, category); final RoadmapNode roadmapNode1 = 로드맵_노드를_생성한다("로드맵 1주차", "로드맵 1주차 내용"); final RoadmapNode roadmapNode2 = 로드맵_노드를_생성한다("로드맵 2주차", "로드맵 2주차 내용"); + final RoadmapContent roadmapContent1 = 로드맵_본문을_저장한다(List.of(roadmapNode1, roadmapNode2), roadmap1.getId()); - final RoadmapContent roadmapContent1 = 로드맵_본문을_생성한다(List.of(roadmapNode1, roadmapNode2)); - final Roadmap roadmap1 = 로드맵을_생성한다(creator, category, roadmapContent1); - + final Roadmap roadmap2 = 로드맵을_저장한다(creator, category); final RoadmapNode roadmapNode3 = 로드맵_노드를_생성한다("로드맵 1주차 입니다.", "로드맵 1주차 내용"); final RoadmapNode roadmapNode4 = 로드맵_노드를_생성한다("로드맵 2주차 입니다.", "로드맵 2주차 내용"); - - final RoadmapContent roadmapContent2 = 로드맵_본문을_생성한다(List.of(roadmapNode3, roadmapNode4)); - 로드맵을_생성한다(creator, category, roadmapContent2); + final RoadmapContent roadmapContent2 = 로드맵_본문을_저장한다(List.of(roadmapNode3, roadmapNode4), roadmap2.getId()); final Member member = 사용자를_생성한다("name2", "kirikiri@email.com", "identifier2", "password!2"); @@ -431,9 +443,10 @@ public GoalRoomRepositoryTest(final MemberRepository memberRepository, // given final Member creator = 크리에이터를_저장한다(); final RoadmapCategory category = 카테고리를_저장한다("게임"); + final Roadmap roadmap = 로드맵을_저장한다(creator, category); + final RoadmapNode roadmapNode1 = 로드맵_노드를_생성한다("로드맵 1주차", "로드맵 1주차 내용"); - final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(List.of(roadmapNode1)); - 로드맵을_생성한다(creator, category, roadmapContent); + final RoadmapContent roadmapContent = 로드맵_본문을_저장한다(List.of(roadmapNode1), roadmap.getId()); final GoalRoomRoadmapNode goalRoomRoadmapNode1 = 골룸_로드맵_노드를_생성한다(TODAY, TODAY.plusDays(10), roadmapNode1); @@ -469,9 +482,10 @@ public GoalRoomRepositoryTest(final MemberRepository memberRepository, //given final Member creator = 크리에이터를_저장한다(); final RoadmapCategory category = 카테고리를_저장한다("게임"); + final Roadmap roadmap = 로드맵을_저장한다(creator, category); + final RoadmapNode roadmapNode = 로드맵_노드를_생성한다("로드맵 1주차", "로드맵 1주차 내용"); - final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(List.of(roadmapNode)); - 로드맵을_생성한다(creator, category, roadmapContent); + final RoadmapContent roadmapContent = 로드맵_본문을_저장한다(List.of(roadmapNode), roadmap.getId()); final GoalRoomRoadmapNode todayGoalRoomRoadmapNode = 골룸_로드맵_노드를_생성한다(TODAY, TEN_DAY_LATER, roadmapNode); @@ -518,17 +532,14 @@ public GoalRoomRepositoryTest(final MemberRepository memberRepository, return new RoadmapNode(title, content); } - private RoadmapContent 로드맵_본문을_생성한다(final List roadmapNodes) { - final RoadmapContent roadmapContent = new RoadmapContent("로드맵 본문"); - roadmapContent.addNodes(new RoadmapNodes(roadmapNodes)); - return roadmapContent; + private RoadmapContent 로드맵_본문을_저장한다(final List roadmapNodes, final Long roadmapId) { + final RoadmapContent roadmapContent = new RoadmapContent("로드맵 본문", roadmapId, new RoadmapNodes(roadmapNodes)); + return roadmapContentRepository.save(roadmapContent); } - private Roadmap 로드맵을_생성한다(final Member creator, final RoadmapCategory category, - final RoadmapContent roadmapContent) { + private Roadmap 로드맵을_저장한다(final Member creator, final RoadmapCategory category) { final Roadmap roadmap = new Roadmap("로드맵 제목", "로드맵 소개글", 30, RoadmapDifficulty.DIFFICULT, - creator, category); - roadmap.addContent(roadmapContent); + creator.getId(), category, new RoadmapTags(new ArrayList<>())); return roadmapRepository.save(roadmap); } diff --git a/backend/kirikiri/src/test/java/co/kirikiri/goalroom/service/GoalRoomCreateEventListenerTest.java b/backend/kirikiri/src/test/java/co/kirikiri/goalroom/service/GoalRoomCreateEventListenerTest.java index c08f168cf..98a1e3de3 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/goalroom/service/GoalRoomCreateEventListenerTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/goalroom/service/GoalRoomCreateEventListenerTest.java @@ -7,13 +7,6 @@ import static org.mockito.BDDMockito.given; import co.kirikiri.common.exception.NotFoundException; -import co.kirikiri.domain.member.EncryptedPassword; -import co.kirikiri.domain.member.Gender; -import co.kirikiri.domain.member.Member; -import co.kirikiri.domain.member.MemberProfile; -import co.kirikiri.domain.member.vo.Identifier; -import co.kirikiri.domain.member.vo.Nickname; -import co.kirikiri.domain.member.vo.Password; import co.kirikiri.goalroom.domain.GoalRoom; import co.kirikiri.goalroom.domain.GoalRoomRoadmapNode; import co.kirikiri.goalroom.domain.GoalRoomRoadmapNodes; @@ -23,7 +16,14 @@ import co.kirikiri.goalroom.persistence.GoalRoomPendingMemberRepository; import co.kirikiri.goalroom.persistence.GoalRoomRepository; import co.kirikiri.goalroom.service.event.GoalRoomCreateEvent; -import co.kirikiri.persistence.member.MemberRepository; +import co.kirikiri.member.domain.EncryptedPassword; +import co.kirikiri.member.domain.Gender; +import co.kirikiri.member.domain.Member; +import co.kirikiri.member.domain.MemberProfile; +import co.kirikiri.member.domain.vo.Identifier; +import co.kirikiri.member.domain.vo.Nickname; +import co.kirikiri.member.domain.vo.Password; +import co.kirikiri.member.persistence.MemberRepository; import java.time.LocalDate; import java.util.List; import java.util.Optional; diff --git a/backend/kirikiri/src/test/java/co/kirikiri/goalroom/service/GoalRoomCreateServiceTest.java b/backend/kirikiri/src/test/java/co/kirikiri/goalroom/service/GoalRoomCreateServiceTest.java index db560e537..738a7010e 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/goalroom/service/GoalRoomCreateServiceTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/goalroom/service/GoalRoomCreateServiceTest.java @@ -17,23 +17,6 @@ import co.kirikiri.common.service.FilePathGenerator; import co.kirikiri.common.service.FileService; import co.kirikiri.common.type.ImageContentType; -import co.kirikiri.domain.member.EncryptedPassword; -import co.kirikiri.domain.member.Gender; -import co.kirikiri.domain.member.Member; -import co.kirikiri.domain.member.MemberProfile; -import co.kirikiri.domain.member.vo.Identifier; -import co.kirikiri.domain.member.vo.Nickname; -import co.kirikiri.domain.member.vo.Password; -import co.kirikiri.domain.roadmap.Roadmap; -import co.kirikiri.domain.roadmap.RoadmapCategory; -import co.kirikiri.domain.roadmap.RoadmapContent; -import co.kirikiri.domain.roadmap.RoadmapContents; -import co.kirikiri.domain.roadmap.RoadmapDifficulty; -import co.kirikiri.domain.roadmap.RoadmapNode; -import co.kirikiri.domain.roadmap.RoadmapNodeImage; -import co.kirikiri.domain.roadmap.RoadmapNodeImages; -import co.kirikiri.domain.roadmap.RoadmapNodes; -import co.kirikiri.domain.roadmap.RoadmapStatus; import co.kirikiri.goalroom.domain.GoalRoom; import co.kirikiri.goalroom.domain.GoalRoomPendingMember; import co.kirikiri.goalroom.domain.GoalRoomRoadmapNode; @@ -47,8 +30,25 @@ import co.kirikiri.goalroom.persistence.GoalRoomRepository; import co.kirikiri.goalroom.service.dto.request.GoalRoomCreateRequest; import co.kirikiri.goalroom.service.dto.request.GoalRoomRoadmapNodeRequest; -import co.kirikiri.persistence.member.MemberRepository; -import co.kirikiri.persistence.roadmap.RoadmapContentRepository; +import co.kirikiri.member.domain.EncryptedPassword; +import co.kirikiri.member.domain.Gender; +import co.kirikiri.member.domain.Member; +import co.kirikiri.member.domain.MemberProfile; +import co.kirikiri.member.domain.vo.Identifier; +import co.kirikiri.member.domain.vo.Nickname; +import co.kirikiri.member.domain.vo.Password; +import co.kirikiri.member.persistence.MemberRepository; +import co.kirikiri.roadmap.domain.Roadmap; +import co.kirikiri.roadmap.domain.RoadmapCategory; +import co.kirikiri.roadmap.domain.RoadmapContent; +import co.kirikiri.roadmap.domain.RoadmapDifficulty; +import co.kirikiri.roadmap.domain.RoadmapNode; +import co.kirikiri.roadmap.domain.RoadmapNodeImage; +import co.kirikiri.roadmap.domain.RoadmapNodeImages; +import co.kirikiri.roadmap.domain.RoadmapNodes; +import co.kirikiri.roadmap.domain.RoadmapStatus; +import co.kirikiri.roadmap.persistence.RoadmapContentRepository; +import co.kirikiri.roadmap.persistence.RoadmapRepository; import co.kirikiri.todo.persistence.GoalRoomToDoCheckRepository; import java.time.LocalDate; import java.util.ArrayList; @@ -68,22 +68,20 @@ class GoalRoomCreateServiceTest { private static final LocalDate TODAY = LocalDate.now(); private static final LocalDate TEN_DAY_LATER = TODAY.plusDays(10); private static final LocalDate TWENTY_DAY_LATER = TODAY.plusDays(20); - - private static final RoadmapNode ROADMAP_NODE = new RoadmapNode(1L, "title", "content"); - private static final RoadmapContent ROADMAP_CONTENT = new RoadmapContent(1L, "content"); - private static final RoadmapContent DELETED_ROADMAP_CONTENT = new RoadmapContent(2L, "content2"); - private static final RoadmapNodes ROADMAP_CONTENTS = new RoadmapNodes(new ArrayList<>(List.of(ROADMAP_NODE))); - private static final Member MEMBER = new Member(1L, new Identifier("identifier2"), null, new EncryptedPassword(new Password("password!2")), new Nickname("name2"), null, new MemberProfile(Gender.FEMALE, "kirikiri@email.com")); - private static final Roadmap ROADMAP = new Roadmap("roadmap", "introduction", 30, RoadmapDifficulty.DIFFICULT, - MEMBER, new RoadmapCategory("IT")); - + MEMBER.getId(), new RoadmapCategory("IT"), null); private static final Roadmap DELETED_ROADMAP = new Roadmap("roadmap", "introduction", 30, - RoadmapDifficulty.DIFFICULT, RoadmapStatus.DELETED, MEMBER, new RoadmapCategory("IT")); + RoadmapDifficulty.DIFFICULT, RoadmapStatus.DELETED, MEMBER.getId(), new RoadmapCategory("IT"), null); + private static final RoadmapNode ROADMAP_NODE = new RoadmapNode(1L, "title", "content"); + private static final RoadmapNodes ROADMAP_NODES = new RoadmapNodes(new ArrayList<>(List.of(ROADMAP_NODE))); + private static final RoadmapContent ROADMAP_CONTENT = new RoadmapContent(1L, "content", ROADMAP.getId(), + ROADMAP_NODES); + private static final RoadmapContent DELETED_ROADMAP_CONTENT = new RoadmapContent(2L, "content2", + DELETED_ROADMAP.getId(), ROADMAP_NODES); private static Member member; @@ -99,6 +97,9 @@ class GoalRoomCreateServiceTest { @Mock private RoadmapContentRepository roadmapContentRepository; + @Mock + private RoadmapRepository roadmapRepository; + @Mock private MemberRepository memberRepository; @@ -122,9 +123,6 @@ class GoalRoomCreateServiceTest { @BeforeAll static void setUp() { - ROADMAP_CONTENT.addNodes(ROADMAP_CONTENTS); - ROADMAP.addContent(ROADMAP_CONTENT); - DELETED_ROADMAP.addContent(DELETED_ROADMAP_CONTENT); final Identifier identifier = new Identifier("identifier1"); final Password password = new Password("password1!"); final EncryptedPassword encryptedPassword = new EncryptedPassword(password); @@ -142,8 +140,10 @@ static void setUp() { final List goalRoomRoadmapNodes = List.of( new GoalRoomRoadmapNode(new Period(TODAY, TEN_DAY_LATER), 10, 1L)); - given(roadmapContentRepository.findByIdWithRoadmap(anyLong())) + given(roadmapContentRepository.findById(anyLong())) .willReturn(Optional.of(ROADMAP_CONTENT)); + given(roadmapRepository.findById(any())) + .willReturn(Optional.of(ROADMAP)); given(goalRoomRepository.save(any())) .willReturn(new GoalRoom(1L, new GoalRoomName("name"), new LimitedMemberCount(20), 1L, new GoalRoomRoadmapNodes(goalRoomRoadmapNodes))); @@ -158,8 +158,10 @@ static void setUp() { final GoalRoomCreateRequest request = new GoalRoomCreateRequest(1L, "name", 20, new ArrayList<>(List.of(new GoalRoomRoadmapNodeRequest(1L, 10, TODAY, TEN_DAY_LATER)))); - given(roadmapContentRepository.findByIdWithRoadmap(anyLong())) + given(roadmapContentRepository.findById(anyLong())) .willReturn(Optional.of(DELETED_ROADMAP_CONTENT)); + given(roadmapRepository.findById(any())) + .willReturn(Optional.of(DELETED_ROADMAP)); //when //then @@ -173,7 +175,7 @@ static void setUp() { final GoalRoomCreateRequest request = new GoalRoomCreateRequest(1L, "name", 20, new ArrayList<>(List.of(new GoalRoomRoadmapNodeRequest(1L, 10, TODAY, TEN_DAY_LATER)))); - given(roadmapContentRepository.findByIdWithRoadmap(anyLong())) + given(roadmapContentRepository.findById(anyLong())) .willReturn(Optional.empty()); //when @@ -191,8 +193,10 @@ static void setUp() { final GoalRoomCreateRequest request = new GoalRoomCreateRequest(1L, "name", 20, wrongSizeGoalRoomRoadmapNodeRequest); - given(roadmapContentRepository.findByIdWithRoadmap(anyLong())) + given(roadmapContentRepository.findById(anyLong())) .willReturn(Optional.of(ROADMAP_CONTENT)); + given(roadmapRepository.findById(any())) + .willReturn(Optional.of(ROADMAP)); //when //then @@ -208,8 +212,10 @@ static void setUp() { 20, new ArrayList<>(List.of(new GoalRoomRoadmapNodeRequest(wrongRoadmapNodId, 10, TODAY, TEN_DAY_LATER)))); - given(roadmapContentRepository.findByIdWithRoadmap(anyLong())) + given(roadmapContentRepository.findById(anyLong())) .willReturn(Optional.of(ROADMAP_CONTENT)); + given(roadmapRepository.findById(any())) + .willReturn(Optional.of(ROADMAP)); //when //then @@ -222,10 +228,10 @@ static void setUp() { //given final Member creator = 사용자를_생성한다(1L, "cokirikiri", "password1!", "시진이", "kirikiri1@email"); final Roadmap roadmap = 로드맵을_생성한다(creator); - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); + final List roadmapNodes = 로드맵_노드들을_생성한다(); + final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmap.getId(), roadmapNodes); final int limitedMemberCount = 20; - final GoalRoom goalRoom = 골룸을_생성한다(1L, creator, targetRoadmapContent, limitedMemberCount); + final GoalRoom goalRoom = 골룸을_생성한다(1L, creator, roadmapContent, limitedMemberCount); final Member follower = 사용자를_생성한다(2L, "identifier2", "password1!", "팔로워", "kirikiri1@email"); when(memberRepository.findByIdentifier(any())) @@ -275,10 +281,10 @@ static void setUp() { //given final Member creator = 사용자를_생성한다(1L, "identifier1", "password1!", "시진이", "kirikiri1@email"); final Roadmap roadmap = 로드맵을_생성한다(creator); - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); + final List roadmapNodes = 로드맵_노드들을_생성한다(); + final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmap.getId(), roadmapNodes); final int limitedMemberCount = 1; - final GoalRoom goalRoom = 골룸을_생성한다(1L, creator, targetRoadmapContent, limitedMemberCount); + final GoalRoom goalRoom = 골룸을_생성한다(1L, creator, roadmapContent, limitedMemberCount); final Member follower = 사용자를_생성한다(1L, "identifier2", "password1!", "팔로워", "kirikiri1@email"); when(memberRepository.findByIdentifier(any())) @@ -297,9 +303,10 @@ static void setUp() { @Test void 골룸_참가_요청시_모집_중이_아닌_경우_예외가_발생한다() { //given + final Member creator = 사용자를_생성한다(1L, "cokirikiri", "password1!", "코끼리", "kirikiri1@email"); + final Roadmap roadmap = 로드맵을_생성한다(creator); final List roadmapNodes = 로드맵_노드들을_생성한다(); - final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmapNodes); - final Member creator = 사용자를_생성한다(1L, "identifier1", "password1!", "시진이", "kirikiri1@email"); + final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmap.getId(), roadmapNodes); final int limitedMemberCount = 20; final GoalRoom goalRoom = 골룸을_생성한다(1L, creator, roadmapContent, limitedMemberCount); final Member follower = 사용자를_생성한다(2L, "identifier2", "password2!", "팔로워", "kirikiri1@email"); @@ -321,9 +328,10 @@ static void setUp() { @Test void 골룸_참가_요청시_이미_챰가한_골룸인_경우_예외가_발생한다() { //given + final Member creator = 사용자를_생성한다(1L, "cokirikiri", "password1!", "코끼리", "kirikiri1@email"); + final Roadmap roadmap = 로드맵을_생성한다(creator); final List roadmapNodes = 로드맵_노드들을_생성한다(); - final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmapNodes); - final Member creator = 사용자를_생성한다(1L, "identifier1", "password1!", "시진이", "kirikiri1@email"); + final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmap.getId(), roadmapNodes); final int limitedMemberCount = 20; final GoalRoom goalRoom = 골룸을_생성한다(1L, creator, roadmapContent, limitedMemberCount); @@ -346,9 +354,9 @@ static void setUp() { final Member creator = 사용자를_생성한다(1L, "cokirikiri", "password1!", "코끼리", "kirikiri1@email"); final Roadmap roadmap = 로드맵을_생성한다(creator); - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); - final GoalRoom goalRoom = 골룸을_생성한다(1L, creator, targetRoadmapContent, 10); + final List roadmapNodes = 로드맵_노드들을_생성한다(); + final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmap.getId(), roadmapNodes); + final GoalRoom goalRoom = 골룸을_생성한다(1L, creator, roadmapContent, 10); when(memberRepository.findByIdentifier(any())) .thenReturn(Optional.of(creator)); @@ -400,9 +408,9 @@ static void setUp() { final Member follower = 사용자를_생성한다(2L, "kirikirico", "password2!", "끼리코", "kirikiri1@email"); final Roadmap roadmap = 로드맵을_생성한다(creator); - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); - final GoalRoom goalRoom = 골룸을_생성한다(1L, creator, targetRoadmapContent, 10); + final List roadmapNodes = 로드맵_노드들을_생성한다(); + final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmap.getId(), roadmapNodes); + final GoalRoom goalRoom = 골룸을_생성한다(1L, creator, roadmapContent, 10); when(memberRepository.findByIdentifier(any())) .thenReturn(Optional.of(follower)); @@ -421,10 +429,10 @@ static void setUp() { // given final Member creator = 사용자를_생성한다(1L, "cokirikiri", "password1!", "코끼리", "kirikiri1@email"); final Roadmap roadmap = 로드맵을_생성한다(creator); + final List roadmapNodes = 로드맵_노드들을_생성한다(); + final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmap.getId(), roadmapNodes); - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); - final GoalRoom goalRoom = 시작_날짜가_미래인_골룸을_생성한다(1L, creator, targetRoadmapContent, 10); + final GoalRoom goalRoom = 시작_날짜가_미래인_골룸을_생성한다(1L, creator, roadmapContent, 10); when(memberRepository.findByIdentifier(any())) .thenReturn(Optional.of(creator)); @@ -510,10 +518,8 @@ static void setUp() { private Roadmap 로드맵을_생성한다(final Member creator) { final RoadmapCategory category = new RoadmapCategory("게임"); - final List roadmapNodes = 로드맵_노드들을_생성한다(); - final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmapNodes); - final Roadmap roadmap = new Roadmap("로드맵 제목", "로드맵 소개글", 10, RoadmapDifficulty.NORMAL, creator, category); - roadmap.addContent(roadmapContent); + final Roadmap roadmap = new Roadmap("로드맵 제목", "로드맵 소개글", 10, RoadmapDifficulty.NORMAL, creator.getId(), + category, null); return roadmap; } @@ -524,9 +530,8 @@ static void setUp() { return List.of(roadmapNode1, roadmapNode2); } - private RoadmapContent 로드맵_본문을_생성한다(final List roadmapNodes) { - final RoadmapContent roadmapContent = new RoadmapContent("로드맵 본문"); - roadmapContent.addNodes(new RoadmapNodes(roadmapNodes)); + private RoadmapContent 로드맵_본문을_생성한다(final Long roadmapId, final List roadmapNodes) { + final RoadmapContent roadmapContent = new RoadmapContent("로드맵 본문", roadmapId, new RoadmapNodes(roadmapNodes)); return roadmapContent; } diff --git a/backend/kirikiri/src/test/java/co/kirikiri/goalroom/service/GoalRoomLeaveEventListenerTest.java b/backend/kirikiri/src/test/java/co/kirikiri/goalroom/service/GoalRoomLeaveEventListenerTest.java index 84a67eaeb..d8e941de8 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/goalroom/service/GoalRoomLeaveEventListenerTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/goalroom/service/GoalRoomLeaveEventListenerTest.java @@ -8,13 +8,6 @@ import static org.mockito.Mockito.verify; import co.kirikiri.common.exception.NotFoundException; -import co.kirikiri.domain.member.EncryptedPassword; -import co.kirikiri.domain.member.Gender; -import co.kirikiri.domain.member.Member; -import co.kirikiri.domain.member.MemberProfile; -import co.kirikiri.domain.member.vo.Identifier; -import co.kirikiri.domain.member.vo.Nickname; -import co.kirikiri.domain.member.vo.Password; import co.kirikiri.goalroom.domain.GoalRoom; import co.kirikiri.goalroom.domain.GoalRoomMember; import co.kirikiri.goalroom.domain.GoalRoomRoadmapNode; @@ -27,6 +20,13 @@ import co.kirikiri.goalroom.persistence.GoalRoomPendingMemberRepository; import co.kirikiri.goalroom.persistence.GoalRoomRepository; import co.kirikiri.goalroom.service.event.GoalRoomLeaveEvent; +import co.kirikiri.member.domain.EncryptedPassword; +import co.kirikiri.member.domain.Gender; +import co.kirikiri.member.domain.Member; +import co.kirikiri.member.domain.MemberProfile; +import co.kirikiri.member.domain.vo.Identifier; +import co.kirikiri.member.domain.vo.Nickname; +import co.kirikiri.member.domain.vo.Password; import java.time.LocalDate; import java.time.LocalDateTime; import java.util.Collections; diff --git a/backend/kirikiri/src/test/java/co/kirikiri/goalroom/service/GoalRoomReadServiceTest.java b/backend/kirikiri/src/test/java/co/kirikiri/goalroom/service/GoalRoomReadServiceTest.java index 5db9b38b8..3934ad781 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/goalroom/service/GoalRoomReadServiceTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/goalroom/service/GoalRoomReadServiceTest.java @@ -13,22 +13,6 @@ import co.kirikiri.common.exception.NotFoundException; import co.kirikiri.common.service.FileService; import co.kirikiri.common.type.ImageContentType; -import co.kirikiri.domain.member.EncryptedPassword; -import co.kirikiri.domain.member.Gender; -import co.kirikiri.domain.member.Member; -import co.kirikiri.domain.member.MemberImage; -import co.kirikiri.domain.member.MemberProfile; -import co.kirikiri.domain.member.vo.Identifier; -import co.kirikiri.domain.member.vo.Nickname; -import co.kirikiri.domain.member.vo.Password; -import co.kirikiri.domain.roadmap.Roadmap; -import co.kirikiri.domain.roadmap.RoadmapCategory; -import co.kirikiri.domain.roadmap.RoadmapContent; -import co.kirikiri.domain.roadmap.RoadmapDifficulty; -import co.kirikiri.domain.roadmap.RoadmapNode; -import co.kirikiri.domain.roadmap.RoadmapNodeImage; -import co.kirikiri.domain.roadmap.RoadmapNodeImages; -import co.kirikiri.domain.roadmap.RoadmapNodes; import co.kirikiri.goalroom.domain.GoalRoom; import co.kirikiri.goalroom.domain.GoalRoomMember; import co.kirikiri.goalroom.domain.GoalRoomPendingMember; @@ -53,13 +37,32 @@ import co.kirikiri.goalroom.service.dto.response.MemberGoalRoomForListResponse; import co.kirikiri.goalroom.service.dto.response.MemberGoalRoomResponse; import co.kirikiri.goalroom.service.dto.response.MemberResponse; -import co.kirikiri.persistence.member.MemberRepository; -import co.kirikiri.persistence.roadmap.RoadmapContentRepository; -import co.kirikiri.persistence.roadmap.RoadmapNodeRepository; +import co.kirikiri.member.domain.EncryptedPassword; +import co.kirikiri.member.domain.Gender; +import co.kirikiri.member.domain.Member; +import co.kirikiri.member.domain.MemberImage; +import co.kirikiri.member.domain.MemberProfile; +import co.kirikiri.member.domain.vo.Identifier; +import co.kirikiri.member.domain.vo.Nickname; +import co.kirikiri.member.domain.vo.Password; +import co.kirikiri.member.persistence.MemberRepository; +import co.kirikiri.roadmap.domain.Roadmap; +import co.kirikiri.roadmap.domain.RoadmapCategory; +import co.kirikiri.roadmap.domain.RoadmapContent; +import co.kirikiri.roadmap.domain.RoadmapDifficulty; +import co.kirikiri.roadmap.domain.RoadmapNode; +import co.kirikiri.roadmap.domain.RoadmapNodeImage; +import co.kirikiri.roadmap.domain.RoadmapNodeImages; +import co.kirikiri.roadmap.domain.RoadmapNodes; +import co.kirikiri.roadmap.domain.RoadmapStatus; +import co.kirikiri.roadmap.domain.RoadmapTags; +import co.kirikiri.roadmap.persistence.RoadmapContentRepository; +import co.kirikiri.roadmap.persistence.RoadmapNodeRepository; import java.net.MalformedURLException; import java.net.URL; import java.time.LocalDate; import java.time.LocalDateTime; +import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Optional; @@ -111,18 +114,15 @@ class GoalRoomReadServiceTest { void 골룸_아이디로_골룸_정보를_조회한다() { // given final Member creator = 크리에이터를_생성한다(); + final Roadmap roadmap = 로드맵을_생성한다(creator); final List roadmapNodes = 로드맵_노드들을_생성한다(); - final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmapNodes); - final Roadmap roadmap = 로드맵을_생성한다(creator, roadmapContent); - + final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmap.getId(), roadmapNodes); final GoalRoom goalRoom = 골룸을_생성한다(creator, roadmapContent); given(goalRoomRepository.findById(any())) .willReturn(Optional.of(goalRoom)); - given(roadmapContentRepository.findById(anyLong())) + given(roadmapContentRepository.findByIdWithRoadmapNodes(any())) .willReturn(Optional.of(roadmapContent)); - given(roadmapNodeRepository.findAllByRoadmapContent(any())) - .willReturn(roadmapNodes); given(goalRoomPendingMemberRepository.findByGoalRoom(any())) .willReturn(List.of(new GoalRoomPendingMember(GoalRoomRole.LEADER, goalRoom, creator.getId()))); @@ -150,10 +150,9 @@ class GoalRoomReadServiceTest { void 모집중인_골룸에_대해서_골룸_아이디와_사용자_아이디로_골룸_조회시_참여하는_사용자면_참여여부가_true로_반환된다() { // given final Member creator = 크리에이터를_생성한다(); + final Roadmap roadmap = 로드맵을_생성한다(creator); final List roadmapNodes = 로드맵_노드들을_생성한다(); - final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmapNodes); - final Roadmap roadmap = 로드맵을_생성한다(creator, roadmapContent); - + final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmap.getId(), roadmapNodes); final GoalRoom goalRoom = 골룸을_생성한다(creator, roadmapContent); final GoalRoomPendingMember goalRoomPendingMember = new GoalRoomPendingMember(1L, GoalRoomRole.LEADER, @@ -163,10 +162,8 @@ class GoalRoomReadServiceTest { .willReturn(Optional.of(goalRoom)); given(goalRoomPendingMemberRepository.findByGoalRoomAndMemberId(any(), any())) .willReturn(Optional.of(goalRoomPendingMember)); - given(roadmapContentRepository.findById(anyLong())) + given(roadmapContentRepository.findByIdWithRoadmapNodes(any())) .willReturn(Optional.of(roadmapContent)); - given(roadmapNodeRepository.findAllByRoadmapContent(any())) - .willReturn(roadmapNodes); given(memberRepository.findByIdentifier(any())) .willReturn(Optional.of(creator)); given(goalRoomPendingMemberRepository.findByGoalRoom(any())) @@ -186,20 +183,17 @@ class GoalRoomReadServiceTest { void 모집중인_골룸에_대해서_골룸_아이디와_사용자_아이디로_골룸_조회시_참여하지_않는_사용자면_참여여부가_false로_반환된다() { // given final Member creator = 크리에이터를_생성한다(); + final Roadmap roadmap = 로드맵을_생성한다(creator); final List roadmapNodes = 로드맵_노드들을_생성한다(); - final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmapNodes); - final Roadmap roadmap = 로드맵을_생성한다(creator, roadmapContent); - + final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmap.getId(), roadmapNodes); final GoalRoom goalRoom = 골룸을_생성한다(creator, roadmapContent); given(goalRoomRepository.findById(any())) .willReturn(Optional.of(goalRoom)); given(goalRoomPendingMemberRepository.findByGoalRoomAndMemberId(any(), any())) .willReturn(Optional.empty()); - given(roadmapContentRepository.findById(anyLong())) + given(roadmapContentRepository.findByIdWithRoadmapNodes(any())) .willReturn(Optional.of(roadmapContent)); - given(roadmapNodeRepository.findAllByRoadmapContent(any())) - .willReturn(roadmapNodes); given(memberRepository.findByIdentifier(any())) .willReturn(Optional.of(creator)); given(goalRoomPendingMemberRepository.findByGoalRoom(any())) @@ -219,10 +213,9 @@ class GoalRoomReadServiceTest { void 모집중이지_않은_골룸에_대해서_골룸_아이디와_사용자_아이디로_골룸_조회시_참여하는_사용자면_참여여부가_true로_반환된다() { // given final Member creator = 크리에이터를_생성한다(); + final Roadmap roadmap = 로드맵을_생성한다(creator); final List roadmapNodes = 로드맵_노드들을_생성한다(); - final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmapNodes); - final Roadmap roadmap = 로드맵을_생성한다(creator, roadmapContent); - + final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmap.getId(), roadmapNodes); final GoalRoom goalRoom = 골룸을_생성한다(creator, roadmapContent); goalRoom.start(); @@ -233,10 +226,8 @@ class GoalRoomReadServiceTest { .willReturn(Optional.of(goalRoom)); given(goalRoomMemberRepository.findByGoalRoomAndMemberId(any(), any())) .willReturn(Optional.of(goalRoomMember)); - given(roadmapContentRepository.findById(anyLong())) + given(roadmapContentRepository.findByIdWithRoadmapNodes(any())) .willReturn(Optional.of(roadmapContent)); - given(roadmapNodeRepository.findAllByRoadmapContent(any())) - .willReturn(roadmapNodes); given(memberRepository.findByIdentifier(any())) .willReturn(Optional.of(creator)); @@ -254,10 +245,9 @@ class GoalRoomReadServiceTest { void 모집중이지_않은_골룸에_대해서_골룸_아이디와_사용자_아이디로_골룸_조회시_참여하지_않는_사용자면_참여여부가_false로_반환된다() { // given final Member creator = 크리에이터를_생성한다(); + final Roadmap roadmap = 로드맵을_생성한다(creator); final List roadmapNodes = 로드맵_노드들을_생성한다(); - final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmapNodes); - final Roadmap roadmap = 로드맵을_생성한다(creator, roadmapContent); - + final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmap.getId(), roadmapNodes); final GoalRoom goalRoom = 골룸을_생성한다(creator, roadmapContent); goalRoom.start(); @@ -265,10 +255,8 @@ class GoalRoomReadServiceTest { .willReturn(Optional.of(goalRoom)); given(goalRoomMemberRepository.findByGoalRoomAndMemberId(any(), any())) .willReturn(Optional.empty()); - given(roadmapContentRepository.findById(anyLong())) + given(roadmapContentRepository.findByIdWithRoadmapNodes(any())) .willReturn(Optional.of(roadmapContent)); - given(roadmapNodeRepository.findAllByRoadmapContent(any())) - .willReturn(roadmapNodes); given(memberRepository.findByIdentifier(any())) .willReturn(Optional.of(creator)); @@ -296,13 +284,11 @@ class GoalRoomReadServiceTest { @Test void 정상적으로_진행중인_골룸의_참여자를_조회한다() throws MalformedURLException { //given - final Member creator = 사용자를_생성한다(1L); + final Member creator = 크리에이터를_생성한다(); final Member follower = 사용자를_생성한다(2L); - + final Roadmap roadmap = 로드맵을_생성한다(creator); final List roadmapNodes = 로드맵_노드들을_생성한다(); - final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmapNodes); - final Roadmap roadmap = 로드맵을_생성한다(creator, roadmapContent); - + final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmap.getId(), roadmapNodes); final GoalRoom goalRoom = 골룸을_생성한다(creator, roadmapContent); goalRoom.start(); @@ -327,7 +313,7 @@ class GoalRoomReadServiceTest { GoalRoomMemberSortTypeDto.ACCOMPLISHMENT_RATE); //then - final GoalRoomMemberResponse expectedGoalRoomMemberResponse1 = new GoalRoomMemberResponse(1L, "name1", + final GoalRoomMemberResponse expectedGoalRoomMemberResponse1 = new GoalRoomMemberResponse(1L, "코끼리", "http://example.com/serverFilePath", 0.0); final GoalRoomMemberResponse expectedGoalRoomMemberResponse2 = new GoalRoomMemberResponse(2L, "name1", "http://example.com/serverFilePath", 0.0); @@ -339,14 +325,12 @@ class GoalRoomReadServiceTest { @Test void 정상적으로_완료된_골룸의_참여자를_조회한다() throws MalformedURLException { //given - final Member creator = 사용자를_생성한다(1L); final Member follower = 사용자를_생성한다(2L); - + final Member creator = 크리에이터를_생성한다(); + final Roadmap roadmap = 로드맵을_생성한다(creator); final List roadmapNodes = 로드맵_노드들을_생성한다(); - final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmapNodes); - final Roadmap roadmap = 로드맵을_생성한다(creator, roadmapContent); - - final GoalRoom goalRoom = 골룸을_생성한다(creator, roadmap.getContents().getValues().get(0)); + final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmap.getId(), roadmapNodes); + final GoalRoom goalRoom = 골룸을_생성한다(creator, roadmapContent); goalRoom.complete(); final GoalRoomMember goalRoomMemberCreator = new GoalRoomMember(GoalRoomRole.LEADER, LocalDateTime.now(), @@ -370,7 +354,7 @@ class GoalRoomReadServiceTest { GoalRoomMemberSortTypeDto.ACCOMPLISHMENT_RATE); //then - final GoalRoomMemberResponse expectedGoalRoomMemberResponse1 = new GoalRoomMemberResponse(1L, "name1", + final GoalRoomMemberResponse expectedGoalRoomMemberResponse1 = new GoalRoomMemberResponse(1L, "코끼리", "http://example.com/serverFilePath", 0.0); final GoalRoomMemberResponse expectedGoalRoomMemberResponse2 = new GoalRoomMemberResponse(2L, "name1", "http://example.com/serverFilePath", 0.0); @@ -384,12 +368,10 @@ class GoalRoomReadServiceTest { //given final Member creator = 사용자를_생성한다(1L); final Member follower = 사용자를_생성한다(2L); - + final Roadmap roadmap = 로드맵을_생성한다(creator); final List roadmapNodes = 로드맵_노드들을_생성한다(); - final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmapNodes); - final Roadmap roadmap = 로드맵을_생성한다(creator, roadmapContent); - - final GoalRoom goalRoom = 골룸을_생성한다(creator, roadmap.getContents().getValues().get(0)); + final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmap.getId(), roadmapNodes); + final GoalRoom goalRoom = 골룸을_생성한다(creator, roadmapContent); final GoalRoomPendingMember goalRoomMemberCreator = new GoalRoomPendingMember(1L, GoalRoomRole.LEADER, LocalDateTime.now(), goalRoom, creator.getId()); @@ -444,8 +426,7 @@ class GoalRoomReadServiceTest { final RoadmapNode roadmapNode4 = new RoadmapNode(4L, "로드맵 4주차", "로드맵 4주차 내용"); final RoadmapNodes roadmapNodes = new RoadmapNodes( List.of(roadmapNode1, roadmapNode2, roadmapNode3, roadmapNode4)); - final RoadmapContent roadmapContent = new RoadmapContent("로드맵 본문"); - roadmapContent.addNodes(roadmapNodes); + final RoadmapContent roadmapContent = new RoadmapContent("로드맵 본문", 1L, roadmapNodes); final GoalRoomRoadmapNode goalRoomRoadmapNode1 = new GoalRoomRoadmapNode( new Period(TODAY, TODAY.plusDays(10)), 5, roadmapNode1.getId()); @@ -469,10 +450,8 @@ class GoalRoomReadServiceTest { .willReturn(Optional.of(member)); given(goalRoomMemberRepository.findByGoalRoomAndMemberId(any(), any())) .willReturn(Optional.of(goalRoomLeader)); - given(roadmapContentRepository.findById(any())) + given(roadmapContentRepository.findByIdWithRoadmapNodes(any())) .willReturn(Optional.of(roadmapContent)); - given(roadmapNodeRepository.findAllByRoadmapContent(any())) - .willReturn(List.of(roadmapNode1, roadmapNode2, roadmapNode3, roadmapNode4)); given(dashBoardCheckFeedService.findCheckFeedsByNodeAndGoalRoomStatus(any())) .willReturn(dashBoardCheckFeedResponses); given(dashBoardToDoService.findMemberCheckedGoalRoomToDoIds(any(), any())) @@ -524,8 +503,7 @@ class GoalRoomReadServiceTest { final RoadmapNode roadmapNode4 = new RoadmapNode(4L, "로드맵 4주차", "로드맵 4주차 내용"); final RoadmapNodes roadmapNodes = new RoadmapNodes( List.of(roadmapNode1, roadmapNode2, roadmapNode3, roadmapNode4)); - final RoadmapContent roadmapContent = new RoadmapContent("로드맵 본문"); - roadmapContent.addNodes(roadmapNodes); + final RoadmapContent roadmapContent = new RoadmapContent("로드맵 본문", 1L, roadmapNodes); final GoalRoomRoadmapNode goalRoomRoadmapNode1 = new GoalRoomRoadmapNode( new Period(TODAY, TODAY.plusDays(10)), 5, roadmapNode1.getId()); @@ -550,10 +528,8 @@ class GoalRoomReadServiceTest { .willReturn(Optional.of(member)); given(goalRoomPendingMemberRepository.findByGoalRoomAndMemberId(any(), any())) .willReturn(Optional.of(goalRoomLeader)); - given(roadmapContentRepository.findById(any())) + given(roadmapContentRepository.findByIdWithRoadmapNodes(any())) .willReturn(Optional.of(roadmapContent)); - given(roadmapNodeRepository.findAllByRoadmapContent(any())) - .willReturn(List.of(roadmapNode1, roadmapNode2, roadmapNode3, roadmapNode4)); given(dashBoardCheckFeedService.findCheckFeedsByNodeAndGoalRoomStatus(any())) .willReturn(Collections.emptyList()); given(dashBoardToDoService.findMemberCheckedGoalRoomToDoIds(any(), any())) @@ -592,8 +568,7 @@ class GoalRoomReadServiceTest { final RoadmapNode roadmapNode4 = new RoadmapNode(4L, "로드맵 4주차", "로드맵 4주차 내용"); final RoadmapNodes roadmapNodes = new RoadmapNodes( List.of(roadmapNode1, roadmapNode2, roadmapNode3, roadmapNode4)); - final RoadmapContent roadmapContent = new RoadmapContent("로드맵 본문"); - roadmapContent.addNodes(roadmapNodes); + final RoadmapContent roadmapContent = new RoadmapContent("로드맵 본문", 1L, roadmapNodes); final GoalRoomRoadmapNode goalRoomRoadmapNode1 = new GoalRoomRoadmapNode( new Period(TODAY, TODAY.plusDays(10)), 5, roadmapNode1.getId()); @@ -622,10 +597,8 @@ class GoalRoomReadServiceTest { .willReturn(Optional.of(member)); given(goalRoomMemberRepository.findByGoalRoomAndMemberId(any(), any())) .willReturn(Optional.of(goalRoomLeader)); - given(roadmapContentRepository.findById(any())) + given(roadmapContentRepository.findByIdWithRoadmapNodes(any())) .willReturn(Optional.of(roadmapContent)); - given(roadmapNodeRepository.findAllByRoadmapContent(any())) - .willReturn(List.of(roadmapNode1, roadmapNode2, roadmapNode3, roadmapNode4)); given(dashBoardCheckFeedService.findCheckFeedsByNodeAndGoalRoomStatus(any())) .willReturn(dashBoardCheckFeedResponses); given(dashBoardToDoService.findMemberCheckedGoalRoomToDoIds(any(), any())) @@ -685,10 +658,9 @@ class GoalRoomReadServiceTest { void 사용자_단일_목록_조회_시_유효하지_않은_아이디일_경우_예외를_반환한다() { // given final Member creator = 크리에이터를_생성한다(); + final Roadmap roadmap = 로드맵을_생성한다(creator); final List roadmapNodes = 로드맵_노드들을_생성한다(); - final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmapNodes); - final Roadmap roadmap = 로드맵을_생성한다(creator, roadmapContent); - + final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmap.getId(), roadmapNodes); final GoalRoom goalRoom = 골룸을_생성한다(creator, roadmapContent); given(goalRoomRepository.findByIdWithNodes(anyLong())) @@ -707,10 +679,9 @@ class GoalRoomReadServiceTest { // given final Member creator = 크리에이터를_생성한다(); final Member member = 사용자를_생성한다(2L); + final Roadmap roadmap = 로드맵을_생성한다(creator); final List roadmapNodes = 로드맵_노드들을_생성한다(); - final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmapNodes); - final Roadmap roadmap = 로드맵을_생성한다(creator, roadmapContent); - + final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmap.getId(), roadmapNodes); final GoalRoom goalRoom = 골룸을_생성한다(creator, roadmapContent); given(goalRoomRepository.findByIdWithNodes(anyLong())) @@ -728,9 +699,9 @@ class GoalRoomReadServiceTest { void 사용자_골룸_목록을_조회한다() throws MalformedURLException { // given final Member creator = 크리에이터를_생성한다(); + final Roadmap roadmap = 로드맵을_생성한다(creator); final List roadmapNodes = 로드맵_노드들을_생성한다(); - final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmapNodes); - final Roadmap roadmap = 로드맵을_생성한다(creator, roadmapContent); + final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmap.getId(), roadmapNodes); final GoalRoom goalRoom1 = 골룸을_생성한다(creator, roadmapContent); 골룸을_생성한다(creator, roadmapContent); @@ -804,10 +775,9 @@ THIRTY_DAY_LATER, new MemberResponse(creator.getId(), creator.getNickname().getV @Test void 사용자_골룸_목록_중_모집_중인_상태만_조회한다() throws MalformedURLException { final Member creator = 크리에이터를_생성한다(); + final Roadmap roadmap = 로드맵을_생성한다(creator); final List roadmapNodes = 로드맵_노드들을_생성한다(); - final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmapNodes); - final Roadmap roadmap = 로드맵을_생성한다(creator, roadmapContent); - + final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmap.getId(), roadmapNodes); final GoalRoom goalRoom1 = 골룸을_생성한다(creator, roadmapContent); final GoalRoom goalRoom2 = 골룸을_생성한다(creator, roadmapContent); final GoalRoom goalRoom3 = 골룸을_생성한다(creator, roadmapContent); @@ -870,10 +840,9 @@ THIRTY_DAY_LATER, new MemberResponse(creator.getId(), creator.getNickname().getV @Test void 사용자_골룸_목록_중_진행_중인_상태만_조회한다() throws MalformedURLException { final Member creator = 크리에이터를_생성한다(); + final Roadmap roadmap = 로드맵을_생성한다(creator); final List roadmapNodes = 로드맵_노드들을_생성한다(); - final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmapNodes); - final Roadmap roadmap = 로드맵을_생성한다(creator, roadmapContent); - + final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmap.getId(), roadmapNodes); final GoalRoom goalRoom1 = 골룸을_생성한다(creator, roadmapContent); final GoalRoom goalRoom2 = 골룸을_생성한다(creator, roadmapContent); final GoalRoom goalRoom3 = 골룸을_생성한다(creator, roadmapContent); @@ -935,10 +904,9 @@ THIRTY_DAY_LATER, new MemberResponse(creator.getId(), creator.getNickname().getV @Test void 사용자_골룸_목록_중_종료된_상태만_조회한다() throws MalformedURLException { final Member creator = 크리에이터를_생성한다(); + final Roadmap roadmap = 로드맵을_생성한다(creator); final List roadmapNodes = 로드맵_노드들을_생성한다(); - final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmapNodes); - final Roadmap roadmap = 로드맵을_생성한다(creator, roadmapContent); - + final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmap.getId(), roadmapNodes); final GoalRoom goalRoom1 = 골룸을_생성한다(creator, roadmapContent); final GoalRoom goalRoom2 = 골룸을_생성한다(creator, roadmapContent); final GoalRoom goalRoom3 = 골룸을_생성한다(creator, roadmapContent); @@ -1000,12 +968,12 @@ THIRTY_DAY_LATER, new MemberResponse(creator.getId(), creator.getNickname().getV @Test void 골룸의_전체_노드를_조회한다() throws MalformedURLException { // given - final Member creator = 사용자를_생성한다(1L); + final Member creator = 크리에이터를_생성한다(); + final Roadmap roadmap = 로드맵을_생성한다(creator); final List roadmapNodes = 로드맵_노드들을_생성한다(); - final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmapNodes); - final Roadmap roadmap = 로드맵을_생성한다(creator, roadmapContent); + final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmap.getId(), roadmapNodes); + final GoalRoom goalRoom = 골룸을_생성한다(creator, roadmapContent); - final GoalRoom goalRoom = 골룸을_생성한다(creator, roadmap.getContents().getValues().get(0)); final GoalRoomMember goalRoomMember = new GoalRoomMember(GoalRoomRole.LEADER, LocalDateTime.now(), goalRoom, creator.getId()); given(goalRoomRepository.findByIdWithNodes(1L)) @@ -1014,9 +982,9 @@ THIRTY_DAY_LATER, new MemberResponse(creator.getId(), creator.getNickname().getV .willReturn(Optional.of(creator)); given(goalRoomMemberRepository.findByGoalRoomIdAndMemberId(anyLong(), any())) .willReturn(Optional.of(goalRoomMember)); - given(roadmapNodeRepository.findById(1L)) + given(roadmapNodeRepository.findByIdWithRoadmapNodeImages(1L)) .willReturn(Optional.of(roadmapNodes.get(0))); - given(roadmapNodeRepository.findById(2L)) + given(roadmapNodeRepository.findByIdWithRoadmapNodeImages(2L)) .willReturn(Optional.of(roadmapNodes.get(1))); given(fileService.generateUrl(anyString(), any())) .willReturn(new URL("http://example.com/serverFilePath")); @@ -1040,12 +1008,11 @@ THIRTY_DAY_LATER, new MemberResponse(creator.getId(), creator.getNickname().getV @Test void 골룸의_노드_조회시_골룸에_참여하지_않은_사용자면_예외가_발생한다() { // given - final Member creator = 사용자를_생성한다(1L); + final Member creator = 크리에이터를_생성한다(); + final Roadmap roadmap = 로드맵을_생성한다(creator); final List roadmapNodes = 로드맵_노드들을_생성한다(); - final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmapNodes); - final Roadmap roadmap = 로드맵을_생성한다(creator, roadmapContent); - - final GoalRoom goalRoom = 골룸을_생성한다(creator, roadmap.getContents().getValues().get(0)); + final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmap.getId(), roadmapNodes); + final GoalRoom goalRoom = 골룸을_생성한다(creator, roadmapContent); given(goalRoomRepository.findByIdWithNodes(1L)) .willReturn(Optional.of(goalRoom)); @@ -1085,11 +1052,10 @@ null, new EncryptedPassword(new Password("password1")), new Nickname("name1"), new MemberProfile(Gender.FEMALE, "kirikiri@email.com")); } - private Roadmap 로드맵을_생성한다(final Member creator, final RoadmapContent roadmapContent) { + private Roadmap 로드맵을_생성한다(final Member creator) { final RoadmapCategory category = new RoadmapCategory("게임"); - final Roadmap roadmap = new Roadmap("로드맵 제목", "로드맵 소개글", 10, RoadmapDifficulty.NORMAL, creator, category); - roadmap.addContent(roadmapContent); - return roadmap; + return new Roadmap(1L, "로드맵 제목", "로드맵 소개글", 10, RoadmapDifficulty.NORMAL, + RoadmapStatus.CREATED, creator.getId(), category, new RoadmapTags(new ArrayList<>())); } private List 로드맵_노드들을_생성한다() { @@ -1099,12 +1065,6 @@ null, new EncryptedPassword(new Password("password1")), new Nickname("name1"), return List.of(roadmapNode1, roadmapNode2); } - private RoadmapContent 로드맵_본문을_생성한다(final List roadmapNodes) { - final RoadmapContent roadmapContent = new RoadmapContent(1L, "로드맵 본문"); - roadmapContent.addNodes(new RoadmapNodes(roadmapNodes)); - return roadmapContent; - } - private List 노드_이미지들을_생성한다() { return List.of( new RoadmapNodeImage("node-image1.png", "node-image1-save-path", ImageContentType.PNG), @@ -1112,6 +1072,10 @@ null, new EncryptedPassword(new Password("password1")), new Nickname("name1"), ); } + private RoadmapContent 로드맵_본문을_생성한다(final Long roadmapId, final List roadmapNodes) { + return new RoadmapContent("로드맵 본문", roadmapId, new RoadmapNodes(roadmapNodes)); + } + private GoalRoom 골룸을_생성한다(final Member member, final RoadmapContent roadmapContent) { final List roadmapNodes = roadmapContent.getNodes().getValues(); diff --git a/backend/kirikiri/src/test/java/co/kirikiri/goalroom/service/GoalRoomSchedulerTest.java b/backend/kirikiri/src/test/java/co/kirikiri/goalroom/service/GoalRoomSchedulerTest.java index 4770a5a39..5b1a4eb37 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/goalroom/service/GoalRoomSchedulerTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/goalroom/service/GoalRoomSchedulerTest.java @@ -11,22 +11,6 @@ import static org.mockito.Mockito.when; import co.kirikiri.common.type.ImageContentType; -import co.kirikiri.domain.member.EncryptedPassword; -import co.kirikiri.domain.member.Gender; -import co.kirikiri.domain.member.Member; -import co.kirikiri.domain.member.MemberProfile; -import co.kirikiri.domain.member.vo.Identifier; -import co.kirikiri.domain.member.vo.Nickname; -import co.kirikiri.domain.member.vo.Password; -import co.kirikiri.domain.roadmap.Roadmap; -import co.kirikiri.domain.roadmap.RoadmapCategory; -import co.kirikiri.domain.roadmap.RoadmapContent; -import co.kirikiri.domain.roadmap.RoadmapContents; -import co.kirikiri.domain.roadmap.RoadmapDifficulty; -import co.kirikiri.domain.roadmap.RoadmapNode; -import co.kirikiri.domain.roadmap.RoadmapNodeImage; -import co.kirikiri.domain.roadmap.RoadmapNodeImages; -import co.kirikiri.domain.roadmap.RoadmapNodes; import co.kirikiri.goalroom.domain.GoalRoom; import co.kirikiri.goalroom.domain.GoalRoomPendingMember; import co.kirikiri.goalroom.domain.GoalRoomRoadmapNode; @@ -43,11 +27,28 @@ import java.time.LocalDateTime; import java.util.Collections; import java.util.List; +import co.kirikiri.member.domain.EncryptedPassword; +import co.kirikiri.member.domain.Gender; +import co.kirikiri.member.domain.Member; +import co.kirikiri.member.domain.MemberProfile; +import co.kirikiri.member.domain.vo.Identifier; +import co.kirikiri.member.domain.vo.Nickname; +import co.kirikiri.member.domain.vo.Password; +import co.kirikiri.roadmap.domain.Roadmap; +import co.kirikiri.roadmap.domain.RoadmapCategory; +import co.kirikiri.roadmap.domain.RoadmapContent; +import co.kirikiri.roadmap.domain.RoadmapDifficulty; +import co.kirikiri.roadmap.domain.RoadmapNode; +import co.kirikiri.roadmap.domain.RoadmapNodeImage; +import co.kirikiri.roadmap.domain.RoadmapNodeImages; +import co.kirikiri.roadmap.domain.RoadmapNodes; +import co.kirikiri.roadmap.domain.RoadmapTags; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; +import java.util.ArrayList; @ExtendWith(MockitoExtension.class) class GoalRoomSchedulerTest { @@ -73,11 +74,10 @@ class GoalRoomSchedulerTest { // given final Member creator = 사용자를_생성한다(1L, "cokirikiri", "password1!", "코끼리", "010-1234-5678"); final Roadmap roadmap = 로드맵을_생성한다(creator); + final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmap.getId()); - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); - final GoalRoom goalRoom1 = 골룸을_생성한다(1L, creator, targetRoadmapContent, 10); - final GoalRoom goalRoom2 = 골룸을_생성한다(2L, creator, targetRoadmapContent, 10); + final GoalRoom goalRoom1 = 골룸을_생성한다(1L, creator, roadmapContent, 10); + final GoalRoom goalRoom2 = 골룸을_생성한다(2L, creator, roadmapContent, 10); final Member follower1 = 사용자를_생성한다(2L, "identifier1", "password2!", "name1", "kirikiri@email.com"); final Member follower2 = 사용자를_생성한다(3L, "identifier2", "password3!", "name2", "kirikiri@email.com"); @@ -109,11 +109,10 @@ class GoalRoomSchedulerTest { // given final Member creator = 사용자를_생성한다(1L, "cokirikiri", "password1!", "코끼리", "kirikiri@email.com"); final Roadmap roadmap = 로드맵을_생성한다(creator); + final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmap.getId()); - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); - final GoalRoom goalRoom1 = 골룸을_생성한다(1L, creator, targetRoadmapContent, 10); - final GoalRoom goalRoom2 = 골룸을_생성한다(2L, creator, targetRoadmapContent, 10); + final GoalRoom goalRoom1 = 골룸을_생성한다(1L, creator, roadmapContent, 10); + final GoalRoom goalRoom2 = 골룸을_생성한다(2L, creator, roadmapContent, 10); final Member follower1 = 사용자를_생성한다(2L, "identifier1", "password2!", "name1", "kirikiri@email.com"); final Member follower2 = 사용자를_생성한다(3L, "identifier2", "password3!", "name2", "kirikiri@email.com"); @@ -145,11 +144,13 @@ class GoalRoomSchedulerTest { private Roadmap 로드맵을_생성한다(final Member creator) { final RoadmapCategory category = new RoadmapCategory("게임"); + return new Roadmap("로드맵 제목", "로드맵 소개글", 10, RoadmapDifficulty.NORMAL, + creator.getId(), category, new RoadmapTags(new ArrayList<>())); + } + + private RoadmapContent 로드맵_본문을_생성한다(final Long roadmapId) { final List roadmapNodes = 로드맵_노드들을_생성한다(); - final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmapNodes); - final Roadmap roadmap = new Roadmap("로드맵 제목", "로드맵 소개글", 10, RoadmapDifficulty.NORMAL, creator, category); - roadmap.addContent(roadmapContent); - return roadmap; + return new RoadmapContent("로드맵 본문", roadmapId, new RoadmapNodes(roadmapNodes)); } private List 로드맵_노드들을_생성한다() { @@ -159,12 +160,6 @@ class GoalRoomSchedulerTest { return List.of(roadmapNode1, roadmapNode2); } - private RoadmapContent 로드맵_본문을_생성한다(final List roadmapNodes) { - final RoadmapContent roadmapContent = new RoadmapContent("로드맵 본문"); - roadmapContent.addNodes(new RoadmapNodes(roadmapNodes)); - return roadmapContent; - } - private List 노드_이미지들을_생성한다() { return List.of( new RoadmapNodeImage("node-image1.png", "node-image1-save-path", ImageContentType.PNG), diff --git a/backend/kirikiri/src/test/java/co/kirikiri/infra/AmazonS3FileServiceTest.java b/backend/kirikiri/src/test/java/co/kirikiri/infra/AmazonS3FileServiceTest.java index abe6232c4..25324e4c3 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/infra/AmazonS3FileServiceTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/infra/AmazonS3FileServiceTest.java @@ -8,6 +8,8 @@ import static org.mockito.Mockito.when; import co.kirikiri.common.exception.ServerException; +import co.kirikiri.common.infra.AmazonS3FileService; +import co.kirikiri.common.infra.CloudFrontService; import co.kirikiri.common.service.dto.FileInformation; import com.amazonaws.AmazonServiceException; import com.amazonaws.Protocol; diff --git a/backend/kirikiri/src/test/java/co/kirikiri/infra/CloudFrontServiceTest.java b/backend/kirikiri/src/test/java/co/kirikiri/infra/CloudFrontServiceTest.java index ae8f9aeb6..6514f6bf6 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/infra/CloudFrontServiceTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/infra/CloudFrontServiceTest.java @@ -5,14 +5,15 @@ import static org.mockito.Mockito.when; import co.kirikiri.common.exception.ServerException; -import java.net.MalformedURLException; -import java.net.URL; +import co.kirikiri.common.infra.CloudFrontService; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.core.env.Environment; +import java.net.MalformedURLException; +import java.net.URL; @ExtendWith(MockitoExtension.class) class CloudFrontServiceTest { diff --git a/backend/kirikiri/src/test/java/co/kirikiri/integration/AuthenticationIntegrationTest.java b/backend/kirikiri/src/test/java/co/kirikiri/integration/AuthenticationIntegrationTest.java index d68f092de..08ba12f04 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/integration/AuthenticationIntegrationTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/integration/AuthenticationIntegrationTest.java @@ -6,11 +6,11 @@ import static co.kirikiri.integration.fixture.MemberAPIFixture.DEFAULT_PASSWORD; import static org.assertj.core.api.Assertions.assertThat; +import co.kirikiri.auth.service.dto.request.LoginRequest; +import co.kirikiri.auth.service.dto.request.ReissueTokenRequest; +import co.kirikiri.auth.service.dto.response.AuthenticationResponse; import co.kirikiri.common.service.dto.ErrorResponse; import co.kirikiri.integration.helper.InitIntegrationTest; -import co.kirikiri.service.dto.auth.request.LoginRequest; -import co.kirikiri.service.dto.auth.request.ReissueTokenRequest; -import co.kirikiri.service.dto.auth.response.AuthenticationResponse; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.type.TypeReference; import io.restassured.response.ExtractableResponse; diff --git a/backend/kirikiri/src/test/java/co/kirikiri/integration/GoalRoomCheckFeedIntegrationTest.java b/backend/kirikiri/src/test/java/co/kirikiri/integration/GoalRoomCheckFeedIntegrationTest.java index 90af24ad4..16662d621 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/integration/GoalRoomCheckFeedIntegrationTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/integration/GoalRoomCheckFeedIntegrationTest.java @@ -21,6 +21,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertAll; +import co.kirikiri.auth.service.dto.request.LoginRequest; import co.kirikiri.checkfeed.service.dto.request.CheckFeedRequest; import co.kirikiri.checkfeed.service.dto.response.GoalRoomCheckFeedResponse; import co.kirikiri.common.service.dto.ErrorResponse; @@ -28,10 +29,9 @@ import co.kirikiri.goalroom.service.dto.request.GoalRoomRoadmapNodeRequest; import co.kirikiri.goalroom.service.dto.response.GoalRoomMemberResponse; import co.kirikiri.integration.helper.InitIntegrationTest; -import co.kirikiri.service.dto.auth.request.LoginRequest; -import co.kirikiri.service.dto.member.request.GenderType; -import co.kirikiri.service.dto.member.request.MemberJoinRequest; -import co.kirikiri.service.dto.roadmap.response.RoadmapResponse; +import co.kirikiri.member.service.dto.request.GenderType; +import co.kirikiri.member.service.dto.request.MemberJoinRequest; +import co.kirikiri.roadmap.service.dto.response.RoadmapResponse; import com.fasterxml.jackson.core.type.TypeReference; import io.restassured.common.mapper.TypeRef; import io.restassured.response.ExtractableResponse; diff --git a/backend/kirikiri/src/test/java/co/kirikiri/integration/GoalRoomCreateIntegrationTest.java b/backend/kirikiri/src/test/java/co/kirikiri/integration/GoalRoomCreateIntegrationTest.java index 13a41c437..cf4323876 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/integration/GoalRoomCreateIntegrationTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/integration/GoalRoomCreateIntegrationTest.java @@ -24,6 +24,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertAll; +import co.kirikiri.auth.service.dto.request.LoginRequest; import co.kirikiri.common.service.dto.ErrorResponse; import co.kirikiri.goalroom.service.dto.GoalRoomFilterTypeDto; import co.kirikiri.goalroom.service.dto.request.GoalRoomCreateRequest; @@ -31,12 +32,11 @@ import co.kirikiri.goalroom.service.dto.response.GoalRoomMemberResponse; import co.kirikiri.goalroom.service.dto.response.MemberGoalRoomResponse; import co.kirikiri.integration.helper.InitIntegrationTest; -import co.kirikiri.service.dto.auth.request.LoginRequest; -import co.kirikiri.service.dto.member.request.GenderType; -import co.kirikiri.service.dto.member.request.MemberJoinRequest; -import co.kirikiri.service.dto.member.response.MemberInformationResponse; -import co.kirikiri.service.dto.roadmap.response.RoadmapGoalRoomResponses; -import co.kirikiri.service.dto.roadmap.response.RoadmapResponse; +import co.kirikiri.member.service.dto.request.GenderType; +import co.kirikiri.member.service.dto.request.MemberJoinRequest; +import co.kirikiri.member.service.dto.response.MemberInformationResponse; +import co.kirikiri.roadmap.service.dto.response.RoadmapGoalRoomResponses; +import co.kirikiri.roadmap.service.dto.response.RoadmapResponse; import com.fasterxml.jackson.core.JsonProcessingException; import io.restassured.common.mapper.TypeRef; import io.restassured.response.ExtractableResponse; @@ -278,7 +278,7 @@ class GoalRoomCreateIntegrationTest extends InitIntegrationTest { () -> assertThat(예외_메시지).contains("제한 인원이 꽉 찬 골룸에는 참여할 수 없습니다.") ); } - + @Test void 이미_참여한_골룸에_참가_요청을_보내면_예외가_발생한다() throws IOException { //given diff --git a/backend/kirikiri/src/test/java/co/kirikiri/integration/GoalRoomReadIntegrationTest.java b/backend/kirikiri/src/test/java/co/kirikiri/integration/GoalRoomReadIntegrationTest.java index 6b3e97fd9..1ba4351fd 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/integration/GoalRoomReadIntegrationTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/integration/GoalRoomReadIntegrationTest.java @@ -30,6 +30,7 @@ import static co.kirikiri.integration.fixture.RoadmapAPIFixture.로드맵을_아이디로_조회하고_응답객체를_반환한다; import static org.assertj.core.api.Assertions.assertThat; +import co.kirikiri.auth.service.dto.request.LoginRequest; import co.kirikiri.checkfeed.service.dto.request.CheckFeedRequest; import co.kirikiri.common.service.dto.ErrorResponse; import co.kirikiri.goalroom.persistence.dto.RoadmapGoalRoomsOrderType; @@ -46,14 +47,13 @@ import co.kirikiri.goalroom.service.dto.response.MemberGoalRoomForListResponse; import co.kirikiri.goalroom.service.dto.response.MemberGoalRoomResponse; import co.kirikiri.integration.helper.InitIntegrationTest; -import co.kirikiri.service.dto.auth.request.LoginRequest; -import co.kirikiri.service.dto.member.request.GenderType; -import co.kirikiri.service.dto.member.request.MemberJoinRequest; -import co.kirikiri.service.dto.roadmap.request.RoadmapDifficultyType; -import co.kirikiri.service.dto.roadmap.request.RoadmapNodeSaveRequest; -import co.kirikiri.service.dto.roadmap.request.RoadmapSaveRequest; -import co.kirikiri.service.dto.roadmap.response.RoadmapGoalRoomResponses; -import co.kirikiri.service.dto.roadmap.response.RoadmapResponse; +import co.kirikiri.member.service.dto.request.GenderType; +import co.kirikiri.member.service.dto.request.MemberJoinRequest; +import co.kirikiri.roadmap.service.dto.request.RoadmapDifficultyType; +import co.kirikiri.roadmap.service.dto.request.RoadmapNodeSaveRequest; +import co.kirikiri.roadmap.service.dto.request.RoadmapSaveRequest; +import co.kirikiri.roadmap.service.dto.response.RoadmapGoalRoomResponses; +import co.kirikiri.roadmap.service.dto.response.RoadmapResponse; import io.restassured.common.mapper.TypeRef; import java.io.IOException; import java.time.LocalDate; diff --git a/backend/kirikiri/src/test/java/co/kirikiri/integration/GoalRoomSchedulerIntegrationTest.java b/backend/kirikiri/src/test/java/co/kirikiri/integration/GoalRoomSchedulerIntegrationTest.java index ff22f6eeb..78c19ff84 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/integration/GoalRoomSchedulerIntegrationTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/integration/GoalRoomSchedulerIntegrationTest.java @@ -14,6 +14,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertAll; +import co.kirikiri.auth.service.dto.request.LoginRequest; import co.kirikiri.goalroom.domain.GoalRoom; import co.kirikiri.goalroom.domain.GoalRoomRoadmapNode; import co.kirikiri.goalroom.domain.GoalRoomRoadmapNodes; @@ -24,10 +25,9 @@ import co.kirikiri.goalroom.service.dto.response.MemberGoalRoomResponse; import co.kirikiri.goalroom.service.scheduler.GoalRoomScheduler; import co.kirikiri.integration.helper.InitIntegrationTest; -import co.kirikiri.service.dto.auth.request.LoginRequest; -import co.kirikiri.service.dto.member.request.GenderType; -import co.kirikiri.service.dto.member.request.MemberJoinRequest; -import co.kirikiri.service.dto.roadmap.response.RoadmapResponse; +import co.kirikiri.member.service.dto.request.GenderType; +import co.kirikiri.member.service.dto.request.MemberJoinRequest; +import co.kirikiri.roadmap.service.dto.response.RoadmapResponse; import java.io.IOException; import java.time.LocalDate; import java.util.List; diff --git a/backend/kirikiri/src/test/java/co/kirikiri/integration/GoalRoomToDoIntegrationTest.java b/backend/kirikiri/src/test/java/co/kirikiri/integration/GoalRoomToDoIntegrationTest.java index 2753f2dce..c40cf88eb 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/integration/GoalRoomToDoIntegrationTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/integration/GoalRoomToDoIntegrationTest.java @@ -20,12 +20,12 @@ import static co.kirikiri.integration.fixture.RoadmapAPIFixture.로드맵을_아이디로_조회하고_응답객체를_반환한다; import static org.assertj.core.api.Assertions.assertThat; +import co.kirikiri.auth.service.dto.request.LoginRequest; import co.kirikiri.common.service.dto.ErrorResponse; import co.kirikiri.integration.helper.InitIntegrationTest; -import co.kirikiri.service.dto.auth.request.LoginRequest; -import co.kirikiri.service.dto.member.request.GenderType; -import co.kirikiri.service.dto.member.request.MemberJoinRequest; -import co.kirikiri.service.dto.roadmap.response.RoadmapResponse; +import co.kirikiri.member.service.dto.request.GenderType; +import co.kirikiri.member.service.dto.request.MemberJoinRequest; +import co.kirikiri.roadmap.service.dto.response.RoadmapResponse; import co.kirikiri.todo.service.dto.request.GoalRoomTodoRequest; import co.kirikiri.todo.service.dto.response.GoalRoomToDoCheckResponse; import co.kirikiri.todo.service.dto.response.GoalRoomTodoResponse; diff --git a/backend/kirikiri/src/test/java/co/kirikiri/integration/MemberCreateIntegrationTest.java b/backend/kirikiri/src/test/java/co/kirikiri/integration/MemberCreateIntegrationTest.java index d31b9c998..33ce378e0 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/integration/MemberCreateIntegrationTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/integration/MemberCreateIntegrationTest.java @@ -6,8 +6,8 @@ import co.kirikiri.common.service.dto.ErrorResponse; import co.kirikiri.integration.helper.InitIntegrationTest; -import co.kirikiri.service.dto.member.request.GenderType; -import co.kirikiri.service.dto.member.request.MemberJoinRequest; +import co.kirikiri.member.service.dto.request.GenderType; +import co.kirikiri.member.service.dto.request.MemberJoinRequest; import io.restassured.common.mapper.TypeRef; import io.restassured.response.ExtractableResponse; import io.restassured.response.Response; diff --git a/backend/kirikiri/src/test/java/co/kirikiri/integration/MemberReadIntegrationTest.java b/backend/kirikiri/src/test/java/co/kirikiri/integration/MemberReadIntegrationTest.java index 2883d10b6..bf3ecf85f 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/integration/MemberReadIntegrationTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/integration/MemberReadIntegrationTest.java @@ -10,11 +10,11 @@ import static org.assertj.core.api.Assertions.assertThat; import co.kirikiri.common.service.dto.ErrorResponse; -import co.kirikiri.domain.member.Gender; import co.kirikiri.integration.helper.InitIntegrationTest; -import co.kirikiri.service.dto.member.request.MemberJoinRequest; -import co.kirikiri.service.dto.member.response.MemberInformationForPublicResponse; -import co.kirikiri.service.dto.member.response.MemberInformationResponse; +import co.kirikiri.member.domain.Gender; +import co.kirikiri.member.service.dto.request.MemberJoinRequest; +import co.kirikiri.member.service.dto.response.MemberInformationForPublicResponse; +import co.kirikiri.member.service.dto.response.MemberInformationResponse; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.type.TypeReference; import io.restassured.response.ExtractableResponse; diff --git a/backend/kirikiri/src/test/java/co/kirikiri/integration/RoadmapCreateIntegrationTest.java b/backend/kirikiri/src/test/java/co/kirikiri/integration/RoadmapCreateIntegrationTest.java index 169295c1f..97cb4703d 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/integration/RoadmapCreateIntegrationTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/integration/RoadmapCreateIntegrationTest.java @@ -12,16 +12,16 @@ import static co.kirikiri.integration.fixture.RoadmapAPIFixture.요청을_받는_이미지가_포함된_로드맵_생성; import static org.assertj.core.api.Assertions.assertThat; +import co.kirikiri.auth.service.dto.request.LoginRequest; import co.kirikiri.common.service.dto.ErrorResponse; import co.kirikiri.integration.helper.InitIntegrationTest; -import co.kirikiri.service.dto.auth.request.LoginRequest; -import co.kirikiri.service.dto.member.request.GenderType; -import co.kirikiri.service.dto.member.request.MemberJoinRequest; -import co.kirikiri.service.dto.roadmap.request.RoadmapCategorySaveRequest; -import co.kirikiri.service.dto.roadmap.request.RoadmapDifficultyType; -import co.kirikiri.service.dto.roadmap.request.RoadmapNodeSaveRequest; -import co.kirikiri.service.dto.roadmap.request.RoadmapSaveRequest; -import co.kirikiri.service.dto.roadmap.request.RoadmapTagSaveRequest; +import co.kirikiri.member.service.dto.request.GenderType; +import co.kirikiri.member.service.dto.request.MemberJoinRequest; +import co.kirikiri.roadmap.service.dto.request.RoadmapCategorySaveRequest; +import co.kirikiri.roadmap.service.dto.request.RoadmapDifficultyType; +import co.kirikiri.roadmap.service.dto.request.RoadmapNodeSaveRequest; +import co.kirikiri.roadmap.service.dto.request.RoadmapSaveRequest; +import co.kirikiri.roadmap.service.dto.request.RoadmapTagSaveRequest; import io.restassured.common.mapper.TypeRef; import io.restassured.response.ExtractableResponse; import io.restassured.response.Response; diff --git a/backend/kirikiri/src/test/java/co/kirikiri/integration/RoadmapReadIntegrationTest.java b/backend/kirikiri/src/test/java/co/kirikiri/integration/RoadmapReadIntegrationTest.java index 6c437131d..a583439c8 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/integration/RoadmapReadIntegrationTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/integration/RoadmapReadIntegrationTest.java @@ -14,18 +14,18 @@ import static org.junit.jupiter.api.Assertions.assertAll; import co.kirikiri.common.service.dto.ErrorResponse; -import co.kirikiri.domain.roadmap.RoadmapCategory; import co.kirikiri.integration.helper.InitIntegrationTest; -import co.kirikiri.persistence.dto.RoadmapOrderType; -import co.kirikiri.service.dto.roadmap.request.RoadmapDifficultyType; -import co.kirikiri.service.dto.roadmap.request.RoadmapNodeSaveRequest; -import co.kirikiri.service.dto.roadmap.request.RoadmapSaveRequest; -import co.kirikiri.service.dto.roadmap.request.RoadmapTagSaveRequest; -import co.kirikiri.service.dto.roadmap.response.MemberRoadmapResponses; -import co.kirikiri.service.dto.roadmap.response.RoadmapCategoryResponse; -import co.kirikiri.service.dto.roadmap.response.RoadmapForListResponse; -import co.kirikiri.service.dto.roadmap.response.RoadmapForListResponses; -import co.kirikiri.service.dto.roadmap.response.RoadmapResponse; +import co.kirikiri.roadmap.domain.RoadmapCategory; +import co.kirikiri.roadmap.persistence.dto.RoadmapOrderType; +import co.kirikiri.roadmap.service.dto.request.RoadmapDifficultyType; +import co.kirikiri.roadmap.service.dto.request.RoadmapNodeSaveRequest; +import co.kirikiri.roadmap.service.dto.request.RoadmapSaveRequest; +import co.kirikiri.roadmap.service.dto.request.RoadmapTagSaveRequest; +import co.kirikiri.roadmap.service.dto.response.MemberRoadmapResponses; +import co.kirikiri.roadmap.service.dto.response.RoadmapCategoryResponse; +import co.kirikiri.roadmap.service.dto.response.RoadmapForListResponse; +import co.kirikiri.roadmap.service.dto.response.RoadmapForListResponses; +import co.kirikiri.roadmap.service.dto.response.RoadmapResponse; import io.restassured.common.mapper.TypeRef; import io.restassured.response.ExtractableResponse; import io.restassured.response.Response; diff --git a/backend/kirikiri/src/test/java/co/kirikiri/integration/RoadmapReadOrderIntegrationTest.java b/backend/kirikiri/src/test/java/co/kirikiri/integration/RoadmapReadOrderIntegrationTest.java index 3f3c3155b..b4398f553 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/integration/RoadmapReadOrderIntegrationTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/integration/RoadmapReadOrderIntegrationTest.java @@ -18,20 +18,20 @@ import static co.kirikiri.integration.fixture.RoadmapAPIFixture.카테고리_생성; import static org.assertj.core.api.Assertions.assertThat; -import co.kirikiri.domain.roadmap.RoadmapCategory; import co.kirikiri.goalroom.domain.GoalRoom; import co.kirikiri.goalroom.service.dto.request.GoalRoomCreateRequest; import co.kirikiri.goalroom.service.dto.request.GoalRoomRoadmapNodeRequest; import co.kirikiri.integration.helper.InitIntegrationTest; -import co.kirikiri.persistence.dto.RoadmapOrderType; -import co.kirikiri.service.dto.member.response.MemberInformationResponse; -import co.kirikiri.service.dto.roadmap.request.RoadmapDifficultyType; -import co.kirikiri.service.dto.roadmap.request.RoadmapNodeSaveRequest; -import co.kirikiri.service.dto.roadmap.request.RoadmapReviewSaveRequest; -import co.kirikiri.service.dto.roadmap.request.RoadmapSaveRequest; -import co.kirikiri.service.dto.roadmap.request.RoadmapTagSaveRequest; -import co.kirikiri.service.dto.roadmap.response.RoadmapForListResponses; -import co.kirikiri.service.dto.roadmap.response.RoadmapResponse; +import co.kirikiri.member.service.dto.response.MemberInformationResponse; +import co.kirikiri.roadmap.domain.RoadmapCategory; +import co.kirikiri.roadmap.persistence.dto.RoadmapOrderType; +import co.kirikiri.roadmap.service.dto.request.RoadmapDifficultyType; +import co.kirikiri.roadmap.service.dto.request.RoadmapNodeSaveRequest; +import co.kirikiri.roadmap.service.dto.request.RoadmapReviewSaveRequest; +import co.kirikiri.roadmap.service.dto.request.RoadmapSaveRequest; +import co.kirikiri.roadmap.service.dto.request.RoadmapTagSaveRequest; +import co.kirikiri.roadmap.service.dto.response.RoadmapForListResponses; +import co.kirikiri.roadmap.service.dto.response.RoadmapResponse; import io.restassured.common.mapper.TypeRef; import java.io.IOException; import java.util.List; diff --git a/backend/kirikiri/src/test/java/co/kirikiri/integration/RoadmapReviewCreateIntegrationTest.java b/backend/kirikiri/src/test/java/co/kirikiri/integration/RoadmapReviewCreateIntegrationTest.java index 4408d3d13..847a265f6 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/integration/RoadmapReviewCreateIntegrationTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/integration/RoadmapReviewCreateIntegrationTest.java @@ -16,17 +16,17 @@ import static co.kirikiri.integration.fixture.RoadmapAPIFixture.리뷰를_생성한다; import static org.assertj.core.api.Assertions.assertThat; +import co.kirikiri.auth.service.dto.request.LoginRequest; import co.kirikiri.common.service.dto.ErrorResponse; import co.kirikiri.goalroom.domain.GoalRoom; import co.kirikiri.goalroom.service.dto.request.GoalRoomCreateRequest; import co.kirikiri.goalroom.service.dto.request.GoalRoomRoadmapNodeRequest; import co.kirikiri.integration.helper.InitIntegrationTest; -import co.kirikiri.service.dto.auth.request.LoginRequest; -import co.kirikiri.service.dto.member.request.GenderType; -import co.kirikiri.service.dto.member.request.MemberJoinRequest; -import co.kirikiri.service.dto.member.response.MemberInformationResponse; -import co.kirikiri.service.dto.roadmap.request.RoadmapReviewSaveRequest; -import co.kirikiri.service.dto.roadmap.response.RoadmapResponse; +import co.kirikiri.member.service.dto.request.GenderType; +import co.kirikiri.member.service.dto.request.MemberJoinRequest; +import co.kirikiri.member.service.dto.response.MemberInformationResponse; +import co.kirikiri.roadmap.service.dto.request.RoadmapReviewSaveRequest; +import co.kirikiri.roadmap.service.dto.response.RoadmapResponse; import io.restassured.common.mapper.TypeRef; import io.restassured.response.ExtractableResponse; import io.restassured.response.Response; diff --git a/backend/kirikiri/src/test/java/co/kirikiri/integration/RoadmapReviewReadIntegrationTest.java b/backend/kirikiri/src/test/java/co/kirikiri/integration/RoadmapReviewReadIntegrationTest.java index 11a57222e..4c0d59d36 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/integration/RoadmapReviewReadIntegrationTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/integration/RoadmapReviewReadIntegrationTest.java @@ -12,18 +12,18 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertAll; +import co.kirikiri.auth.service.dto.request.LoginRequest; +import co.kirikiri.common.service.dto.CustomScrollRequest; import co.kirikiri.common.service.dto.ErrorResponse; import co.kirikiri.goalroom.domain.GoalRoom; import co.kirikiri.integration.helper.InitIntegrationTest; -import co.kirikiri.service.dto.CustomScrollRequest; -import co.kirikiri.service.dto.auth.request.LoginRequest; -import co.kirikiri.service.dto.member.request.GenderType; -import co.kirikiri.service.dto.member.request.MemberJoinRequest; -import co.kirikiri.service.dto.member.response.MemberInformationResponse; -import co.kirikiri.service.dto.member.response.MemberResponse; -import co.kirikiri.service.dto.roadmap.request.RoadmapReviewSaveRequest; -import co.kirikiri.service.dto.roadmap.response.RoadmapResponse; -import co.kirikiri.service.dto.roadmap.response.RoadmapReviewResponse; +import co.kirikiri.member.service.dto.request.GenderType; +import co.kirikiri.member.service.dto.request.MemberJoinRequest; +import co.kirikiri.member.service.dto.response.MemberInformationResponse; +import co.kirikiri.member.service.dto.response.MemberResponse; +import co.kirikiri.roadmap.service.dto.request.RoadmapReviewSaveRequest; +import co.kirikiri.roadmap.service.dto.response.RoadmapResponse; +import co.kirikiri.roadmap.service.dto.response.RoadmapReviewResponse; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.type.TypeReference; import io.restassured.common.mapper.TypeRef; diff --git a/backend/kirikiri/src/test/java/co/kirikiri/integration/RoadmapSchedulerIntegrationTest.java b/backend/kirikiri/src/test/java/co/kirikiri/integration/RoadmapSchedulerIntegrationTest.java index cacf1efd7..fecf22296 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/integration/RoadmapSchedulerIntegrationTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/integration/RoadmapSchedulerIntegrationTest.java @@ -15,9 +15,9 @@ import co.kirikiri.goalroom.service.dto.request.GoalRoomCreateRequest; import co.kirikiri.goalroom.service.dto.request.GoalRoomRoadmapNodeRequest; import co.kirikiri.integration.helper.InitIntegrationTest; -import co.kirikiri.persistence.roadmap.RoadmapRepository; -import co.kirikiri.service.dto.roadmap.response.RoadmapResponse; -import co.kirikiri.service.scheduler.RoadmapScheduler; +import co.kirikiri.roadmap.persistence.RoadmapRepository; +import co.kirikiri.roadmap.service.dto.response.RoadmapResponse; +import co.kirikiri.roadmap.service.scheduler.RoadmapScheduler; import java.io.IOException; import java.time.LocalDate; import java.util.List; @@ -65,7 +65,7 @@ public RoadmapSchedulerIntegrationTest(final RoadmapScheduler roadmapScheduler, roadmapScheduler.deleteRoadmaps(); // then - assertThat(roadmapRepository.findAll()).hasSize(0); + assertThat(roadmapRepository.findAll()).isEmpty(); } @Test diff --git a/backend/kirikiri/src/test/java/co/kirikiri/integration/RoadmapSearchIntegrationTest.java b/backend/kirikiri/src/test/java/co/kirikiri/integration/RoadmapSearchIntegrationTest.java index 0f763186e..aec2b8e55 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/integration/RoadmapSearchIntegrationTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/integration/RoadmapSearchIntegrationTest.java @@ -1,19 +1,16 @@ package co.kirikiri.integration; import static co.kirikiri.integration.fixture.MemberAPIFixture.요청을_받는_사용자_자신의_정보_조회_요청; -import static co.kirikiri.integration.fixture.RoadmapAPIFixture.로드맵_생성; -import static co.kirikiri.integration.fixture.RoadmapAPIFixture.제목으로_최신순_정렬된_로드맵을_검색한다; -import static co.kirikiri.integration.fixture.RoadmapAPIFixture.크리에이터_닉네임으로_정렬된_로드맵을_생성한다; -import static co.kirikiri.integration.fixture.RoadmapAPIFixture.태그_이름으로_최신순_정렬된_로드맵을_검색한다; +import static co.kirikiri.integration.fixture.RoadmapAPIFixture.*; import static org.assertj.core.api.Assertions.assertThat; import co.kirikiri.integration.helper.InitIntegrationTest; -import co.kirikiri.service.dto.member.response.MemberInformationResponse; -import co.kirikiri.service.dto.roadmap.request.RoadmapDifficultyType; -import co.kirikiri.service.dto.roadmap.request.RoadmapNodeSaveRequest; -import co.kirikiri.service.dto.roadmap.request.RoadmapSaveRequest; -import co.kirikiri.service.dto.roadmap.request.RoadmapTagSaveRequest; -import co.kirikiri.service.dto.roadmap.response.RoadmapForListResponses; +import co.kirikiri.member.service.dto.response.MemberInformationResponse; +import co.kirikiri.roadmap.service.dto.request.RoadmapDifficultyType; +import co.kirikiri.roadmap.service.dto.request.RoadmapNodeSaveRequest; +import co.kirikiri.roadmap.service.dto.request.RoadmapSaveRequest; +import co.kirikiri.roadmap.service.dto.request.RoadmapTagSaveRequest; +import co.kirikiri.roadmap.service.dto.response.RoadmapForListResponses; import io.restassured.common.mapper.TypeRef; import org.junit.jupiter.api.Test; import java.io.IOException; diff --git a/backend/kirikiri/src/test/java/co/kirikiri/integration/fixture/AuthenticationAPIFixture.java b/backend/kirikiri/src/test/java/co/kirikiri/integration/fixture/AuthenticationAPIFixture.java index 09e803db7..a5b7caef9 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/integration/fixture/AuthenticationAPIFixture.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/integration/fixture/AuthenticationAPIFixture.java @@ -5,9 +5,9 @@ import static co.kirikiri.integration.fixture.MemberAPIFixture.DEFAULT_PASSWORD; import static io.restassured.RestAssured.given; -import co.kirikiri.service.dto.auth.request.LoginRequest; -import co.kirikiri.service.dto.auth.request.ReissueTokenRequest; -import co.kirikiri.service.dto.auth.response.AuthenticationResponse; +import co.kirikiri.auth.service.dto.request.LoginRequest; +import co.kirikiri.auth.service.dto.request.ReissueTokenRequest; +import co.kirikiri.auth.service.dto.response.AuthenticationResponse; import io.restassured.response.ExtractableResponse; import io.restassured.response.Response; import org.springframework.http.MediaType; diff --git a/backend/kirikiri/src/test/java/co/kirikiri/integration/fixture/GoalRoomAPIFixture.java b/backend/kirikiri/src/test/java/co/kirikiri/integration/fixture/GoalRoomAPIFixture.java index b7f8b5cd7..7dee91904 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/integration/fixture/GoalRoomAPIFixture.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/integration/fixture/GoalRoomAPIFixture.java @@ -9,7 +9,7 @@ import co.kirikiri.goalroom.service.dto.request.GoalRoomCreateRequest; import co.kirikiri.goalroom.service.dto.request.GoalRoomRoadmapNodeRequest; import co.kirikiri.goalroom.service.dto.response.MemberGoalRoomResponse; -import co.kirikiri.service.dto.roadmap.response.RoadmapResponse; +import co.kirikiri.roadmap.service.dto.response.RoadmapResponse; import co.kirikiri.todo.service.dto.request.GoalRoomTodoRequest; import io.restassured.common.mapper.TypeRef; import io.restassured.http.Header; @@ -30,10 +30,10 @@ public class GoalRoomAPIFixture { public static final LocalDate 십일_후 = 오늘.plusDays(10L); public static final LocalDate 이십일_후 = 십일_후.plusDays(10L); public static final LocalDate 삼십일_후 = 이십일_후.plusDays(10L); + public static final int 정상적인_골룸_노드_인증_횟수 = (int) ChronoUnit.DAYS.between(오늘, 십일_후); public static final String 정상적인_골룸_이름 = "GOAL_ROOM_NAME"; public static final int 정상적인_골룸_제한_인원 = 20; public static final String 정상적인_골룸_투두_컨텐츠 = "GOAL_ROOM_TO_DO_CONTENT"; - public static final int 정상적인_골룸_노드_인증_횟수 = (int) ChronoUnit.DAYS.between(오늘, 십일_후); public static Long 골룸을_생성하고_아이디를_반환한다(final GoalRoomCreateRequest 골룸_생성_요청, final String 액세스_토큰) { final String 골룸_생성_응답_Location_헤더 = 골룸_생성(골룸_생성_요청, 액세스_토큰).response().getHeader(LOCATION); @@ -160,7 +160,7 @@ public class GoalRoomAPIFixture { } public static ExtractableResponse 골룸을_시작한다(final String 로그인_토큰, final Long 골룸_아이디) { - final ExtractableResponse 골룸_시작_요청_응답 = given().log().all() + return given().log().all() .contentType(MediaType.APPLICATION_JSON_VALUE) .when() .header(new Header(HttpHeaders.AUTHORIZATION, 로그인_토큰)) @@ -168,7 +168,6 @@ public class GoalRoomAPIFixture { .then() .log().all() .extract(); - return 골룸_시작_요청_응답; } public static ExtractableResponse 골룸의_사용자_정보를_정렬_기준없이_조회(final Long 골룸_아이디, final String 로그인_토큰) { diff --git a/backend/kirikiri/src/test/java/co/kirikiri/integration/fixture/MemberAPIFixture.java b/backend/kirikiri/src/test/java/co/kirikiri/integration/fixture/MemberAPIFixture.java index 5cec01f3c..e8800017d 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/integration/fixture/MemberAPIFixture.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/integration/fixture/MemberAPIFixture.java @@ -1,14 +1,12 @@ package co.kirikiri.integration.fixture; import static co.kirikiri.integration.fixture.AuthenticationAPIFixture.로그인; -import static co.kirikiri.integration.fixture.CommonFixture.API_PREFIX; -import static co.kirikiri.integration.fixture.CommonFixture.AUTHORIZATION; -import static co.kirikiri.integration.fixture.CommonFixture.BEARER_TOKEN_FORMAT; +import static co.kirikiri.integration.fixture.CommonFixture.*; import static io.restassured.RestAssured.given; -import co.kirikiri.service.dto.auth.request.LoginRequest; -import co.kirikiri.service.dto.member.request.GenderType; -import co.kirikiri.service.dto.member.request.MemberJoinRequest; +import co.kirikiri.auth.service.dto.request.LoginRequest; +import co.kirikiri.member.service.dto.request.GenderType; +import co.kirikiri.member.service.dto.request.MemberJoinRequest; import io.restassured.response.ExtractableResponse; import io.restassured.response.Response; import org.springframework.http.MediaType; diff --git a/backend/kirikiri/src/test/java/co/kirikiri/integration/fixture/RoadmapAPIFixture.java b/backend/kirikiri/src/test/java/co/kirikiri/integration/fixture/RoadmapAPIFixture.java index 0acc14aae..7a783246b 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/integration/fixture/RoadmapAPIFixture.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/integration/fixture/RoadmapAPIFixture.java @@ -4,25 +4,25 @@ import static co.kirikiri.integration.fixture.CommonFixture.AUTHORIZATION; import static io.restassured.RestAssured.given; -import co.kirikiri.domain.roadmap.RoadmapCategory; -import co.kirikiri.persistence.dto.RoadmapOrderType; -import co.kirikiri.service.dto.CustomScrollRequest; -import co.kirikiri.service.dto.roadmap.request.RoadmapCategorySaveRequest; -import co.kirikiri.service.dto.roadmap.request.RoadmapNodeSaveRequest; -import co.kirikiri.service.dto.roadmap.request.RoadmapReviewSaveRequest; -import co.kirikiri.service.dto.roadmap.request.RoadmapSaveRequest; -import co.kirikiri.service.dto.roadmap.response.RoadmapResponse; +import co.kirikiri.common.service.dto.CustomScrollRequest; +import co.kirikiri.roadmap.domain.RoadmapCategory; +import co.kirikiri.roadmap.persistence.dto.RoadmapOrderType; +import co.kirikiri.roadmap.service.dto.request.RoadmapCategorySaveRequest; +import co.kirikiri.roadmap.service.dto.request.RoadmapNodeSaveRequest; +import co.kirikiri.roadmap.service.dto.request.RoadmapReviewSaveRequest; +import co.kirikiri.roadmap.service.dto.request.RoadmapSaveRequest; +import co.kirikiri.roadmap.service.dto.response.RoadmapResponse; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import io.restassured.response.ExtractableResponse; import io.restassured.response.Response; import io.restassured.specification.RequestSpecification; -import org.springframework.http.HttpHeaders; -import org.springframework.http.MediaType; -import org.springframework.mock.web.MockMultipartFile; import java.io.IOException; import java.util.ArrayList; import java.util.List; +import org.springframework.http.HttpHeaders; +import org.springframework.http.MediaType; +import org.springframework.mock.web.MockMultipartFile; public class RoadmapAPIFixture { @@ -215,7 +215,8 @@ private static RequestSpecification makeRequestSpecification(final RoadmapSaveRe .extract(); } - public static ExtractableResponse 로드맵_카테고리를_생성한다(final String 로그인_토큰_정보, final RoadmapCategorySaveRequest 카테고리_생성_요청) { + public static ExtractableResponse 로드맵_카테고리를_생성한다(final String 로그인_토큰_정보, + final RoadmapCategorySaveRequest 카테고리_생성_요청) { return given().log().all() .contentType(MediaType.APPLICATION_JSON_VALUE) .when() diff --git a/backend/kirikiri/src/test/java/co/kirikiri/integration/helper/InitIntegrationTest.java b/backend/kirikiri/src/test/java/co/kirikiri/integration/helper/InitIntegrationTest.java index 28b448b74..243e577e3 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/integration/helper/InitIntegrationTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/integration/helper/InitIntegrationTest.java @@ -5,11 +5,11 @@ import static co.kirikiri.integration.fixture.MemberAPIFixture.기본_회원가입; import static co.kirikiri.integration.fixture.RoadmapAPIFixture.카테고리_생성; -import co.kirikiri.domain.roadmap.RoadmapCategory; -import co.kirikiri.service.dto.roadmap.request.RoadmapDifficultyType; -import co.kirikiri.service.dto.roadmap.request.RoadmapNodeSaveRequest; -import co.kirikiri.service.dto.roadmap.request.RoadmapSaveRequest; -import co.kirikiri.service.dto.roadmap.request.RoadmapTagSaveRequest; +import co.kirikiri.roadmap.domain.RoadmapCategory; +import co.kirikiri.roadmap.service.dto.request.RoadmapDifficultyType; +import co.kirikiri.roadmap.service.dto.request.RoadmapNodeSaveRequest; +import co.kirikiri.roadmap.service.dto.request.RoadmapSaveRequest; +import co.kirikiri.roadmap.service.dto.request.RoadmapTagSaveRequest; import org.junit.jupiter.api.BeforeEach; import java.util.List; diff --git a/backend/kirikiri/src/test/java/co/kirikiri/integration/helper/IntegrationTest.java b/backend/kirikiri/src/test/java/co/kirikiri/integration/helper/IntegrationTest.java index 4ce173e30..85cfdef3f 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/integration/helper/IntegrationTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/integration/helper/IntegrationTest.java @@ -20,15 +20,12 @@ @Import(TestConfig.class) public class IntegrationTest { - @LocalServerPort - private int port; - @Autowired protected ObjectMapper objectMapper; - @Autowired protected TestTransactionService testTransactionService; - + @LocalServerPort + private int port; @Autowired private DatabaseCleaner databaseCleaner; diff --git a/backend/kirikiri/src/test/java/co/kirikiri/integration/helper/TestConfig.java b/backend/kirikiri/src/test/java/co/kirikiri/integration/helper/TestConfig.java index 2122c142e..8aec60c77 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/integration/helper/TestConfig.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/integration/helper/TestConfig.java @@ -1,9 +1,9 @@ package co.kirikiri.integration.helper; +import co.kirikiri.auth.persistence.RefreshTokenRepository; import co.kirikiri.common.service.FileService; import co.kirikiri.goalroom.persistence.GoalRoomMemberRepository; import co.kirikiri.goalroom.persistence.GoalRoomRepository; -import co.kirikiri.persistence.auth.RefreshTokenRepository; import org.springframework.boot.test.context.TestConfiguration; import org.springframework.context.annotation.Bean; diff --git a/backend/kirikiri/src/test/java/co/kirikiri/integration/helper/TestRefreshTokenRepository.java b/backend/kirikiri/src/test/java/co/kirikiri/integration/helper/TestRefreshTokenRepository.java index 94f9344a0..9862d9501 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/integration/helper/TestRefreshTokenRepository.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/integration/helper/TestRefreshTokenRepository.java @@ -2,7 +2,7 @@ import static co.kirikiri.integration.fixture.MemberAPIFixture.DEFAULT_IDENTIFIER; -import co.kirikiri.persistence.auth.RefreshTokenRepository; +import co.kirikiri.auth.persistence.RefreshTokenRepository; import java.util.Optional; public class TestRefreshTokenRepository implements RefreshTokenRepository { diff --git a/backend/kirikiri/src/test/java/co/kirikiri/integration/helper/TestTransactionService.java b/backend/kirikiri/src/test/java/co/kirikiri/integration/helper/TestTransactionService.java index df0fa35d4..c305b76fa 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/integration/helper/TestTransactionService.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/integration/helper/TestTransactionService.java @@ -9,13 +9,6 @@ import static co.kirikiri.integration.fixture.MemberAPIFixture.DEFAULT_PASSWORD; import static co.kirikiri.integration.helper.InitIntegrationTest.기본_로그인_토큰; -import co.kirikiri.domain.member.EncryptedPassword; -import co.kirikiri.domain.member.Gender; -import co.kirikiri.domain.member.Member; -import co.kirikiri.domain.member.MemberProfile; -import co.kirikiri.domain.member.vo.Identifier; -import co.kirikiri.domain.member.vo.Nickname; -import co.kirikiri.domain.member.vo.Password; import co.kirikiri.goalroom.domain.GoalRoom; import co.kirikiri.goalroom.domain.GoalRoomMember; import co.kirikiri.goalroom.domain.GoalRoomRole; @@ -24,8 +17,15 @@ import co.kirikiri.goalroom.persistence.GoalRoomRepository; import co.kirikiri.goalroom.service.dto.request.GoalRoomCreateRequest; import co.kirikiri.goalroom.service.dto.request.GoalRoomRoadmapNodeRequest; -import co.kirikiri.service.dto.member.response.MemberInformationResponse; -import co.kirikiri.service.dto.roadmap.response.RoadmapResponse; +import co.kirikiri.member.domain.EncryptedPassword; +import co.kirikiri.member.domain.Gender; +import co.kirikiri.member.domain.Member; +import co.kirikiri.member.domain.MemberProfile; +import co.kirikiri.member.domain.vo.Identifier; +import co.kirikiri.member.domain.vo.Nickname; +import co.kirikiri.member.domain.vo.Password; +import co.kirikiri.member.service.dto.response.MemberInformationResponse; +import co.kirikiri.roadmap.service.dto.response.RoadmapResponse; import jakarta.persistence.EntityManager; import jakarta.persistence.PersistenceContext; import java.time.LocalDate; @@ -37,11 +37,10 @@ @Transactional public class TestTransactionService { - @PersistenceContext - private EntityManager em; - private final GoalRoomRepository goalRoomRepository; private final GoalRoomMemberRepository goalRoomMemberRepository; + @PersistenceContext + private EntityManager em; public TestTransactionService(final GoalRoomRepository goalRoomRepository, final GoalRoomMemberRepository goalRoomMemberRepository) { diff --git a/backend/kirikiri/src/test/java/co/kirikiri/controller/MemberCreateApiTest.java b/backend/kirikiri/src/test/java/co/kirikiri/member/controller/MemberCreateApiTest.java similarity index 98% rename from backend/kirikiri/src/test/java/co/kirikiri/controller/MemberCreateApiTest.java rename to backend/kirikiri/src/test/java/co/kirikiri/member/controller/MemberCreateApiTest.java index 89320fed1..5ff3fbdb9 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/controller/MemberCreateApiTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/member/controller/MemberCreateApiTest.java @@ -1,4 +1,4 @@ -package co.kirikiri.controller; +package co.kirikiri.member.controller; import static co.kirikiri.integration.fixture.MemberAPIFixture.DEFAULT_EMAIL; import static org.assertj.core.api.Assertions.assertThat; @@ -14,11 +14,11 @@ import co.kirikiri.common.exception.BadRequestException; import co.kirikiri.common.exception.ConflictException; import co.kirikiri.common.helper.ControllerTestHelper; -import co.kirikiri.common.service.dto.ErrorResponse; import co.kirikiri.common.helper.FieldDescriptionHelper.FieldDescription; -import co.kirikiri.service.dto.member.request.GenderType; -import co.kirikiri.service.dto.member.request.MemberJoinRequest; -import co.kirikiri.service.member.MemberService; +import co.kirikiri.common.service.dto.ErrorResponse; +import co.kirikiri.member.service.MemberService; +import co.kirikiri.member.service.dto.request.GenderType; +import co.kirikiri.member.service.dto.request.MemberJoinRequest; import com.fasterxml.jackson.core.type.TypeReference; import java.util.List; import org.junit.jupiter.api.Test; diff --git a/backend/kirikiri/src/test/java/co/kirikiri/controller/MemberReadApiTest.java b/backend/kirikiri/src/test/java/co/kirikiri/member/controller/MemberReadApiTest.java similarity index 96% rename from backend/kirikiri/src/test/java/co/kirikiri/controller/MemberReadApiTest.java rename to backend/kirikiri/src/test/java/co/kirikiri/member/controller/MemberReadApiTest.java index 6ecb6a607..ca3c9865e 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/controller/MemberReadApiTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/member/controller/MemberReadApiTest.java @@ -1,4 +1,4 @@ -package co.kirikiri.controller; +package co.kirikiri.member.controller; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; @@ -15,10 +15,10 @@ import co.kirikiri.common.exception.NotFoundException; import co.kirikiri.common.helper.ControllerTestHelper; import co.kirikiri.common.service.dto.ErrorResponse; -import co.kirikiri.domain.member.Gender; -import co.kirikiri.service.dto.member.response.MemberInformationForPublicResponse; -import co.kirikiri.service.dto.member.response.MemberInformationResponse; -import co.kirikiri.service.member.MemberService; +import co.kirikiri.member.domain.Gender; +import co.kirikiri.member.service.MemberService; +import co.kirikiri.member.service.dto.response.MemberInformationForPublicResponse; +import co.kirikiri.member.service.dto.response.MemberInformationResponse; import com.fasterxml.jackson.core.type.TypeReference; import org.junit.jupiter.api.Test; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; diff --git a/backend/kirikiri/src/test/java/co/kirikiri/domain/member/vo/EncryptedPasswordTest.java b/backend/kirikiri/src/test/java/co/kirikiri/member/domain/vo/EncryptedPasswordTest.java similarity index 87% rename from backend/kirikiri/src/test/java/co/kirikiri/domain/member/vo/EncryptedPasswordTest.java rename to backend/kirikiri/src/test/java/co/kirikiri/member/domain/vo/EncryptedPasswordTest.java index 83d2fa36d..95eb573f7 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/domain/member/vo/EncryptedPasswordTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/member/domain/vo/EncryptedPasswordTest.java @@ -1,8 +1,8 @@ -package co.kirikiri.domain.member.vo; +package co.kirikiri.member.domain.vo; import static org.assertj.core.api.Assertions.assertThat; -import co.kirikiri.domain.member.EncryptedPassword; +import co.kirikiri.member.domain.EncryptedPassword; import org.junit.jupiter.api.Test; class EncryptedPasswordTest { diff --git a/backend/kirikiri/src/test/java/co/kirikiri/domain/member/vo/IdentifierTest.java b/backend/kirikiri/src/test/java/co/kirikiri/member/domain/vo/IdentifierTest.java similarity index 90% rename from backend/kirikiri/src/test/java/co/kirikiri/domain/member/vo/IdentifierTest.java rename to backend/kirikiri/src/test/java/co/kirikiri/member/domain/vo/IdentifierTest.java index 2555e7155..ea84c231f 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/domain/member/vo/IdentifierTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/member/domain/vo/IdentifierTest.java @@ -1,9 +1,9 @@ -package co.kirikiri.domain.member.vo; +package co.kirikiri.member.domain.vo; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; -import co.kirikiri.domain.member.exception.MemberException; +import co.kirikiri.member.domain.exception.MemberException; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; diff --git a/backend/kirikiri/src/test/java/co/kirikiri/domain/member/vo/NicknameTest.java b/backend/kirikiri/src/test/java/co/kirikiri/member/domain/vo/NicknameTest.java similarity index 90% rename from backend/kirikiri/src/test/java/co/kirikiri/domain/member/vo/NicknameTest.java rename to backend/kirikiri/src/test/java/co/kirikiri/member/domain/vo/NicknameTest.java index 80876918e..fea53e646 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/domain/member/vo/NicknameTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/member/domain/vo/NicknameTest.java @@ -1,9 +1,9 @@ -package co.kirikiri.domain.member.vo; +package co.kirikiri.member.domain.vo; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; -import co.kirikiri.domain.member.exception.MemberException; +import co.kirikiri.member.domain.exception.MemberException; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; diff --git a/backend/kirikiri/src/test/java/co/kirikiri/domain/member/vo/PasswordTest.java b/backend/kirikiri/src/test/java/co/kirikiri/member/domain/vo/PasswordTest.java similarity index 96% rename from backend/kirikiri/src/test/java/co/kirikiri/domain/member/vo/PasswordTest.java rename to backend/kirikiri/src/test/java/co/kirikiri/member/domain/vo/PasswordTest.java index a0fe0d3cb..90dc1f842 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/domain/member/vo/PasswordTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/member/domain/vo/PasswordTest.java @@ -1,9 +1,9 @@ -package co.kirikiri.domain.member.vo; +package co.kirikiri.member.domain.vo; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; -import co.kirikiri.domain.member.exception.MemberException; +import co.kirikiri.member.domain.exception.MemberException; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; diff --git a/backend/kirikiri/src/test/java/co/kirikiri/persistence/member/MemberRepositoryTest.java b/backend/kirikiri/src/test/java/co/kirikiri/member/persistence/MemberRepositoryTest.java similarity index 89% rename from backend/kirikiri/src/test/java/co/kirikiri/persistence/member/MemberRepositoryTest.java rename to backend/kirikiri/src/test/java/co/kirikiri/member/persistence/MemberRepositoryTest.java index 67d6da865..d2d0a47dd 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/persistence/member/MemberRepositoryTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/member/persistence/MemberRepositoryTest.java @@ -1,18 +1,18 @@ -package co.kirikiri.persistence.member; +package co.kirikiri.member.persistence; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertAll; -import co.kirikiri.common.type.ImageContentType; -import co.kirikiri.domain.member.EncryptedPassword; -import co.kirikiri.domain.member.Gender; -import co.kirikiri.domain.member.Member; -import co.kirikiri.domain.member.MemberImage; -import co.kirikiri.domain.member.MemberProfile; -import co.kirikiri.domain.member.vo.Identifier; -import co.kirikiri.domain.member.vo.Nickname; -import co.kirikiri.domain.member.vo.Password; import co.kirikiri.common.helper.RepositoryTest; +import co.kirikiri.common.type.ImageContentType; +import co.kirikiri.member.domain.EncryptedPassword; +import co.kirikiri.member.domain.Gender; +import co.kirikiri.member.domain.Member; +import co.kirikiri.member.domain.MemberImage; +import co.kirikiri.member.domain.MemberProfile; +import co.kirikiri.member.domain.vo.Identifier; +import co.kirikiri.member.domain.vo.Nickname; +import co.kirikiri.member.domain.vo.Password; import java.util.Optional; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; diff --git a/backend/kirikiri/src/test/java/co/kirikiri/service/MemberServiceTest.java b/backend/kirikiri/src/test/java/co/kirikiri/member/service/MemberServiceTest.java similarity index 79% rename from backend/kirikiri/src/test/java/co/kirikiri/service/MemberServiceTest.java rename to backend/kirikiri/src/test/java/co/kirikiri/member/service/MemberServiceTest.java index c7c488d20..aa0212588 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/service/MemberServiceTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/member/service/MemberServiceTest.java @@ -1,4 +1,4 @@ -package co.kirikiri.service; +package co.kirikiri.member.service; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; @@ -9,28 +9,22 @@ import co.kirikiri.common.exception.ConflictException; import co.kirikiri.common.exception.NotFoundException; import co.kirikiri.common.service.FileService; +import co.kirikiri.common.service.NumberGenerator; import co.kirikiri.common.type.ImageContentType; -import co.kirikiri.domain.member.EncryptedPassword; -import co.kirikiri.domain.member.Gender; -import co.kirikiri.domain.member.Member; -import co.kirikiri.domain.member.MemberImage; -import co.kirikiri.domain.member.MemberProfile; -import co.kirikiri.domain.member.vo.Identifier; -import co.kirikiri.domain.member.vo.Nickname; -import co.kirikiri.domain.member.vo.Password; -import co.kirikiri.persistence.auth.RefreshTokenRepository; -import co.kirikiri.persistence.member.MemberRepository; -import co.kirikiri.service.auth.TokenProvider; -import co.kirikiri.service.dto.auth.response.AuthenticationResponse; -import co.kirikiri.service.dto.member.OauthMemberJoinDto; -import co.kirikiri.service.dto.member.request.GenderType; -import co.kirikiri.service.dto.member.request.MemberJoinRequest; -import co.kirikiri.service.dto.member.response.MemberInformationForPublicResponse; -import co.kirikiri.service.dto.member.response.MemberInformationResponse; -import co.kirikiri.service.member.MemberService; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.Optional; +import co.kirikiri.member.domain.EncryptedPassword; +import co.kirikiri.member.domain.Gender; +import co.kirikiri.member.domain.Member; +import co.kirikiri.member.domain.MemberImage; +import co.kirikiri.member.domain.MemberProfile; +import co.kirikiri.member.domain.vo.Identifier; +import co.kirikiri.member.domain.vo.Nickname; +import co.kirikiri.member.domain.vo.Password; +import co.kirikiri.member.persistence.MemberRepository; +import co.kirikiri.member.service.dto.OauthMemberJoinDto; +import co.kirikiri.member.service.dto.request.GenderType; +import co.kirikiri.member.service.dto.request.MemberJoinRequest; +import co.kirikiri.member.service.dto.response.MemberInformationForPublicResponse; +import co.kirikiri.member.service.dto.response.MemberInformationResponse; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.params.ParameterizedTest; @@ -39,6 +33,9 @@ import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.core.env.Environment; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.Optional; @ExtendWith(MockitoExtension.class) class MemberServiceTest { @@ -56,12 +53,6 @@ class MemberServiceTest { @Mock private NumberGenerator numberGenerator; - @Mock - private TokenProvider tokenProvider; - - @Mock - private RefreshTokenRepository refreshTokenRepository; - @Mock private FileService fileService; @@ -217,11 +208,16 @@ class MemberServiceTest { @Test void oauth_회원가입을_한다() { //given - final OauthMemberJoinDto request = new OauthMemberJoinDto("oauthId", "kirikiri@email.com", "nickname", - GenderType.UNDEFINED); + final OauthMemberJoinDto oauthMemberJoinDto = new OauthMemberJoinDto("oauthId", "kirikiri@email.com", + "nickname", GenderType.UNDEFINED); + + final MemberProfile memberProfile = new MemberProfile(Gender.valueOf(oauthMemberJoinDto.gender().name()), + oauthMemberJoinDto.email()); + final Member member = new Member(new Identifier("kirikiri"), oauthMemberJoinDto.oauthId(), + new Nickname(oauthMemberJoinDto.nickname()), null, memberProfile); given(memberRepository.save(any())) - .willReturn(new Member(1L, null, null, null, null, null, null)); + .willReturn(member); given(environment.getProperty(IMAGE_DEFAULT_ORIGINAL_FILE_NAME_PROPERTY)) .willReturn("default-member-image"); given(environment.getProperty(IMAGE_DEFAULT_SERVER_FILE_PATH_PROPERTY)) @@ -230,27 +226,28 @@ class MemberServiceTest { .willReturn("JPG"); given(numberGenerator.generate()) .willReturn(7); - given(tokenProvider.createRefreshToken(any(), any())) - .willReturn("refreshToken"); - given(tokenProvider.createAccessToken(any(), any())) - .willReturn("accessToken"); //when - final AuthenticationResponse result = memberService.oauthJoin(request); + final Member result = memberService.oauthJoin(oauthMemberJoinDto); //then - assertThat(result).isEqualTo(new AuthenticationResponse("refreshToken", "accessToken")); + assertThat(result).isEqualTo(member); } @ParameterizedTest @ValueSource(strings = {"k", "kk", "kkk", "kkkk"}) void oauth_회원가입_시_이메일의_아이디와_UUID_길이의_합이_40이하일때_회원을_생성한다(final String value) { //given - final OauthMemberJoinDto request = new OauthMemberJoinDto("oauthId", value + "@email.com", "nickname", + final OauthMemberJoinDto oauthMemberJoinDto = new OauthMemberJoinDto("oauthId", value + "@email.com", "nickname", GenderType.UNDEFINED); + final MemberProfile memberProfile = new MemberProfile(Gender.valueOf(oauthMemberJoinDto.gender().name()), + oauthMemberJoinDto.email()); + final Member member = new Member(new Identifier("kirikiri"), oauthMemberJoinDto.oauthId(), + new Nickname(oauthMemberJoinDto.nickname()), null, memberProfile); + given(memberRepository.save(any())) - .willReturn(new Member(1L, null, null, null, null, null, null)); + .willReturn(member); given(environment.getProperty(IMAGE_DEFAULT_ORIGINAL_FILE_NAME_PROPERTY)) .willReturn("default-member-image"); given(environment.getProperty(IMAGE_DEFAULT_SERVER_FILE_PATH_PROPERTY)) @@ -259,27 +256,28 @@ class MemberServiceTest { .willReturn("JPG"); given(numberGenerator.generate()) .willReturn(7); - given(tokenProvider.createRefreshToken(any(), any())) - .willReturn("refreshToken"); - given(tokenProvider.createAccessToken(any(), any())) - .willReturn("accessToken"); //when - final AuthenticationResponse result = memberService.oauthJoin(request); + final Member result = memberService.oauthJoin(oauthMemberJoinDto); //then - assertThat(result).isEqualTo(new AuthenticationResponse("refreshToken", "accessToken")); + assertThat(result).isEqualTo(member); } @ParameterizedTest @ValueSource(strings = {"kkkkk", "kkkkkk", "kkkkkkkkkkkkkkkkk"}) void oauth_회원가입_시_이메일의_아이디와_UUID_길이의_합이_40초과일때_회원을_생성한다(final String value) { //given - final OauthMemberJoinDto request = new OauthMemberJoinDto("oauthId", value + "@email.com", "nickname", + final OauthMemberJoinDto oauthMemberJoinDto = new OauthMemberJoinDto("oauthId", value + "@email.com", "nickname", GenderType.UNDEFINED); + final MemberProfile memberProfile = new MemberProfile(Gender.valueOf(oauthMemberJoinDto.gender().name()), + oauthMemberJoinDto.email()); + final Member member = new Member(new Identifier("kirikiri"), oauthMemberJoinDto.oauthId(), + new Nickname(oauthMemberJoinDto.nickname()), null, memberProfile); + given(memberRepository.save(any())) - .willReturn(new Member(1L, null, null, null, null, null, null)); + .willReturn(member); given(environment.getProperty(IMAGE_DEFAULT_ORIGINAL_FILE_NAME_PROPERTY)) .willReturn("default-member-image"); given(environment.getProperty(IMAGE_DEFAULT_SERVER_FILE_PATH_PROPERTY)) @@ -288,15 +286,11 @@ class MemberServiceTest { .willReturn("JPG"); given(numberGenerator.generate()) .willReturn(7); - given(tokenProvider.createRefreshToken(any(), any())) - .willReturn("refreshToken"); - given(tokenProvider.createAccessToken(any(), any())) - .willReturn("accessToken"); //when - final AuthenticationResponse result = memberService.oauthJoin(request); + final Member result = memberService.oauthJoin(oauthMemberJoinDto); //then - assertThat(result).isEqualTo(new AuthenticationResponse("refreshToken", "accessToken")); + assertThat(result).isEqualTo(member); } } diff --git a/backend/kirikiri/src/test/java/co/kirikiri/service/dto/member/request/GenderTypeTest.java b/backend/kirikiri/src/test/java/co/kirikiri/member/service/dto/GenderTypeTest.java similarity index 91% rename from backend/kirikiri/src/test/java/co/kirikiri/service/dto/member/request/GenderTypeTest.java rename to backend/kirikiri/src/test/java/co/kirikiri/member/service/dto/GenderTypeTest.java index 0c043f4e4..2fceffcb4 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/service/dto/member/request/GenderTypeTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/member/service/dto/GenderTypeTest.java @@ -1,7 +1,8 @@ -package co.kirikiri.service.dto.member.request; +package co.kirikiri.member.service.dto; import static org.assertj.core.api.Assertions.assertThat; +import co.kirikiri.member.service.dto.request.GenderType; import org.junit.jupiter.api.Test; class GenderTypeTest { diff --git a/backend/kirikiri/src/test/java/co/kirikiri/persistence/roadmap/RoadmapContentRepositoryTest.java b/backend/kirikiri/src/test/java/co/kirikiri/persistence/roadmap/RoadmapContentRepositoryTest.java deleted file mode 100644 index 96bcbbf74..000000000 --- a/backend/kirikiri/src/test/java/co/kirikiri/persistence/roadmap/RoadmapContentRepositoryTest.java +++ /dev/null @@ -1,100 +0,0 @@ -package co.kirikiri.persistence.roadmap; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertAll; - -import co.kirikiri.domain.member.EncryptedPassword; -import co.kirikiri.domain.member.Gender; -import co.kirikiri.domain.member.Member; -import co.kirikiri.domain.member.MemberProfile; -import co.kirikiri.domain.member.vo.Identifier; -import co.kirikiri.domain.member.vo.Nickname; -import co.kirikiri.domain.member.vo.Password; -import co.kirikiri.domain.roadmap.Roadmap; -import co.kirikiri.domain.roadmap.RoadmapCategory; -import co.kirikiri.domain.roadmap.RoadmapContent; -import co.kirikiri.domain.roadmap.RoadmapDifficulty; -import co.kirikiri.common.helper.RepositoryTest; -import co.kirikiri.persistence.member.MemberRepository; -import org.junit.jupiter.api.Test; - -@RepositoryTest -class RoadmapContentRepositoryTest { - - private final MemberRepository memberRepository; - private final RoadmapCategoryRepository roadmapCategoryRepository; - private final RoadmapRepository roadmapRepository; - private final RoadmapContentRepository roadmapContentRepository; - - public RoadmapContentRepositoryTest(final MemberRepository memberRepository, - final RoadmapCategoryRepository roadmapCategoryRepository, - final RoadmapRepository roadmapRepository, - final RoadmapContentRepository roadmapContentRepository) { - this.memberRepository = memberRepository; - this.roadmapCategoryRepository = roadmapCategoryRepository; - this.roadmapRepository = roadmapRepository; - this.roadmapContentRepository = roadmapContentRepository; - } - - @Test - void 로드맵_컨텐츠를_로드맵과_함께_조회한다() { - // given - final Roadmap roadmap = 로드맵을_생성한다(); - final Roadmap savedRoadmap = roadmapRepository.save(roadmap); - final Long roadmapContentId = savedRoadmap.getContents().getValues().get(0).getId(); - - // when - final RoadmapContent roadmapContent = roadmapContentRepository.findByIdWithRoadmap(roadmapContentId).get(); - - // then - assertAll( - () -> assertThat(roadmapContent).isEqualTo(savedRoadmap.getContents().getValues().get(0)), - () -> assertThat(roadmapContent.getRoadmap()).isEqualTo(savedRoadmap) - ); - } - - @Test - void 로드맵의_가장_최근_컨텐츠를_조회한다() { - // given - final Roadmap savedRoadmap = roadmapRepository.save(로드맵을_생성한다()); - final RoadmapContent oldRoadmapContent = roadmapContentRepository.findFirstByRoadmapOrderByCreatedAtDesc( - savedRoadmap).get(); - - final RoadmapContent newRoadmapContent = new RoadmapContent("로드맵 제목"); - savedRoadmap.addContent(newRoadmapContent); - - // when - final RoadmapContent expectedRoadmapContent = roadmapContentRepository.findFirstByRoadmapOrderByCreatedAtDesc( - savedRoadmap).get(); - - // then - assertAll( - () -> assertThat(oldRoadmapContent).isNotEqualTo(expectedRoadmapContent), - () -> assertThat(expectedRoadmapContent).isEqualTo(newRoadmapContent) - ); - } - - private Roadmap 로드맵을_생성한다() { - final Member creator = 사용자를_생성한다(); - final RoadmapCategory category = 로드맵_카테고리를_생성한다(); - final RoadmapContent content = new RoadmapContent("로드맵 제목"); - - final Roadmap roadmap = new Roadmap("로드맵 제목", "로드맵 설명", 100, RoadmapDifficulty.NORMAL, creator, category); - roadmap.addContent(content); - - return roadmap; - } - - private Member 사용자를_생성한다() { - final MemberProfile memberProfile = new MemberProfile(Gender.MALE, "kirikiri1@email.com"); - final Member member = new Member(new Identifier("identifier1"), - new EncryptedPassword(new Password("password1!")), new Nickname("썬샷"), null, memberProfile); - - return memberRepository.save(member); - } - - private RoadmapCategory 로드맵_카테고리를_생성한다() { - final RoadmapCategory category = new RoadmapCategory("운동"); - return roadmapCategoryRepository.save(category); - } -} diff --git a/backend/kirikiri/src/test/java/co/kirikiri/controller/RoadmapCreateApiTest.java b/backend/kirikiri/src/test/java/co/kirikiri/roadmap/controller/RoadmapCreateApiTest.java similarity index 98% rename from backend/kirikiri/src/test/java/co/kirikiri/controller/RoadmapCreateApiTest.java rename to backend/kirikiri/src/test/java/co/kirikiri/roadmap/controller/RoadmapCreateApiTest.java index 6a34ccb28..6cde54c09 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/controller/RoadmapCreateApiTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/roadmap/controller/RoadmapCreateApiTest.java @@ -1,4 +1,4 @@ -package co.kirikiri.controller; +package co.kirikiri.roadmap.controller; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; @@ -31,14 +31,14 @@ import co.kirikiri.common.exception.NotFoundException; import co.kirikiri.common.helper.ControllerTestHelper; import co.kirikiri.common.service.dto.ErrorResponse; -import co.kirikiri.service.dto.roadmap.request.RoadmapCategorySaveRequest; -import co.kirikiri.service.dto.roadmap.request.RoadmapDifficultyType; -import co.kirikiri.service.dto.roadmap.request.RoadmapNodeSaveRequest; -import co.kirikiri.service.dto.roadmap.request.RoadmapReviewSaveRequest; -import co.kirikiri.service.dto.roadmap.request.RoadmapSaveRequest; -import co.kirikiri.service.dto.roadmap.request.RoadmapTagSaveRequest; -import co.kirikiri.service.roadmap.RoadmapCreateService; -import co.kirikiri.service.roadmap.RoadmapReadService; +import co.kirikiri.roadmap.service.RoadmapCreateService; +import co.kirikiri.roadmap.service.RoadmapReadService; +import co.kirikiri.roadmap.service.dto.request.RoadmapCategorySaveRequest; +import co.kirikiri.roadmap.service.dto.request.RoadmapDifficultyType; +import co.kirikiri.roadmap.service.dto.request.RoadmapNodeSaveRequest; +import co.kirikiri.roadmap.service.dto.request.RoadmapReviewSaveRequest; +import co.kirikiri.roadmap.service.dto.request.RoadmapSaveRequest; +import co.kirikiri.roadmap.service.dto.request.RoadmapTagSaveRequest; import com.fasterxml.jackson.core.type.TypeReference; import java.util.ArrayList; import java.util.List; diff --git a/backend/kirikiri/src/test/java/co/kirikiri/controller/RoadmapReadApiTest.java b/backend/kirikiri/src/test/java/co/kirikiri/roadmap/controller/RoadmapReadApiTest.java similarity index 96% rename from backend/kirikiri/src/test/java/co/kirikiri/controller/RoadmapReadApiTest.java rename to backend/kirikiri/src/test/java/co/kirikiri/roadmap/controller/RoadmapReadApiTest.java index ceaca5704..c3d9f5b85 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/controller/RoadmapReadApiTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/roadmap/controller/RoadmapReadApiTest.java @@ -1,4 +1,4 @@ -package co.kirikiri.controller; +package co.kirikiri.roadmap.controller; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; @@ -18,26 +18,27 @@ import co.kirikiri.common.exception.NotFoundException; import co.kirikiri.common.helper.ControllerTestHelper; +import co.kirikiri.common.service.dto.CustomScrollRequest; import co.kirikiri.common.service.dto.ErrorResponse; -import co.kirikiri.domain.roadmap.RoadmapDifficulty; import co.kirikiri.goalroom.domain.GoalRoomStatus; -import co.kirikiri.goalroom.service.dto.response.RoadmapGoalRoomResponse; -import co.kirikiri.service.dto.CustomScrollRequest; -import co.kirikiri.service.dto.member.response.MemberResponse; -import co.kirikiri.service.dto.roadmap.request.RoadmapOrderTypeRequest; -import co.kirikiri.service.dto.roadmap.response.MemberRoadmapResponse; -import co.kirikiri.service.dto.roadmap.response.MemberRoadmapResponses; -import co.kirikiri.service.dto.roadmap.response.RoadmapCategoryResponse; -import co.kirikiri.service.dto.roadmap.response.RoadmapContentResponse; -import co.kirikiri.service.dto.roadmap.response.RoadmapForListResponse; -import co.kirikiri.service.dto.roadmap.response.RoadmapForListResponses; -import co.kirikiri.service.dto.roadmap.response.RoadmapGoalRoomResponses; -import co.kirikiri.service.dto.roadmap.response.RoadmapNodeResponse; -import co.kirikiri.service.dto.roadmap.response.RoadmapResponse; -import co.kirikiri.service.dto.roadmap.response.RoadmapReviewResponse; -import co.kirikiri.service.dto.roadmap.response.RoadmapTagResponse; -import co.kirikiri.service.roadmap.RoadmapCreateService; -import co.kirikiri.service.roadmap.RoadmapReadService; +import co.kirikiri.member.service.dto.response.MemberResponse; +import co.kirikiri.roadmap.domain.RoadmapDifficulty; +import co.kirikiri.roadmap.service.RoadmapCreateService; +import co.kirikiri.roadmap.service.RoadmapReadService; +import co.kirikiri.roadmap.service.dto.request.RoadmapOrderTypeRequest; +import co.kirikiri.roadmap.service.dto.response.MemberRoadmapGoalRoomResponse; +import co.kirikiri.roadmap.service.dto.response.MemberRoadmapResponse; +import co.kirikiri.roadmap.service.dto.response.MemberRoadmapResponses; +import co.kirikiri.roadmap.service.dto.response.RoadmapCategoryResponse; +import co.kirikiri.roadmap.service.dto.response.RoadmapContentResponse; +import co.kirikiri.roadmap.service.dto.response.RoadmapForListResponse; +import co.kirikiri.roadmap.service.dto.response.RoadmapForListResponses; +import co.kirikiri.roadmap.service.dto.response.RoadmapGoalRoomResponse; +import co.kirikiri.roadmap.service.dto.response.RoadmapGoalRoomResponses; +import co.kirikiri.roadmap.service.dto.response.RoadmapNodeResponse; +import co.kirikiri.roadmap.service.dto.response.RoadmapResponse; +import co.kirikiri.roadmap.service.dto.response.RoadmapReviewResponse; +import co.kirikiri.roadmap.service.dto.response.RoadmapTagResponse; import com.fasterxml.jackson.core.type.TypeReference; import java.time.LocalDate; import java.time.LocalDateTime; @@ -472,7 +473,7 @@ class RoadmapReadApiTest extends ControllerTestHelper { responseFields( fieldWithPath("responses[0].goalRoomId").description("골룸 아이디"), fieldWithPath("responses[0].name").description("골룸 이름"), - fieldWithPath("responses[0].status").description("골룸 상태"), + fieldWithPath("responses[0].goalRoomStatus").description("골룸 상태"), fieldWithPath("responses[0].currentMemberCount").description("현재 골룸에 참여한 인원 수"), fieldWithPath("responses[0].limitedMemberCount").description( "골룸에 참여할 수 있는 제한 인원 수"), @@ -689,15 +690,15 @@ class RoadmapReadApiTest extends ControllerTestHelper { private RoadmapGoalRoomResponses 골룸_응답들을_생성한다() { final RoadmapGoalRoomResponse roadmapGoalRoomResponse1 = new RoadmapGoalRoomResponse(1L, "골룸 이름1", - GoalRoomStatus.RECRUITING, 3, 6, + GoalRoomStatus.RECRUITING.name(), 3, 6, LocalDateTime.of(2023, 7, 20, 13, 0, 0), LocalDate.now(), LocalDate.now().plusDays(100), - new co.kirikiri.goalroom.service.dto.response.MemberResponse(1L, "황시진", "default-member-image")); + new MemberRoadmapGoalRoomResponse(1L, "황시진", "default-member-image")); final RoadmapGoalRoomResponse roadmapGoalRoomResponse2 = new RoadmapGoalRoomResponse(2L, "골룸 이름2", - GoalRoomStatus.RECRUITING, 4, 10, + GoalRoomStatus.RECRUITING.name(), 4, 10, LocalDateTime.of(2023, 7, 10, 13, 0, 0), LocalDate.now(), LocalDate.now().plusDays(100), - new co.kirikiri.goalroom.service.dto.response.MemberResponse(2L, "시진이", "default-member-image")); + new MemberRoadmapGoalRoomResponse(2L, "시진이", "default-member-image")); final List responses = List.of(roadmapGoalRoomResponse1, roadmapGoalRoomResponse2); return new RoadmapGoalRoomResponses(responses, false); diff --git a/backend/kirikiri/src/test/java/co/kirikiri/domain/roadmap/RoadmapCategoryTest.java b/backend/kirikiri/src/test/java/co/kirikiri/roadmap/domain/RoadmapCategoryTest.java similarity index 92% rename from backend/kirikiri/src/test/java/co/kirikiri/domain/roadmap/RoadmapCategoryTest.java rename to backend/kirikiri/src/test/java/co/kirikiri/roadmap/domain/RoadmapCategoryTest.java index 726de9855..255ad2f96 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/domain/roadmap/RoadmapCategoryTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/roadmap/domain/RoadmapCategoryTest.java @@ -1,9 +1,9 @@ -package co.kirikiri.domain.roadmap; +package co.kirikiri.roadmap.domain; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; -import co.kirikiri.domain.roadmap.exception.RoadmapException; +import co.kirikiri.roadmap.domain.exception.RoadmapException; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; diff --git a/backend/kirikiri/src/test/java/co/kirikiri/roadmap/domain/RoadmapContentTest.java b/backend/kirikiri/src/test/java/co/kirikiri/roadmap/domain/RoadmapContentTest.java new file mode 100644 index 000000000..d6974a0f3 --- /dev/null +++ b/backend/kirikiri/src/test/java/co/kirikiri/roadmap/domain/RoadmapContentTest.java @@ -0,0 +1,29 @@ +package co.kirikiri.roadmap.domain; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; + +import co.kirikiri.roadmap.domain.exception.RoadmapException; +import org.junit.jupiter.api.Test; + +class RoadmapContentTest { + + @Test + void 로드맵_본문의_길이가_2000보다_크면_예외가_발생한다() { + // given + final String content = "a".repeat(2001); + + // expect + assertThatThrownBy(() -> new RoadmapContent(content, 1L, null)) + .isInstanceOf(RoadmapException.class); + } + + @Test + void 로드맵_본문은_null값을_허용한다() { + // given + final String content = null; + + // expect + assertDoesNotThrow(() -> new RoadmapContent(content, 1L, null)); + } +} diff --git a/backend/kirikiri/src/test/java/co/kirikiri/roadmap/domain/RoadmapContentsTest.java b/backend/kirikiri/src/test/java/co/kirikiri/roadmap/domain/RoadmapContentsTest.java new file mode 100644 index 000000000..a3f0b63f8 --- /dev/null +++ b/backend/kirikiri/src/test/java/co/kirikiri/roadmap/domain/RoadmapContentsTest.java @@ -0,0 +1,22 @@ +package co.kirikiri.roadmap.domain; + +class RoadmapContentsTest { + +// @Test +// void 로드맵_본문을_추가한다() { +// // given +// final RoadmapNodes roadmapNodes = new RoadmapNodes(List.of(new RoadmapNode("로드맵 노드 제목", "로드맵 노드 내용"))); +// final RoadmapContent roadmapContent = new RoadmapContent("로드맵 본문"); +// roadmapContent.addNodes(roadmapNodes); +// final RoadmapContents roadmapContents = new RoadmapContents(List.of(roadmapContent)); +// final RoadmapContent updatedRoadmapContent = new RoadmapContent("로드맵 본문 수정본"); +// updatedRoadmapContent.addNodes(roadmapNodes); +// +// // when +// roadmapContents.add(updatedRoadmapContent); +// +// // then +// assertThat(roadmapContents.getValues()).usingRecursiveComparison() +// .isEqualTo(List.of(roadmapContent, updatedRoadmapContent)); +// } +} diff --git a/backend/kirikiri/src/test/java/co/kirikiri/domain/roadmap/RoadmapNodeImagesTest.java b/backend/kirikiri/src/test/java/co/kirikiri/roadmap/domain/RoadmapNodeImagesTest.java similarity index 97% rename from backend/kirikiri/src/test/java/co/kirikiri/domain/roadmap/RoadmapNodeImagesTest.java rename to backend/kirikiri/src/test/java/co/kirikiri/roadmap/domain/RoadmapNodeImagesTest.java index 12b46e1ee..ba0566cd6 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/domain/roadmap/RoadmapNodeImagesTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/roadmap/domain/RoadmapNodeImagesTest.java @@ -1,12 +1,12 @@ -package co.kirikiri.domain.roadmap; +package co.kirikiri.roadmap.domain; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import co.kirikiri.common.type.ImageContentType; -import co.kirikiri.domain.roadmap.exception.RoadmapException; -import java.util.List; +import co.kirikiri.roadmap.domain.exception.RoadmapException; import org.junit.jupiter.api.Test; +import java.util.List; class RoadmapNodeImagesTest { diff --git a/backend/kirikiri/src/test/java/co/kirikiri/domain/roadmap/RoadmapNodeTest.java b/backend/kirikiri/src/test/java/co/kirikiri/roadmap/domain/RoadmapNodeTest.java similarity index 91% rename from backend/kirikiri/src/test/java/co/kirikiri/domain/roadmap/RoadmapNodeTest.java rename to backend/kirikiri/src/test/java/co/kirikiri/roadmap/domain/RoadmapNodeTest.java index 97ae660fc..c54a409cf 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/domain/roadmap/RoadmapNodeTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/roadmap/domain/RoadmapNodeTest.java @@ -1,8 +1,8 @@ -package co.kirikiri.domain.roadmap; +package co.kirikiri.roadmap.domain; import static org.assertj.core.api.Assertions.assertThatThrownBy; -import co.kirikiri.domain.roadmap.exception.RoadmapException; +import co.kirikiri.roadmap.domain.exception.RoadmapException; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; diff --git a/backend/kirikiri/src/test/java/co/kirikiri/roadmap/domain/RoadmapNodesTest.java b/backend/kirikiri/src/test/java/co/kirikiri/roadmap/domain/RoadmapNodesTest.java new file mode 100644 index 000000000..965808b8b --- /dev/null +++ b/backend/kirikiri/src/test/java/co/kirikiri/roadmap/domain/RoadmapNodesTest.java @@ -0,0 +1,78 @@ +package co.kirikiri.roadmap.domain; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.jupiter.api.Assertions.assertAll; + +import co.kirikiri.roadmap.domain.exception.RoadmapException; +import org.junit.jupiter.api.Test; +import java.util.List; +import java.util.Optional; + +class RoadmapNodesTest { + + @Test + void 로드맵_본문의_노드의_이름이_겹치면_예외를_던진다() { + // given + final String title = "title"; + final RoadmapNode node1 = new RoadmapNode(title, "content1"); + final RoadmapNode node2 = new RoadmapNode(title, "content1"); + + // when,then + assertThatThrownBy(() -> new RoadmapNodes(List.of(node1, node2))) + .isInstanceOf(RoadmapException.class) + .hasMessage("한 로드맵에 같은 이름의 노드가 존재할 수 없습니다."); + } + + @Test + void 로드맵_노드_아이디로_노드를_반환한다() { + // given + final RoadmapNode node1 = new RoadmapNode(1L, "title1", "content1"); + final RoadmapNode node2 = new RoadmapNode(2L, "title2", "content2"); + final RoadmapNodes roadmapNodes = new RoadmapNodes(List.of(node1, node2)); + + // when + final long findNodeId = 1; + final long notExistId = 3; + final Optional foundNode1 = roadmapNodes.findById(findNodeId); + final Optional foundNode2 = roadmapNodes.findById(notExistId); + + // then + assertAll( + () -> assertThat(node1).isEqualTo(foundNode1.get()), + () -> assertThat(foundNode2).isEmpty() + ); + } + + @Test + void 로드맵_노드_제목으로_노드를_반환한다() { + // given + final RoadmapNode node1 = new RoadmapNode(1L, "title1", "content1"); + final RoadmapNode node2 = new RoadmapNode(2L, "title2", "content2"); + final RoadmapNodes roadmapNodes = new RoadmapNodes(List.of(node1, node2)); + + // when + final String findNodeTitle = "title1"; + final String notExistTitle = "nothing"; + final Optional foundNode1 = roadmapNodes.findByTitle(findNodeTitle); + final Optional foundNode2 = roadmapNodes.findByTitle(notExistTitle); + + // then + assertAll( + () -> assertThat(node1).isEqualTo(foundNode1.get()), + () -> assertThat(foundNode2).isEmpty() + ); + } + + @Test + void 로드맵_노드를_추가한다() { + // given + final RoadmapNodes roadmapNodes = new RoadmapNodes(List.of(new RoadmapNode("로드맵 노드 제목1", "로드맵 노드 내용"))); + + // when + roadmapNodes.add(new RoadmapNode("로드맵 노드 제목2", "로드맵 노드 내용")); + + // then + assertThat(roadmapNodes.getValues()).hasSize(2); + } +} diff --git a/backend/kirikiri/src/test/java/co/kirikiri/domain/roadmap/RoadmapReviewTest.java b/backend/kirikiri/src/test/java/co/kirikiri/roadmap/domain/RoadmapReviewTest.java similarity index 54% rename from backend/kirikiri/src/test/java/co/kirikiri/domain/roadmap/RoadmapReviewTest.java rename to backend/kirikiri/src/test/java/co/kirikiri/roadmap/domain/RoadmapReviewTest.java index 0e7dcd492..54515e4c0 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/domain/roadmap/RoadmapReviewTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/roadmap/domain/RoadmapReviewTest.java @@ -1,17 +1,10 @@ -package co.kirikiri.domain.roadmap; +package co.kirikiri.roadmap.domain; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; -import co.kirikiri.domain.member.EncryptedPassword; -import co.kirikiri.domain.member.Gender; -import co.kirikiri.domain.member.Member; -import co.kirikiri.domain.member.MemberProfile; -import co.kirikiri.domain.member.vo.Identifier; -import co.kirikiri.domain.member.vo.Nickname; -import co.kirikiri.domain.member.vo.Password; -import co.kirikiri.domain.roadmap.exception.RoadmapException; +import co.kirikiri.roadmap.domain.exception.RoadmapException; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; @@ -23,13 +16,12 @@ class RoadmapReviewTest { void 별점이_0부터_5사이의_소수점이_5로_끝나는_값이면서_내용이_1000자_이내라면_정상적으로_생성된다(final Double rate) { // given final String content = "a".repeat(1000); - final MemberProfile profile = new MemberProfile(Gender.FEMALE, "kirikiri1@email.com"); - final Member member = new Member(new Identifier("creator"), new EncryptedPassword(new Password("password1")), - new Nickname("nickname"), null, profile); + final Long memberId = 1L; + final Long roadmapId = 1L; // expected final RoadmapReview roadmapReview = - assertDoesNotThrow(() -> new RoadmapReview(content, rate, member)); + assertDoesNotThrow(() -> new RoadmapReview(content, rate, memberId, roadmapId)); assertThat(roadmapReview) .isInstanceOf(RoadmapReview.class); } @@ -38,12 +30,11 @@ class RoadmapReviewTest { void 리뷰_내용이_1000자를_넘으면_예외가_발생한다() { // given final String content = "a".repeat(1001); - final MemberProfile profile = new MemberProfile(Gender.FEMALE, "kirikiri1@email.com"); - final Member member = new Member(new Identifier("creator"), new EncryptedPassword(new Password("password1")), - new Nickname("nickname"), null, profile); + final Long memberId = 1L; + final Long roadmapId = 1L; // expected - assertThatThrownBy(() -> new RoadmapReview(content, null, member)) + assertThatThrownBy(() -> new RoadmapReview(content, null, memberId, roadmapId)) .isInstanceOf(RoadmapException.class); } @@ -51,12 +42,11 @@ class RoadmapReviewTest { @ValueSource(doubles = {-1, -1.5, 5.5, 1.2, 3.7, 4.55}) void 리뷰_별점이_0과_5사이의_소수점_5_단위의_값이_아니면_예외가_발생한다(final double rate) { // given - final MemberProfile profile = new MemberProfile(Gender.FEMALE, "kirikiri1@email.com"); - final Member member = new Member(new Identifier("creator"), new EncryptedPassword(new Password("password1")), - new Nickname("nickname"), null, profile); + final Long memberId = 1L; + final Long roadmapId = 1L; // expected - assertThatThrownBy(() -> new RoadmapReview("리뷰", rate, member)) + assertThatThrownBy(() -> new RoadmapReview("리뷰", rate, memberId, roadmapId)) .isInstanceOf(RoadmapException.class); } } diff --git a/backend/kirikiri/src/test/java/co/kirikiri/domain/roadmap/RoadmapTagsTest.java b/backend/kirikiri/src/test/java/co/kirikiri/roadmap/domain/RoadmapTagsTest.java similarity index 93% rename from backend/kirikiri/src/test/java/co/kirikiri/domain/roadmap/RoadmapTagsTest.java rename to backend/kirikiri/src/test/java/co/kirikiri/roadmap/domain/RoadmapTagsTest.java index 76ba65ba5..73524b170 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/domain/roadmap/RoadmapTagsTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/roadmap/domain/RoadmapTagsTest.java @@ -1,13 +1,13 @@ -package co.kirikiri.domain.roadmap; +package co.kirikiri.roadmap.domain; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; -import co.kirikiri.domain.roadmap.exception.RoadmapException; -import co.kirikiri.domain.roadmap.vo.RoadmapTagName; -import java.util.List; +import co.kirikiri.roadmap.domain.exception.RoadmapException; +import co.kirikiri.roadmap.domain.vo.RoadmapTagName; import org.junit.jupiter.api.Test; +import java.util.List; class RoadmapTagsTest { diff --git a/backend/kirikiri/src/test/java/co/kirikiri/roadmap/domain/RoadmapTest.java b/backend/kirikiri/src/test/java/co/kirikiri/roadmap/domain/RoadmapTest.java new file mode 100644 index 000000000..becb76891 --- /dev/null +++ b/backend/kirikiri/src/test/java/co/kirikiri/roadmap/domain/RoadmapTest.java @@ -0,0 +1,59 @@ +package co.kirikiri.roadmap.domain; + +import static co.kirikiri.roadmap.domain.RoadmapDifficulty.DIFFICULT; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; + +import co.kirikiri.roadmap.domain.exception.RoadmapException; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; +import java.util.ArrayList; + +class RoadmapTest { + + private final Long creatorId = 1L; + private final RoadmapCategory category = 카테고리를_생성한다(); + private final RoadmapTags emptyTags = new RoadmapTags(new ArrayList<>()); + + @Test + void 로드맵이_성공적으로_생성된다() { + // expect + assertDoesNotThrow(() -> new Roadmap("로드맵 제목", "로드맵 소개글", 30, DIFFICULT, + creatorId, category, null)); + } + + @ParameterizedTest + @ValueSource(ints = {0, 41}) + void 로드맵_제목의_길이가_1보다_작거나_40보다_크면_예외가_발생한다(final int titleLength) { + // given + final String title = "a".repeat(titleLength); + + // expect + assertThatThrownBy(() -> new Roadmap(title, "로드맵 소개글", 30, DIFFICULT, creatorId, category, emptyTags)) + .isInstanceOf(RoadmapException.class); + } + + @ParameterizedTest + @ValueSource(ints = {0, 151}) + void 로드맵_소개글의_길이가_1보다_작거나_150보다_크면_예외가_발생한다(final int introductionLength) { + // given + final String introduction = "a".repeat(introductionLength); + + // expect + assertThatThrownBy(() -> new Roadmap("로드맵 제목", introduction, 30, DIFFICULT, creatorId, category, emptyTags)) + .isInstanceOf(RoadmapException.class); + } + + @ParameterizedTest + @ValueSource(ints = {-1, 1001}) + void 로드맵_추천_소요_기간이_0보다_작고_1000보다_크면_예외가_발생한다(final int requiredPeriod) { + // expect + assertThatThrownBy(() -> new Roadmap("로드맵 제목", "로드맵 소개글", requiredPeriod, DIFFICULT, creatorId, category, emptyTags)) + .isInstanceOf(RoadmapException.class); + } + + private RoadmapCategory 카테고리를_생성한다() { + return new RoadmapCategory(1L, "여가"); + } +} diff --git a/backend/kirikiri/src/test/java/co/kirikiri/domain/roadmap/vo/RoadmapTagNameTest.java b/backend/kirikiri/src/test/java/co/kirikiri/roadmap/domain/vo/RoadmapTagNameTest.java similarity index 94% rename from backend/kirikiri/src/test/java/co/kirikiri/domain/roadmap/vo/RoadmapTagNameTest.java rename to backend/kirikiri/src/test/java/co/kirikiri/roadmap/domain/vo/RoadmapTagNameTest.java index d563697df..84fdd7532 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/domain/roadmap/vo/RoadmapTagNameTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/roadmap/domain/vo/RoadmapTagNameTest.java @@ -1,10 +1,10 @@ -package co.kirikiri.domain.roadmap.vo; +package co.kirikiri.roadmap.domain.vo; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; -import co.kirikiri.domain.roadmap.exception.RoadmapException; +import co.kirikiri.roadmap.domain.exception.RoadmapException; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.CsvSource; import org.junit.jupiter.params.provider.ValueSource; diff --git a/backend/kirikiri/src/test/java/co/kirikiri/roadmap/persistence/RoadmapContentRepositoryTest.java b/backend/kirikiri/src/test/java/co/kirikiri/roadmap/persistence/RoadmapContentRepositoryTest.java new file mode 100644 index 000000000..851df11b8 --- /dev/null +++ b/backend/kirikiri/src/test/java/co/kirikiri/roadmap/persistence/RoadmapContentRepositoryTest.java @@ -0,0 +1,107 @@ +package co.kirikiri.roadmap.persistence; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertAll; + +import co.kirikiri.common.helper.RepositoryTest; +import co.kirikiri.member.domain.EncryptedPassword; +import co.kirikiri.member.domain.Gender; +import co.kirikiri.member.domain.Member; +import co.kirikiri.member.domain.MemberProfile; +import co.kirikiri.member.domain.vo.Identifier; +import co.kirikiri.member.domain.vo.Nickname; +import co.kirikiri.member.domain.vo.Password; +import co.kirikiri.member.persistence.MemberRepository; +import co.kirikiri.roadmap.domain.Roadmap; +import co.kirikiri.roadmap.domain.RoadmapCategory; +import co.kirikiri.roadmap.domain.RoadmapContent; +import co.kirikiri.roadmap.domain.RoadmapDifficulty; +import co.kirikiri.roadmap.domain.RoadmapTags; +import java.util.ArrayList; +import java.util.List; +import org.junit.jupiter.api.Test; + +@RepositoryTest +class RoadmapContentRepositoryTest { + + private final MemberRepository memberRepository; + private final RoadmapCategoryRepository roadmapCategoryRepository; + private final RoadmapRepository roadmapRepository; + private final RoadmapContentRepository roadmapContentRepository; + + public RoadmapContentRepositoryTest(final MemberRepository memberRepository, + final RoadmapCategoryRepository roadmapCategoryRepository, + final RoadmapRepository roadmapRepository, + final RoadmapContentRepository roadmapContentRepository) { + this.memberRepository = memberRepository; + this.roadmapCategoryRepository = roadmapCategoryRepository; + this.roadmapRepository = roadmapRepository; + this.roadmapContentRepository = roadmapContentRepository; + } + + @Test + void 로드맵_아이디로_로드맵의_가장_최근_컨텐츠를_조회한다() { + // given + final Roadmap roadmap = 로드맵을_저장한다(); + 로드맵_컨텐츠를_저장한다(roadmap.getId()); + final RoadmapContent oldRoadmapContent = roadmapContentRepository.findFirstByRoadmapIdOrderByCreatedAtDesc( + roadmap.getId()).get(); + + final RoadmapContent newRoadmapContent = 로드맵_컨텐츠를_저장한다(roadmap.getId()); + + // when + final RoadmapContent expectedRoadmapContent = roadmapContentRepository.findFirstByRoadmapIdOrderByCreatedAtDesc( + roadmap.getId()).get(); + + // then + assertAll( + () -> assertThat(oldRoadmapContent).isNotEqualTo(expectedRoadmapContent), + () -> assertThat(newRoadmapContent).isEqualTo(expectedRoadmapContent) + ); + } + + @Test + void 로드맵에_생성된_모든_컨텐츠를_삭제한다() { + // given + final Roadmap roadmap = 로드맵을_저장한다(); + 로드맵_컨텐츠를_저장한다(roadmap.getId()); + 로드맵_컨텐츠를_저장한다(roadmap.getId()); + + // when + final List roadmapContents = roadmapContentRepository.findAllByRoadmapId(roadmap.getId()); + roadmapContentRepository.deleteAllByRoadmapId(roadmap.getId()); + + // then + assertAll( + () -> assertThat(roadmapContents).hasSize(2), + () -> assertThat(roadmapContentRepository.findAllByRoadmapId(roadmap.getId())) + .isEmpty() + ); + } + + private Roadmap 로드맵을_저장한다() { + final Member creator = 사용자를_생성한다(); + final RoadmapCategory category = 로드맵_카테고리를_생성한다(); + final Roadmap roadmap = new Roadmap("로드맵 제목", "로드맵 설명", 100, RoadmapDifficulty.NORMAL, creator.getId(), + category, new RoadmapTags(new ArrayList<>())); + + return roadmapRepository.save(roadmap); + } + + private Member 사용자를_생성한다() { + final MemberProfile memberProfile = new MemberProfile(Gender.MALE, "kirikiri1@email.com"); + final Member member = new Member(new Identifier("identifier1"), + new EncryptedPassword(new Password("password1!")), new Nickname("썬샷"), null, memberProfile); + + return memberRepository.save(member); + } + + private RoadmapCategory 로드맵_카테고리를_생성한다() { + final RoadmapCategory category = new RoadmapCategory("운동"); + return roadmapCategoryRepository.save(category); + } + + private RoadmapContent 로드맵_컨텐츠를_저장한다(final Long roadmapId) { + return roadmapContentRepository.save(new RoadmapContent("content", roadmapId, null)); + } +} diff --git a/backend/kirikiri/src/test/java/co/kirikiri/persistence/roadmap/RoadmapRepositoryTest.java b/backend/kirikiri/src/test/java/co/kirikiri/roadmap/persistence/RoadmapRepositoryTest.java similarity index 81% rename from backend/kirikiri/src/test/java/co/kirikiri/persistence/roadmap/RoadmapRepositoryTest.java rename to backend/kirikiri/src/test/java/co/kirikiri/roadmap/persistence/RoadmapRepositoryTest.java index 895092486..67275181d 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/persistence/roadmap/RoadmapRepositoryTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/roadmap/persistence/RoadmapRepositoryTest.java @@ -1,29 +1,10 @@ -package co.kirikiri.persistence.roadmap; +package co.kirikiri.roadmap.persistence; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertAll; import co.kirikiri.common.helper.RepositoryTest; import co.kirikiri.common.type.ImageContentType; -import co.kirikiri.domain.member.EncryptedPassword; -import co.kirikiri.domain.member.Gender; -import co.kirikiri.domain.member.Member; -import co.kirikiri.domain.member.MemberImage; -import co.kirikiri.domain.member.MemberProfile; -import co.kirikiri.domain.member.vo.Identifier; -import co.kirikiri.domain.member.vo.Nickname; -import co.kirikiri.domain.member.vo.Password; -import co.kirikiri.domain.roadmap.Roadmap; -import co.kirikiri.domain.roadmap.RoadmapCategory; -import co.kirikiri.domain.roadmap.RoadmapContent; -import co.kirikiri.domain.roadmap.RoadmapDifficulty; -import co.kirikiri.domain.roadmap.RoadmapNode; -import co.kirikiri.domain.roadmap.RoadmapNodes; -import co.kirikiri.domain.roadmap.RoadmapReview; -import co.kirikiri.domain.roadmap.RoadmapStatus; -import co.kirikiri.domain.roadmap.RoadmapTag; -import co.kirikiri.domain.roadmap.RoadmapTags; -import co.kirikiri.domain.roadmap.vo.RoadmapTagName; import co.kirikiri.goalroom.domain.GoalRoom; import co.kirikiri.goalroom.domain.GoalRoomMember; import co.kirikiri.goalroom.domain.GoalRoomRoadmapNode; @@ -34,34 +15,60 @@ import co.kirikiri.goalroom.domain.vo.Period; import co.kirikiri.goalroom.persistence.GoalRoomMemberRepository; import co.kirikiri.goalroom.persistence.GoalRoomRepository; -import co.kirikiri.persistence.dto.RoadmapOrderType; -import co.kirikiri.persistence.dto.RoadmapSearchDto; -import co.kirikiri.persistence.member.MemberRepository; +import co.kirikiri.member.domain.EncryptedPassword; +import co.kirikiri.member.domain.Gender; +import co.kirikiri.member.domain.Member; +import co.kirikiri.member.domain.MemberImage; +import co.kirikiri.member.domain.MemberProfile; +import co.kirikiri.member.domain.vo.Identifier; +import co.kirikiri.member.domain.vo.Nickname; +import co.kirikiri.member.domain.vo.Password; +import co.kirikiri.member.persistence.MemberRepository; +import co.kirikiri.roadmap.domain.Roadmap; +import co.kirikiri.roadmap.domain.RoadmapCategory; +import co.kirikiri.roadmap.domain.RoadmapContent; +import co.kirikiri.roadmap.domain.RoadmapDifficulty; +import co.kirikiri.roadmap.domain.RoadmapNode; +import co.kirikiri.roadmap.domain.RoadmapNodes; +import co.kirikiri.roadmap.domain.RoadmapReview; +import co.kirikiri.roadmap.domain.RoadmapStatus; +import co.kirikiri.roadmap.domain.RoadmapTag; +import co.kirikiri.roadmap.domain.RoadmapTags; +import co.kirikiri.roadmap.domain.vo.RoadmapTagName; +import co.kirikiri.roadmap.persistence.dto.RoadmapOrderType; +import co.kirikiri.roadmap.persistence.dto.RoadmapSearchDto; +import org.junit.jupiter.api.Test; import java.time.LocalDate; import java.time.LocalDateTime; +import java.util.ArrayList; import java.util.List; import java.util.Optional; -import org.junit.jupiter.api.Test; @RepositoryTest class RoadmapRepositoryTest { private final MemberRepository memberRepository; + private final RoadmapCategoryRepository roadmapCategoryRepository; private final RoadmapRepository roadmapRepository; + private final RoadmapContentRepository roadmapContentRepository; + private final RoadmapReviewRepository roadmapReviewRepository; private final GoalRoomRepository goalRoomRepository; private final GoalRoomMemberRepository goalRoomMemberRepository; - private final RoadmapCategoryRepository roadmapCategoryRepository; public RoadmapRepositoryTest(final MemberRepository memberRepository, + final RoadmapCategoryRepository roadmapCategoryRepository, final RoadmapRepository roadmapRepository, + final RoadmapContentRepository roadmapContentRepository, + final RoadmapReviewRepository roadmapReviewRepository, final GoalRoomRepository goalRoomRepository, - final GoalRoomMemberRepository goalRoomMemberRepository, - final RoadmapCategoryRepository roadmapCategoryRepository) { + final GoalRoomMemberRepository goalRoomMemberRepository) { this.memberRepository = memberRepository; + this.roadmapCategoryRepository = roadmapCategoryRepository; this.roadmapRepository = roadmapRepository; + this.roadmapContentRepository = roadmapContentRepository; + this.roadmapReviewRepository = roadmapReviewRepository; this.goalRoomRepository = goalRoomRepository; this.goalRoomMemberRepository = goalRoomMemberRepository; - this.roadmapCategoryRepository = roadmapCategoryRepository; } @Test @@ -69,7 +76,7 @@ public RoadmapRepositoryTest(final MemberRepository memberRepository, // given final Member creator = 사용자를_생성한다("cokirikiri", "코끼리"); final RoadmapCategory category = 카테고리를_생성한다("여가"); - final Roadmap roadmap = new Roadmap("로드맵 제목", "로드맵 소개글", 10, RoadmapDifficulty.NORMAL, creator, category); + final Roadmap roadmap = new Roadmap("로드맵 제목", "로드맵 소개글", 10, RoadmapDifficulty.NORMAL, creator.getId(), category, new RoadmapTags(new ArrayList<>())); // when final Roadmap savedRoadmap = roadmapRepository.save(roadmap); @@ -87,7 +94,7 @@ public RoadmapRepositoryTest(final MemberRepository memberRepository, final Roadmap savedRoadmap = 로드맵을_저장한다("로드맵 제목", creator, category); // when - final Roadmap expectedRoadmap = roadmapRepository.findRoadmapById(savedRoadmap.getId()).get(); + final Roadmap expectedRoadmap = roadmapRepository.findById(savedRoadmap.getId()).get(); assertThat(expectedRoadmap) .usingRecursiveComparison() @@ -191,19 +198,26 @@ public RoadmapRepositoryTest(final MemberRepository memberRepository, final RoadmapCategory gameCategory = 카테고리를_생성한다("게임"); final RoadmapCategory travelCategory = 카테고리를_생성한다("여행"); - final Roadmap gameRoadmap1 = 노드_정보를_포함한_로드맵을_생성한다("게임 로드맵", creator, gameCategory); - final Roadmap gameRoadmap2 = 노드_정보를_포함한_로드맵을_생성한다("게임 로드맵2", creator, gameCategory); - final Roadmap travelRoadmap = 노드_정보를_포함한_로드맵을_생성한다("여행 로드맵", creator, travelCategory); - 노드_정보를_포함한_삭제된_로드맵을_저장한다("여행 로드맵2", creator, travelCategory); + final Roadmap gameRoadmap1 = 로드맵을_저장한다("게임 로드맵", creator, gameCategory); + final RoadmapContent gameRoadmapContent1 = 로드맵_컨텐츠를_저장한다(gameRoadmap1.getId()); + + final Roadmap gameRoadmap2 = 로드맵을_저장한다("게임 로드맵2", creator, gameCategory); + 로드맵_컨텐츠를_저장한다(gameRoadmap2.getId()); + + final Roadmap travelRoadmap = 로드맵을_저장한다("여행 로드맵", creator, travelCategory); + final RoadmapContent travelRoadmapContent = 로드맵_컨텐츠를_저장한다(travelRoadmap.getId()); + + final Roadmap deletedRoadmap = 삭제된_로드맵을_저장한다("여행 로드맵2", creator, travelCategory); + 로드맵_컨텐츠를_저장한다(deletedRoadmap.getId()); // gameRoadmap1 : 골룸 3개 - 골룸을_생성한다(gameRoadmap1.getContents().getValues().get(0), creator); - 골룸을_생성한다(gameRoadmap1.getContents().getValues().get(0), creator); - 골룸을_생성한다(gameRoadmap1.getContents().getValues().get(0), creator); + 골룸을_생성한다(gameRoadmapContent1, creator); + 골룸을_생성한다(gameRoadmapContent1, creator); + 골룸을_생성한다(gameRoadmapContent1, creator); // gameRoadmap2 : 골룸 0개 // travelRoadmap : 골룸 1개 - 골룸을_생성한다(travelRoadmap.getContents().getValues().get(0), creator); + 골룸을_생성한다(travelRoadmapContent, creator); final RoadmapCategory category = null; final RoadmapOrderType orderType = RoadmapOrderType.GOAL_ROOM_COUNT; @@ -236,14 +250,21 @@ public RoadmapRepositoryTest(final MemberRepository memberRepository, final RoadmapCategory gameCategory = 카테고리를_생성한다("게임"); final RoadmapCategory travelCategory = 카테고리를_생성한다("여행"); - final Roadmap gameRoadmap1 = 노드_정보를_포함한_로드맵을_생성한다("게임 로드맵", creator, gameCategory); - final Roadmap gameRoadmap2 = 노드_정보를_포함한_로드맵을_생성한다("게임 로드맵2", creator, gameCategory); - final Roadmap travelRoadmap = 노드_정보를_포함한_로드맵을_생성한다("여행 로드맵", creator, travelCategory); - 노드_정보를_포함한_삭제된_로드맵을_저장한다("여행 로드맵2", creator, travelCategory); + final Roadmap gameRoadmap1 = 로드맵을_저장한다("게임 로드맵", creator, gameCategory); + final RoadmapContent gameRoadmapContent1 = 로드맵_컨텐츠를_저장한다(gameRoadmap1.getId()); + + final Roadmap gameRoadmap2 = 로드맵을_저장한다("게임 로드맵2", creator, gameCategory); + final RoadmapContent gameRoadmapContent2 = 로드맵_컨텐츠를_저장한다(gameRoadmap2.getId()); + + final Roadmap travelRoadmap = 로드맵을_저장한다("여행 로드맵", creator, travelCategory); + final RoadmapContent travelRoadmapContent = 로드맵_컨텐츠를_저장한다(travelRoadmap.getId()); + + final Roadmap deletedRoadmap = 삭제된_로드맵을_저장한다("여행 로드맵2", creator, travelCategory); + 로드맵_컨텐츠를_저장한다(deletedRoadmap.getId()); - 골룸을_생성한다(gameRoadmap1.getContents().getValues().get(0), creator); - final GoalRoom gameRoadmap2GoalRoom = 골룸을_생성한다(gameRoadmap2.getContents().getValues().get(0), creator); - final GoalRoom travelRoadmapGoalRoom = 골룸을_생성한다(travelRoadmap.getContents().getValues().get(0), creator); + 골룸을_생성한다(gameRoadmapContent1, creator); + final GoalRoom gameRoadmap2GoalRoom = 골룸을_생성한다(gameRoadmapContent2, creator); + final GoalRoom travelRoadmapGoalRoom = 골룸을_생성한다(travelRoadmapContent, creator); // gameRoadmap1 : 참가인원 0명 // gameRoadmap2 : 참가인원 1명 @@ -289,25 +310,22 @@ public RoadmapRepositoryTest(final MemberRepository memberRepository, final RoadmapCategory gameCategory = 카테고리를_생성한다("게임"); final RoadmapCategory travelCategory = 카테고리를_생성한다("여행"); - final Roadmap gameRoadmap1 = 노드_정보를_포함한_로드맵을_생성한다("게임 로드맵", creator, gameCategory); - final Roadmap gameRoadmap2 = 노드_정보를_포함한_로드맵을_생성한다("게임 로드맵2", creator, gameCategory); - final Roadmap travelRoadmap = 노드_정보를_포함한_로드맵을_생성한다("여행 로드맵", creator, travelCategory); - 노드_정보를_포함한_삭제된_로드맵을_저장한다("여행 로드맵2", creator, travelCategory); + final Roadmap gameRoadmap1 = 로드맵을_저장한다("게임 로드맵", creator, gameCategory); + final Roadmap gameRoadmap2 = 로드맵을_저장한다("게임 로드맵2", creator, gameCategory); + final Roadmap travelRoadmap = 로드맵을_저장한다("여행 로드맵", creator, travelCategory); + 삭제된_로드맵을_저장한다("여행 로드맵2", creator, travelCategory); // gameRoadmap1 : 4.5 - final RoadmapReview gameRoadmap1Review = new RoadmapReview("리뷰1", 4.5, follower); - gameRoadmap1.addReview(gameRoadmap1Review); - roadmapRepository.save(gameRoadmap1); + final RoadmapReview gameRoadmap1Review = new RoadmapReview("리뷰1", 4.5, follower.getId(), gameRoadmap1.getId()); + roadmapReviewRepository.save(gameRoadmap1Review); // gameRoadmap2 : 5.0 - final RoadmapReview gameRoadmap2Review = new RoadmapReview("리뷰2", 5.0, follower); - gameRoadmap2.addReview(gameRoadmap2Review); - roadmapRepository.save(gameRoadmap2); + final RoadmapReview gameRoadmap2Review = new RoadmapReview("리뷰2", 5.0, follower.getId(), gameRoadmap2.getId()); + roadmapReviewRepository.save(gameRoadmap2Review); // travelRoadmap : 4.0 - final RoadmapReview travelRoadmapReview = new RoadmapReview("리뷰3", 4.0, follower); - travelRoadmap.addReview(travelRoadmapReview); - roadmapRepository.save(travelRoadmap); + final RoadmapReview travelRoadmapReview = new RoadmapReview("리뷰3", 4.0, follower.getId(), travelRoadmap.getId()); + roadmapReviewRepository.save(travelRoadmapReview); final RoadmapCategory category = null; final RoadmapOrderType orderType = RoadmapOrderType.REVIEW_RATE; @@ -463,10 +481,10 @@ public RoadmapRepositoryTest(final MemberRepository memberRepository, roadmapRepository.saveAll(List.of(gameRoadmap, travelRoadmap, deletedGameRoadmap)); // when - final List roadmapsFirstPage = roadmapRepository.findRoadmapsWithCategoryByMemberOrderByLatest(creator, + final List roadmapsFirstPage = roadmapRepository.findRoadmapsWithCategoryByMemberIdOrderByLatest(creator.getId(), null, 2); - final List roadmapsSecondPage = roadmapRepository.findRoadmapsWithCategoryByMemberOrderByLatest( - creator, roadmapsFirstPage.get(1).getId(), 2); + final List roadmapsSecondPage = roadmapRepository.findRoadmapsWithCategoryByMemberIdOrderByLatest( + creator.getId(), roadmapsFirstPage.get(1).getId(), 2); // then assertAll( @@ -525,7 +543,7 @@ public RoadmapRepositoryTest(final MemberRepository memberRepository, } @Test - void 삭제된_로드맵을_로드맵_본문과_함께_조회한다() { + void 삭제된_로드맵을_조회한다() { // given final Member creator = 사용자를_생성한다("cokirikiri", "코끼리"); final RoadmapCategory gameCategory = 카테고리를_생성한다("게임"); @@ -536,14 +554,10 @@ public RoadmapRepositoryTest(final MemberRepository memberRepository, final Roadmap deletedRoadmap = 삭제된_로드맵을_저장한다("로드맵", creator, travelCategory); // when - final List roadmapsByStatus = roadmapRepository.findWithRoadmapContentByStatus(RoadmapStatus.DELETED); + final List roadmapsByStatus = roadmapRepository.findByStatus(RoadmapStatus.DELETED); // then - assertAll( - () -> assertThat(roadmapsByStatus).isEqualTo(List.of(deletedRoadmap)), - () -> assertThat(roadmapsByStatus.get(0).getContents().getValues().get(0).getContent()) - .isEqualTo("로드맵 본문2") - ); + assertThat(roadmapsByStatus).isEqualTo(List.of(deletedRoadmap)); } private Member 사용자를_생성한다(final String identifier, final String nickname) { @@ -560,41 +574,26 @@ public RoadmapRepositoryTest(final MemberRepository memberRepository, } private Roadmap 로드맵을_저장한다(final String title, final Member creator, final RoadmapCategory category) { - final Roadmap roadmap = new Roadmap(title, "로드맵 소개글", 10, RoadmapDifficulty.NORMAL, creator, category); - roadmap.addContent(new RoadmapContent("로드맵 본문")); + final Roadmap roadmap = new Roadmap(title, "로드맵 소개글", 10, RoadmapDifficulty.NORMAL, creator.getId(), category, new RoadmapTags(new ArrayList<>())); return roadmapRepository.save(roadmap); } private Roadmap 삭제된_로드맵을_저장한다(final String title, final Member creator, final RoadmapCategory category) { - final Roadmap roadmap = new Roadmap(title, "로드맵 소개글2", 7, RoadmapDifficulty.DIFFICULT, creator, category); - roadmap.addContent(new RoadmapContent("로드맵 본문2")); + final Roadmap roadmap = new Roadmap(title, "로드맵 소개글2", 7, RoadmapDifficulty.DIFFICULT, creator.getId(), category, new RoadmapTags(new ArrayList<>())); roadmap.delete(); return roadmapRepository.save(roadmap); } - private Roadmap 로드맵을_태그와_저장한다(final String title, final Member creator, final RoadmapCategory category, - final RoadmapTags roadmapTags) { - final Roadmap roadmap = new Roadmap(title, "로드맵 소개글", 10, RoadmapDifficulty.NORMAL, creator, category); - roadmap.addTags(roadmapTags); - return roadmapRepository.save(roadmap); - } - - private Roadmap 노드_정보를_포함한_로드맵을_생성한다(final String title, final Member creator, final RoadmapCategory category) { - final Roadmap roadmap = new Roadmap(title, "로드맵 소개글", 10, RoadmapDifficulty.NORMAL, creator, category); + private RoadmapContent 로드맵_컨텐츠를_저장한다(final Long roadmapId) { final RoadmapNode roadmapNode1 = 로드맵_노드를_생성한다("로드맵 1주차", "로드맵 1주차 내용"); final RoadmapNode roadmapNode2 = 로드맵_노드를_생성한다("로드맵 2주차", "로드맵 2주차 내용"); - final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(List.of(roadmapNode1, roadmapNode2)); - roadmap.addContent(roadmapContent); - return roadmapRepository.save(roadmap); + final RoadmapContent roadmapContent = new RoadmapContent("로드맵 본문", roadmapId, new RoadmapNodes(List.of(roadmapNode1, roadmapNode2))); + return roadmapContentRepository.save(roadmapContent); } - private Roadmap 노드_정보를_포함한_삭제된_로드맵을_저장한다(final String title, final Member creator, final RoadmapCategory category) { - final Roadmap roadmap = new Roadmap(title, "로드맵 소개글", 10, RoadmapDifficulty.NORMAL, creator, category); - final RoadmapNode roadmapNode1 = 로드맵_노드를_생성한다("로드맵 1주차", "로드맵 1주차 내용"); - final RoadmapNode roadmapNode2 = 로드맵_노드를_생성한다("로드맵 2주차", "로드맵 2주차 내용"); - final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(List.of(roadmapNode1, roadmapNode2)); - roadmap.addContent(roadmapContent); - roadmap.delete(); + private Roadmap 로드맵을_태그와_저장한다(final String title, final Member creator, final RoadmapCategory category, + final RoadmapTags roadmapTags) { + final Roadmap roadmap = new Roadmap(title, "로드맵 소개글", 10, RoadmapDifficulty.NORMAL, creator.getId(), category, roadmapTags); return roadmapRepository.save(roadmap); } @@ -602,12 +601,6 @@ public RoadmapRepositoryTest(final MemberRepository memberRepository, return new RoadmapNode(title, content); } - private RoadmapContent 로드맵_본문을_생성한다(final List roadmapNodes) { - final RoadmapContent roadmapContent = new RoadmapContent("로드맵 본문"); - roadmapContent.addNodes(new RoadmapNodes(roadmapNodes)); - return roadmapContent; - } - private GoalRoom 골룸을_생성한다(final RoadmapContent roadmapContent, final Member member) { final LocalDate today = LocalDate.now(); final GoalRoomRoadmapNode goalRoomRoadmapNode1 = 골룸_로드맵_노드를_생성한다(today, today.plusDays(10), diff --git a/backend/kirikiri/src/test/java/co/kirikiri/persistence/roadmap/RoadmapReviewRepositoryTest.java b/backend/kirikiri/src/test/java/co/kirikiri/roadmap/persistence/RoadmapReviewRepositoryTest.java similarity index 54% rename from backend/kirikiri/src/test/java/co/kirikiri/persistence/roadmap/RoadmapReviewRepositoryTest.java rename to backend/kirikiri/src/test/java/co/kirikiri/roadmap/persistence/RoadmapReviewRepositoryTest.java index 184fe21f1..ff6cf8bfb 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/persistence/roadmap/RoadmapReviewRepositoryTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/roadmap/persistence/RoadmapReviewRepositoryTest.java @@ -1,26 +1,21 @@ -package co.kirikiri.persistence.roadmap; +package co.kirikiri.roadmap.persistence; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertAll; -import co.kirikiri.common.type.ImageContentType; -import co.kirikiri.domain.member.EncryptedPassword; -import co.kirikiri.domain.member.Gender; -import co.kirikiri.domain.member.Member; -import co.kirikiri.domain.member.MemberImage; -import co.kirikiri.domain.member.MemberProfile; -import co.kirikiri.domain.member.vo.Identifier; -import co.kirikiri.domain.member.vo.Nickname; -import co.kirikiri.domain.member.vo.Password; -import co.kirikiri.domain.roadmap.Roadmap; -import co.kirikiri.domain.roadmap.RoadmapCategory; -import co.kirikiri.domain.roadmap.RoadmapContent; -import co.kirikiri.domain.roadmap.RoadmapDifficulty; -import co.kirikiri.domain.roadmap.RoadmapNode; -import co.kirikiri.domain.roadmap.RoadmapNodes; -import co.kirikiri.domain.roadmap.RoadmapReview; import co.kirikiri.common.helper.RepositoryTest; -import co.kirikiri.persistence.member.MemberRepository; +import co.kirikiri.common.type.ImageContentType; +import co.kirikiri.member.domain.EncryptedPassword; +import co.kirikiri.member.domain.Gender; +import co.kirikiri.member.domain.Member; +import co.kirikiri.member.domain.MemberImage; +import co.kirikiri.member.domain.MemberProfile; +import co.kirikiri.member.domain.vo.Identifier; +import co.kirikiri.member.domain.vo.Nickname; +import co.kirikiri.member.domain.vo.Password; +import co.kirikiri.member.persistence.MemberRepository; +import co.kirikiri.roadmap.domain.RoadmapCategory; +import co.kirikiri.roadmap.domain.RoadmapReview; import java.util.List; import java.util.Optional; import org.junit.jupiter.api.Test; @@ -47,19 +42,18 @@ public RoadmapReviewRepositoryTest(final MemberRepository memberRepository, void 로드맵과_사용자로_로드맵_리뷰_정보가_존재하면_반환한다() { // given final Member member = 사용자를_저장한다("코끼리", "cokirikiri"); - final RoadmapCategory category = 카테고리를_저장한다("게임"); - final Roadmap roadmap = 로드맵을_저장한다(member, category); + final Long roadmapId = 1L; - final RoadmapReview roadmapReview = new RoadmapReview("리뷰", 1.5, member); - roadmapReview.updateRoadmap(roadmap); + final RoadmapReview roadmapReview = new RoadmapReview("리뷰", 1.5, member.getId(), roadmapId); roadmapReviewRepository.save(roadmapReview); // when - final RoadmapReview findRoadmapReview = roadmapReviewRepository.findByRoadmapAndMember(roadmap, member).get(); + final RoadmapReview findRoadmapReview = roadmapReviewRepository.findByRoadmapIdAndMemberId(roadmapId, + member.getId()) + .get(); // then - assertThat(findRoadmapReview) - .isEqualTo(roadmapReview); + assertThat(findRoadmapReview).isEqualTo(roadmapReview); } @Test @@ -67,20 +61,17 @@ public RoadmapReviewRepositoryTest(final MemberRepository memberRepository, // given final Member member = 사용자를_저장한다("코끼리", "cokirikiri"); final Member member2 = 사용자를_저장한다("끼리코", "kirikirico"); - final RoadmapCategory category = 카테고리를_저장한다("게임"); - final Roadmap roadmap = 로드맵을_저장한다(member, category); + final Long roadmapId = 1L; - final RoadmapReview roadmapReview = new RoadmapReview("리뷰", 2.5, member); - roadmapReview.updateRoadmap(roadmap); + final RoadmapReview roadmapReview = new RoadmapReview("리뷰", 2.5, member.getId(), roadmapId); roadmapReviewRepository.save(roadmapReview); // when - final Optional findRoadmapReview = roadmapReviewRepository.findByRoadmapAndMember(roadmap, - member2); + final Optional findRoadmapReview = roadmapReviewRepository.findByRoadmapIdAndMemberId(roadmapId, + member2.getId()); // then - assertThat(findRoadmapReview) - .isEmpty(); + assertThat(findRoadmapReview).isEmpty(); } @Test @@ -89,25 +80,21 @@ public RoadmapReviewRepositoryTest(final MemberRepository memberRepository, final Member member = 사용자를_저장한다("코끼리", "cokirikiri"); final Member member2 = 사용자를_저장한다("끼리코", "kirikirico"); final Member member3 = 사용자를_저장한다("리끼코", "rikirikico"); - final RoadmapCategory category = 카테고리를_저장한다("게임"); - final Roadmap roadmap = 로드맵을_저장한다(member, category); - - final RoadmapReview roadmapReview1 = new RoadmapReview("리뷰1", 2.5, member); - final RoadmapReview roadmapReview2 = new RoadmapReview("리뷰2", 4.0, member2); - final RoadmapReview roadmapReview3 = new RoadmapReview("리뷰3", 5.0, member3); - roadmapReview1.updateRoadmap(roadmap); - roadmapReview2.updateRoadmap(roadmap); - roadmapReview3.updateRoadmap(roadmap); + final Long roadmapId = 1L; + + final RoadmapReview roadmapReview1 = new RoadmapReview("리뷰1", 2.5, member.getId(), roadmapId); + final RoadmapReview roadmapReview2 = new RoadmapReview("리뷰2", 4.0, member2.getId(), roadmapId); + final RoadmapReview roadmapReview3 = new RoadmapReview("리뷰3", 5.0, member3.getId(), roadmapId); roadmapReviewRepository.save(roadmapReview1); roadmapReviewRepository.save(roadmapReview2); roadmapReviewRepository.save(roadmapReview3); // when - final List roadmapReviewsFirstPage = roadmapReviewRepository.findRoadmapReviewWithMemberByRoadmapOrderByLatest( - roadmap, null, 2); + final List roadmapReviewsFirstPage = roadmapReviewRepository.findRoadmapReviewByRoadmapIdOrderByLatest( + roadmapId, null, 2); - final List roadmapReviewsSecondPage = roadmapReviewRepository.findRoadmapReviewWithMemberByRoadmapOrderByLatest( - roadmap, roadmapReviewsFirstPage.get(1).getId(), 2); + final List roadmapReviewsSecondPage = roadmapReviewRepository.findRoadmapReviewByRoadmapIdOrderByLatest( + roadmapId, roadmapReviewsFirstPage.get(1).getId(), 2); // then assertAll( @@ -122,18 +109,15 @@ public RoadmapReviewRepositoryTest(final MemberRepository memberRepository, void 로드맵에_대한_리뷰_정보가_없으면_빈_값을_반환한다() { // given final Member member = 사용자를_저장한다("코끼리", "cokirikiri"); - final Member member2 = 사용자를_저장한다("끼리코", "kirikirico"); - final RoadmapCategory category = 카테고리를_저장한다("게임"); - final Roadmap roadmap1 = 로드맵을_저장한다(member, category); - final Roadmap roadmap2 = 로드맵을_저장한다(member2, category); + final Long roadmapId = 1L; + final Long roadmapId2 = 2L; - final RoadmapReview roadmapReview = new RoadmapReview("리뷰", 2.5, member); - roadmapReview.updateRoadmap(roadmap1); + final RoadmapReview roadmapReview = new RoadmapReview("리뷰", 2.5, member.getId(), roadmapId2); roadmapReviewRepository.save(roadmapReview); // when - final List roadmapReviewsFirstPage = roadmapReviewRepository.findRoadmapReviewWithMemberByRoadmapOrderByLatest( - roadmap2, null, 1); + final List roadmapReviewsFirstPage = roadmapReviewRepository.findRoadmapReviewByRoadmapIdOrderByLatest( + roadmapId, null, 1); // then assertThat(roadmapReviewsFirstPage).isEmpty(); @@ -151,24 +135,4 @@ public RoadmapReviewRepositoryTest(final MemberRepository memberRepository, final RoadmapCategory roadmapCategory = new RoadmapCategory(name); return roadmapCategoryRepository.save(roadmapCategory); } - - private Roadmap 로드맵을_저장한다(final Member creator, final RoadmapCategory category) { - final List roadmapNodes = 로드맵_노드들을_생성한다(); - final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmapNodes); - final Roadmap roadmap = new Roadmap("로드맵 제목", "로드맵 소개글", 10, RoadmapDifficulty.NORMAL, creator, category); - roadmap.addContent(roadmapContent); - return roadmapRepository.save(roadmap); - } - - private List 로드맵_노드들을_생성한다() { - final RoadmapNode roadmapNode1 = new RoadmapNode("로드맵 1주차", "로드맵 1주차 내용"); - final RoadmapNode roadmapNode2 = new RoadmapNode("로드맵 2주차", "로드맵 2주차 내용"); - return List.of(roadmapNode1, roadmapNode2); - } - - private RoadmapContent 로드맵_본문을_생성한다(final List roadmapNodes) { - final RoadmapContent roadmapContent = new RoadmapContent("로드맵 본문"); - roadmapContent.addNodes(new RoadmapNodes(roadmapNodes)); - return roadmapContent; - } } diff --git a/backend/kirikiri/src/test/java/co/kirikiri/persistence/dto/RoadmapSearchTagNameTest.java b/backend/kirikiri/src/test/java/co/kirikiri/roadmap/persistence/dto/RoadmapSearchTagNameTest.java similarity index 89% rename from backend/kirikiri/src/test/java/co/kirikiri/persistence/dto/RoadmapSearchTagNameTest.java rename to backend/kirikiri/src/test/java/co/kirikiri/roadmap/persistence/dto/RoadmapSearchTagNameTest.java index 795be340d..eaac6349a 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/persistence/dto/RoadmapSearchTagNameTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/roadmap/persistence/dto/RoadmapSearchTagNameTest.java @@ -1,10 +1,10 @@ -package co.kirikiri.persistence.dto; +package co.kirikiri.roadmap.persistence.dto; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; -import co.kirikiri.common.exception.BadRequestException; +import co.kirikiri.roadmap.domain.exception.RoadmapException; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.CsvSource; import org.junit.jupiter.params.provider.ValueSource; @@ -40,6 +40,6 @@ class RoadmapSearchTagNameTest { // expected assertThatThrownBy(() -> new RoadmapSearchTagName(name)) - .isInstanceOf(BadRequestException.class); + .isInstanceOf(RoadmapException.class); } } diff --git a/backend/kirikiri/src/test/java/co/kirikiri/persistence/dto/RoadmapSearchTitleTest.java b/backend/kirikiri/src/test/java/co/kirikiri/roadmap/persistence/dto/RoadmapSearchTitleTest.java similarity index 89% rename from backend/kirikiri/src/test/java/co/kirikiri/persistence/dto/RoadmapSearchTitleTest.java rename to backend/kirikiri/src/test/java/co/kirikiri/roadmap/persistence/dto/RoadmapSearchTitleTest.java index 10e762ae4..698710a89 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/persistence/dto/RoadmapSearchTitleTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/roadmap/persistence/dto/RoadmapSearchTitleTest.java @@ -1,10 +1,10 @@ -package co.kirikiri.persistence.dto; +package co.kirikiri.roadmap.persistence.dto; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; -import co.kirikiri.common.exception.BadRequestException; +import co.kirikiri.roadmap.domain.exception.RoadmapException; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.CsvSource; import org.junit.jupiter.params.provider.ValueSource; @@ -40,6 +40,6 @@ class RoadmapSearchTitleTest { // expected assertThatThrownBy(() -> new RoadmapSearchTitle(title)) - .isInstanceOf(BadRequestException.class); + .isInstanceOf(RoadmapException.class); } } diff --git a/backend/kirikiri/src/test/java/co/kirikiri/common/resolver/RoadmapSaveArgumentResolverTest.java b/backend/kirikiri/src/test/java/co/kirikiri/roadmap/resolver/RoadmapSaveArgumentResolverImplTest.java similarity index 91% rename from backend/kirikiri/src/test/java/co/kirikiri/common/resolver/RoadmapSaveArgumentResolverTest.java rename to backend/kirikiri/src/test/java/co/kirikiri/roadmap/resolver/RoadmapSaveArgumentResolverImplTest.java index 5ee14a499..bf63d3c5e 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/common/resolver/RoadmapSaveArgumentResolverTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/roadmap/resolver/RoadmapSaveArgumentResolverImplTest.java @@ -1,15 +1,14 @@ -package co.kirikiri.common.resolver; +package co.kirikiri.roadmap.resolver; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.mockito.Mockito.when; import co.kirikiri.common.exception.BadRequestException; -import co.kirikiri.service.dto.member.request.MemberJoinRequest; -import co.kirikiri.service.dto.roadmap.request.RoadmapSaveRequest; +import co.kirikiri.member.service.dto.request.MemberJoinRequest; +import co.kirikiri.roadmap.service.dto.request.RoadmapSaveRequest; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; -import javax.xml.validation.Validator; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; @@ -24,14 +23,11 @@ import org.springframework.web.method.support.ModelAndViewContainer; @ExtendWith(MockitoExtension.class) -class RoadmapSaveArgumentResolverTest { +class RoadmapSaveArgumentResolverImplTest { @Mock private ObjectMapper objectMapper; - @Mock - private Validator validator; - @Mock private MethodParameter parameter; @@ -45,7 +41,7 @@ class RoadmapSaveArgumentResolverTest { private WebDataBinderFactory binderFactory; @InjectMocks - private RoadmapSaveArgumentResolver resolver; + private RoadmapSaveArgumentResolverImpl resolver; @Test void 정상적으로_핸들러의_파라미터가_객체를_타도록_한다() { diff --git a/backend/kirikiri/src/test/java/co/kirikiri/service/RoadmapCreateEventListenerTest.java b/backend/kirikiri/src/test/java/co/kirikiri/roadmap/service/RoadmapCreateEventListenerTest.java similarity index 62% rename from backend/kirikiri/src/test/java/co/kirikiri/service/RoadmapCreateEventListenerTest.java rename to backend/kirikiri/src/test/java/co/kirikiri/roadmap/service/RoadmapCreateEventListenerTest.java index c102b2277..a73936ced 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/service/RoadmapCreateEventListenerTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/roadmap/service/RoadmapCreateEventListenerTest.java @@ -1,36 +1,34 @@ -package co.kirikiri.service; +package co.kirikiri.roadmap.service; import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; import co.kirikiri.common.exception.BadRequestException; import co.kirikiri.common.exception.ServerException; import co.kirikiri.common.service.FilePathGenerator; import co.kirikiri.common.service.FileService; import co.kirikiri.common.service.dto.FileInformation; -import co.kirikiri.domain.member.EncryptedPassword; -import co.kirikiri.domain.member.Gender; -import co.kirikiri.domain.member.Member; -import co.kirikiri.domain.member.MemberProfile; -import co.kirikiri.domain.member.vo.Identifier; -import co.kirikiri.domain.member.vo.Nickname; -import co.kirikiri.domain.member.vo.Password; -import co.kirikiri.domain.roadmap.Roadmap; -import co.kirikiri.domain.roadmap.RoadmapCategory; -import co.kirikiri.domain.roadmap.RoadmapContent; -import co.kirikiri.domain.roadmap.RoadmapDifficulty; -import co.kirikiri.domain.roadmap.RoadmapNode; -import co.kirikiri.domain.roadmap.RoadmapNodes; -import co.kirikiri.persistence.roadmap.RoadmapContentRepository; -import co.kirikiri.service.dto.roadmap.RoadmapNodeSaveDto; -import co.kirikiri.service.dto.roadmap.RoadmapSaveDto; -import co.kirikiri.service.dto.roadmap.RoadmapTagSaveDto; -import co.kirikiri.service.dto.roadmap.request.RoadmapDifficultyType; -import co.kirikiri.service.event.RoadmapCreateEvent; -import co.kirikiri.service.roadmap.RoadmapCreateEventListener; +import co.kirikiri.roadmap.domain.Roadmap; +import co.kirikiri.roadmap.domain.RoadmapCategory; +import co.kirikiri.roadmap.domain.RoadmapContent; +import co.kirikiri.roadmap.domain.RoadmapDifficulty; +import co.kirikiri.roadmap.domain.RoadmapNode; +import co.kirikiri.roadmap.domain.RoadmapNodes; +import co.kirikiri.roadmap.domain.RoadmapStatus; +import co.kirikiri.roadmap.domain.RoadmapTags; +import co.kirikiri.roadmap.persistence.RoadmapContentRepository; +import co.kirikiri.roadmap.service.dto.RoadmapNodeSaveDto; +import co.kirikiri.roadmap.service.dto.RoadmapSaveDto; +import co.kirikiri.roadmap.service.dto.RoadmapTagSaveDto; +import co.kirikiri.roadmap.service.dto.request.RoadmapDifficultyType; +import co.kirikiri.roadmap.service.event.RoadmapCreateEvent; import java.io.IOException; +import java.util.ArrayList; import java.util.List; +import java.util.Optional; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; @@ -42,9 +40,7 @@ @ExtendWith(MockitoExtension.class) class RoadmapCreateEventListenerTest { - private static final Member member = new Member(1L, new Identifier("identifier1"), - null, new EncryptedPassword(new Password("password1!")), new Nickname("닉네임"), null, - new MemberProfile(Gender.FEMALE, "kirikiri@email.com")); + private final Long memberId = 1L; @Mock private RoadmapContentRepository roadmapContentRepository; @@ -60,13 +56,12 @@ null, new EncryptedPassword(new Password("password1!")), new Nickname("닉네임 @Test void 정상적으로_로드맵_노드_이미지를_저장한다() throws IOException { - // given - final RoadmapContent roadmapContent = new RoadmapContent("roadmapContent"); + final Roadmap roadmap = new Roadmap(1L, "roadmapTitle", "introduction", 10, + RoadmapDifficulty.DIFFICULT, RoadmapStatus.CREATED, memberId, new RoadmapCategory("category"), + new RoadmapTags(new ArrayList<>())); final RoadmapNode roadmapNode = new RoadmapNode("roadmapNodeTitle", "roadmapNodeContent"); - roadmapContent.addNodes(new RoadmapNodes(List.of(roadmapNode))); - - final Roadmap roadmap = new Roadmap("roadmapTitle", "inroduction", 10, - RoadmapDifficulty.DIFFICULT, member, new RoadmapCategory("category")); + final RoadmapContent roadmapContent = new RoadmapContent("roadmapContent", roadmap.getId(), + new RoadmapNodes(List.of(roadmapNode))); final MultipartFile imageFile = new MockMultipartFile(roadmapNode.getTitle(), "originalFileName.jpeg", "image/jpeg", "tempImage".getBytes()); @@ -78,22 +73,22 @@ null, new EncryptedPassword(new Password("password1!")), new Nickname("닉네임 roadmapContent.getContent(), RoadmapDifficultyType.DIFFICULT, 10, List.of(roadmapNodeSaveDto), List.of(new RoadmapTagSaveDto("tag"))); - roadmap.addContent(roadmapContent); - - final RoadmapCreateEvent roadmapCreateEvent = new RoadmapCreateEvent(roadmap, roadmapSaveDto); + final RoadmapCreateEvent roadmapCreateEvent = new RoadmapCreateEvent(roadmap.getId(), roadmapSaveDto); - // when + // When + when(roadmapContentRepository.findFirstByRoadmapIdOrderByCreatedAtDesc(anyLong())) + .thenReturn(Optional.of(roadmapContent)); roadmapCreateEventListener.handleRoadmapCreate(roadmapCreateEvent); - // then + // Then verify(roadmapContentRepository, times(1)).save(roadmapContent); } @Test void 로드맵에_컨텐츠가_존재하지_않을_경우_예외를_던진다() throws IOException { //given - final Roadmap roadmap = new Roadmap("roadmapTitle", "inroduction", 10, - RoadmapDifficulty.DIFFICULT, member, new RoadmapCategory("category")); + final Roadmap roadmap = new Roadmap(1L, "roadmapTitle", "inroduction", 10, RoadmapDifficulty.DIFFICULT, + RoadmapStatus.CREATED, memberId, new RoadmapCategory("category"), new RoadmapTags(new ArrayList<>())); final MultipartFile imageFile = new MockMultipartFile("roadmapNodeTitle", "originalFileName.jpeg", "image/jpeg", "tempImage".getBytes()); @@ -105,23 +100,26 @@ null, new EncryptedPassword(new Password("password1!")), new Nickname("닉네임 "roadmapNodeContent", RoadmapDifficultyType.DIFFICULT, 10, List.of(roadmapNodeSaveDto), List.of(new RoadmapTagSaveDto("tag"))); - final RoadmapCreateEvent roadmapCreateEvent = new RoadmapCreateEvent(roadmap, roadmapSaveDto); + final RoadmapCreateEvent roadmapCreateEvent = new RoadmapCreateEvent(roadmap.getId(), roadmapSaveDto); //when + when(roadmapContentRepository.findFirstByRoadmapIdOrderByCreatedAtDesc(anyLong())) + .thenReturn(Optional.empty()); + //then assertThatThrownBy(() -> roadmapCreateEventListener.handleRoadmapCreate(roadmapCreateEvent)) - .isInstanceOf(ServerException.class); + .isInstanceOf(ServerException.class) + .hasMessage("로드맵 컨텐츠가 존재하지 않습니다."); } @Test void 로드맵_노드_제목을_가진_노드가_로드맵에_존재하지_않을때_예외를_던진다() throws IOException { //given - final RoadmapContent roadmapContent = new RoadmapContent("roadmapContent"); + final Roadmap roadmap = new Roadmap(1L, "roadmapTitle", "introduction", 10, RoadmapDifficulty.DIFFICULT, + RoadmapStatus.CREATED, memberId, new RoadmapCategory("category"), new RoadmapTags(new ArrayList<>())); final RoadmapNode roadmapNode = new RoadmapNode("roadmapNodeTitle", "roadmapNodeContent"); - roadmapContent.addNodes(new RoadmapNodes(List.of(roadmapNode))); - - final Roadmap roadmap = new Roadmap("roadmapTitle", "inroduction", 10, - RoadmapDifficulty.DIFFICULT, member, new RoadmapCategory("category")); + final RoadmapContent roadmapContent = new RoadmapContent("roadmapContent", roadmap.getId(), + new RoadmapNodes(List.of(roadmapNode))); final MultipartFile imageFile = new MockMultipartFile(roadmapNode.getTitle(), "originalFileName.jpeg", "image/jpeg", "tempImage".getBytes()); @@ -133,43 +131,47 @@ null, new EncryptedPassword(new Password("password1!")), new Nickname("닉네임 roadmapContent.getContent(), RoadmapDifficultyType.DIFFICULT, 10, List.of(roadmapNodeSaveDto), List.of(new RoadmapTagSaveDto("tag"))); - roadmap.addContent(roadmapContent); - - final RoadmapCreateEvent roadmapCreateEvent = new RoadmapCreateEvent(roadmap, roadmapSaveDto); + final RoadmapCreateEvent roadmapCreateEvent = new RoadmapCreateEvent(roadmap.getId(), roadmapSaveDto); //when + when(roadmapContentRepository.findFirstByRoadmapIdOrderByCreatedAtDesc(anyLong())) + .thenReturn(Optional.of(roadmapContent)); + //then assertThatThrownBy(() -> roadmapCreateEventListener.handleRoadmapCreate(roadmapCreateEvent)) - .isInstanceOf(BadRequestException.class); + .isInstanceOf(BadRequestException.class) + .hasMessage("해당 제목을 가지고 있는 로드맵 노드가 없습니다. title = Wrong Title"); } @Test void 로드맵_노드_이미지에_원본_파일_이름이_없을_경우_예외를_던진다() throws IOException { //given - final RoadmapContent roadmapContent = new RoadmapContent("roadmapContent"); + final Roadmap roadmap = new Roadmap(1L, "roadmapTitle", "inroduction", 10, RoadmapDifficulty.DIFFICULT, + RoadmapStatus.CREATED, memberId, new RoadmapCategory("category"), new RoadmapTags(new ArrayList<>())); final RoadmapNode roadmapNode = new RoadmapNode("roadmapNodeTitle", "roadmapNodeContent"); - roadmapContent.addNodes(new RoadmapNodes(List.of(roadmapNode))); - - final Roadmap roadmap = new Roadmap("roadmapTitle", "inroduction", 10, - RoadmapDifficulty.DIFFICULT, member, new RoadmapCategory("category")); + final RoadmapContent roadmapContent = new RoadmapContent("roadmapContent", roadmap.getId(), + new RoadmapNodes(List.of(roadmapNode))); final MultipartFile imageFile = new MockMultipartFile(roadmapNode.getTitle(), null, "image/jpeg", "tempImage".getBytes()); - final FileInformation fileInformation = new FileInformation(imageFile.getOriginalFilename(), - imageFile.getSize(), imageFile.getContentType(), imageFile.getInputStream()); - final RoadmapNodeSaveDto roadmapNodeSaveDto = new RoadmapNodeSaveDto("Wrong Title", roadmapNode.getContent(), + final FileInformation fileInformation = new FileInformation(null, imageFile.getSize(), + imageFile.getContentType(), imageFile.getInputStream()); + final RoadmapNodeSaveDto roadmapNodeSaveDto = new RoadmapNodeSaveDto("roadmapNodeTitle", + roadmapNode.getContent(), List.of(fileInformation)); final RoadmapSaveDto roadmapSaveDto = new RoadmapSaveDto(1L, roadmap.getTitle(), roadmap.getIntroduction(), roadmapContent.getContent(), RoadmapDifficultyType.DIFFICULT, 10, List.of(roadmapNodeSaveDto), List.of(new RoadmapTagSaveDto("tag"))); - roadmap.addContent(roadmapContent); - - final RoadmapCreateEvent roadmapCreateEvent = new RoadmapCreateEvent(roadmap, roadmapSaveDto); + final RoadmapCreateEvent roadmapCreateEvent = new RoadmapCreateEvent(roadmap.getId(), roadmapSaveDto); //when + when(roadmapContentRepository.findFirstByRoadmapIdOrderByCreatedAtDesc(anyLong())) + .thenReturn(Optional.of(roadmapContent)); + //then assertThatThrownBy(() -> roadmapCreateEventListener.handleRoadmapCreate(roadmapCreateEvent)) - .isInstanceOf(BadRequestException.class); + .isInstanceOf(BadRequestException.class) + .hasMessage("원본 파일의 이름이 존재하지 않습니다."); } } diff --git a/backend/kirikiri/src/test/java/co/kirikiri/service/RoadmapCreateServiceTest.java b/backend/kirikiri/src/test/java/co/kirikiri/roadmap/service/RoadmapCreateServiceTest.java similarity index 71% rename from backend/kirikiri/src/test/java/co/kirikiri/service/RoadmapCreateServiceTest.java rename to backend/kirikiri/src/test/java/co/kirikiri/roadmap/service/RoadmapCreateServiceTest.java index 61472c51b..d1b374bfe 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/service/RoadmapCreateServiceTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/roadmap/service/RoadmapCreateServiceTest.java @@ -1,4 +1,4 @@ -package co.kirikiri.service; +package co.kirikiri.roadmap.service; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; @@ -17,43 +17,34 @@ import co.kirikiri.common.exception.ConflictException; import co.kirikiri.common.exception.ForbiddenException; import co.kirikiri.common.exception.NotFoundException; -import co.kirikiri.domain.member.EncryptedPassword; -import co.kirikiri.domain.member.Gender; -import co.kirikiri.domain.member.Member; -import co.kirikiri.domain.member.MemberProfile; -import co.kirikiri.domain.member.vo.Identifier; -import co.kirikiri.domain.member.vo.Nickname; -import co.kirikiri.domain.member.vo.Password; -import co.kirikiri.domain.roadmap.Roadmap; -import co.kirikiri.domain.roadmap.RoadmapCategory; -import co.kirikiri.domain.roadmap.RoadmapContent; -import co.kirikiri.domain.roadmap.RoadmapContents; -import co.kirikiri.domain.roadmap.RoadmapDifficulty; -import co.kirikiri.domain.roadmap.RoadmapReview; -import co.kirikiri.goalroom.domain.GoalRoom; -import co.kirikiri.goalroom.domain.GoalRoomMember; -import co.kirikiri.goalroom.domain.GoalRoomRoadmapNode; -import co.kirikiri.goalroom.domain.GoalRoomRoadmapNodes; -import co.kirikiri.goalroom.domain.GoalRoomRole; -import co.kirikiri.goalroom.domain.vo.GoalRoomName; -import co.kirikiri.goalroom.domain.vo.LimitedMemberCount; -import co.kirikiri.goalroom.domain.vo.Period; -import co.kirikiri.goalroom.persistence.GoalRoomMemberRepository; -import co.kirikiri.goalroom.persistence.GoalRoomRepository; -import co.kirikiri.persistence.member.MemberRepository; -import co.kirikiri.persistence.roadmap.RoadmapCategoryRepository; -import co.kirikiri.persistence.roadmap.RoadmapContentRepository; -import co.kirikiri.persistence.roadmap.RoadmapRepository; -import co.kirikiri.persistence.roadmap.RoadmapReviewRepository; -import co.kirikiri.service.dto.roadmap.request.RoadmapCategorySaveRequest; -import co.kirikiri.service.dto.roadmap.request.RoadmapDifficultyType; -import co.kirikiri.service.dto.roadmap.request.RoadmapNodeSaveRequest; -import co.kirikiri.service.dto.roadmap.request.RoadmapReviewSaveRequest; -import co.kirikiri.service.dto.roadmap.request.RoadmapSaveRequest; -import co.kirikiri.service.dto.roadmap.request.RoadmapTagSaveRequest; -import co.kirikiri.service.roadmap.RoadmapCreateService; -import java.time.LocalDate; -import java.time.LocalDateTime; +import co.kirikiri.member.domain.EncryptedPassword; +import co.kirikiri.member.domain.Gender; +import co.kirikiri.member.domain.Member; +import co.kirikiri.member.domain.MemberProfile; +import co.kirikiri.member.domain.vo.Identifier; +import co.kirikiri.member.domain.vo.Nickname; +import co.kirikiri.member.domain.vo.Password; +import co.kirikiri.member.persistence.MemberRepository; +import co.kirikiri.roadmap.domain.Roadmap; +import co.kirikiri.roadmap.domain.RoadmapCategory; +import co.kirikiri.roadmap.domain.RoadmapContent; +import co.kirikiri.roadmap.domain.RoadmapDifficulty; +import co.kirikiri.roadmap.domain.RoadmapReview; +import co.kirikiri.roadmap.domain.RoadmapStatus; +import co.kirikiri.roadmap.domain.RoadmapTag; +import co.kirikiri.roadmap.domain.RoadmapTags; +import co.kirikiri.roadmap.domain.vo.RoadmapTagName; +import co.kirikiri.roadmap.persistence.RoadmapCategoryRepository; +import co.kirikiri.roadmap.persistence.RoadmapContentRepository; +import co.kirikiri.roadmap.persistence.RoadmapRepository; +import co.kirikiri.roadmap.persistence.RoadmapReviewRepository; +import co.kirikiri.roadmap.service.dto.request.RoadmapCategorySaveRequest; +import co.kirikiri.roadmap.service.dto.request.RoadmapDifficultyType; +import co.kirikiri.roadmap.service.dto.request.RoadmapNodeSaveRequest; +import co.kirikiri.roadmap.service.dto.request.RoadmapReviewSaveRequest; +import co.kirikiri.roadmap.service.dto.request.RoadmapSaveRequest; +import co.kirikiri.roadmap.service.dto.request.RoadmapTagSaveRequest; +import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Optional; @@ -78,22 +69,19 @@ null, new EncryptedPassword(new Password("password1!")), new Nickname("닉네임 private RoadmapRepository roadmapRepository; @Mock - private RoadmapReviewRepository roadmapReviewRepository; - - @Mock - private GoalRoomRepository goalRoomRepository; + private RoadmapContentRepository roadmapContentRepository; @Mock - private GoalRoomMemberRepository goalRoomMemberRepository; + private RoadmapReviewRepository roadmapReviewRepository; @Mock private RoadmapCategoryRepository roadmapCategoryRepository; @Mock - private RoadmapContentRepository roadmapContentRepository; + private ApplicationEventPublisher applicationEventPublisher; @Mock - private ApplicationEventPublisher applicationEventPublisher; + private RoadmapGoalRoomService roadmapGoalRoomService; @InjectMocks private RoadmapCreateService roadmapCreateService; @@ -114,13 +102,17 @@ null, new EncryptedPassword(new Password("password1!")), new Nickname("닉네임 final RoadmapSaveRequest request = new RoadmapSaveRequest(1L, roadmapTitle, roadmapIntroduction, roadmapContent, difficulty, requiredPeriod, roadmapNodes, roadmapTags); + when(memberRepository.findByIdentifier(MEMBER.getIdentifier())) + .thenReturn(Optional.of(MEMBER)); given(roadmapCategoryRepository.findById(any())) .willReturn(Optional.of(category)); given(roadmapRepository.save(any())) .willReturn(new Roadmap(1L, roadmapTitle, roadmapIntroduction, requiredPeriod, - RoadmapDifficulty.valueOf(difficulty.name()), MEMBER, category)); - when(memberRepository.findByIdentifier(MEMBER.getIdentifier())) - .thenReturn(Optional.of(MEMBER)); + RoadmapDifficulty.valueOf(difficulty.name()), + RoadmapStatus.CREATED, MEMBER.getId(), category, + new RoadmapTags(List.of(new RoadmapTag(new RoadmapTagName("태그 1")))))); + given(roadmapContentRepository.save(any())) + .willReturn(new RoadmapContent(roadmapContent, 1L, null)); // expect assertDoesNotThrow(() -> roadmapCreateService.create(request, "identifier1")); @@ -169,18 +161,13 @@ null, new EncryptedPassword(new Password("password1!")), new Nickname("닉네임 new MemberProfile(Gender.FEMALE, "kirikiri@email.com")); final RoadmapCategory category = new RoadmapCategory(1L, "운동"); - final Roadmap roadmap = 로드맵을_생성한다(MEMBER, category); - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); - final GoalRoom goalRoom = 골룸을_생성한다(MEMBER, targetRoadmapContent); when(roadmapRepository.findById(anyLong())) .thenReturn(Optional.of(roadmap)); - when(goalRoomMemberRepository.findByRoadmapIdAndMemberIdentifierAndGoalRoomStatus(anyLong(), any(), any())) - .thenReturn(Optional.of( - new GoalRoomMember(GoalRoomRole.FOLLOWER, LocalDateTime.now(), goalRoom, follower.getId()))); - when(roadmapReviewRepository.findByRoadmapAndMember(any(), any())) + when(roadmapGoalRoomService.findCompletedGoalRoomMemberId(anyLong(), any())) + .thenReturn(follower.getId()); + when(roadmapReviewRepository.findByRoadmapIdAndMemberId(any(), anyLong())) .thenReturn(Optional.empty()); final RoadmapReviewSaveRequest roadmapReviewSaveRequest = new RoadmapReviewSaveRequest("최고의 로드맵이네요", 5.0); @@ -212,8 +199,8 @@ null, new EncryptedPassword(new Password("password1!")), new Nickname("닉네임 when(roadmapRepository.findById(anyLong())) .thenReturn(Optional.of(roadmap)); - when(goalRoomMemberRepository.findByRoadmapIdAndMemberIdentifierAndGoalRoomStatus(anyLong(), any(), any())) - .thenReturn(Optional.empty()); + when(roadmapGoalRoomService.findCompletedGoalRoomMemberId(anyLong(), any())) + .thenThrow(new BadRequestException("Error Message")); final RoadmapReviewSaveRequest roadmapReviewSaveRequest = new RoadmapReviewSaveRequest("리뷰 내용", null); @@ -232,19 +219,14 @@ null, new EncryptedPassword(new Password("password1!")), new Nickname("닉네임 new MemberProfile(Gender.FEMALE, "kirikiri@email.com")); final RoadmapCategory category = new RoadmapCategory(1L, "운동"); - final Roadmap roadmap = 로드맵을_생성한다(MEMBER, category); - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); - final GoalRoom goalRoom = 골룸을_생성한다(MEMBER, targetRoadmapContent); when(roadmapRepository.findById(anyLong())) .thenReturn(Optional.of(roadmap)); - when(goalRoomMemberRepository.findByRoadmapIdAndMemberIdentifierAndGoalRoomStatus(anyLong(), any(), any())) - .thenReturn(Optional.of( - new GoalRoomMember(GoalRoomRole.FOLLOWER, LocalDateTime.now(), goalRoom, follower.getId()))); - when(roadmapReviewRepository.findByRoadmapAndMember(any(), any())) - .thenReturn(Optional.of(new RoadmapReview("로드맵 짱!", 5.0, MEMBER))); + when(roadmapGoalRoomService.findCompletedGoalRoomMemberId(anyLong(), any())) + .thenReturn(follower.getId()); + when(roadmapReviewRepository.findByRoadmapIdAndMemberId(any(), anyLong())) + .thenReturn(Optional.of(new RoadmapReview("로드맵 짱!", 5.0, MEMBER.getId(), roadmap.getId()))); final RoadmapReviewSaveRequest roadmapReviewSaveRequest = new RoadmapReviewSaveRequest("최고의 로드맵이네요", 5.0); @@ -263,8 +245,8 @@ null, new EncryptedPassword(new Password("password1!")), new Nickname("닉네임 .thenReturn(Optional.of(roadmap)); when(roadmapRepository.findByIdAndMemberIdentifier(anyLong(), anyString())) .thenReturn(Optional.of(roadmap)); - when(goalRoomRepository.findByRoadmapContentId(any())) - .thenReturn(Collections.emptyList()); + when(roadmapGoalRoomService.hasGoalRooms(roadmap.getId())) + .thenReturn(false); // when // then @@ -282,16 +264,12 @@ null, new EncryptedPassword(new Password("password1!")), new Nickname("닉네임 final RoadmapCategory category = new RoadmapCategory(1L, "운동"); final Roadmap roadmap = 로드맵을_생성한다(MEMBER, category); - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); - final GoalRoom goalRoom = 골룸을_생성한다(follower, targetRoadmapContent); - when(roadmapRepository.findById(anyLong())) .thenReturn(Optional.of(roadmap)); when(roadmapRepository.findByIdAndMemberIdentifier(anyLong(), anyString())) .thenReturn(Optional.of(roadmap)); - when(goalRoomRepository.findByRoadmapContentId(any())) - .thenReturn(List.of(goalRoom)); + when(roadmapGoalRoomService.hasGoalRooms(roadmap.getId())) + .thenReturn(true); // when // then @@ -319,10 +297,6 @@ null, new EncryptedPassword(new Password("password1!")), new Nickname("닉네임 final RoadmapCategory category = new RoadmapCategory(1L, "운동"); final Roadmap roadmap = 로드맵을_생성한다(MEMBER, category); - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); - 골룸을_생성한다(MEMBER, targetRoadmapContent); - when(roadmapRepository.findById(anyLong())) .thenReturn(Optional.of(roadmap)); when(roadmapRepository.findByIdAndMemberIdentifier(anyLong(), anyString())) @@ -363,20 +337,7 @@ null, new EncryptedPassword(new Password("password1!")), new Nickname("닉네임 } private Roadmap 로드맵을_생성한다(final Member creator, final RoadmapCategory category) { - final RoadmapContent content = new RoadmapContent("콘텐츠 제목"); - final Roadmap roadmap = new Roadmap("로드맵 제목", "로드맵 설명", 100, RoadmapDifficulty.NORMAL, creator, category); - roadmap.addContent(content); - return roadmap; - } - - private GoalRoom 골룸을_생성한다(final Member member, final RoadmapContent roadmapContent) { - return new GoalRoom(new GoalRoomName("골룸"), new LimitedMemberCount(10), roadmapContent.getId(), - 골룸_로드맵_노드들을_생성한다()); - } - - private GoalRoomRoadmapNodes 골룸_로드맵_노드들을_생성한다() { - return new GoalRoomRoadmapNodes(List.of( - new GoalRoomRoadmapNode(new Period(LocalDate.now(), LocalDate.now().plusDays(5)), 5, 1L)) - ); + return new Roadmap(1L, "로드맵 제목", "로드맵 설명", 100, RoadmapDifficulty.NORMAL, + RoadmapStatus.CREATED, creator.getId(), category, new RoadmapTags(new ArrayList<>())); } } diff --git a/backend/kirikiri/src/test/java/co/kirikiri/service/RoadmapReadServiceTest.java b/backend/kirikiri/src/test/java/co/kirikiri/roadmap/service/RoadmapReadServiceTest.java similarity index 71% rename from backend/kirikiri/src/test/java/co/kirikiri/service/RoadmapReadServiceTest.java rename to backend/kirikiri/src/test/java/co/kirikiri/roadmap/service/RoadmapReadServiceTest.java index f3769cb1b..c8368f514 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/service/RoadmapReadServiceTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/roadmap/service/RoadmapReadServiceTest.java @@ -1,4 +1,4 @@ -package co.kirikiri.service; +package co.kirikiri.roadmap.service; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; @@ -11,61 +11,56 @@ import co.kirikiri.common.exception.NotFoundException; import co.kirikiri.common.service.FileService; +import co.kirikiri.common.service.dto.CustomScrollRequest; import co.kirikiri.common.type.ImageContentType; -import co.kirikiri.domain.member.EncryptedPassword; -import co.kirikiri.domain.member.Gender; -import co.kirikiri.domain.member.Member; -import co.kirikiri.domain.member.MemberImage; -import co.kirikiri.domain.member.MemberProfile; -import co.kirikiri.domain.member.vo.Identifier; -import co.kirikiri.domain.member.vo.Nickname; -import co.kirikiri.domain.member.vo.Password; -import co.kirikiri.domain.roadmap.Roadmap; -import co.kirikiri.domain.roadmap.RoadmapCategory; -import co.kirikiri.domain.roadmap.RoadmapContent; -import co.kirikiri.domain.roadmap.RoadmapDifficulty; -import co.kirikiri.domain.roadmap.RoadmapNode; -import co.kirikiri.domain.roadmap.RoadmapNodes; -import co.kirikiri.domain.roadmap.RoadmapReview; -import co.kirikiri.domain.roadmap.RoadmapTag; -import co.kirikiri.domain.roadmap.RoadmapTags; -import co.kirikiri.domain.roadmap.vo.RoadmapTagName; -import co.kirikiri.goalroom.domain.GoalRoom; -import co.kirikiri.goalroom.domain.GoalRoomRoadmapNode; -import co.kirikiri.goalroom.domain.GoalRoomRoadmapNodes; import co.kirikiri.goalroom.domain.GoalRoomStatus; -import co.kirikiri.goalroom.domain.vo.GoalRoomName; -import co.kirikiri.goalroom.domain.vo.LimitedMemberCount; -import co.kirikiri.goalroom.domain.vo.Period; -import co.kirikiri.goalroom.persistence.GoalRoomRepository; -import co.kirikiri.goalroom.persistence.dto.RoadmapGoalRoomsOrderType; -import co.kirikiri.goalroom.service.dto.response.RoadmapGoalRoomResponse; -import co.kirikiri.persistence.member.MemberRepository; -import co.kirikiri.persistence.roadmap.RoadmapCategoryRepository; -import co.kirikiri.persistence.roadmap.RoadmapContentRepository; -import co.kirikiri.persistence.roadmap.RoadmapRepository; -import co.kirikiri.persistence.roadmap.RoadmapReviewRepository; -import co.kirikiri.service.dto.CustomScrollRequest; -import co.kirikiri.service.dto.member.response.MemberResponse; -import co.kirikiri.service.dto.roadmap.RoadmapGoalRoomsOrderTypeDto; -import co.kirikiri.service.dto.roadmap.request.RoadmapOrderTypeRequest; -import co.kirikiri.service.dto.roadmap.request.RoadmapSearchRequest; -import co.kirikiri.service.dto.roadmap.response.MemberRoadmapResponse; -import co.kirikiri.service.dto.roadmap.response.MemberRoadmapResponses; -import co.kirikiri.service.dto.roadmap.response.RoadmapCategoryResponse; -import co.kirikiri.service.dto.roadmap.response.RoadmapContentResponse; -import co.kirikiri.service.dto.roadmap.response.RoadmapForListResponse; -import co.kirikiri.service.dto.roadmap.response.RoadmapForListResponses; -import co.kirikiri.service.dto.roadmap.response.RoadmapGoalRoomResponses; -import co.kirikiri.service.dto.roadmap.response.RoadmapNodeResponse; -import co.kirikiri.service.dto.roadmap.response.RoadmapResponse; -import co.kirikiri.service.dto.roadmap.response.RoadmapReviewResponse; -import co.kirikiri.service.dto.roadmap.response.RoadmapTagResponse; -import co.kirikiri.service.roadmap.RoadmapReadService; +import co.kirikiri.member.domain.EncryptedPassword; +import co.kirikiri.member.domain.Gender; +import co.kirikiri.member.domain.Member; +import co.kirikiri.member.domain.MemberImage; +import co.kirikiri.member.domain.MemberProfile; +import co.kirikiri.member.domain.vo.Identifier; +import co.kirikiri.member.domain.vo.Nickname; +import co.kirikiri.member.domain.vo.Password; +import co.kirikiri.member.persistence.MemberRepository; +import co.kirikiri.member.service.dto.response.MemberResponse; +import co.kirikiri.roadmap.domain.Roadmap; +import co.kirikiri.roadmap.domain.RoadmapCategory; +import co.kirikiri.roadmap.domain.RoadmapContent; +import co.kirikiri.roadmap.domain.RoadmapDifficulty; +import co.kirikiri.roadmap.domain.RoadmapNode; +import co.kirikiri.roadmap.domain.RoadmapNodes; +import co.kirikiri.roadmap.domain.RoadmapReview; +import co.kirikiri.roadmap.domain.RoadmapStatus; +import co.kirikiri.roadmap.domain.RoadmapTag; +import co.kirikiri.roadmap.domain.RoadmapTags; +import co.kirikiri.roadmap.domain.vo.RoadmapTagName; +import co.kirikiri.roadmap.persistence.RoadmapCategoryRepository; +import co.kirikiri.roadmap.persistence.RoadmapContentRepository; +import co.kirikiri.roadmap.persistence.RoadmapRepository; +import co.kirikiri.roadmap.persistence.RoadmapReviewRepository; +import co.kirikiri.roadmap.service.dto.RoadmapGoalRoomNumberDto; +import co.kirikiri.roadmap.service.dto.RoadmapGoalRoomsOrderTypeDto; +import co.kirikiri.roadmap.service.dto.request.RoadmapOrderTypeRequest; +import co.kirikiri.roadmap.service.dto.request.RoadmapSearchRequest; +import co.kirikiri.roadmap.service.dto.response.MemberRoadmapGoalRoomResponse; +import co.kirikiri.roadmap.service.dto.response.MemberRoadmapResponse; +import co.kirikiri.roadmap.service.dto.response.MemberRoadmapResponses; +import co.kirikiri.roadmap.service.dto.response.RoadmapCategoryResponse; +import co.kirikiri.roadmap.service.dto.response.RoadmapContentResponse; +import co.kirikiri.roadmap.service.dto.response.RoadmapForListResponse; +import co.kirikiri.roadmap.service.dto.response.RoadmapForListResponses; +import co.kirikiri.roadmap.service.dto.response.RoadmapGoalRoomResponse; +import co.kirikiri.roadmap.service.dto.response.RoadmapGoalRoomResponses; +import co.kirikiri.roadmap.service.dto.response.RoadmapNodeResponse; +import co.kirikiri.roadmap.service.dto.response.RoadmapResponse; +import co.kirikiri.roadmap.service.dto.response.RoadmapReviewResponse; +import co.kirikiri.roadmap.service.dto.response.RoadmapTagResponse; import java.net.MalformedURLException; import java.net.URL; import java.time.LocalDate; import java.time.LocalDateTime; +import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Optional; @@ -86,6 +81,9 @@ null, new EncryptedPassword(new Password("password1!")), new Nickname("닉네임 new MemberProfile(Gender.FEMALE, "kirikiri1@email.com")); private final LocalDateTime now = LocalDateTime.now(); + @Mock + private MemberRepository memberRepository; + @Mock private RoadmapRepository roadmapRepository; @@ -96,13 +94,10 @@ null, new EncryptedPassword(new Password("password1!")), new Nickname("닉네임 private RoadmapContentRepository roadmapContentRepository; @Mock - private GoalRoomRepository goalRoomRepository; - - @Mock - private MemberRepository memberRepository; + private RoadmapReviewRepository roadmapReviewRepository; @Mock - private RoadmapReviewRepository roadmapReviewRepository; + private RoadmapGoalRoomService roadmapGoalRoomService; @Mock private FileService fileService; @@ -113,30 +108,27 @@ null, new EncryptedPassword(new Password("password1!")), new Nickname("닉네임 @Test void 특정_아이디를_가지는_로드맵_단일_조회시_해당_로드맵의_정보를_반환한다() throws MalformedURLException { //given - final Member member = 사용자를_생성한다(1L, "identifier1", "코끼리"); final RoadmapCategory category = 로드맵_카테고리를_생성한다(1L, "운동"); - final RoadmapContent content = 로드맵_컨텐츠를_생성한다(1L, "콘텐츠 내용"); final Roadmap roadmap = 로드맵을_생성한다("로드맵 제목", category); - roadmap.addContent(content); - final Long roadmapId = 1L; + final RoadmapContent roadmapContent = 로드맵_컨텐츠를_생성한다("로드맵 본문", roadmap.getId()); - final List goalRooms = 상태별_골룸_목록을_생성한다(); - - when(roadmapRepository.findRoadmapById(anyLong())) + when(roadmapRepository.findById(anyLong())) .thenReturn(Optional.of(roadmap)); - when(roadmapContentRepository.findFirstByRoadmapOrderByCreatedAtDesc(any())) - .thenReturn(Optional.of(roadmap.getContents().getValues().get(0))); - when(goalRoomRepository.findByRoadmapContentId(any())) - .thenReturn(goalRooms); + when(roadmapContentRepository.findFirstByRoadmapIdOrderByCreatedAtDesc(anyLong())) + .thenReturn(Optional.of(roadmapContent)); + when(roadmapGoalRoomService.findRoadmapGoalRoomsByRoadmap(any())) + .thenReturn(new RoadmapGoalRoomNumberDto(2, 2, 2)); + when(memberRepository.findWithMemberProfileAndImageById(anyLong())) + .thenReturn(Optional.of(member)); when(fileService.generateUrl(anyString(), any())) .thenReturn(new URL("http://example.com/serverFilePath")); //when - final RoadmapResponse roadmapResponse = roadmapService.findRoadmap(roadmapId); + final RoadmapResponse roadmapResponse = roadmapService.findRoadmap(roadmap.getId()); //then final RoadmapResponse expectedResponse = new RoadmapResponse( - roadmapId, new RoadmapCategoryResponse(1L, "운동"), "로드맵 제목", "로드맵 소개글", + roadmap.getId(), new RoadmapCategoryResponse(1L, "운동"), "로드맵 제목", "로드맵 소개글", new MemberResponse(1L, "닉네임", "http://example.com/serverFilePath"), new RoadmapContentResponse(1L, "로드맵 본문", List.of( new RoadmapNodeResponse(1L, "로드맵 노드1 제목", "로드맵 노드1 설명", Collections.emptyList()) @@ -155,7 +147,7 @@ roadmapId, new RoadmapCategoryResponse(1L, "운동"), "로드맵 제목", "로 @Test void 로드맵_단일_조회_시_로드맵_아이디가_존재하지_않는_아이디일_경우_예외를_반환한다() { //when - when(roadmapRepository.findRoadmapById(anyLong())) + when(roadmapRepository.findById(anyLong())) .thenReturn(Optional.empty()); //then @@ -190,6 +182,8 @@ roadmapId, new RoadmapCategoryResponse(1L, "운동"), "로드맵 제목", "로 .thenReturn(Optional.of(category)); when(roadmapRepository.findRoadmapsByCategory(any(), any(), any(), anyInt())) .thenReturn(roadmaps); + when(memberRepository.findWithMemberProfileAndImageById(anyLong())) + .thenReturn(Optional.of(member)); given(fileService.generateUrl(anyString(), any())) .willReturn(new URL("http://example.com/serverFilePath")); @@ -239,6 +233,8 @@ roadmapId, new RoadmapCategoryResponse(1L, "운동"), "로드맵 제목", "로 .thenReturn(Optional.of(category)); when(roadmapRepository.findRoadmapsByCategory(any(), any(), any(), anyInt())) .thenReturn(roadmaps); + when(memberRepository.findWithMemberProfileAndImageById(anyLong())) + .thenReturn(Optional.of(member)); given(fileService.generateUrl(anyString(), any())) .willReturn(new URL("http://example.com/serverFilePath")); @@ -276,6 +272,8 @@ roadmapId, new RoadmapCategoryResponse(1L, "운동"), "로드맵 제목", "로 when(roadmapRepository.findRoadmapsByCategory(any(), any(), any(), anyInt())) .thenReturn(roadmaps); + when(memberRepository.findWithMemberProfileAndImageById(anyLong())) + .thenReturn(Optional.of(member)); given(fileService.generateUrl(anyString(), any())) .willReturn(new URL("http://example.com/serverFilePath")); @@ -323,6 +321,8 @@ roadmapId, new RoadmapCategoryResponse(1L, "운동"), "로드맵 제목", "로 .thenReturn(Optional.of(new RoadmapCategory("여행"))); when(roadmapRepository.findRoadmapsByCategory(any(), any(), any(), anyInt())) .thenReturn(roadmaps); + when(memberRepository.findWithMemberProfileAndImageById(anyLong())) + .thenReturn(Optional.of(member)); given(fileService.generateUrl(anyString(), any())) .willReturn(new URL("http://example.com/serverFilePath")); @@ -377,6 +377,8 @@ roadmapId, new RoadmapCategoryResponse(1L, "운동"), "로드맵 제목", "로 when(roadmapRepository.findRoadmapsByCond(any(), any(), any(), anyInt())) .thenReturn(roadmaps); + when(memberRepository.findWithMemberProfileAndImageById(anyLong())) + .thenReturn(Optional.of(member)); given(fileService.generateUrl(anyString(), any())) .willReturn(new URL("http://example.com/serverFilePath")); @@ -425,7 +427,7 @@ roadmapId, new RoadmapCategoryResponse(1L, "운동"), "로드맵 제목", "로 when(memberRepository.findByIdentifier(any())) .thenReturn(Optional.of(member)); - when(roadmapRepository.findRoadmapsWithCategoryByMemberOrderByLatest(any(), any(), anyInt())) + when(roadmapRepository.findRoadmapsWithCategoryByMemberIdOrderByLatest(anyLong(), any(), anyInt())) .thenReturn(List.of(roadmap2, roadmap1)); // when @@ -459,68 +461,40 @@ roadmapId, new RoadmapCategoryResponse(1L, "운동"), "로드맵 제목", "로 } @Test - void 로드맵의_골룸_목록을_최신순으로_조회한다() throws MalformedURLException { + void 로드맵의_골룸_목록을_최신순으로_조회한다() { // given final Member member1 = 사용자를_생성한다(1L, "identifier1", "name1"); - final RoadmapNode roadmapNode1 = new RoadmapNode("로드맵 1주차", "로드맵 1주차 내용"); - final RoadmapNode roadmapNode2 = new RoadmapNode("로드맵 2주차", "로드맵 2주차 내용"); - final RoadmapNodes roadmapNodes = new RoadmapNodes(List.of(roadmapNode1, roadmapNode2)); - final RoadmapContent roadmapContent = new RoadmapContent("로드맵 본문"); - roadmapContent.addNodes(roadmapNodes); - final Roadmap roadmap = new Roadmap(1L, "로드맵 제목", "로드맵 설명", 100, RoadmapDifficulty.DIFFICULT, member1, - new RoadmapCategory("it")); - - final GoalRoomRoadmapNode goalRoomRoadmapNode1 = new GoalRoomRoadmapNode(new Period(TODAY, TODAY.plusDays(10)), - 1, roadmapNode1.getId()); - final GoalRoomRoadmapNode goalRoomRoadmapNode2 = new GoalRoomRoadmapNode( - new Period(TODAY.plusDays(11), TODAY.plusDays(20)), 1, roadmapNode2.getId()); - final GoalRoomRoadmapNode goalRoomRoadmapNode3 = new GoalRoomRoadmapNode(new Period(TODAY, TODAY.plusDays(10)), - 1, roadmapNode1.getId()); - final GoalRoomRoadmapNode goalRoomRoadmapNode4 = new GoalRoomRoadmapNode( - new Period(TODAY.plusDays(11), TODAY.plusDays(20)), 1, roadmapNode2.getId()); + final Roadmap roadmap = new Roadmap(1L, "로드맵 제목", "로드맵 설명", 100, RoadmapDifficulty.DIFFICULT, + RoadmapStatus.CREATED, + member1.getId(), new RoadmapCategory("it"), new RoadmapTags(new ArrayList<>())); final Member member2 = 사용자를_생성한다(2L, "identifier2", "name2"); - final GoalRoom goalRoom1 = new GoalRoom(1L, new GoalRoomName("goalroom1"), new LimitedMemberCount(10), - roadmapContent.getId(), new GoalRoomRoadmapNodes(List.of(goalRoomRoadmapNode1, goalRoomRoadmapNode2))); - final Member member3 = 사용자를_생성한다(3L, "identifier2", "name3"); - final GoalRoom goalRoom2 = new GoalRoom(2L, new GoalRoomName("goalroom2"), new LimitedMemberCount(10), - roadmapContent.getId(), new GoalRoomRoadmapNodes(List.of(goalRoomRoadmapNode3, goalRoomRoadmapNode4))); - - final List goalRooms = List.of(goalRoom2, goalRoom1); - given(roadmapRepository.findRoadmapById(anyLong())) - .willReturn(Optional.of(roadmap)); - given(roadmapContentRepository.findFirstByRoadmapOrderByCreatedAtDesc(any())) - .willReturn(Optional.of(roadmapContent)); - given(goalRoomRepository.findGoalRoomsByRoadmapContentIdAndCond(roadmapContent.getId(), - RoadmapGoalRoomsOrderType.LATEST, null, 10)) - .willReturn(goalRooms); - given(memberRepository.findById(2L)) - .willReturn(Optional.of(member2)); - given(memberRepository.findById(3L)) - .willReturn(Optional.of(member3)); - given(fileService.generateUrl(anyString(), any())) - .willReturn(new URL("http://example.com/serverFilePath")); - - // when - final RoadmapGoalRoomResponses result = roadmapService.findRoadmapGoalRoomsByOrderType(1L, - RoadmapGoalRoomsOrderTypeDto.LATEST, new CustomScrollRequest(null, 10)); final RoadmapGoalRoomResponses expected = new RoadmapGoalRoomResponses(List.of( - new RoadmapGoalRoomResponse(2L, "goalroom2", GoalRoomStatus.RECRUITING, 1, 10, + new RoadmapGoalRoomResponse(2L, "goalroom2", GoalRoomStatus.RECRUITING.name(), 1, 10, LocalDateTime.now(), TODAY, TODAY.plusDays(20), - new co.kirikiri.goalroom.service.dto.response.MemberResponse(member3.getId(), + new MemberRoadmapGoalRoomResponse(member3.getId(), member3.getNickname().getValue(), "http://example.com/serverFilePath")), - new RoadmapGoalRoomResponse(1L, "goalroom1", GoalRoomStatus.RECRUITING, 1, 10, + new RoadmapGoalRoomResponse(1L, "goalroom1", GoalRoomStatus.RECRUITING.name(), 1, 10, LocalDateTime.now(), TODAY, TODAY.plusDays(20), - new co.kirikiri.goalroom.service.dto.response.MemberResponse(member2.getId(), + new MemberRoadmapGoalRoomResponse(member2.getId(), member2.getNickname().getValue(), "http://example.com/serverFilePath"))), false); + given(roadmapRepository.findById(anyLong())) + .willReturn(Optional.of(roadmap)); + given(roadmapGoalRoomService.makeRoadmapGoalRoomResponsesByOrderType(any(), any(), any())) + .willReturn(expected); + + // when + final RoadmapGoalRoomResponses result = roadmapService.findRoadmapGoalRoomsByOrderType(1L, + RoadmapGoalRoomsOrderTypeDto.LATEST, new CustomScrollRequest(null, 10)); + assertThat(result) .usingRecursiveComparison() .ignoringFields("responses.createdAt") @@ -530,7 +504,7 @@ roadmapId, new RoadmapCategoryResponse(1L, "운동"), "로드맵 제목", "로 @Test void 로드맵의_골룸_목록을_조회할때_존재하지_않는_로드맵이면_예외가_발생한다() { // given - given(roadmapRepository.findRoadmapById(anyLong())) + given(roadmapRepository.findById(anyLong())) .willThrow(new NotFoundException("존재하지 않는 로드맵입니다. roadmapId = 1")); // when @@ -547,22 +521,18 @@ RoadmapGoalRoomsOrderTypeDto.LATEST, new CustomScrollRequest(null, 10))) // given final Member member1 = 사용자를_생성한다(1L, "identifier1", "리뷰어1"); final Member member2 = 사용자를_생성한다(2L, "identifier2", "리뷰어2"); - final RoadmapNode roadmapNode1 = new RoadmapNode("로드맵 1주차", "로드맵 1주차 내용"); - final RoadmapNode roadmapNode2 = new RoadmapNode("로드맵 2주차", "로드맵 2주차 내용"); - final RoadmapNodes roadmapNodes = new RoadmapNodes(List.of(roadmapNode1, roadmapNode2)); - final RoadmapContent roadmapContent = new RoadmapContent("로드맵 본문"); - roadmapContent.addNodes(roadmapNodes); - final Roadmap roadmap = new Roadmap(1L, "로드맵 제목", "로드맵 설명", 100, RoadmapDifficulty.DIFFICULT, member1, - new RoadmapCategory("it")); - - final RoadmapReview roadmapReview1 = new RoadmapReview("리뷰 내용", 5.0, member1); - final RoadmapReview roadmapReview2 = new RoadmapReview("리뷰 내용", 4.5, member2); - roadmapReview1.updateRoadmap(roadmap); - roadmapReview2.updateRoadmap(roadmap); - - when(roadmapRepository.findRoadmapById(anyLong())).thenReturn(Optional.of(roadmap)); - when(roadmapReviewRepository.findRoadmapReviewWithMemberByRoadmapOrderByLatest(any(), any(), anyInt())) + final Roadmap roadmap = new Roadmap(1L, "로드맵 제목", "로드맵 설명", 100, RoadmapDifficulty.DIFFICULT, + RoadmapStatus.CREATED, + member1.getId(), new RoadmapCategory("it"), new RoadmapTags(new ArrayList<>())); + + final RoadmapReview roadmapReview1 = new RoadmapReview("리뷰 내용", 5.0, member1.getId(), roadmap.getId()); + final RoadmapReview roadmapReview2 = new RoadmapReview("리뷰 내용", 4.5, member2.getId(), roadmap.getId()); + + when(roadmapRepository.findById(anyLong())).thenReturn(Optional.of(roadmap)); + when(roadmapReviewRepository.findRoadmapReviewByRoadmapIdOrderByLatest(any(), any(), anyInt())) .thenReturn(List.of(roadmapReview2, roadmapReview1)); + when(memberRepository.findWithMemberProfileAndImageById(anyLong())) + .thenReturn(Optional.of(member2), Optional.of(member1)); given(fileService.generateUrl(anyString(), any())) .willReturn(new URL("http://example.com/serverFilePath")); @@ -586,7 +556,7 @@ RoadmapGoalRoomsOrderTypeDto.LATEST, new CustomScrollRequest(null, 10))) @Test void 로드맵_리뷰_조회_시_유효하지_않은_로드맵_아이디라면_예외를_반환한다() { // given - when(roadmapRepository.findRoadmapById(anyLong())) + when(roadmapRepository.findById(anyLong())) .thenThrow(new NotFoundException("존재하지 않는 로드맵입니다. roadmapId = 1")); // when, then @@ -604,29 +574,22 @@ null, new EncryptedPassword(new Password("password1!")), } private Roadmap 로드맵을_생성한다(final String roadmapTitle, final RoadmapCategory category) { - final Roadmap roadmap = new Roadmap(1L, roadmapTitle, "로드맵 소개글", 30, - RoadmapDifficulty.valueOf("DIFFICULT"), member, category); - final RoadmapTags roadmapTags = new RoadmapTags( List.of(new RoadmapTag(1L, new RoadmapTagName("태그1")), new RoadmapTag(2L, new RoadmapTagName("태그2")))); - roadmap.addTags(roadmapTags); - - final RoadmapContent roadmapContent = new RoadmapContent(1L, "로드맵 본문"); - final RoadmapNodes roadmapNodes = new RoadmapNodes( - List.of(new RoadmapNode(1L, "로드맵 노드1 제목", "로드맵 노드1 설명"))); - roadmapContent.addNodes(roadmapNodes); - roadmap.addContent(roadmapContent); - return roadmap; + return new Roadmap(1L, roadmapTitle, "로드맵 소개글", 30, + RoadmapDifficulty.valueOf("DIFFICULT"), RoadmapStatus.CREATED, member.getId(), category, roadmapTags); } private RoadmapCategory 로드맵_카테고리를_생성한다(final Long id, final String title) { return new RoadmapCategory(id, title); } - private RoadmapContent 로드맵_컨텐츠를_생성한다(final Long id, final String content) { - return new RoadmapContent(id, content); + private RoadmapContent 로드맵_컨텐츠를_생성한다(final String content, final Long roadmapId) { + final RoadmapNodes roadmapNodes = new RoadmapNodes( + List.of(new RoadmapNode(1L, "로드맵 노드1 제목", "로드맵 노드1 설명"))); + return new RoadmapContent(1L, content, roadmapId, roadmapNodes); } private List 로드맵_카테고리_리스트를_반환한다() { @@ -656,34 +619,4 @@ null, new EncryptedPassword(new Password("password1!")), return List.of(category1, category2, category3, category4, category5, category6, category7, category8, category9); } - - private List 상태별_골룸_목록을_생성한다() { - final RoadmapContent roadmapContent = new RoadmapContent("로드맵 내용"); - final GoalRoom recruitedGoalRoom1 = new GoalRoom(new GoalRoomName("모집 중 골룸 1"), - new LimitedMemberCount(20), roadmapContent.getId(), 골룸_로드맵_노드들을_생성한다()); - final GoalRoom recruitedGoalRoom2 = new GoalRoom(new GoalRoomName("모집 중 골룸 2"), - new LimitedMemberCount(20), roadmapContent.getId(), 골룸_로드맵_노드들을_생성한다()); - final GoalRoom runningGoalRoom1 = new GoalRoom(new GoalRoomName("진행 중 골룸 1"), - new LimitedMemberCount(20), roadmapContent.getId(), 골룸_로드맵_노드들을_생성한다()); - final GoalRoom runningGoalRoom2 = new GoalRoom(new GoalRoomName("진행 중 골룸 2"), - new LimitedMemberCount(20), roadmapContent.getId(), 골룸_로드맵_노드들을_생성한다()); - final GoalRoom completedGoalRoom1 = new GoalRoom(new GoalRoomName("완료된 골룸 1"), - new LimitedMemberCount(20), roadmapContent.getId(), 골룸_로드맵_노드들을_생성한다()); - final GoalRoom completedGoalRoom2 = new GoalRoom(new GoalRoomName("완료된 골룸 2"), - new LimitedMemberCount(20), roadmapContent.getId(), 골룸_로드맵_노드들을_생성한다()); - - runningGoalRoom1.start(); - runningGoalRoom2.start(); - completedGoalRoom1.complete(); - completedGoalRoom2.complete(); - - return List.of(recruitedGoalRoom1, recruitedGoalRoom2, runningGoalRoom1, runningGoalRoom2, - completedGoalRoom1, completedGoalRoom2); - } - - private GoalRoomRoadmapNodes 골룸_로드맵_노드들을_생성한다() { - return new GoalRoomRoadmapNodes(List.of( - new GoalRoomRoadmapNode(new Period(LocalDate.now(), LocalDate.now().plusDays(5)), 5, 1L)) - ); - } } diff --git a/backend/kirikiri/src/test/java/co/kirikiri/roadmap/service/RoadmapSchedulerTest.java b/backend/kirikiri/src/test/java/co/kirikiri/roadmap/service/RoadmapSchedulerTest.java new file mode 100644 index 000000000..14e3544ff --- /dev/null +++ b/backend/kirikiri/src/test/java/co/kirikiri/roadmap/service/RoadmapSchedulerTest.java @@ -0,0 +1,107 @@ +package co.kirikiri.roadmap.service; + +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyLong; +import static org.mockito.BDDMockito.given; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; + +import co.kirikiri.member.domain.EncryptedPassword; +import co.kirikiri.member.domain.Gender; +import co.kirikiri.member.domain.Member; +import co.kirikiri.member.domain.MemberProfile; +import co.kirikiri.member.domain.vo.Identifier; +import co.kirikiri.member.domain.vo.Nickname; +import co.kirikiri.member.domain.vo.Password; +import co.kirikiri.roadmap.domain.Roadmap; +import co.kirikiri.roadmap.domain.RoadmapCategory; +import co.kirikiri.roadmap.domain.RoadmapDifficulty; +import co.kirikiri.roadmap.domain.RoadmapStatus; +import co.kirikiri.roadmap.domain.RoadmapTags; +import co.kirikiri.roadmap.persistence.RoadmapRepository; +import co.kirikiri.roadmap.service.scheduler.RoadmapScheduler; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import java.time.LocalDate; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +@ExtendWith(MockitoExtension.class) +class RoadmapSchedulerTest { + + private static final LocalDate TODAY = LocalDate.now(); + private static final LocalDate TEN_DAY_LATER = TODAY.plusDays(10); + + @Mock + private RoadmapRepository roadmapRepository; + + @Mock + private RoadmapGoalRoomService roadmapGoalRoomService; + + @InjectMocks + private RoadmapScheduler roadmapScheduler; + + @Test + void 삭제된_상태의_로드맵_삭제시_종료되지_않은_골룸이_있으면_삭제되지_않는다() { + // given + final Member member = new Member(new Identifier("identifier1"), + new EncryptedPassword(new Password("password1!")), new Nickname("name1"), null, + new MemberProfile(Gender.FEMALE, "kirikiri@email.com")); + + final RoadmapCategory category = new RoadmapCategory("여행"); + final Roadmap roadmap = new Roadmap(1L, "로드맵2", "로드맵 설명2", 30, RoadmapDifficulty.DIFFICULT, + RoadmapStatus.CREATED, member.getId(), category, new RoadmapTags(new ArrayList<>())); + + given(roadmapRepository.findByStatus(any())) + .willReturn(List.of(roadmap)); + given(roadmapGoalRoomService.canDeleteGoalRoomsInRoadmap(anyLong())) + .willReturn(false); + + // when + roadmap.delete(); + + // then + assertDoesNotThrow(() -> roadmapScheduler.deleteRoadmaps()); + verify(roadmapRepository, never()).delete(any()); + } + + @Test + void 삭제된_상태의_로드맵_삭제시_골룸이_종료된지_3개월이_지나지_않으면_삭제되지_않는다() { + // given + final Member member = new Member(new Identifier("identifier1"), + new EncryptedPassword(new Password("password1!")), new Nickname("name1"), null, + new MemberProfile(Gender.FEMALE, "kirikiri@email.com")); + + final RoadmapCategory category = new RoadmapCategory("여행"); + final Roadmap roadmap = new Roadmap("로드맵1", "로드맵 설명1", 30, RoadmapDifficulty.DIFFICULT, member.getId(), category, new RoadmapTags(new ArrayList<>())); + + given(roadmapRepository.findByStatus(any())) + .willReturn(List.of(roadmap)); + given(roadmapGoalRoomService.canDeleteGoalRoomsInRoadmap(any())) + .willReturn(false); + + // when + roadmap.delete(); + + // then + assertDoesNotThrow(() -> roadmapScheduler.deleteRoadmaps()); + verify(roadmapRepository, never()).delete(any()); + } + + @Test + void 삭제된_상태의_로드맵이_없는_경우_삭제되지_않는다() { + // given + given(roadmapRepository.findByStatus(any())) + .willReturn(Collections.emptyList()); + + // when + // then + assertDoesNotThrow(() -> roadmapScheduler.deleteRoadmaps()); + verify(roadmapRepository, never()).deleteAll(any()); + } +} diff --git a/backend/kirikiri/src/test/java/co/kirikiri/service/RoadmapSchedulerTest.java b/backend/kirikiri/src/test/java/co/kirikiri/service/RoadmapSchedulerTest.java deleted file mode 100644 index ef6ed3b83..000000000 --- a/backend/kirikiri/src/test/java/co/kirikiri/service/RoadmapSchedulerTest.java +++ /dev/null @@ -1,168 +0,0 @@ -package co.kirikiri.service; - -import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.never; -import static org.mockito.Mockito.verify; - -import co.kirikiri.domain.member.EncryptedPassword; -import co.kirikiri.domain.member.Gender; -import co.kirikiri.domain.member.Member; -import co.kirikiri.domain.member.MemberProfile; -import co.kirikiri.domain.member.vo.Identifier; -import co.kirikiri.domain.member.vo.Nickname; -import co.kirikiri.domain.member.vo.Password; -import co.kirikiri.domain.roadmap.Roadmap; -import co.kirikiri.domain.roadmap.RoadmapCategory; -import co.kirikiri.domain.roadmap.RoadmapContent; -import co.kirikiri.domain.roadmap.RoadmapDifficulty; -import co.kirikiri.domain.roadmap.RoadmapNode; -import co.kirikiri.domain.roadmap.RoadmapNodes; -import co.kirikiri.goalroom.domain.GoalRoom; -import co.kirikiri.goalroom.domain.GoalRoomRoadmapNode; -import co.kirikiri.goalroom.domain.GoalRoomRoadmapNodes; -import co.kirikiri.goalroom.domain.vo.GoalRoomName; -import co.kirikiri.goalroom.domain.vo.LimitedMemberCount; -import co.kirikiri.goalroom.domain.vo.Period; -import co.kirikiri.goalroom.persistence.GoalRoomRepository; -import co.kirikiri.persistence.roadmap.RoadmapRepository; -import co.kirikiri.service.scheduler.RoadmapScheduler; -import java.time.LocalDate; -import java.util.Collections; -import java.util.List; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; - -@ExtendWith(MockitoExtension.class) -class RoadmapSchedulerTest { - - private static final LocalDate TODAY = LocalDate.now(); - private static final LocalDate TEN_DAY_LATER = TODAY.plusDays(10); - - @Mock - private RoadmapRepository roadmapRepository; - - @Mock - private GoalRoomRepository goalRoomRepository; - - @InjectMocks - private RoadmapScheduler roadmapScheduler; - - @Test - void 삭제된_상태의_로드맵_삭제시_종료되지_않은_골룸이_있으면_삭제되지_않는다() { - // given - final Member member1 = new Member(new Identifier("identifier1"), - new EncryptedPassword(new Password("password1!")), new Nickname("name1"), null, - new MemberProfile(Gender.FEMALE, "kirikiri@email.com")); - final Member member2 = new Member(new Identifier("identifier2"), - new EncryptedPassword(new Password("password2!")), new Nickname("name2"), null, - new MemberProfile(Gender.FEMALE, "kirikiri@email.com")); - - final RoadmapCategory category = new RoadmapCategory("여행"); - final RoadmapContent roadmapContent1_1 = new RoadmapContent("로드맵 본문2"); - final RoadmapContent roadmapContent1_2 = new RoadmapContent("로드맵 본문2 - 수정본"); - final RoadmapNode roadmapNode1 = new RoadmapNode("로드맵1 노드", "로드맵 노드 내용"); - roadmapContent1_1.addNodes(new RoadmapNodes(List.of(roadmapNode1))); - roadmapContent1_2.addNodes(new RoadmapNodes(List.of(roadmapNode1))); - final Roadmap roadmap1 = new Roadmap("로드맵2", "로드맵 설명2", 30, RoadmapDifficulty.DIFFICULT, member1, category); - roadmap1.addContent(roadmapContent1_1); - roadmap1.addContent(roadmapContent1_2); - - final GoalRoomRoadmapNodes goalRoomRoadmapNodes1 = new GoalRoomRoadmapNodes(List.of( - new GoalRoomRoadmapNode(new Period(TODAY, TEN_DAY_LATER), 5, roadmapNode1.getId()))); - final GoalRoom goalRoom1_1 = new GoalRoom(new GoalRoomName("골룸2"), new LimitedMemberCount(10), - roadmapContent1_1.getId(), goalRoomRoadmapNodes1); - final GoalRoom goalRoom1_2 = new GoalRoom(new GoalRoomName("골룸2-1"), new LimitedMemberCount(10), - roadmapContent1_2.getId(), goalRoomRoadmapNodes1); - - given(roadmapRepository.findWithRoadmapContentByStatus(any())) - .willReturn(List.of(roadmap1)); - given(goalRoomRepository.findByRoadmapContentId(roadmapContent1_2.getId())) - .willReturn(List.of(goalRoom1_1, goalRoom1_2)); - - // when - roadmap1.delete(); - goalRoom1_1.complete(); - - // then - assertDoesNotThrow(() -> roadmapScheduler.deleteRoadmaps()); - verify(goalRoomRepository, never()).deleteAll(any()); - verify(roadmapRepository, never()).delete(any()); - } - - @Test - void 삭제된_상태의_로드맵_삭제시_골룸이_종료된지_3개월이_지나지_않으면_삭제되지_않는다() { - // given - final Member member1 = new Member(new Identifier("identifier1"), - new EncryptedPassword(new Password("password1!")), new Nickname("name1"), null, - new MemberProfile(Gender.FEMALE, "kirikiri@email.com")); - final Member member2 = new Member(new Identifier("identifier2"), - new EncryptedPassword(new Password("password2!")), new Nickname("name2"), null, - new MemberProfile(Gender.FEMALE, "kirikiri@email.com")); - - final RoadmapCategory category = new RoadmapCategory("여행"); - final RoadmapContent roadmapContent1 = new RoadmapContent("로드맵 본문1"); - final RoadmapNode roadmapNode1 = new RoadmapNode("로드맵1 노드", "로드맵 노드 내용"); - roadmapContent1.addNodes(new RoadmapNodes(List.of(roadmapNode1))); - - final Roadmap roadmap1 = new Roadmap("로드맵1", "로드맵 설명1", 30, RoadmapDifficulty.DIFFICULT, member1, category); - roadmap1.addContent(roadmapContent1); - - final GoalRoomRoadmapNodes goalRoomRoadmapNodes1 = new GoalRoomRoadmapNodes(List.of( - new GoalRoomRoadmapNode(new Period(TODAY, TEN_DAY_LATER), 5, roadmapNode1.getId()))); - final GoalRoom goalRoom1 = new GoalRoom(new GoalRoomName("골룸1"), new LimitedMemberCount(10), - roadmapContent1.getId(), goalRoomRoadmapNodes1); - - given(roadmapRepository.findWithRoadmapContentByStatus(any())) - .willReturn(List.of(roadmap1)); - given(goalRoomRepository.findByRoadmapContentId(roadmapContent1.getId())) - .willReturn(List.of(goalRoom1)); - - // when - roadmap1.delete(); - goalRoom1.complete(); - - // then - assertDoesNotThrow(() -> roadmapScheduler.deleteRoadmaps()); - verify(goalRoomRepository, never()).deleteAll(any()); - verify(roadmapRepository, never()).delete(any()); - } - - @Test - void 삭제된_상태의_로드맵이_없는_경우_삭제되지_않는다() { - // given - final Member member1 = new Member(new Identifier("identifier1"), - new EncryptedPassword(new Password("password1!")), new Nickname("name1"), null, - new MemberProfile(Gender.FEMALE, "kirikiri@email.com")); - final Member member2 = new Member(new Identifier("identifier2"), - new EncryptedPassword(new Password("password2!")), new Nickname("name2"), null, - new MemberProfile(Gender.FEMALE, "kirikiri@email.com")); - - final RoadmapCategory category = new RoadmapCategory("여행"); - final RoadmapContent roadmapContent1 = new RoadmapContent("로드맵 본문1"); - final RoadmapNode roadmapNode = new RoadmapNode("로드맵 노드", "로드맵 노드 내용"); - final Roadmap roadmap1 = new Roadmap("로드맵1", "로드맵 설명1", 30, RoadmapDifficulty.DIFFICULT, member1, category); - roadmapContent1.addNodes(new RoadmapNodes(List.of(roadmapNode))); - roadmap1.addContent(roadmapContent1); - - final GoalRoomRoadmapNodes goalRoomRoadmapNodes = new GoalRoomRoadmapNodes(List.of( - new GoalRoomRoadmapNode(new Period(TODAY, TEN_DAY_LATER), 5, roadmapNode.getId()))); - final GoalRoom goalRoom1 = new GoalRoom(new GoalRoomName("골룸1"), new LimitedMemberCount(10), - roadmapContent1.getId(), goalRoomRoadmapNodes); - - goalRoom1.complete(); - - given(roadmapRepository.findWithRoadmapContentByStatus(any())) - .willReturn(Collections.emptyList()); - - // when - // then - assertDoesNotThrow(() -> roadmapScheduler.deleteRoadmaps()); - verify(goalRoomRepository, never()).findByRoadmapContentId(any()); - verify(roadmapRepository, never()).deleteAll(any()); - } -} diff --git a/backend/kirikiri/src/test/java/co/kirikiri/todo/persistence/GoalRoomToDoCheckRepositoryTest.java b/backend/kirikiri/src/test/java/co/kirikiri/todo/persistence/GoalRoomToDoCheckRepositoryTest.java index 34f9adc00..c50e98bfb 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/todo/persistence/GoalRoomToDoCheckRepositoryTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/todo/persistence/GoalRoomToDoCheckRepositoryTest.java @@ -3,19 +3,6 @@ import static org.assertj.core.api.Assertions.assertThat; import co.kirikiri.common.helper.RepositoryTest; -import co.kirikiri.domain.member.EncryptedPassword; -import co.kirikiri.domain.member.Gender; -import co.kirikiri.domain.member.Member; -import co.kirikiri.domain.member.MemberProfile; -import co.kirikiri.domain.member.vo.Identifier; -import co.kirikiri.domain.member.vo.Nickname; -import co.kirikiri.domain.member.vo.Password; -import co.kirikiri.domain.roadmap.Roadmap; -import co.kirikiri.domain.roadmap.RoadmapCategory; -import co.kirikiri.domain.roadmap.RoadmapContent; -import co.kirikiri.domain.roadmap.RoadmapDifficulty; -import co.kirikiri.domain.roadmap.RoadmapNode; -import co.kirikiri.domain.roadmap.RoadmapNodes; import co.kirikiri.goalroom.domain.GoalRoom; import co.kirikiri.goalroom.domain.GoalRoomMember; import co.kirikiri.goalroom.domain.GoalRoomRoadmapNode; @@ -26,17 +13,33 @@ import co.kirikiri.goalroom.domain.vo.Period; import co.kirikiri.goalroom.persistence.GoalRoomMemberRepository; import co.kirikiri.goalroom.persistence.GoalRoomRepository; -import co.kirikiri.persistence.member.MemberRepository; -import co.kirikiri.persistence.roadmap.RoadmapCategoryRepository; -import co.kirikiri.persistence.roadmap.RoadmapRepository; import co.kirikiri.todo.domain.GoalRoomToDo; import co.kirikiri.todo.domain.GoalRoomToDoCheck; import co.kirikiri.todo.domain.vo.GoalRoomTodoContent; import co.kirikiri.todo.domain.vo.ToDoPeriod; +import co.kirikiri.member.domain.EncryptedPassword; +import co.kirikiri.member.domain.Gender; +import co.kirikiri.member.domain.Member; +import co.kirikiri.member.domain.MemberProfile; +import co.kirikiri.member.domain.vo.Identifier; +import co.kirikiri.member.domain.vo.Nickname; +import co.kirikiri.member.domain.vo.Password; +import co.kirikiri.member.persistence.MemberRepository; +import co.kirikiri.roadmap.domain.Roadmap; +import co.kirikiri.roadmap.domain.RoadmapCategory; +import co.kirikiri.roadmap.domain.RoadmapContent; +import co.kirikiri.roadmap.domain.RoadmapDifficulty; +import co.kirikiri.roadmap.domain.RoadmapNode; +import co.kirikiri.roadmap.domain.RoadmapNodes; +import co.kirikiri.roadmap.domain.RoadmapTags; +import co.kirikiri.roadmap.persistence.RoadmapCategoryRepository; +import co.kirikiri.roadmap.persistence.RoadmapContentRepository; +import co.kirikiri.roadmap.persistence.RoadmapRepository; +import org.junit.jupiter.api.Test; import java.time.LocalDate; import java.time.LocalDateTime; +import java.util.ArrayList; import java.util.List; -import org.junit.jupiter.api.Test; @RepositoryTest class GoalRoomToDoCheckRepositoryTest { @@ -45,6 +48,7 @@ class GoalRoomToDoCheckRepositoryTest { private final MemberRepository memberRepository; private final RoadmapRepository roadmapRepository; + private final RoadmapContentRepository roadmapContentRepository; private final GoalRoomRepository goalRoomRepository; private final GoalRoomMemberRepository goalRoomMemberRepository; private final RoadmapCategoryRepository roadmapCategoryRepository; @@ -53,6 +57,7 @@ class GoalRoomToDoCheckRepositoryTest { public GoalRoomToDoCheckRepositoryTest(final MemberRepository memberRepository, final RoadmapRepository roadmapRepository, + final RoadmapContentRepository roadmapContentRepository, final GoalRoomRepository goalRoomRepository, final GoalRoomMemberRepository goalRoomMemberRepository, final RoadmapCategoryRepository roadmapCategoryRepository, @@ -60,6 +65,7 @@ public GoalRoomToDoCheckRepositoryTest(final MemberRepository memberRepository, final GoalRoomToDoCheckRepository goalRoomToDoCheckRepository) { this.memberRepository = memberRepository; this.roadmapRepository = roadmapRepository; + this.roadmapContentRepository = roadmapContentRepository; this.goalRoomRepository = goalRoomRepository; this.goalRoomMemberRepository = goalRoomMemberRepository; this.roadmapCategoryRepository = roadmapCategoryRepository; @@ -72,10 +78,11 @@ public GoalRoomToDoCheckRepositoryTest(final MemberRepository memberRepository, // given final Member creator = 사용자를_생성한다("name1", "01011111111", "identifier1", "password!1"); final RoadmapCategory category = 카테고리를_저장한다("여가"); + final Roadmap roadmap = 로드맵을_저장한다(creator, category); + final RoadmapNode roadmapNode1 = 로드맵_노드를_생성한다("로드맵 1주차", "로드맵 1주차 내용"); final RoadmapNode roadmapNode2 = 로드맵_노드를_생성한다("로드맵 2주차", "로드맵 2주차 내용"); - final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(List.of(roadmapNode1, roadmapNode2)); - 로드맵을_생성한다(creator, category, roadmapContent); + final RoadmapContent roadmapContent = 로드맵_본문을_저장한다(List.of(roadmapNode1, roadmapNode2), roadmap.getId()); final GoalRoomRoadmapNode goalRoomRoadmapNode1 = 골룸_로드맵_노드를_생성한다(TODAY, TODAY.plusDays(10), roadmapNode1); @@ -120,10 +127,11 @@ public GoalRoomToDoCheckRepositoryTest(final MemberRepository memberRepository, // given final Member creator = 사용자를_생성한다("name1", "01011111111", "identifier1", "password!1"); final RoadmapCategory category = 카테고리를_저장한다("여가"); + final Roadmap roadmap = 로드맵을_저장한다(creator, category); + final RoadmapNode roadmapNode1 = 로드맵_노드를_생성한다("로드맵 1주차", "로드맵 1주차 내용"); final RoadmapNode roadmapNode2 = 로드맵_노드를_생성한다("로드맵 2주차", "로드맵 2주차 내용"); - final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(List.of(roadmapNode1, roadmapNode2)); - 로드맵을_생성한다(creator, category, roadmapContent); + final RoadmapContent roadmapContent = 로드맵_본문을_저장한다(List.of(roadmapNode1, roadmapNode2), roadmap.getId()); final GoalRoomRoadmapNode goalRoomRoadmapNode1 = 골룸_로드맵_노드를_생성한다(TODAY, TODAY.plusDays(10), roadmapNode1); @@ -168,10 +176,10 @@ public GoalRoomToDoCheckRepositoryTest(final MemberRepository memberRepository, // given final Member creator = 사용자를_생성한다("name1", "01011111111", "identifier1", "password!1"); final RoadmapCategory category = 카테고리를_저장한다("여가"); + final Roadmap roadmap = 로드맵을_저장한다(creator, category); final RoadmapNode roadmapNode1 = 로드맵_노드를_생성한다("로드맵 1주차", "로드맵 1주차 내용"); final RoadmapNode roadmapNode2 = 로드맵_노드를_생성한다("로드맵 2주차", "로드맵 2주차 내용"); - final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(List.of(roadmapNode1, roadmapNode2)); - 로드맵을_생성한다(creator, category, roadmapContent); + final RoadmapContent roadmapContent = 로드맵_본문을_저장한다(List.of(roadmapNode1, roadmapNode2), roadmap.getId()); final GoalRoomRoadmapNode goalRoomRoadmapNode1 = 골룸_로드맵_노드를_생성한다(TODAY, TODAY.plusDays(10), roadmapNode1); @@ -231,17 +239,14 @@ public GoalRoomToDoCheckRepositoryTest(final MemberRepository memberRepository, return new RoadmapNode(title, content); } - private RoadmapContent 로드맵_본문을_생성한다(final List roadmapNodes) { - final RoadmapContent roadmapContent = new RoadmapContent("로드맵 본문"); - roadmapContent.addNodes(new RoadmapNodes(roadmapNodes)); - return roadmapContent; + private RoadmapContent 로드맵_본문을_저장한다(final List roadmapNodes, final Long roadmapId) { + final RoadmapContent roadmapContent = new RoadmapContent("로드맵 본문", roadmapId, new RoadmapNodes(roadmapNodes)); + return roadmapContentRepository.save(roadmapContent); } - private Roadmap 로드맵을_생성한다(final Member creator, final RoadmapCategory category, - final RoadmapContent roadmapContent) { + private Roadmap 로드맵을_저장한다(final Member creator, final RoadmapCategory category) { final Roadmap roadmap = new Roadmap("로드맵 제목", "로드맵 소개글", 30, RoadmapDifficulty.DIFFICULT, - creator, category); - roadmap.addContent(roadmapContent); + creator.getId(), category, new RoadmapTags(new ArrayList<>())); return roadmapRepository.save(roadmap); } diff --git a/backend/kirikiri/src/test/java/co/kirikiri/todo/persistence/GoalRoomToDoRepositoryTest.java b/backend/kirikiri/src/test/java/co/kirikiri/todo/persistence/GoalRoomToDoRepositoryTest.java index 28726c1bb..01296ad9b 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/todo/persistence/GoalRoomToDoRepositoryTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/todo/persistence/GoalRoomToDoRepositoryTest.java @@ -3,19 +3,6 @@ import static org.assertj.core.api.Assertions.assertThat; import co.kirikiri.common.helper.RepositoryTest; -import co.kirikiri.domain.member.EncryptedPassword; -import co.kirikiri.domain.member.Gender; -import co.kirikiri.domain.member.Member; -import co.kirikiri.domain.member.MemberProfile; -import co.kirikiri.domain.member.vo.Identifier; -import co.kirikiri.domain.member.vo.Nickname; -import co.kirikiri.domain.member.vo.Password; -import co.kirikiri.domain.roadmap.Roadmap; -import co.kirikiri.domain.roadmap.RoadmapCategory; -import co.kirikiri.domain.roadmap.RoadmapContent; -import co.kirikiri.domain.roadmap.RoadmapDifficulty; -import co.kirikiri.domain.roadmap.RoadmapNode; -import co.kirikiri.domain.roadmap.RoadmapNodes; import co.kirikiri.goalroom.domain.GoalRoom; import co.kirikiri.goalroom.domain.GoalRoomMember; import co.kirikiri.goalroom.domain.GoalRoomRoadmapNode; @@ -26,9 +13,22 @@ import co.kirikiri.goalroom.domain.vo.Period; import co.kirikiri.goalroom.persistence.GoalRoomMemberRepository; import co.kirikiri.goalroom.persistence.GoalRoomRepository; -import co.kirikiri.persistence.member.MemberRepository; -import co.kirikiri.persistence.roadmap.RoadmapCategoryRepository; -import co.kirikiri.persistence.roadmap.RoadmapRepository; +import co.kirikiri.member.domain.EncryptedPassword; +import co.kirikiri.member.domain.Gender; +import co.kirikiri.member.domain.Member; +import co.kirikiri.member.domain.MemberProfile; +import co.kirikiri.member.domain.vo.Identifier; +import co.kirikiri.member.domain.vo.Nickname; +import co.kirikiri.member.domain.vo.Password; +import co.kirikiri.member.persistence.MemberRepository; +import co.kirikiri.roadmap.domain.Roadmap; +import co.kirikiri.roadmap.domain.RoadmapCategory; +import co.kirikiri.roadmap.domain.RoadmapContent; +import co.kirikiri.roadmap.domain.RoadmapDifficulty; +import co.kirikiri.roadmap.domain.RoadmapNode; +import co.kirikiri.roadmap.domain.RoadmapNodes; +import co.kirikiri.roadmap.persistence.RoadmapCategoryRepository; +import co.kirikiri.roadmap.persistence.RoadmapRepository; import co.kirikiri.todo.domain.GoalRoomToDo; import co.kirikiri.todo.domain.vo.GoalRoomTodoContent; import co.kirikiri.todo.domain.vo.ToDoPeriod; @@ -70,8 +70,8 @@ public GoalRoomToDoRepositoryTest(final MemberRepository memberRepository, final RoadmapCategory category = 카테고리를_저장한다("여가"); final RoadmapNode roadmapNode1 = 로드맵_노드를_생성한다("로드맵 1주차", "로드맵 1주차 내용"); final RoadmapNode roadmapNode2 = 로드맵_노드를_생성한다("로드맵 2주차", "로드맵 2주차 내용"); - final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(List.of(roadmapNode1, roadmapNode2)); - 로드맵을_생성한다(creator, category, roadmapContent); + final Roadmap roadmap = 로드맵을_생성한다(creator, category); + final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmap.getId(), List.of(roadmapNode1, roadmapNode2)); final GoalRoomRoadmapNode goalRoomRoadmapNode1 = 골룸_로드맵_노드를_생성한다(TODAY, TODAY.plusDays(10), roadmapNode1); @@ -118,24 +118,21 @@ public GoalRoomToDoRepositoryTest(final MemberRepository memberRepository, return memberRepository.save(creator); } + private Roadmap 로드맵을_생성한다(final Member creator, final RoadmapCategory category) { + final Roadmap roadmap = new Roadmap("로드맵 제목", "로드맵 소개글", 30, RoadmapDifficulty.DIFFICULT, + creator.getId(), category, null); + return roadmapRepository.save(roadmap); + } + private RoadmapNode 로드맵_노드를_생성한다(final String title, final String content) { return new RoadmapNode(title, content); } - private RoadmapContent 로드맵_본문을_생성한다(final List roadmapNodes) { - final RoadmapContent roadmapContent = new RoadmapContent("로드맵 본문"); - roadmapContent.addNodes(new RoadmapNodes(roadmapNodes)); + private RoadmapContent 로드맵_본문을_생성한다(final Long roadmapId, final List roadmapNodes) { + final RoadmapContent roadmapContent = new RoadmapContent("로드맵 본문", roadmapId, new RoadmapNodes(roadmapNodes)); return roadmapContent; } - private Roadmap 로드맵을_생성한다(final Member creator, final RoadmapCategory category, - final RoadmapContent roadmapContent) { - final Roadmap roadmap = new Roadmap("로드맵 제목", "로드맵 소개글", 30, RoadmapDifficulty.DIFFICULT, - creator, category); - roadmap.addContent(roadmapContent); - return roadmapRepository.save(roadmap); - } - private GoalRoomRoadmapNode 골룸_로드맵_노드를_생성한다(final LocalDate startDate, final LocalDate endDate, final RoadmapNode roadmapNode) { return new GoalRoomRoadmapNode(new Period(startDate, endDate), 1, roadmapNode.getId()); diff --git a/backend/kirikiri/src/test/java/co/kirikiri/todo/service/GoalRoomToDoServiceTest.java b/backend/kirikiri/src/test/java/co/kirikiri/todo/service/GoalRoomToDoServiceTest.java index ffdc56ffa..a47b05c1e 100644 --- a/backend/kirikiri/src/test/java/co/kirikiri/todo/service/GoalRoomToDoServiceTest.java +++ b/backend/kirikiri/src/test/java/co/kirikiri/todo/service/GoalRoomToDoServiceTest.java @@ -12,22 +12,6 @@ import co.kirikiri.common.exception.ForbiddenException; import co.kirikiri.common.exception.NotFoundException; import co.kirikiri.common.type.ImageContentType; -import co.kirikiri.domain.member.EncryptedPassword; -import co.kirikiri.domain.member.Gender; -import co.kirikiri.domain.member.Member; -import co.kirikiri.domain.member.MemberProfile; -import co.kirikiri.domain.member.vo.Identifier; -import co.kirikiri.domain.member.vo.Nickname; -import co.kirikiri.domain.member.vo.Password; -import co.kirikiri.domain.roadmap.Roadmap; -import co.kirikiri.domain.roadmap.RoadmapCategory; -import co.kirikiri.domain.roadmap.RoadmapContent; -import co.kirikiri.domain.roadmap.RoadmapContents; -import co.kirikiri.domain.roadmap.RoadmapDifficulty; -import co.kirikiri.domain.roadmap.RoadmapNode; -import co.kirikiri.domain.roadmap.RoadmapNodeImage; -import co.kirikiri.domain.roadmap.RoadmapNodeImages; -import co.kirikiri.domain.roadmap.RoadmapNodes; import co.kirikiri.goalroom.domain.GoalRoom; import co.kirikiri.goalroom.domain.GoalRoomMember; import co.kirikiri.goalroom.domain.GoalRoomRoadmapNode; @@ -38,7 +22,22 @@ import co.kirikiri.goalroom.domain.vo.Period; import co.kirikiri.goalroom.persistence.GoalRoomMemberRepository; import co.kirikiri.goalroom.persistence.GoalRoomRepository; -import co.kirikiri.persistence.member.MemberRepository; +import co.kirikiri.member.domain.EncryptedPassword; +import co.kirikiri.member.domain.Gender; +import co.kirikiri.member.domain.Member; +import co.kirikiri.member.domain.MemberProfile; +import co.kirikiri.member.domain.vo.Identifier; +import co.kirikiri.member.domain.vo.Nickname; +import co.kirikiri.member.domain.vo.Password; +import co.kirikiri.member.persistence.MemberRepository; +import co.kirikiri.roadmap.domain.Roadmap; +import co.kirikiri.roadmap.domain.RoadmapCategory; +import co.kirikiri.roadmap.domain.RoadmapContent; +import co.kirikiri.roadmap.domain.RoadmapDifficulty; +import co.kirikiri.roadmap.domain.RoadmapNode; +import co.kirikiri.roadmap.domain.RoadmapNodeImage; +import co.kirikiri.roadmap.domain.RoadmapNodeImages; +import co.kirikiri.roadmap.domain.RoadmapNodes; import co.kirikiri.todo.domain.GoalRoomToDo; import co.kirikiri.todo.domain.GoalRoomToDoCheck; import co.kirikiri.todo.domain.vo.GoalRoomTodoContent; @@ -103,10 +102,10 @@ static void setUp() { //given final Member creator = 사용자를_생성한다(1L, "identifier1", "password1!", "시진이", "kirikiri1@email"); final Roadmap roadmap = 로드맵을_생성한다(creator); - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); + final List roadmapNodes = 로드맵_노드들을_생성한다(); + final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmap.getId(), roadmapNodes); final int limitedMemberCount = 20; - final GoalRoom goalRoom = 골룸을_생성한다(1L, creator, targetRoadmapContent, limitedMemberCount); + final GoalRoom goalRoom = 골룸을_생성한다(1L, creator, roadmapContent, limitedMemberCount); final GoalRoomToDo goalRoomTodo = new GoalRoomToDo(null, 1L, new GoalRoomTodoContent("goalRoomTodoContent"), new ToDoPeriod(TODAY, TEN_DAY_LATER)); @@ -148,10 +147,10 @@ static void setUp() { //given final Member creator = 사용자를_생성한다(1L, "identifier1", "password1!", "시진이", "kirikiri1@email"); final Roadmap roadmap = 로드맵을_생성한다(creator); - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); + final List roadmapNodes = 로드맵_노드들을_생성한다(); + final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmap.getId(), roadmapNodes); final int limitedMemberCount = 20; - final GoalRoom goalRoom = 골룸을_생성한다(1L, creator, targetRoadmapContent, limitedMemberCount); + final GoalRoom goalRoom = 골룸을_생성한다(1L, creator, roadmapContent, limitedMemberCount); given(memberRepository.findByIdentifier(any())) .willReturn(Optional.of(creator)); @@ -172,10 +171,10 @@ static void setUp() { //given final Member creator = 사용자를_생성한다(1L, "identifier1", "password1!", "시진이", "kirikiri1@email"); final Roadmap roadmap = 로드맵을_생성한다(creator); - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); + final List roadmapNodes = 로드맵_노드들을_생성한다(); + final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmap.getId(), roadmapNodes); final int limitedMemberCount = 20; - final GoalRoom goalRoom = 골룸을_생성한다(1L, creator, targetRoadmapContent, limitedMemberCount); + final GoalRoom goalRoom = 골룸을_생성한다(1L, creator, roadmapContent, limitedMemberCount); goalRoom.complete(); given(memberRepository.findByIdentifier(any())) @@ -197,10 +196,10 @@ static void setUp() { //given final Member creator = 사용자를_생성한다(1L, "identifier1", "password1!", "시진이", "kirikiri1@email"); final Roadmap roadmap = 로드맵을_생성한다(creator); - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); + final List roadmapNodes = 로드맵_노드들을_생성한다(); + final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmap.getId(), roadmapNodes); final int limitedMemberCount = 20; - final GoalRoom goalRoom = 골룸을_생성한다(1L, creator, targetRoadmapContent, limitedMemberCount); + final GoalRoom goalRoom = 골룸을_생성한다(1L, creator, roadmapContent, limitedMemberCount); given(memberRepository.findByIdentifier(any())) .willReturn(Optional.of(member)); @@ -224,10 +223,9 @@ static void setUp() { // given final Member creator = 사용자를_생성한다(1L, "cokirikiri", "password1!", "코끼리", "kirikiri1@email"); final Roadmap roadmap = 로드맵을_생성한다(creator); - - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); - final GoalRoom goalRoom = 골룸을_생성한다(1L, creator, targetRoadmapContent, 10); + final List roadmapNodes = 로드맵_노드들을_생성한다(); + final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmap.getId(), roadmapNodes); + final GoalRoom goalRoom = 골룸을_생성한다(1L, creator, roadmapContent, 10); final GoalRoomToDo goalRoomToDo = new GoalRoomToDo(1L, goalRoom.getId(), new GoalRoomTodoContent("투두 1"), new ToDoPeriod(TODAY, TODAY.plusDays(3))); final GoalRoomMember goalRoomMember = new GoalRoomMember(GoalRoomRole.LEADER, LocalDateTime.now(), goalRoom, @@ -258,10 +256,9 @@ static void setUp() { // given final Member creator = 사용자를_생성한다(1L, "cokirikiri", "password1!", "코끼리", "kirikiri1@email"); final Roadmap roadmap = 로드맵을_생성한다(creator); - - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); - final GoalRoom goalRoom = 골룸을_생성한다(1L, creator, targetRoadmapContent, 10); + final List roadmapNodes = 로드맵_노드들을_생성한다(); + final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmap.getId(), roadmapNodes); + final GoalRoom goalRoom = 골룸을_생성한다(1L, creator, roadmapContent, 10); final GoalRoomToDo goalRoomToDo = new GoalRoomToDo(1L, goalRoom.getId(), new GoalRoomTodoContent("투두 1"), new ToDoPeriod(TODAY, TODAY.plusDays(3))); @@ -306,10 +303,9 @@ static void setUp() { // given final Member creator = 사용자를_생성한다(1L, "cokirikiri", "password1!", "코끼리", "kirikiri1@email"); final Roadmap roadmap = 로드맵을_생성한다(creator); - - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); - final GoalRoom goalRoom = 골룸을_생성한다(1L, creator, targetRoadmapContent, 10); + final List roadmapNodes = 로드맵_노드들을_생성한다(); + final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmap.getId(), roadmapNodes); + final GoalRoom goalRoom = 골룸을_생성한다(1L, creator, roadmapContent, 10); when(goalRoomRepository.findById(anyLong())) .thenReturn(Optional.of(goalRoom)); @@ -325,10 +321,9 @@ static void setUp() { // given final Member creator = 사용자를_생성한다(1L, "cokirikiri", "password1!", "코끼리", "kirikiri1@email"); final Roadmap roadmap = 로드맵을_생성한다(creator); - - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); - final GoalRoom goalRoom = 골룸을_생성한다(1L, creator, targetRoadmapContent, 10); + final List roadmapNodes = 로드맵_노드들을_생성한다(); + final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmap.getId(), roadmapNodes); + final GoalRoom goalRoom = 골룸을_생성한다(1L, creator, roadmapContent, 10); final GoalRoomToDo goalRoomToDo = new GoalRoomToDo(1L, goalRoom.getId(), new GoalRoomTodoContent("투두 1"), new ToDoPeriod(TODAY, TODAY.plusDays(3))); @@ -352,9 +347,9 @@ static void setUp() { // given final Member creator = 사용자를_생성한다(1L, "cokirikiri", "password1!", "코끼리", "kirikiri1@email"); final Roadmap roadmap = 로드맵을_생성한다(creator); - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); - final GoalRoom goalRoom = 골룸을_생성한다(1L, creator, targetRoadmapContent, 10); + final List roadmapNodes = 로드맵_노드들을_생성한다(); + final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmap.getId(), roadmapNodes); + final GoalRoom goalRoom = 골룸을_생성한다(1L, creator, roadmapContent, 10); final GoalRoomToDo firstGoalRoomTodo = new GoalRoomToDo(1L, goalRoom.getId(), new GoalRoomTodoContent("투두 1"), new ToDoPeriod(TODAY, TEN_DAY_LATER)); @@ -404,9 +399,9 @@ static void setUp() { // given final Member creator = 사용자를_생성한다(1L, "cokirikiri", "password1!", "코끼리", "kirikiri1@email"); final Roadmap roadmap = 로드맵을_생성한다(creator); - final RoadmapContents roadmapContents = roadmap.getContents(); - final RoadmapContent targetRoadmapContent = roadmapContents.getValues().get(0); - final GoalRoom goalRoom = 골룸을_생성한다(1L, creator, targetRoadmapContent, 10); + final List roadmapNodes = 로드맵_노드들을_생성한다(); + final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmap.getId(), roadmapNodes); + final GoalRoom goalRoom = 골룸을_생성한다(1L, creator, roadmapContent, 10); when(goalRoomRepository.findById(1L)) .thenReturn(Optional.of(goalRoom)); @@ -430,10 +425,8 @@ static void setUp() { private Roadmap 로드맵을_생성한다(final Member creator) { final RoadmapCategory category = new RoadmapCategory("게임"); - final List roadmapNodes = 로드맵_노드들을_생성한다(); - final RoadmapContent roadmapContent = 로드맵_본문을_생성한다(roadmapNodes); - final Roadmap roadmap = new Roadmap("로드맵 제목", "로드맵 소개글", 10, RoadmapDifficulty.NORMAL, creator, category); - roadmap.addContent(roadmapContent); + final Roadmap roadmap = new Roadmap("로드맵 제목", "로드맵 소개글", 10, RoadmapDifficulty.NORMAL, creator.getId(), + category, null); return roadmap; } @@ -444,9 +437,8 @@ static void setUp() { return List.of(roadmapNode1, roadmapNode2); } - private RoadmapContent 로드맵_본문을_생성한다(final List roadmapNodes) { - final RoadmapContent roadmapContent = new RoadmapContent("로드맵 본문"); - roadmapContent.addNodes(new RoadmapNodes(roadmapNodes)); + private RoadmapContent 로드맵_본문을_생성한다(final Long roadmapId, final List roadmapNodes) { + final RoadmapContent roadmapContent = new RoadmapContent("로드맵 본문", roadmapId, new RoadmapNodes(roadmapNodes)); return roadmapContent; }