-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: 서버 시간 체크 컨트롤러 구현 * feat: 루틴 인증 기능 및 ClockHolder 구현 * feat: UrlSubstringParser 구현 * test: 루틴 인증 관련 테스트 구현 * refactor: 방 공지 길이 수정 * feat: constant 및 error 작성 * feat: s3 이미지 업로드 기능 구현 * test: s3 이미지 업로드 테스트 * chore: build.gradle s3 추가 * Merge branch 'develop' into feature/#8-upload-image * refactor: build 오류 수정 * test: CertificationsSearchRepository 테스트 * chore: s3Manager 커버리지 제외 * refactor: UrlParser 코드스멜 제거 * refactor: 코드 리뷰 반영 --------- Co-authored-by: ymkim97 <[email protected]> Co-authored-by: Youngmyung Kim <[email protected]>
- Loading branch information
1 parent
0d084fa
commit 43d18ce
Showing
32 changed files
with
1,153 additions
and
14 deletions.
There are no files selected for viewing
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
54 changes: 54 additions & 0 deletions
54
src/main/java/com/moabam/api/application/ImageService.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,54 @@ | ||
package com.moabam.api.application; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
import com.moabam.api.domain.resizedimage.ImageName; | ||
import com.moabam.api.domain.resizedimage.ImageResizer; | ||
import com.moabam.api.domain.resizedimage.ImageType; | ||
import com.moabam.api.infrastructure.s3.S3Manager; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional(readOnly = true) | ||
public class ImageService { | ||
|
||
private final S3Manager s3Manager; | ||
|
||
@Transactional | ||
public List<String> uploadImages(List<MultipartFile> multipartFiles, ImageType imageType) { | ||
|
||
List<String> result = new ArrayList<>(); | ||
|
||
List<ImageResizer> imageResizers = multipartFiles.stream() | ||
.map(multipartFile -> this.toImageResizer(multipartFile, imageType)) | ||
.toList(); | ||
|
||
imageResizers.forEach(resizer -> { | ||
resizer.resizeImageToFixedSize(imageType); | ||
result.add(s3Manager.uploadImage(resizer.getResizedImage().getName(), resizer.getResizedImage())); | ||
}); | ||
|
||
return result; | ||
} | ||
|
||
private ImageResizer toImageResizer(MultipartFile multipartFile, ImageType imageType) { | ||
ImageName imageName = ImageName.of(multipartFile, imageType); | ||
|
||
return ImageResizer.builder() | ||
.image(multipartFile) | ||
.fileName(imageName.getFileName()) | ||
.build(); | ||
} | ||
|
||
@Transactional | ||
public void deleteImage(String imageUrl) { | ||
s3Manager.deleteImage(imageUrl); | ||
} | ||
} |
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
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
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
43 changes: 43 additions & 0 deletions
43
src/main/java/com/moabam/api/domain/entity/enums/RequireExp.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,43 @@ | ||
package com.moabam.api.domain.entity.enums; | ||
|
||
import java.util.Collections; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
/** | ||
* 방 경험치 | ||
* 방 레벨 - 현재 경험치 / 전체 경험치 | ||
* 레벨0 - 0 / 1 | ||
* 레벨1 - 0 / 3 | ||
* 레벨2 - 0 / 5 | ||
* 레벨3 - 0 / 10 | ||
*/ | ||
|
||
@Getter | ||
@RequiredArgsConstructor(access = AccessLevel.PRIVATE) | ||
public enum RequireExp { | ||
|
||
ROOM_LEVEL_0(0, 1), | ||
ROOM_LEVEL_1(1, 5), | ||
ROOM_LEVEL_2(2, 10), | ||
ROOM_LEVEL_3(3, 20), | ||
ROOM_LEVEL_4(4, 40), | ||
ROOM_LEVEL_5(5, 80); | ||
|
||
private static final Map<Integer, String> requireExpMap = Collections.unmodifiableMap( | ||
Stream.of(values()) | ||
.collect(Collectors.toMap(RequireExp::getLevel, RequireExp::name)) | ||
); | ||
|
||
private final int level; | ||
private final int totalExp; | ||
|
||
public static RequireExp of(int level) { | ||
return RequireExp.valueOf(requireExpMap.get(level)); | ||
} | ||
} |
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
Oops, something went wrong.