|
1 | 1 | package grep.neogul_coder.domain.study.service; |
2 | 2 |
|
3 | | -import grep.neogul_coder.domain.buddy.service.BuddyEnergyService; |
4 | 3 | import grep.neogul_coder.domain.recruitment.post.repository.RecruitmentPostRepository; |
5 | 4 | import grep.neogul_coder.domain.study.Study; |
6 | 5 | import grep.neogul_coder.domain.study.StudyMember; |
|
17 | 16 | import grep.neogul_coder.domain.users.repository.UserRepository; |
18 | 17 | import grep.neogul_coder.global.exception.business.BusinessException; |
19 | 18 | import grep.neogul_coder.global.exception.business.NotFoundException; |
| 19 | +import grep.neogul_coder.global.utils.upload.AbstractFileManager; |
20 | 20 | import grep.neogul_coder.global.utils.upload.FileUploadResponse; |
21 | 21 | import grep.neogul_coder.global.utils.upload.FileUsageType; |
22 | | -import grep.neogul_coder.global.utils.upload.uploader.GcpFileUploader; |
23 | | -import grep.neogul_coder.global.utils.upload.uploader.LocalFileUploader; |
24 | 22 | import lombok.RequiredArgsConstructor; |
25 | | -import org.springframework.beans.factory.annotation.Autowired; |
26 | | -import org.springframework.core.env.Environment; |
27 | 23 | import org.springframework.data.domain.Page; |
28 | 24 | import org.springframework.data.domain.Pageable; |
29 | 25 | import org.springframework.stereotype.Service; |
|
43 | 39 | @Service |
44 | 40 | public class StudyService { |
45 | 41 |
|
| 42 | + private final AbstractFileManager fileUploader; |
46 | 43 | private final StudyRepository studyRepository; |
47 | 44 | private final StudyMemberRepository studyMemberRepository; |
48 | 45 | private final StudyQueryRepository studyQueryRepository; |
49 | 46 | private final RecruitmentPostRepository recruitmentPostRepository; |
50 | 47 | private final StudyMemberQueryRepository studyMemberQueryRepository; |
51 | 48 | private final UserRepository userRepository; |
52 | | - private final BuddyEnergyService buddyEnergyService; |
53 | | - |
54 | | - @Autowired(required = false) |
55 | | - private GcpFileUploader gcpFileUploader; |
56 | | - |
57 | | - @Autowired(required = false) |
58 | | - private LocalFileUploader localFileUploader; |
59 | | - |
60 | | - @Autowired |
61 | | - private Environment environment; |
62 | 49 |
|
63 | 50 | public StudyItemPagingResponse getMyStudiesPaging(Pageable pageable, Long userId) { |
64 | 51 | Page<StudyItemResponse> page = studyQueryRepository.findMyStudiesPaging(pageable, userId); |
@@ -203,38 +190,25 @@ private void validateStudyDeletable(Long studyId) { |
203 | 190 | } |
204 | 191 | } |
205 | 192 |
|
206 | | - private boolean isProductionEnvironment() { |
207 | | - for (String profile : environment.getActiveProfiles()) { |
208 | | - if ("prod".equals(profile)) { |
209 | | - return true; |
210 | | - } |
211 | | - } |
212 | | - return false; |
213 | | - } |
214 | | - |
215 | 193 | private String createImageUrl(Long userId, MultipartFile image) throws IOException { |
216 | | - String imageUrl = null; |
| 194 | + FileUploadResponse response = null; |
217 | 195 | if (isImgExists(image)) { |
218 | | - FileUploadResponse uploadResult = isProductionEnvironment() |
219 | | - ? gcpFileUploader.upload(image, userId, FileUsageType.STUDY_COVER, userId) |
220 | | - : localFileUploader.upload(image, userId, FileUsageType.STUDY_COVER, userId); |
221 | | - imageUrl = uploadResult.getFileUrl(); |
| 196 | + response = fileUploader.upload(image, userId, FileUsageType.STUDY_COVER, userId); |
| 197 | + return response.getFileUrl(); |
222 | 198 | } |
223 | | - return imageUrl; |
| 199 | + return null; |
224 | 200 | } |
225 | 201 |
|
226 | 202 | private String updateImageUrl(Long userId, MultipartFile image, String originalImageUrl) throws IOException { |
227 | 203 | if (isImgExists(image)) { |
228 | | - FileUploadResponse uploadResult = isProductionEnvironment() |
229 | | - ? gcpFileUploader.upload(image, userId, FileUsageType.STUDY_COVER, userId) |
230 | | - : localFileUploader.upload(image, userId, FileUsageType.STUDY_COVER, userId); |
231 | | - return uploadResult.getFileUrl(); |
| 204 | + FileUploadResponse response = fileUploader.upload(image, userId, FileUsageType.STUDY_COVER, userId); |
| 205 | + return response.getFileUrl(); |
232 | 206 | } |
233 | 207 | return originalImageUrl; |
234 | 208 | } |
235 | 209 |
|
236 | | - |
237 | 210 | private boolean isImgExists(MultipartFile image) { |
238 | 211 | return image != null && !image.isEmpty(); |
239 | 212 | } |
| 213 | + |
240 | 214 | } |
0 commit comments