diff --git a/src/main/java/com/prgrms/prolog/domain/post/service/PostServiceImpl.java b/src/main/java/com/prgrms/prolog/domain/post/service/PostServiceImpl.java index 9e0f88b..26ddf9a 100644 --- a/src/main/java/com/prgrms/prolog/domain/post/service/PostServiceImpl.java +++ b/src/main/java/com/prgrms/prolog/domain/post/service/PostServiceImpl.java @@ -94,8 +94,8 @@ public Page findAll(Pageable pageable) { @Override @Transactional public PostResponse update(UpdateRequest update, Long userId, Long postId) { - Post findPost = postRepository.joinUserFindById(postId) - .orElseThrow(() -> new IllegalArgumentException("exception.post.notExists")); + Post findPost = postRepository.findById(postId) + .orElseThrow(() -> new IllegalArgumentException(POST_NOT_EXIST_MESSAGE)); if (!findPost.getUser().checkSameUserId(userId)) { throw new IllegalArgumentException("exception.post.not.owner"); @@ -114,6 +114,12 @@ public PostResponse update(UpdateRequest update, Long userId, Long postId) { public void delete(Long postId) { Post findPost = postRepository.findById(postId) .orElseThrow(() -> new IllegalArgumentException(POST_NOT_EXIST_MESSAGE)); + Set findRootTags = postTagRepository.joinRootTagFindByPostId(findPost.getId()) + .stream() + .map(PostTag::getRootTag) + .collect(Collectors.toSet()); + removeOrDecreaseUserTags(findPost.getUser(), findRootTags); + postTagRepository.deleteByPostId(postId); postRepository.delete(findPost); } diff --git a/src/main/java/com/prgrms/prolog/domain/posttag/repository/PostTagRepository.java b/src/main/java/com/prgrms/prolog/domain/posttag/repository/PostTagRepository.java index c42fd74..2b79d56 100644 --- a/src/main/java/com/prgrms/prolog/domain/posttag/repository/PostTagRepository.java +++ b/src/main/java/com/prgrms/prolog/domain/posttag/repository/PostTagRepository.java @@ -30,4 +30,12 @@ void deleteByPostIdAndRootTagIds( WHERE pt.post.id = :postId """) Set joinRootTagFindByPostId(@Param(value = "postId") Long postId); + + @Modifying + @Query(""" + DELETE + FROM PostTag pt + WHERE pt.post.id = :postId + """) + void deleteByPostId(@Param(value = "postId") Long postId); } diff --git a/src/main/java/com/prgrms/prolog/domain/series/api/SeriesController.java b/src/main/java/com/prgrms/prolog/domain/series/api/SeriesController.java index 395ceaa..de6c972 100644 --- a/src/main/java/com/prgrms/prolog/domain/series/api/SeriesController.java +++ b/src/main/java/com/prgrms/prolog/domain/series/api/SeriesController.java @@ -3,8 +3,8 @@ import org.springframework.http.ResponseEntity; import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import com.prgrms.prolog.domain.series.dto.SeriesResponse; @@ -20,9 +20,9 @@ public class SeriesController { private final SeriesService seriesService; - @GetMapping("/{title}") + @GetMapping() ResponseEntity findSeriesByTitle( - @PathVariable String title, + @RequestParam String title, @AuthenticationPrincipal JwtAuthentication user ) { return ResponseEntity.ok( diff --git a/src/test/java/com/prgrms/prolog/domain/series/api/SeriesControllerTest.java b/src/test/java/com/prgrms/prolog/domain/series/api/SeriesControllerTest.java index ca14c6c..4a646bd 100644 --- a/src/test/java/com/prgrms/prolog/domain/series/api/SeriesControllerTest.java +++ b/src/test/java/com/prgrms/prolog/domain/series/api/SeriesControllerTest.java @@ -87,8 +87,9 @@ void findSeriesByTitleTest() throws Exception { // given Claims claims = Claims.from(savedUser.getId(), USER_ROLE); // when - mockMvc.perform(get("/api/v1/series/{title}", SERIES_TITLE) + mockMvc.perform(get("/api/v1/series") .header(AUTHORIZATION, BEARER_TYPE + jwtTokenProvider.createAccessToken(claims)) + .param("title", SERIES_TITLE) ) // then .andExpectAll(