Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] 공고 삭제 - 반려된 신청이 존재하는 공고도 삭제하도록 구현 #235

Merged
merged 1 commit into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading