-
Notifications
You must be signed in to change notification settings - Fork 0
Feature / admin / app #134
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
5 commits
Select commit
Hold shift + click to select a range
5f3d8e0
feat(admin): add endpoint to retrieve Redot app info list with filter…
eraser502 e7ac593
feat(admin): add endpoint to retrieve specific Redot app info by ID
eraser502 81bd50a
feat(admin): add endpoint and logic to update Redot app status with r…
eraser502 bf15c3f
feat(admin): refactor CMS admin impersonation logic to remove unneces…
eraser502 0ea440f
feat(admin): enhance Redot app retrieval by adding site info and refa…
eraser502 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
10 changes: 10 additions & 0 deletions
10
src/main/java/redot/redot_server/domain/admin/dto/request/RedotAppInfoSearchCondition.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,10 @@ | ||
| package redot.redot_server.domain.admin.dto.request; | ||
|
|
||
| import redot.redot_server.domain.redot.app.entity.RedotAppStatus; | ||
|
|
||
| public record RedotAppInfoSearchCondition( | ||
| String name, | ||
| Long redotMemberId, | ||
| RedotAppStatus status | ||
| ) { | ||
| } |
10 changes: 10 additions & 0 deletions
10
src/main/java/redot/redot_server/domain/admin/dto/request/RedotAppStatusUpdateRequest.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,10 @@ | ||
| package redot.redot_server.domain.admin.dto.request; | ||
|
|
||
| import jakarta.validation.constraints.NotNull; | ||
| import redot.redot_server.domain.redot.app.entity.RedotAppStatus; | ||
|
|
||
| public record RedotAppStatusUpdateRequest( | ||
| @NotNull(message = "status 는 필수입니다.") RedotAppStatus status, | ||
| String remark | ||
| ) { | ||
| } |
108 changes: 108 additions & 0 deletions
108
src/main/java/redot/redot_server/domain/admin/service/AdminRedotAppService.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 |
|---|---|---|
| @@ -1,20 +1,128 @@ | ||
| package redot.redot_server.domain.admin.service; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.function.Function; | ||
| import java.util.stream.Collectors; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.data.domain.Page; | ||
| import org.springframework.data.domain.Pageable; | ||
| import org.springframework.stereotype.Service; | ||
| import org.springframework.transaction.annotation.Transactional; | ||
| import redot.redot_server.domain.admin.dto.request.RedotAppInfoSearchCondition; | ||
| import redot.redot_server.domain.admin.dto.request.RedotAppStatusUpdateRequest; | ||
| import redot.redot_server.domain.cms.site.setting.dto.response.SiteSettingResponse; | ||
| import redot.redot_server.domain.cms.site.style.dto.response.StyleInfoResponse; | ||
| import redot.redot_server.domain.redot.app.dto.request.RedotAppCreateRequest; | ||
| import redot.redot_server.domain.redot.app.dto.response.RedotAppInfoResponse; | ||
| import redot.redot_server.domain.redot.app.dto.response.RedotAppResponse; | ||
| import redot.redot_server.domain.redot.app.entity.RedotApp; | ||
| import redot.redot_server.domain.redot.app.exception.RedotAppErrorCode; | ||
| import redot.redot_server.domain.redot.app.exception.RedotAppException; | ||
| import redot.redot_server.domain.redot.app.repository.RedotAppRepository; | ||
| import redot.redot_server.domain.redot.app.service.RedotAppCreationService; | ||
| import redot.redot_server.domain.redot.member.dto.response.RedotMemberResponse; | ||
| import redot.redot_server.domain.site.domain.entity.Domain; | ||
| import redot.redot_server.domain.site.domain.repository.DomainRepository; | ||
| import redot.redot_server.domain.site.setting.entity.SiteSetting; | ||
| import redot.redot_server.domain.site.setting.repository.SiteSettingRepository; | ||
| import redot.redot_server.domain.site.style.entity.StyleInfo; | ||
| import redot.redot_server.domain.site.style.repository.StyleInfoRepository; | ||
| import redot.redot_server.global.s3.util.ImageUrlResolver; | ||
| import redot.redot_server.global.util.dto.response.PageResponse; | ||
|
|
||
| @Service | ||
| @RequiredArgsConstructor | ||
| @Transactional(readOnly = true) | ||
| public class AdminRedotAppService { | ||
| private final RedotAppCreationService redotAppCreationService; | ||
| private final RedotAppRepository redotAppRepository; | ||
| private final DomainRepository domainRepository; | ||
| private final SiteSettingRepository siteSettingRepository; | ||
| private final StyleInfoRepository styleInfoRepository; | ||
| private final ImageUrlResolver imageUrlResolver; | ||
|
|
||
| @Transactional | ||
| public RedotAppInfoResponse createRedotApp(RedotAppCreateRequest request) { | ||
| return redotAppCreationService.createWithoutOwner(request); | ||
| } | ||
|
|
||
| public PageResponse<RedotAppInfoResponse> getRedotAppInfoList(RedotAppInfoSearchCondition searchCondition, | ||
| Pageable pageable) { | ||
| Page<RedotApp> redotApps = redotAppRepository.findAllBySearchCondition(searchCondition, pageable); | ||
|
|
||
| List<Long> redotAppIds = redotApps.stream() | ||
| .map(RedotApp::getId) | ||
| .toList(); | ||
|
|
||
| Map<Long, Domain> domainMap = redotAppIds.isEmpty() ? Map.of() | ||
| : domainRepository.findByRedotAppIdIn(redotAppIds) | ||
| .stream() | ||
| .collect(Collectors.toMap(domain -> domain.getRedotApp().getId(), Function.identity())); | ||
|
|
||
| Map<Long, StyleInfo> styleInfoMap = redotAppIds.isEmpty() ? Map.of() | ||
| : styleInfoRepository.findByRedotApp_IdIn(redotAppIds) | ||
| .stream() | ||
| .collect(Collectors.toMap(style -> style.getRedotApp().getId(), Function.identity())); | ||
|
|
||
| Map<Long, SiteSetting> siteSettingMap = redotAppIds.isEmpty() ? Map.of() | ||
| : siteSettingRepository.findByRedotAppIdIn(redotAppIds) | ||
| .stream() | ||
| .collect(Collectors.toMap(setting -> setting.getRedotApp().getId(), Function.identity())); | ||
|
|
||
| Page<RedotAppInfoResponse> responsePage = redotApps.map(redotApp -> | ||
| toRedotAppInfoResponse( | ||
| redotApp, | ||
| domainMap.get(redotApp.getId()), | ||
| styleInfoMap.get(redotApp.getId()), | ||
| siteSettingMap.get(redotApp.getId()) | ||
| )); | ||
|
|
||
| return PageResponse.from(responsePage); | ||
| } | ||
|
|
||
| private RedotAppInfoResponse toRedotAppInfoResponse(RedotApp redotApp) { | ||
| Domain domain = domainRepository.findByRedotAppId(redotApp.getId()).orElse(null); | ||
| StyleInfo styleInfo = styleInfoRepository.findByRedotApp_Id(redotApp.getId()).orElse(null); | ||
| SiteSetting siteSetting = siteSettingRepository.findByRedotAppId(redotApp.getId()).orElse(null); | ||
|
|
||
| return toRedotAppInfoResponse(redotApp, domain, styleInfo, siteSetting); | ||
| } | ||
|
|
||
| private RedotAppInfoResponse toRedotAppInfoResponse(RedotApp redotApp, | ||
| Domain domain, | ||
| StyleInfo styleInfo, | ||
| SiteSetting siteSetting) { | ||
| SiteSettingResponse siteSettingResponse = (siteSetting != null && domain != null) | ||
| ? SiteSettingResponse.fromEntity(siteSetting, domain, imageUrlResolver) | ||
| : null; | ||
|
|
||
| StyleInfoResponse styleInfoResponse = styleInfo != null | ||
| ? StyleInfoResponse.fromEntity(styleInfo) | ||
| : null; | ||
|
|
||
| return new RedotAppInfoResponse( | ||
| RedotAppResponse.fromEntity(redotApp), | ||
| siteSettingResponse, | ||
| styleInfoResponse, | ||
| RedotMemberResponse.fromNullable(redotApp.getOwner(), imageUrlResolver) | ||
| ); | ||
| } | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| public RedotAppInfoResponse getRedotAppInfo(Long redotAppId) { | ||
| RedotApp redotApp = redotAppRepository.findById(redotAppId) | ||
| .orElseThrow(() -> new RedotAppException(RedotAppErrorCode.REDOT_APP_NOT_FOUND)); | ||
|
|
||
| return toRedotAppInfoResponse(redotApp); | ||
| } | ||
|
|
||
| @Transactional | ||
| public RedotAppInfoResponse updateRedotAppStatus(Long redotAppId, RedotAppStatusUpdateRequest request) { | ||
| RedotApp redotApp = redotAppRepository.findById(redotAppId) | ||
| .orElseThrow(() -> new RedotAppException(RedotAppErrorCode.REDOT_APP_NOT_FOUND)); | ||
|
|
||
| redotApp.updateStatus(request.status(), request.remark()); | ||
|
|
||
| return toRedotAppInfoResponse(redotApp); | ||
| } | ||
| } | ||
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
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
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 |
|---|---|---|
|
|
@@ -5,5 +5,6 @@ public enum RedotAppStatus { | |
| INACTIVE, | ||
| DELETED, | ||
| RESIGNED, | ||
| PAYMENT_DELAYED | ||
| PAYMENT_DELAYED, | ||
| BANNED | ||
| } | ||
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
18 changes: 18 additions & 0 deletions
18
src/main/java/redot/redot_server/domain/redot/app/repository/RedotAppRepositoryCustom.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,18 @@ | ||
| package redot.redot_server.domain.redot.app.repository; | ||
|
|
||
| import java.util.List; | ||
| import org.springframework.data.domain.Page; | ||
| import org.springframework.data.domain.Pageable; | ||
| import redot.redot_server.domain.admin.dto.request.RedotAppInfoSearchCondition; | ||
| import redot.redot_server.domain.redot.app.entity.RedotApp; | ||
|
|
||
| public interface RedotAppRepositoryCustom { | ||
|
|
||
| Page<RedotApp> findAllBySearchCondition(RedotAppInfoSearchCondition searchCondition, | ||
| Pageable pageable); | ||
|
|
||
| List<RedotAppWithSiteInfo> findAllWithSiteInfo(RedotAppInfoSearchCondition searchCondition, | ||
| Pageable pageable); | ||
|
|
||
| long countBySearchCondition(RedotAppInfoSearchCondition searchCondition); | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
중복 키 발생 시 예외 처리 필요
Collectors.toMap에 merge function이 없어 하나의 RedotApp에 여러 Domain/StyleInfo/SiteSetting이 존재할 경우IllegalStateException이 발생합니다. 또한getRedotApp()이 null을 반환하면 NPE가 발생할 수 있습니다.다음 diff를 적용하여 중복 키와 null 처리를 개선하세요:
Map<Long, Domain> domainMap = redotAppIds.isEmpty() ? Map.of() : domainRepository.findByRedotAppIdIn(redotAppIds) .stream() + .filter(domain -> domain.getRedotApp() != null) - .collect(Collectors.toMap(domain -> domain.getRedotApp().getId(), Function.identity())); + .collect(Collectors.toMap( + domain -> domain.getRedotApp().getId(), + Function.identity(), + (existing, replacement) -> existing)); Map<Long, StyleInfo> styleInfoMap = redotAppIds.isEmpty() ? Map.of() : styleInfoRepository.findByRedotApp_IdIn(redotAppIds) .stream() + .filter(style -> style.getRedotApp() != null) - .collect(Collectors.toMap(style -> style.getRedotApp().getId(), Function.identity())); + .collect(Collectors.toMap( + style -> style.getRedotApp().getId(), + Function.identity(), + (existing, replacement) -> existing)); Map<Long, SiteSetting> siteSettingMap = redotAppIds.isEmpty() ? Map.of() : siteSettingRepository.findByRedotAppIdIn(redotAppIds) .stream() + .filter(setting -> setting.getRedotApp() != null) - .collect(Collectors.toMap(setting -> setting.getRedotApp().getId(), Function.identity())); + .collect(Collectors.toMap( + setting -> setting.getRedotApp().getId(), + Function.identity(), + (existing, replacement) -> existing));📝 Committable suggestion
🤖 Prompt for AI Agents
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.
한개의 앱에는 하나의 domain, styleinfo, sitesetting만 존재해요.
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.
@eraser502 이해했습니다! 1:1 관계라면 중복 키 문제는 발생하지 않겠네요. 명확하게 설명해 주셔서 감사합니다. 😊
✏️ Learnings added