Skip to content

Commit

Permalink
Merge pull request #83 from AR-TTUBEOG/feature/82
Browse files Browse the repository at this point in the history
[Feat] Store 삭제 시 삭제되는 엔티티 추가
  • Loading branch information
Jeongmin39 authored Feb 18, 2024
2 parents 34b3998 + de64185 commit 67bf974
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Optional;

@Repository
Expand All @@ -21,4 +22,5 @@ public interface RoadRepository extends JpaRepository<Road, Long> {

Page<Road> findAllByStore_Id(Long storeId, PageRequest pageRequest);

List<Road> findByStore(Store store);
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package com.ttubeog.domain.roadcoordinate.domain.repository;

import com.ttubeog.domain.road.domain.Road;
import com.ttubeog.domain.roadcoordinate.domain.RoadCoordinate;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface RoadCoordinateRepository extends JpaRepository<RoadCoordinate, Long> {
List<RoadCoordinate> findByRoad(Road road);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
import com.ttubeog.domain.likes.domain.repository.LikesRepository;
import com.ttubeog.domain.member.domain.repository.MemberRepository;
import com.ttubeog.domain.member.exception.InvalidMemberException;
import com.ttubeog.domain.road.domain.Road;
import com.ttubeog.domain.road.domain.repository.RoadRepository;
import com.ttubeog.domain.roadcoordinate.domain.RoadCoordinate;
import com.ttubeog.domain.roadcoordinate.domain.repository.RoadCoordinateRepository;
import com.ttubeog.domain.spot.exception.InvalidImageListSizeException;
import com.ttubeog.domain.store.domain.Store;
import com.ttubeog.domain.store.domain.repository.StoreRepository;
Expand Down Expand Up @@ -49,6 +53,9 @@ public class StoreService {
private final MemberBenefitRepository memberBenefitRepository;
private final GuestBookRepository guestBookRepository;
private final LikesRepository likesRepository;
private final RoadRepository roadRepository;
private final RoadCoordinateRepository roadCoordinateRepository;

private final JwtTokenProvider jwtTokenProvider;

// 매장 등록
Expand Down Expand Up @@ -183,12 +190,19 @@ public ResponseEntity<?> deleteStore(HttpServletRequest request, Long storeId) {
List<Image> images = imageRepository.findByStoreId(storeId);
imageRepository.deleteAll(images);

// TODO 해당 매장과 연관된 경로 삭제
// TODO 해당 매장과 연관된 저장경로 삭제
// 특정 경로와 연관된 좌표 삭제
List<Road> roadsToDelete = roadRepository.findByStore(store);
for (Road road : roadsToDelete) {
List<RoadCoordinate> roadCoordinates = roadCoordinateRepository.findByRoad(road);
roadCoordinateRepository.deleteAll(roadCoordinates);
}

// 해당 매장과 연관된 경로 삭제
List<Road> roads = roadRepository.findByStore(store);
roadRepository.deleteAll(roads);

storeRepository.delete(store);


ApiResponse apiResponse = ApiResponse.builder()
.check(true)
.information(Message.builder().message("매장 정보가 정상적으로 삭제되었습니다.").build())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
public class UnathorizedMemberException extends RuntimeException {

public UnathorizedMemberException() {
super("해당 매장에 대한 수정 권한이 없습니다.");
super("해당 매장에 대한 수정 및 삭제 권한이 없습니다.");
}
}

0 comments on commit 67bf974

Please sign in to comment.