Skip to content

Commit

Permalink
#451 [fix] conflict 해결
Browse files Browse the repository at this point in the history
  • Loading branch information
parkheeddong committed Aug 6, 2024
2 parents f244216 + aefd4ab commit f1d435f
Show file tree
Hide file tree
Showing 12 changed files with 33 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -54,6 +56,9 @@ public class MoimControllerTest {
@Autowired
private MoimService moimService;

@Autowired
private PostService postService;

@Autowired
private ObjectMapper objectMapper;

Expand Down Expand Up @@ -81,6 +86,7 @@ public void aTestForDummyUser() throws JsonProcessingException {
테스트 이전 더미 모임 쌓기
*/
@Test
@Transactional
@DisplayName("더미 모임 생성")
public void bSaveNewMoimAndGetMoimId() {
String randomTagString = UUID.randomUUID().toString().substring(0, 3);
Expand All @@ -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);
}

/*
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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, "해당 모임의 주제가 존재하지 않습니다."),
Expand All @@ -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(), "해당 글감의 글이 존재하지 않습니다."),
Expand All @@ -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를 다시 확인해주세요"),
Expand All @@ -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, "사용자는 해당 모임의 모임장이 아닙니다."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ public Post findById(

}


public String getTemporaryPostExist(
final Moim moim,
final WriterName writerName
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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<Post> postList = getPostHaveCuriousCount(postRepository.findTop2ByMoimOrderByCuriousCountDesc(moim));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ContentWithIsSelectedResponse> contentResponse = topicService.getContentsWithIsSelectedFromMoim(moim.getId(), selectedTopic.getId());
return TemporaryPostGetResponse.of(post, contentResponse);
Expand Down Expand Up @@ -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);
Expand All @@ -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()));
Expand All @@ -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());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -22,6 +23,7 @@ public interface TopicRepository extends JpaRepository<Topic, Long>, TopicReposi

Page<Topic> findByMoimIdOrderByCreatedAtDesc(Long moimId, Pageable pageable);

@Transactional
@Modifying
@Query("DELETE FROM Topic t where t.moim = :moim")
void deleteByMoim(@Param("moim") Moim moim);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Topic> topics
) {

}

private void deletePostsOfTopic(
final Topic topic
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ public class TopicService {
private final TopicCreator topicCreator;
private final UserService userService;


public List<ContentWithIsSelectedResponse> getContentsWithIsSelectedFromMoim(
final Long moimId,
final Long selectedTopicId
Expand All @@ -42,37 +41,13 @@ 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<Topic> 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
) {
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,
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
);
}

Expand Down

0 comments on commit f1d435f

Please sign in to comment.