diff --git a/module-api/src/main/java/com/mile/controller/user/facade/AuthFacade.java b/module-api/src/main/java/com/mile/controller/user/facade/AuthFacade.java index 690b9eb0..0a5f92d1 100644 --- a/module-api/src/main/java/com/mile/controller/user/facade/AuthFacade.java +++ b/module-api/src/main/java/com/mile/controller/user/facade/AuthFacade.java @@ -65,7 +65,7 @@ private LoginSuccessResponse getTokenDto( if (userService.isExistingUser(userResponse.socialId(), userResponse.socialType())) { return getTokenByUserId(userService.getBySocialId(userResponse.socialId(), userResponse.socialType()).getId()); } else { - Long id = userService.createuser(userResponse.socialId(), userResponse.socialType(), userResponse.email()); + Long id = userService.createUser(userResponse.socialId(), userResponse.socialType(), userResponse.email()); return getTokenByUserId(id); } } catch (DataIntegrityViolationException e) { diff --git a/module-api/src/test/java/com/mile/controller/MoimControllerTest.java b/module-api/src/test/java/com/mile/controller/MoimControllerTest.java index 5d18e818..89727cdf 100644 --- a/module-api/src/test/java/com/mile/controller/MoimControllerTest.java +++ b/module-api/src/test/java/com/mile/controller/MoimControllerTest.java @@ -9,6 +9,8 @@ import com.mile.moim.service.dto.MoimInfoModifyRequest; import com.mile.moim.service.dto.TopicCreateRequest; import com.mile.moim.service.dto.WriterMemberJoinRequest; +import com.mile.post.service.PostService; +import com.mile.post.service.dto.PostCreateRequest; import com.mile.user.domain.User; import com.mile.user.repository.UserRepository; import com.mile.utils.SecureUrlUtil; @@ -54,6 +56,9 @@ public class MoimControllerTest { @Autowired private MoimService moimService; + @Autowired + private PostService postService; + @Autowired private ObjectMapper objectMapper; @@ -81,6 +86,7 @@ public void aTestForDummyUser() throws JsonProcessingException { 테스트 이전 더미 모임 쌓기 */ @Test + @Transactional @DisplayName("더미 모임 생성") public void bSaveNewMoimAndGetMoimId() { String randomTagString = UUID.randomUUID().toString().substring(0, 3); @@ -95,7 +101,13 @@ public void bSaveNewMoimAndGetMoimId() { randomTagString, randomString ); + + TopicCreateRequest topicCreateRequest = new TopicCreateRequest(randomString, randomTagString, randomTagString); MOIM_ID = moimService.createMoim(USER_ID, createRequest).moimId(); + String topicId = secureUrlUtil + .encodeUrl(Long.parseLong(moimService.createTopic(secureUrlUtil.decodeUrl(MOIM_ID), USER_ID, topicCreateRequest))); + PostCreateRequest postCreateRequest =new PostCreateRequest(MOIM_ID, topicId, randomString, randomString, randomString, false); + postService.createPost(USER_ID, postCreateRequest); } /* @@ -435,7 +447,6 @@ public void createTopicTest() throws Exception { @Test @DisplayName("글모임이 정상적으로 삭제된다.") - @Transactional public void zdeleteMoimTest() throws Exception { //given String token = "Bearer " + jwtTokenProvider.issueAccessToken(USER_ID); diff --git a/module-common/src/main/java/com/mile/exception/message/ErrorMessage.java b/module-common/src/main/java/com/mile/exception/message/ErrorMessage.java index 944513a7..8ab516e7 100644 --- a/module-common/src/main/java/com/mile/exception/message/ErrorMessage.java +++ b/module-common/src/main/java/com/mile/exception/message/ErrorMessage.java @@ -12,7 +12,7 @@ public enum ErrorMessage { Not Found */ USER_NOT_FOUND(40400, "해당 유저는 존재하지 않습니다."), - REFRESH_TOKEN_NOT_FOUND(HttpStatus.NOT_FOUND.value(), "해당 유저의 리프레시 토큰이 존재하지 않습니다."), + REFRESH_TOKEN_NOT_FOUND(40401, "해당 유저의 리프레시 토큰이 존재하지 않습니다."), POST_NOT_FOUND(40402, "해당 글은 존재하지 않습니다."), MOIM_NOT_FOUND(40403, "해당 글모임이 존재하지 않습니다."), CONTENT_NOT_FOUND(40404, "해당 모임의 주제가 존재하지 않습니다."), @@ -22,7 +22,7 @@ public enum ErrorMessage { TOPIC_NOT_FOUND(40408, "해당 글감이 존재하지 않습니다."), KEYWORD_NOT_FOUND(40409, "해당 글모임의 글감 키워드가 존재하지 않습니다."), WRITERS_NOT_FOUND(HttpStatus.NOT_FOUND.value(), "해당 모임의 작가가 요청한 개수 이상 존재하지 않습니다"), - WRITER_NOT_FOUND(HttpStatus.NOT_FOUND.value(), "해당 작가는 존재하지 않습니다."), + WRITER_NOT_FOUND(40411, "해당 작가는 존재하지 않습니다."), RECOMMEND_NOT_FOUND(40412, "추천 글감을 받아오는데 실패했습니다."), MOIM_TOPIC_NOT_FOUND(40413, "해당 모임의 글감이 존재하지 않습니다."), TOPIC_POST_NOT_FOUND(HttpStatus.NOT_FOUND.value(), "해당 글감의 글이 존재하지 않습니다."), @@ -33,14 +33,14 @@ public enum ErrorMessage { Bad Request */ ENUM_VALUE_BAD_REQUEST(HttpStatus.BAD_REQUEST.value(), "요청한 값이 유효하지 않습니다."), - AUTHENTICATION_CODE_EXPIRED(HttpStatus.BAD_REQUEST.value(), "인가 코드가 만료되었습니다."), + AUTHENTICATION_CODE_EXPIRED(40001, "인가 코드가 만료되었습니다."), SOCIAL_TYPE_BAD_REQUEST(HttpStatus.BAD_REQUEST.value(), "로그인 요청이 유효하지 않습니다."), INVALID_BUCKET_PREFIX(HttpStatus.BAD_REQUEST.value(), "유효하지 않는 S3 버킷 디렉터리 이름입니다."), VALIDATION_REQUEST_MISSING_EXCEPTION(HttpStatus.BAD_REQUEST.value(), "요청 값이 유효하지 않습니다."), VALIDATION_REQUEST_NULL_OR_BLANK_EXCEPTION(40005,"요청 값이 비어있습니다."), VALIDATION_REQUEST_LENGTH_EXCEPTION(40006,"요청 값이 길이를 초과했습니다."), BEARER_LOST_ERROR(HttpStatus.BAD_REQUEST.value(), "토큰의 요청에 Bearer이 담겨 있지 않습니다."), - POST_NOT_TEMPORARY_ERROR(HttpStatus.BAD_REQUEST.value(), "해당 글은 임시저장 글이 아닙니다."), + POST_NOT_TEMPORARY_ERROR(40008, "해당 글은 임시저장 글이 아닙니다."), POST_TEMPORARY_ERROR(HttpStatus.BAD_REQUEST.value(), "해당 글은 임시저장글입니다."), PATH_PARAMETER_INVALID_ERROR(HttpStatus.BAD_REQUEST.value(), "요청 URI를 다시 확인해주세요."), REQUEST_URL_WRONG_ERROR(HttpStatus.BAD_REQUEST.value(), "요청 URL를 다시 확인해주세요"), @@ -67,7 +67,7 @@ public enum ErrorMessage { /* Forbidden */ - USER_AUTHENTICATE_ERROR(40300, "해당 사용자는 모임에 접근 권한이 없습니다."), + USER_MOIM_AUTHENTICATE_ERROR(40300, "해당 사용자는 모임에 접근 권한이 없습니다."), REPLY_USER_FORBIDDEN(40301, "사용자에게 해당 대댓글에 대한 권한이 없습니다."), WRITER_AUTHENTICATE_ERROR(40302, "해당 사용자는 글 생성/수정/삭제 권한이 없습니다."), MOIM_OWNER_AUTHENTICATION_ERROR(40303, "사용자는 해당 모임의 모임장이 아닙니다."), diff --git a/module-domain/src/main/java/com/mile/moim/service/MoimService.java b/module-domain/src/main/java/com/mile/moim/service/MoimService.java index f577de34..a56bd9b8 100644 --- a/module-domain/src/main/java/com/mile/moim/service/MoimService.java +++ b/module-domain/src/main/java/com/mile/moim/service/MoimService.java @@ -225,8 +225,12 @@ public void modifyMoimInforation( final Long userId, final MoimInfoModifyRequest modifyRequest ) { - checkMoimNameUnique(modifyRequest.moimTitle()); Moim moim = moimRetriever.findById(moimId); + + if (!moim.getName().equals(modifyRequest.moimTitle())) { + validateMoimName(modifyRequest.moimTitle()); + } + moimRetriever.authenticateOwnerOfMoim(moim, userRetriever.findById(userId)); moim.modifyMoimInfo(modifyRequest); } diff --git a/module-domain/src/main/java/com/mile/post/service/PostRetriever.java b/module-domain/src/main/java/com/mile/post/service/PostRetriever.java index 8c6179ed..74fcd2a4 100644 --- a/module-domain/src/main/java/com/mile/post/service/PostRetriever.java +++ b/module-domain/src/main/java/com/mile/post/service/PostRetriever.java @@ -40,7 +40,6 @@ public Post findById( } - public String getTemporaryPostExist( final Moim moim, final WriterName writerName @@ -99,7 +98,7 @@ public void authenticateUserOfMoim( final boolean isUserInMoim ) { if (!isUserInMoim) { - throw new ForbiddenException(ErrorMessage.USER_AUTHENTICATE_ERROR); + throw new ForbiddenException(ErrorMessage.USER_MOIM_AUTHENTICATE_ERROR); } } @@ -131,14 +130,6 @@ public boolean isWriterOfPost(final Post post, final WriterName writerName) { return post.getWriterName().equals(writerName); } - public void authenticateWriterOfMoim( - final Long userId, - final Long moimId - ) { - if (!writerNameRetriever.isUserInMoim(moimId, userId)) { - throw new ForbiddenException(ErrorMessage.WRITER_AUTHENTICATE_ERROR); - } - } public MoimCuriousPostListResponse getMostCuriousPostByMoim(final Moim moim) { List postList = getPostHaveCuriousCount(postRepository.findTop2ByMoimOrderByCuriousCountDesc(moim)); diff --git a/module-domain/src/main/java/com/mile/post/service/PostService.java b/module-domain/src/main/java/com/mile/post/service/PostService.java index 1cc2d1c3..eabc117c 100644 --- a/module-domain/src/main/java/com/mile/post/service/PostService.java +++ b/module-domain/src/main/java/com/mile/post/service/PostService.java @@ -176,7 +176,7 @@ public TemporaryPostGetResponse getTemporaryPost( Post post = postRetriever.findById(postId); Topic selectedTopic = post.getTopic(); Moim moim = selectedTopic.getMoim(); - postRetriever.authenticateUserWithPost(post, userId); + postRetriever.authenticateWriter(postId, writerNameRetriever.findByMoimAndUser(moim.getId(), userId)); isPostTemporary(post); List contentResponse = topicService.getContentsWithIsSelectedFromMoim(moim.getId(), selectedTopic.getId()); return TemporaryPostGetResponse.of(post, contentResponse); @@ -224,7 +224,6 @@ public WriterNameResponse createPost( final Long userId, final PostCreateRequest postCreateRequest ) { - postRetriever.authenticateUserOfMoim(writerNameRetriever.isUserInMoim(decodeUrlToLong(postCreateRequest.moimId()), userId)); WriterName writerName = writerNameRetriever.findByMoimAndUser(decodeUrlToLong(postCreateRequest.moimId()), userId); Topic topic = topicRetriever.findById(decodeUrlToLong(postCreateRequest.topicId())); String postIdUrl = postCreator.create(postCreateRequest, topic, writerName); @@ -237,7 +236,6 @@ public void createTemporaryPost( final Long userId, final TemporaryPostCreateRequest temporaryPostCreateRequest ) { - postRetriever.authenticateWriterOfMoim(userId, decodeUrlToLong(temporaryPostCreateRequest.moimId())); WriterName writerName = writerNameRetriever.findByMoimAndUser(secureUrlUtil.decodeUrl(temporaryPostCreateRequest.moimId()), userId); postRemover.deleteTemporaryPosts(topicRetriever.findById(secureUrlUtil.decodeUrl(temporaryPostCreateRequest.topicId())).getMoim(), writerName); Topic topic = topicRetriever.findById(decodeUrlToLong(temporaryPostCreateRequest.topicId())); @@ -250,7 +248,7 @@ public WriterNameResponse putTemporaryToFixedPost(final Long userId, final PostP WriterName writerName = writerNameRetriever.findByMoimAndUser(post.getTopic().getMoim().getId(), userId); postRetriever.authenticateWriter(postId, writerName); isPostTemporary(post); - postUpdator.updateTemporaryPost(postId, post.getTopic(), request); + postUpdator.updateTemporaryPost(post, post.getTopic(), request); return WriterNameResponse.of(post.getIdUrl(), writerName.getName()); } diff --git a/module-domain/src/main/java/com/mile/post/service/PostUpdator.java b/module-domain/src/main/java/com/mile/post/service/PostUpdator.java index 55ff603b..17f1200e 100644 --- a/module-domain/src/main/java/com/mile/post/service/PostUpdator.java +++ b/module-domain/src/main/java/com/mile/post/service/PostUpdator.java @@ -28,11 +28,10 @@ public void update( } public void updateTemporaryPost( - final Long postId, + final Post post, final Topic topic, final PostPutRequest putRequest ) { - Post post = postRetriever.findById(postId); post.setTemporary(false); post.updateCratedAt(LocalDateTime.now()); update(post, topic, putRequest); diff --git a/module-domain/src/main/java/com/mile/topic/repository/TopicRepository.java b/module-domain/src/main/java/com/mile/topic/repository/TopicRepository.java index a63e3e36..1e4a5728 100644 --- a/module-domain/src/main/java/com/mile/topic/repository/TopicRepository.java +++ b/module-domain/src/main/java/com/mile/topic/repository/TopicRepository.java @@ -9,6 +9,7 @@ import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.query.Param; import org.springframework.lang.NonNull; +import org.springframework.transaction.annotation.Transactional; import java.util.List; @@ -22,6 +23,7 @@ public interface TopicRepository extends JpaRepository, TopicReposi Page findByMoimIdOrderByCreatedAtDesc(Long moimId, Pageable pageable); + @Transactional @Modifying @Query("DELETE FROM Topic t where t.moim = :moim") void deleteByMoim(@Param("moim") Moim moim); diff --git a/module-domain/src/main/java/com/mile/topic/service/TopicRemover.java b/module-domain/src/main/java/com/mile/topic/service/TopicRemover.java index 00552c1c..ea08f73d 100644 --- a/module-domain/src/main/java/com/mile/topic/service/TopicRemover.java +++ b/module-domain/src/main/java/com/mile/topic/service/TopicRemover.java @@ -20,19 +20,12 @@ public class TopicRemover { private final TopicRepository topicRepository; public void deleteTopic( - final Topic topic, - final User user + final Topic topic ) { deletePostsOfTopic(topic); topicRepository.deleteById(topic.getId()); } - public void deleteTopics( - final List topics - ) { - - } - private void deletePostsOfTopic( final Topic topic ) { diff --git a/module-domain/src/main/java/com/mile/topic/service/TopicService.java b/module-domain/src/main/java/com/mile/topic/service/TopicService.java index 2c4a3d45..98084a60 100644 --- a/module-domain/src/main/java/com/mile/topic/service/TopicService.java +++ b/module-domain/src/main/java/com/mile/topic/service/TopicService.java @@ -27,7 +27,6 @@ public class TopicService { private final TopicCreator topicCreator; private final UserService userService; - public List getContentsWithIsSelectedFromMoim( final Long moimId, final Long selectedTopicId @@ -42,23 +41,6 @@ public PostListInTopicResponse getPostListByTopic( return topicRetriever.getPostListByTopic(topicId, lastPostId); } - public MoimTopicInfoListResponse getTopicListFromMoim( - final Long moimId, - final int page - ) { - return topicRetriever.getTopicListFromMoim(moimId, page); - } - - public MoimTopicInfoListResponse getTopicResponsesFromPage(Page topicPage, final Long moimId) { - return topicRetriever.getTopicResponsesFromPage(topicPage, moimId); - } - - public Long getNumberOfTopicFromMoim( - final Long moimId - ) { - return topicRetriever.getNumberOfTopicFromMoim(moimId); - } - public TopicDetailResponse getTopicDetail( final Long userId, final Long topicId @@ -66,13 +48,6 @@ public TopicDetailResponse getTopicDetail( return topicRetriever.getTopicDetail(userId, topicId); } - public Long createTopicOfMoim( - final Moim moim, - final TopicCreateRequest createRequest - ) { - return topicCreator.createTopicOfMoim(moim, createRequest); - } - @Transactional public void deleteTopic( final Long userId, @@ -82,7 +57,7 @@ public void deleteTopic( User user = userService.findById(userId); topicRetriever.authenticateTopicWithUser(topic, user); topicRetriever.checkSingleTopicDeletion(topic); - topicRemover.deleteTopic(topic, user); + topicRemover.deleteTopic(topic); } public void putTopic( diff --git a/module-domain/src/main/java/com/mile/user/service/UserService.java b/module-domain/src/main/java/com/mile/user/service/UserService.java index 30d36bab..a4925f45 100644 --- a/module-domain/src/main/java/com/mile/user/service/UserService.java +++ b/module-domain/src/main/java/com/mile/user/service/UserService.java @@ -28,7 +28,7 @@ public boolean isExistingUser(final String socialId, final SocialType socialType return userRetriever.isExistingUser(socialId, socialType); } - public Long createuser(final String socialId, final SocialType socialType, final String email) { + public Long createUser(final String socialId, final SocialType socialType, final String email) { return userCreator.createUser(socialId, socialType, email); } diff --git a/module-domain/src/main/java/com/mile/writername/service/WriterNameRetriever.java b/module-domain/src/main/java/com/mile/writername/service/WriterNameRetriever.java index 09ecef7c..dfeec0fb 100644 --- a/module-domain/src/main/java/com/mile/writername/service/WriterNameRetriever.java +++ b/module-domain/src/main/java/com/mile/writername/service/WriterNameRetriever.java @@ -25,16 +25,6 @@ public class WriterNameRetriever { private final WriterNameRepository writerNameRepository; private static final int MIN_TOTAL_CURIOUS_COUNT = 0; - public WriterName getWriterNameByPostAndUserId( - final Post post, - final Long userId - ) { - return writerNameRepository.findByMoimIdAndWriterId(post.getTopic().getMoim().getId(), userId) - .orElseThrow( - () -> new NotFoundException(ErrorMessage.WRITER_NOT_FOUND) - ); - } - public boolean existWriterNamesByMoimAndName( final Moim moim, final String name @@ -76,7 +66,7 @@ public WriterName findByMoimAndUser( ) { return writerNameRepository.findByMoimIdAndWriterId(moimId, writerId) .orElseThrow( - () -> new ForbiddenException(ErrorMessage.USER_AUTHENTICATE_ERROR) + () -> new ForbiddenException(ErrorMessage.USER_MOIM_AUTHENTICATE_ERROR) ); }