-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- 프로필 이미지 업데이트 유스케이스및 구현체 구현 - 요청 레코드 생성 - 테스트및 검증 완료
- Loading branch information
Showing
4 changed files
with
131 additions
and
0 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
src/main/java/com/somemore/center/dto/request/CenterProfileImgUpdateRequestDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.somemore.center.dto.request; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
|
||
public record CenterProfileImgUpdateRequestDto( | ||
@Schema(description = "파일 이름", example = "image.png") | ||
String fileName | ||
) { | ||
} |
46 changes: 46 additions & 0 deletions
46
src/main/java/com/somemore/center/service/UpdateCenterProfileImgService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.somemore.center.service; | ||
|
||
import com.somemore.center.domain.NEWCenter; | ||
import com.somemore.center.dto.request.CenterProfileImgUpdateRequestDto; | ||
import com.somemore.center.repository.NEWCenterRepository; | ||
import com.somemore.center.usecase.UpdateCenterProfileImgUseCase; | ||
import com.somemore.global.exception.BadRequestException; | ||
import com.somemore.global.imageupload.usecase.ImageUploadUseCase; | ||
import com.somemore.user.dto.request.UpdateProfileImgUrlRequestDto; | ||
import com.somemore.user.usecase.UpdateProfileImgUrlUseCase; | ||
import com.somemore.user.usecase.UserQueryUseCase; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.UUID; | ||
|
||
import static com.somemore.global.exception.ExceptionMessage.NOT_EXISTS_CENTER; | ||
|
||
@RequiredArgsConstructor | ||
@Service | ||
@Transactional | ||
public class UpdateCenterProfileImgService implements UpdateCenterProfileImgUseCase { | ||
|
||
private final ImageUploadUseCase imageUploadUseCase; | ||
private final UserQueryUseCase userQueryUseCase; | ||
private final UpdateProfileImgUrlUseCase updateProfileImgUrlUseCase; | ||
private final NEWCenterRepository centerRepository; | ||
|
||
@Override | ||
public String updateCenterProfileImg(UUID centerId, CenterProfileImgUpdateRequestDto requestDto) { | ||
|
||
NEWCenter center = centerRepository.findById(centerId) | ||
.orElseThrow(() -> new BadRequestException(NOT_EXISTS_CENTER)); | ||
|
||
String presignedUrl = imageUploadUseCase.getPresignedUrl(requestDto.fileName()); | ||
|
||
String fileUrl = presignedUrl.split("\\?")[0]; | ||
|
||
UpdateProfileImgUrlRequestDto updateProfileImgUrlRequestDto = new UpdateProfileImgUrlRequestDto(center.getUserId(), fileUrl); | ||
|
||
updateProfileImgUrlUseCase.updateProfileImgUrl(updateProfileImgUrlRequestDto); | ||
|
||
return presignedUrl; | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/com/somemore/center/usecase/UpdateCenterProfileImgUseCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.somemore.center.usecase; | ||
|
||
import com.somemore.center.dto.request.CenterProfileImgUpdateRequestDto; | ||
|
||
import java.util.UUID; | ||
|
||
public interface UpdateCenterProfileImgUseCase { | ||
String updateCenterProfileImg(UUID centerId, CenterProfileImgUpdateRequestDto requestDto); | ||
} |
67 changes: 67 additions & 0 deletions
67
src/test/java/com/somemore/center/service/UpdateCenterProfileImgServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package com.somemore.center.service; | ||
|
||
import com.somemore.center.domain.NEWCenter; | ||
import com.somemore.center.dto.request.CenterProfileImgUpdateRequestDto; | ||
import com.somemore.center.repository.NEWCenterRepository; | ||
import com.somemore.global.imageupload.usecase.ImageUploadUseCase; | ||
import com.somemore.support.IntegrationTestSupport; | ||
import com.somemore.user.domain.UserCommonAttribute; | ||
import com.somemore.user.repository.usercommonattribute.UserCommonAttributeRepository; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.Optional; | ||
import java.util.UUID; | ||
|
||
import static com.somemore.user.domain.UserRole.CENTER; | ||
import static org.junit.jupiter.api.Assertions.*; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
@Transactional | ||
class UpdateCenterProfileImgServiceTest extends IntegrationTestSupport { | ||
|
||
@Autowired | ||
private UpdateCenterProfileImgService updateCenterProfileImgService; | ||
|
||
@Autowired | ||
private ImageUploadUseCase imageUploadUseCase; | ||
|
||
@Autowired | ||
private NEWCenterRepository centerRepository; | ||
|
||
@Autowired | ||
private UserCommonAttributeRepository userCommonAttributeRepository; | ||
|
||
@DisplayName("파일명을 받아 기관 프로필 이미지의 presignedUrl을 발급해준다.") | ||
@Test | ||
void updateCenterProfileImg() { | ||
|
||
//given | ||
UUID userId = UUID.randomUUID(); | ||
|
||
NEWCenter center = NEWCenter.createDefault(userId); | ||
centerRepository.save(center); | ||
UUID centerId = center.getId(); | ||
|
||
UserCommonAttribute userCommonAttribute = UserCommonAttribute.createDefault(userId, CENTER); | ||
userCommonAttributeRepository.save(userCommonAttribute); | ||
|
||
CenterProfileImgUpdateRequestDto requestDto = new CenterProfileImgUpdateRequestDto("test.png"); | ||
|
||
//when | ||
String presignedUrl = updateCenterProfileImgService.updateCenterProfileImg(centerId, requestDto); | ||
|
||
//then | ||
assertThat(presignedUrl).isNotNull(); | ||
|
||
Optional<UserCommonAttribute> updatedUserCommonAttribute = userCommonAttributeRepository.findByUserId(userId); | ||
assertThat(updatedUserCommonAttribute) | ||
.isNotNull(); | ||
assertTrue(updatedUserCommonAttribute.get().getImgUrl().contains(requestDto.fileName())); | ||
|
||
} | ||
|
||
|
||
} |