Skip to content

Commit

Permalink
Merge pull request #231 from Kernel360/update/single-image-update
Browse files Browse the repository at this point in the history
Update/ 단일 이미지 업로드 로직 변경
  • Loading branch information
kdh10806 authored Feb 11, 2025
2 parents b8cd7d6 + d60a51d commit c2a4bd7
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class CompanyFileController {

/**
* 1. 회사 로고 이미지 업로드
* 등록된 이미지가 있는 경우 새 이미지로 등록 된다.
* @param file 업로드할 이미지 파일
* @return 업로드된 파일 메타데이터, 성공 메시지
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,19 @@ public void uploadLogoImage(MultipartFile file, Long companyId, Long uploaderId)

//3. 로고 이미 존재하는지 판별
if(fileMetadataRepository.existsByCategoryAndReferenceId(FileCategory.COMPANY_LOGO_IMAGE, companyEntity.getId())){
throw new BusinessException(ErrorCode.LOGO_ALREADY_EXIST_ERROR);
//기존 로고 이미지 파일을 삭제한다.
//3-1. 삭제수행
FileMetadata deletedEntity = fileHandler.deleteFile(FileCategory.COMPANY_LOGO_IMAGE, companyEntity.getId());
//3-2. 삭제 이력 등록
companyFileHistoryService.deleteLogoImageHistory(deletedEntity, uploaderId);

//새 로고 이미지를 등록한다.
//3-3. S3파일 업로드, 메타데이터 테이블 저장
FileMetadata uploadedFileEntity = fileHandler.uploadFile(file, FileCategory.COMPANY_LOGO_IMAGE, companyEntity.getId());
//3-4. 파일 이력 등록
companyFileHistoryService.registerLogoImageHistory(uploadedFileEntity, uploaderId);

return;
}

//4. S3파일 업로드, 메타데이터 테이블 저장
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public ResponseEntity<APIResponse<SuccessCode>> deleteMember(@AuthenticationPrin

/**
* 함수명 : uploadProfileImage
* 계정 프로필 이미지를 업로드합니다.
* 계정 프로필 이미지 업로드. 이미 등록되어 있는 경우 새 이미지로 교체된다.
* @auth admin, 해당 계정주
* @param memberId 해당 회원 Id
* @return ResponseEntity<APIResponse<SuccessCode>> 성공 응답 객체
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class MemberFileService {
/**
* 함수명 : uploadProfileImage
* 1. 계정 프로필 이미지 등록
* 이미지를 다시 등록할 경우 해당 이미지로 교체된다.
* @auth admin, user(해당 회원)
* @param file 업로드할 프로필 이미지 파일
* @param memberId 해당 회원 id
Expand All @@ -40,7 +41,19 @@ public void uploadProfileImage(MultipartFile file, Long memberId, Long uploaderI

//3. 프로필 이미지 존재하는지 판별
if(fileMetadataRepository.existsByCategoryAndReferenceId(FileCategory.USER_PROFILE_IMAGE, memberEntity.getId())){
throw new BusinessException(ErrorCode.PROFILE_IMAGE_ALREADY_EXIST);
//기존 프로필 이미지 파일을 삭제한다.
//3-1. 삭제 수행
FileMetadata deletedFile = fileHandler.deleteFile(FileCategory.USER_PROFILE_IMAGE, memberEntity.getId());
//3-2. 삭제 이력 등록
memberFileHistoryService.deleteLogoImageHistory(deletedFile, uploaderId);

//새 로고 이미지를 등록한다.
//3-3. S3 파일 업로드, 메타데이터 테이블 저장
FileMetadata uploadedFileEntity = fileHandler.uploadFile(file, FileCategory.USER_PROFILE_IMAGE, memberEntity.getId());
//3-4. 업로드 이력 등록
memberFileHistoryService.registerProfileImageHistory(uploadedFileEntity, uploaderId);

return;
}

//4. S3 파일 업로드, 메타데이터 테이블 저장
Expand Down

0 comments on commit c2a4bd7

Please sign in to comment.