-
Notifications
You must be signed in to change notification settings - Fork 1
[Feat] 스케줄링을 위한, S3 URL을 반환하는 신고글 랜덤 조회 기능 구현 #155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
2b1c6bf
[Feat] #152 실종신고글 레포지토리 - findByDate 추가
JJUYAAA 5a87455
[Feat] #152 서비스 인터페이스 생성
JJUYAAA 6374b55
[Feat] #152 MissingReportRetrieveWithS3ServiceImpl 생성 - missingDate 기…
JJUYAAA fddca32
[Feat] #152 MissingReportDetailStrategy 에 s3url 포함하여 반환하는 toDetailDto…
JJUYAAA 6d9a3e8
[Feat] #152 reportController에 실종 신고글 랜덤조회 API 추가
JJUYAAA 17d37e4
[Feat] #152 실종신고글 랜덤조회 API에 토큰 인증 비활성화
JJUYAAA ffc1eff
[Test] #152 실종신고글 랜덤조회 서비스 테스트코드 생성
JJUYAAA 09981a1
[Test] #152 ReportControllerTest 테스트코드 추가
JJUYAAA a2f5459
[Refactor] #152 서비스 코드 수정 - s3 업로드 필요 없음
JJUYAAA 3adcadd
[Test] #152 서비스 테스트 코드 - 이미지 업로드 제거 및 테스트 추가
JJUYAAA 5cc75d9
[Test] #152 컨트롤러 테스트 코드 - 신고글 생성 시 이미지 그대로 반환하도록 수정
JJUYAAA File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
9 changes: 9 additions & 0 deletions
9
...a/com/kuit/findyou/domain/report/service/retrieve/MissingReportRetrieveWithS3Service.java
This file contains hidden or 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.kuit.findyou.domain.report.service.retrieve; | ||
|
|
||
| import com.kuit.findyou.domain.report.dto.response.MissingReportDetailResponseDTO; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| public interface MissingReportRetrieveWithS3Service { | ||
| List<MissingReportDetailResponseDTO> getRandomMissingReportsWithS3(int count); | ||
| } |
59 changes: 59 additions & 0 deletions
59
...m/kuit/findyou/domain/report/service/retrieve/MissingReportRetrieveWithS3ServiceImpl.java
This file contains hidden or 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,59 @@ | ||
| package com.kuit.findyou.domain.report.service.retrieve; | ||
|
|
||
| import com.kuit.findyou.domain.image.model.ReportImage; | ||
| import com.kuit.findyou.domain.report.dto.response.MissingReportDetailResponseDTO; | ||
| import com.kuit.findyou.domain.report.model.MissingReport; | ||
| import com.kuit.findyou.domain.report.repository.MissingReportRepository; | ||
| import com.kuit.findyou.domain.report.service.detail.strategy.MissingReportDetailStrategy; | ||
| import lombok.RequiredArgsConstructor; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
|
|
||
| import java.time.LocalDate; | ||
| import java.util.ArrayList; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
|
|
||
| @RequiredArgsConstructor | ||
| @Service | ||
| @Slf4j | ||
| public class MissingReportRetrieveWithS3ServiceImpl implements MissingReportRetrieveWithS3Service{ | ||
| private final MissingReportRepository missingReportRepository; | ||
| private final MissingReportDetailStrategy missingReportDetailStrategy; | ||
|
|
||
| @Override | ||
| @Transactional(readOnly = true) | ||
| public List<MissingReportDetailResponseDTO> getRandomMissingReportsWithS3(int count) { | ||
| LocalDate yesterday = LocalDate.now().minusDays(1); | ||
|
|
||
| List<MissingReport> allReports = missingReportRepository.findByDate(yesterday); | ||
|
|
||
| if (allReports.isEmpty()) { | ||
| // 204 no content | ||
| return Collections.emptyList(); | ||
| } | ||
|
|
||
| Collections.shuffle(allReports); | ||
|
|
||
| int limit = Math.max(1, count); | ||
| List<MissingReport> selectedReports = allReports.stream().limit(limit).toList(); | ||
|
|
||
| List<MissingReportDetailResponseDTO> result = new ArrayList<>(); | ||
|
|
||
| for (MissingReport report : selectedReports) { | ||
|
|
||
| List<String> imageUrls = report.getReportImages().stream() | ||
| .map(ReportImage::getImageUrl) | ||
| .filter(url -> url != null && !url.isBlank()) | ||
| .distinct() | ||
| .toList(); | ||
|
|
||
| MissingReportDetailResponseDTO dto = | ||
| missingReportDetailStrategy.toDetailDto(report, imageUrls,false); | ||
| result.add(dto); | ||
| } | ||
|
|
||
| return result; | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
예전에 작성해주신 신고글 저장 로직을 보면 이미지 URL 중복을 제거하시긴 하던데, 여기서도 중복 제거를 수행하네요. 의도하신건가요??
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
음 저장 시에 중복제거를 수행하긴 하지만 조회 단에서도 방어적으로 한번 더 검증하는 것이 좋겠다 싶어서 넣긴 했어요. 물론 저장 시에만 제거해도 웬만한 경우에는 DB에 중복이 안 들어갈 거긴 합니다만, 버그나 기타 상황을 생각하고 중복제거를 수행했습니다!