Skip to content

Commit

Permalink
refact : 사진 관련 API 요청시 유효성 검증 코드 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
jjeongdong committed Aug 4, 2024
1 parent 41bb1f4 commit 9a000de
Showing 1 changed file with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public class PhotoServiceImpl implements PhotoService {
@Override
@Transactional
public List<PhotoResponse.PreSignedUrlInfo> getPreSignedUrlList(PhotoRequest.PreSignedUrlRequest request, Member member) {
shareGroupService.findProfile(request.getShareGroupId(), member.getId());
validateShareGroupAndProfile(request.getShareGroupId(), member);

return request.getPhotoNameList().stream()
.map(this::getPreSignedUrl)
Expand Down Expand Up @@ -118,8 +118,8 @@ private String generateFileAccessUrl(String fileName) {
@Override
@Transactional
public PhotoResponse.PhotoUploadInfo uploadPhotoList(PhotoRequest.PhotoUploadRequest request, Member member) {
shareGroupService.findProfile(request.getShareGroupId(), member.getId());
ShareGroup shareGroup = shareGroupService.findShareGroup(request.getShareGroupId());
shareGroupService.findProfile(request.getShareGroupId(), member.getId());
int uploadCount = 0;

for (String photoUrl : request.getPhotoUrlList()) {
Expand Down Expand Up @@ -162,8 +162,7 @@ public Page<Photo> getAllPhotoList(Long shareGroupId, Member member, Pageable pa
@Override
@Transactional
public List<Photo> deletePhotoList(PhotoRequest.PhotoDeletedRequest request, Member member) {
// 멤버가 해당 공유 그룹에 대한 권한이 있는지 확인
shareGroupService.findProfile(request.getShareGroupId(), member.getId());
validateShareGroupAndProfile(request.getShareGroupId(), member);

// 요청된 사진 ID 목록과 공유 그룹 ID를 기반으로 사진 목록 조회
List<Photo> photoList = photoRepository.findByIdInAndShareGroupId(request.getPhotoIdList(), request.getShareGroupId());
Expand Down Expand Up @@ -195,7 +194,7 @@ private void deletePhoto(Photo photo) {
@Override
@Transactional(readOnly = true)
public PhotoResponse.PhotoDownloadUrlListInfo getPhotoDownloadUrlList(List<Long> photoIdList, Long shareGroupId, Member member) {
shareGroupService.findProfile(shareGroupId, member.getId());
validateShareGroupAndProfile(shareGroupId, member);
List<Photo> photoList = photoRepository.findByIdIn(photoIdList);

if (photoList.size() != photoIdList.size()) {
Expand All @@ -205,4 +204,11 @@ public PhotoResponse.PhotoDownloadUrlListInfo getPhotoDownloadUrlList(List<Long>

return photoConverter.toPhotoDownloadUrlListResponse(photoList);
}

private void validateShareGroupAndProfile(Long shareGroupId, Member member) {
// 해당 공유 그룹이 존재하는지 확인
shareGroupService.findShareGroup(shareGroupId);
// 멤버가 해당 공유 그룹에 속해있는지 확인
shareGroupService.findProfile(shareGroupId, member.getId());
}
}

0 comments on commit 9a000de

Please sign in to comment.