메인 페이지 디자인 수정

This commit is contained in:
현성필
2025-11-18 12:43:24 +09:00
parent c94ede55aa
commit 176326ff21
12 changed files with 213 additions and 360 deletions
@@ -10,6 +10,7 @@ import com.eactive.apim.portal.apps.community.notice.service.PortalNoticeFacade;
import com.eactive.apim.portal.apps.main.service.MainApiFacade;
import com.eactive.apim.portal.common.util.SecurityUtil;
import com.eactive.apim.portal.portalproperty.service.PortalPropertyService;
import java.util.*;
import java.util.stream.Collectors;
@@ -25,13 +26,12 @@ public class IndexController {
private final ApiSearchFacade apiSearchFacade;
private final MainApiFacade mainApiFacade;
private final PortalNoticeFacade portalNoticeFacade;
private final PortalPropertyService portalPropertyService;
/**
* 메인 페이지 API는 Portal Property 에 main.service.list 에 등록된 그룹을 기준으로 API를 조회함.
* 프로퍼티에 등록되어 있어도 어드민의 그룹 표시 설정이 N이면 표시 되지 않음.
* 어드민의 API 스펙의 표시 설정이 N이면 표시되지 않음.
* 그룹 또는 권한이 지정된 경우, 해당사용자의 권한 또는 기관이 일치해야 표시됨.
* 어드민의 API 스펙의 표시 설정이 N이면 표시되지 않음. 그룹 또는 권한이 지정된 경우, 해당사용자의 권한 또는 기관이 일치해야 표시됨.
* <p>
* 검색어는 Portal Property 또는 메인 관리 화면에 main.keyword.list 에 등록된 내용이 표시 됨.
*
@@ -40,23 +40,15 @@ public class IndexController {
*/
@GetMapping("/")
public String index(Model model) {
Map<String, String> propertyMap = portalPropertyService.getPortalPropertiesAsMap("Portal");
String serviceList = propertyMap.get("main.service.list");
// Step 1: Fetch and sort API services
List<ApiServiceDTO> apiServices = getSortedApiServices(null);
// Step 2: Create a map of API ID to ApiServiceDTO for icon mapping
Map<String, ApiServiceDTO> mainIconsMap = createMainIconsMap(apiServices);
// Step 3: Merge all API lists from apiServices
List<ApiServiceApiDTO> allApis = getAllApis(apiServices);
// Step 4: Enrich API spec info DTOs with main icon and service info
List<ApiSpecInfoDto> apiSpecInfoDtos = enrichApiSpecInfo(apiServices, allApis, mainIconsMap);
// Step 5: Calculate total API count
// Step 2: Calculate total API count
int totalApiCount = calculateTotalApiCount(apiServices);
// Step 6: Fetch portal notices and hashtags
List<PortalNoticeDTO> portalNotices = portalNoticeFacade.getLatestNotices();
List<String> hashTags = mainApiFacade.getHashTags();
ApiGroupSearch search = new ApiGroupSearch();
@@ -70,8 +62,7 @@ public class IndexController {
// 승인된 기업 건수
int approvedOrgCount = mainApiFacade.getApprovedOrgCount();
// Step 7: Add attributes to model
addAttributesToModel(model, apiServices, apiSearchFacade.sortApisByService(apiSpecInfoDtos, apiServices), totalApiCount, portalNotices, hashTags, serviceCount, approvedOrgCount, selectedApiCount);
addAttributesToModel(model, apiServices, totalApiCount, hashTags, serviceCount, approvedOrgCount, selectedApiCount);
return "apps/main/index";
}
@@ -82,89 +73,17 @@ public class IndexController {
return apiServices;
}
private Map<String, ApiServiceDTO> createMainIconsMap(List<ApiServiceDTO> apiServices) {
Map<String, ApiServiceDTO> mainIconsMap = new HashMap<>();
apiServices.forEach(service ->
service.getApiGroupApiList().forEach(api ->
mainIconsMap.put(api.getApiId(), service)
)
);
return mainIconsMap;
}
private List<ApiServiceApiDTO> getAllApis(List<ApiServiceDTO> apiServices) {
return apiServices.stream()
.flatMap(service -> service.getApiGroupApiList().stream())
.collect(Collectors.toList());
}
private List<ApiSpecInfoDto> enrichApiSpecInfo(List<ApiServiceDTO> services, List<ApiServiceApiDTO> allApis, Map<String, ApiServiceDTO> mainIconsMap) {
List<String> apiIds = allApis.stream().map(ApiServiceApiDTO::getApiId).collect(Collectors.toList());
List<ApiSpecInfoDto> apiSpecInfoDtos = mainApiFacade.getOpenApis(apiIds);
apiSpecInfoDtos.forEach(spec -> {
ApiServiceDTO serviceDTO = mainIconsMap.get(spec.getApiId());
if (serviceDTO != null) {
spec.setMainIcon(serviceDTO.getMainIcon());
spec.setService(serviceDTO.getGroupName());
}
});
boolean isAuthenticated = SecurityUtil.isAuthenticated();
String roleCode;
String org;
if (isAuthenticated) {
roleCode = SecurityUtil.getPortalAuthenticatedUser().getRoleCode().toString();
org = SecurityUtil.getUserOrg().getId();
} else {
roleCode = null;
org = null;
}
List<ApiSpecInfoDto> filteredApiSpecInfoDtos = apiSpecInfoDtos.stream()
.filter(spec -> {
if (!isAuthenticated) {
return spec.getDisplayOrg() == null && spec.getDisplayRoleCode() == null;
}
boolean orgMatch = false;
if (org != null) {
orgMatch = spec.getDisplayOrg() == null || spec.getDisplayOrg().isEmpty() || spec.getDisplayOrg().contains(org);
}
boolean roleMatch = spec.getDisplayRoleCode() == null || spec.getDisplayRoleCode().isEmpty() || spec.getDisplayRoleCode().contains(roleCode);
return orgMatch || roleMatch;
})
.collect(Collectors.toList());
Set<String> filteredApiIds = filteredApiSpecInfoDtos.stream()
.map(ApiSpecInfoDto::getApiId)
.collect(Collectors.toSet());
services.forEach(service -> {
if (service.getApiGroupApiList() != null) {
List<ApiServiceApiDTO> filteredApiList = service.getApiGroupApiList().stream()
.filter(api -> filteredApiIds.contains(api.getApiId()))
.collect(Collectors.toList());
service.setApiGroupApiList(filteredApiList);
}
});
return filteredApiSpecInfoDtos.stream().collect(Collectors.toList());
}
private int calculateTotalApiCount(List<ApiServiceDTO> apiServices) {
return apiServices.stream()
.mapToInt(service -> service.getApiGroupApiList().size())
.sum();
.mapToInt(service -> service.getApiGroupApiList().size())
.sum();
}
private void addAttributesToModel(Model model, List<ApiServiceDTO> apiServices,
List<ApiSpecInfoDto> apiSpecInfoDtos, int totalApiCount,
List<PortalNoticeDTO> portalNotices, List<String> hashTags, int serviceCount, int approvedOrgCount, int selectedApiCount) {
int totalApiCount, List<String> hashTags, int serviceCount, int approvedOrgCount, int selectedApiCount) {
model.addAttribute("services", apiServices);
model.addAttribute("apis", apiSpecInfoDtos);
model.addAttribute("totalApiCount", totalApiCount);
model.addAttribute("portalNotices", portalNotices);
model.addAttribute("hashtags", hashTags);
model.addAttribute("serviceCount", serviceCount);
@@ -172,15 +91,4 @@ public class IndexController {
model.addAttribute("selectedApiCount", selectedApiCount);
}
@GetMapping("/api_fragments")
public String getApiFragments(@RequestParam(value = "id", required = false) String id, Model model) {
List<ApiServiceDTO> apiServices = getSortedApiServices(id);
Map<String, ApiServiceDTO> mainIconsMap = createMainIconsMap(apiServices);
List<ApiServiceApiDTO> allApis = getAllApis(apiServices);
List<ApiSpecInfoDto> apiSpecInfoDtos = enrichApiSpecInfo(apiServices, allApis, mainIconsMap);
model.addAttribute("apis", apiSpecInfoDtos);
return "apps/main/apiListFragment :: apiListFragment";
}
}