Skip to content

Commit

Permalink
Merge pull request #235 from PawWithU/fix/234-rejected-post-delete-api
Browse files Browse the repository at this point in the history
[Fix] 공고 삭제 - 반려된 신청이 존재하는 공고도 삭제하도록 구현
  • Loading branch information
kyeong-hyeok authored Jun 4, 2024
2 parents c092b6b + 99b4e46 commit 9dd596c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public interface ApplicationRepository extends JpaRepository<Application, Long>
Long countAllByPostId(Long id);
List<Application> findByVolunteer(Volunteer volunteer);
Optional<Application> findByPostIdAndStatusNot(Long postId, ApplicationStatus status);

void deleteAllByPostId(Long postId);
List<Application> findByIntermediary(Intermediary intermediary);

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ public interface PostRepository extends JpaRepository<Post, Long> {

Optional<Post> findByIdAndIntermediaryId(Long id, Long intermediaryId);
Optional<Post> findByIdAndStatus(Long id, PostStatus postStatus);

Optional<Post> findByIdAndIntermediaryIdAndStatus(Long id, Long intermediaryId, PostStatus status);
List<Post> findByIntermediary(Intermediary intermediary);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.pawwithu.connectdog.domain.post.service;

import com.pawwithu.connectdog.common.s3.FileService;
import com.pawwithu.connectdog.domain.application.repository.ApplicationRepository;
import com.pawwithu.connectdog.domain.bookmark.repository.BookmarkRepository;
import com.pawwithu.connectdog.domain.dog.entity.Dog;
import com.pawwithu.connectdog.domain.dog.repository.DogRepository;
Expand All @@ -12,6 +13,7 @@
import com.pawwithu.connectdog.domain.post.dto.response.*;
import com.pawwithu.connectdog.domain.post.entity.Post;
import com.pawwithu.connectdog.domain.post.entity.PostImage;
import com.pawwithu.connectdog.domain.post.entity.PostStatus;
import com.pawwithu.connectdog.domain.post.repository.CustomPostRepository;
import com.pawwithu.connectdog.domain.post.repository.PostImageRepository;
import com.pawwithu.connectdog.domain.post.repository.PostRepository;
Expand Down Expand Up @@ -46,6 +48,7 @@ public class PostService {
private final PostImageRepository postImageRepository;
private final CustomPostRepository customPostRepository;
private final BookmarkRepository bookmarkRepository;
private final ApplicationRepository applicationRepository;

@CacheEvict(value = "homePosts", key = "'volunteer'", cacheManager = "redisCacheManager") // 공고 등록 시 홈 화면 공고 조회 캐시 삭제
public void createPost(String email, PostCreateRequest request, List<MultipartFile> fileList) {
Expand Down Expand Up @@ -153,8 +156,9 @@ public void deletePost(String email, Long postId) {
// 이동봉사 중개
Intermediary intermediary = intermediaryRepository.findByEmail(email).orElseThrow(() -> new BadRequestException(INTERMEDIARY_NOT_FOUND));
// 공고
Post post = postRepository.findByIdAndIntermediaryId(postId, intermediary.getId()).orElseThrow(() -> new BadRequestException(POST_NOT_FOUND));
// 공고 이미지, 공고, 강아지 삭제
Post post = postRepository.findByIdAndIntermediaryIdAndStatus(postId, intermediary.getId(), PostStatus.RECRUITING).orElseThrow(() -> new BadRequestException(POST_NOT_FOUND));
// 신청, 공고 이미지, 공고, 강아지 삭제
applicationRepository.deleteAllByPostId(postId);
postImageRepository.deleteAllByPostId(postId);
postRepository.deleteById(post.getId());
dogRepository.deleteById(post.getDog().getId());
Expand Down

0 comments on commit 9dd596c

Please sign in to comment.