Skip to content

Commit d0f4086

Browse files
authored
feat: 사진 일괄 삭제 API 추가 (#31)
* feat: 사진 삭제 API 추가 * chore: import문 정리
1 parent 9b973f1 commit d0f4086

4 files changed

Lines changed: 27 additions & 8 deletions

File tree

src/main/java/kr/kro/photoliner/domain/photo/controller/PhotoController.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,20 @@
22

33
import jakarta.validation.Valid;
44
import java.util.List;
5+
import kr.kro.photoliner.domain.photo.dto.DeletePhotosRequest;
56
import kr.kro.photoliner.domain.photo.dto.request.MapMarkersRequest;
67
import kr.kro.photoliner.domain.photo.dto.request.PhotoCapturedDateUpdateRequest;
78
import kr.kro.photoliner.domain.photo.dto.request.PhotoLocationUpdateRequest;
89
import kr.kro.photoliner.domain.photo.dto.response.MapMarkersResponse;
910
import kr.kro.photoliner.domain.photo.dto.response.PhotoUploadResponse;
1011
import kr.kro.photoliner.domain.photo.dto.response.PhotosResponse;
11-
import kr.kro.photoliner.domain.photo.model.Photo;
1212
import kr.kro.photoliner.domain.photo.service.PhotoService;
1313
import kr.kro.photoliner.domain.photo.service.PhotoUploadService;
1414
import lombok.RequiredArgsConstructor;
1515
import org.springframework.http.HttpStatus;
1616
import org.springframework.http.MediaType;
1717
import org.springframework.http.ResponseEntity;
18+
import org.springframework.web.bind.annotation.DeleteMapping;
1819
import org.springframework.web.bind.annotation.GetMapping;
1920
import org.springframework.web.bind.annotation.PatchMapping;
2021
import org.springframework.web.bind.annotation.PathVariable;
@@ -72,4 +73,12 @@ public ResponseEntity<Void> updatePhotoLocation(
7273
photoService.updatePhotoLocation(photoId, request);
7374
return ResponseEntity.noContent().build();
7475
}
76+
77+
@DeleteMapping
78+
public ResponseEntity<Void> deletePhoto(
79+
@Valid @RequestBody DeletePhotosRequest request
80+
) {
81+
photoService.deletePhotos(request);
82+
return ResponseEntity.noContent().build();
83+
}
7584
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package kr.kro.photoliner.domain.photo.dto;
2+
3+
import java.util.List;
4+
5+
public record DeletePhotosRequest(
6+
List<Long> ids
7+
) {
8+
9+
}

src/main/java/kr/kro/photoliner/domain/photo/repository/PhotoRepository.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
package kr.kro.photoliner.domain.photo.repository;
22

33
import java.util.List;
4-
import java.util.Optional;
54
import kr.kro.photoliner.domain.photo.model.Photo;
65
import kr.kro.photoliner.domain.photo.model.Photos;
76
import org.locationtech.jts.geom.Point;
87
import org.springframework.data.domain.Pageable;
8+
import org.springframework.data.jpa.repository.JpaRepository;
99
import org.springframework.data.jpa.repository.Query;
10-
import org.springframework.data.repository.Repository;
1110

12-
public interface PhotoRepository extends Repository<Photo, Long> {
11+
public interface PhotoRepository extends JpaRepository<Photo, Long> {
1312

1413
List<Photo> findByUserId(
1514
Long userId,
@@ -37,8 +36,4 @@ List<Photo> findByUserIdInBox(
3736
default Photos findPhotosByUserIdInBox(Long userId, Point sw, Point ne) {
3837
return new Photos(findByUserIdInBox(userId, sw, ne));
3938
}
40-
41-
Photo save(Photo photo);
42-
43-
Optional<Photo> findById(Long photoId);
4439
}

src/main/java/kr/kro/photoliner/domain/photo/service/PhotoService.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package kr.kro.photoliner.domain.photo.service;
22

3+
import kr.kro.photoliner.domain.photo.dto.DeletePhotosRequest;
34
import kr.kro.photoliner.domain.photo.dto.request.MapMarkersRequest;
45
import kr.kro.photoliner.domain.photo.dto.request.PhotoCapturedDateUpdateRequest;
56
import kr.kro.photoliner.domain.photo.dto.request.PhotoLocationUpdateRequest;
@@ -61,4 +62,9 @@ public void updatePhotoLocation(Long photoId, PhotoLocationUpdateRequest request
6162
);
6263
photo.updateLocation(location);
6364
}
65+
66+
@Transactional
67+
public void deletePhotos(DeletePhotosRequest request) {
68+
photoRepository.deleteAllByIdInBatch(request.ids());
69+
}
6470
}

0 commit comments

Comments
 (0)