-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Feat/#20 interface separation
- Loading branch information
Showing
22 changed files
with
471 additions
and
247 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
21 changes: 21 additions & 0 deletions
21
src/main/java/sopt/org/homepage/aboutsopt/service/AboutSoptService.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,21 @@ | ||
package sopt.org.homepage.aboutsopt.service; | ||
|
||
import sopt.org.homepage.aboutsopt.dto.GetAboutSoptResponseDto; | ||
|
||
public interface AboutSoptService { | ||
/** | ||
* 특정 기수의 AboutSopt 정보를 조회. | ||
* | ||
* @param generation 조회할 기수. null인 경우 최근 기수 정보를 조회. | ||
* @return AboutSopt 정보 및 활동 기록이 포함된 응답 DTO | ||
*/ | ||
GetAboutSoptResponseDto getAboutSopt(Integer generation); | ||
|
||
/** | ||
* 특정 기수의 스터디 수를 조회. | ||
* | ||
* @param generation 조회할 기수 | ||
* @return 해당 기수의 스터디 수 | ||
*/ | ||
Integer getStudyCount(Integer generation); | ||
} |
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
17 changes: 17 additions & 0 deletions
17
src/main/java/sopt/org/homepage/common/service/GenerationService.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,17 @@ | ||
package sopt.org.homepage.common.service; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import sopt.org.homepage.main.entity.MainEntity; | ||
import sopt.org.homepage.main.repository.MainRepository; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class GenerationService { | ||
private final MainRepository mainRepository; | ||
|
||
public int getLatestGeneration() { | ||
MainEntity mainEntity = mainRepository.findFirstByOrderByGenerationDesc(); | ||
return mainEntity.getGeneration(); | ||
} | ||
} |
137 changes: 7 additions & 130 deletions
137
src/main/java/sopt/org/homepage/internal/playground/PlaygroundService.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 |
---|---|---|
@@ -1,141 +1,18 @@ | ||
package sopt.org.homepage.internal.playground; | ||
|
||
import java.util.ArrayList; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Service; | ||
import com.fasterxml.jackson.core.type.TypeReference; | ||
import sopt.org.homepage.cache.CacheService; | ||
import sopt.org.homepage.common.constants.CacheType; | ||
import sopt.org.homepage.common.util.ArrayUtil; | ||
import sopt.org.homepage.config.AuthConfig; | ||
import sopt.org.homepage.internal.playground.dto.PlaygroundMemberListResponse; | ||
import sopt.org.homepage.internal.playground.dto.PlaygroundProjectAxiosResponseDto; | ||
import sopt.org.homepage.internal.playground.dto.PlaygroundProjectResponseDto; | ||
import sopt.org.homepage.internal.playground.dto.PlaygroundUserResponse; | ||
import sopt.org.homepage.project.dto.request.GetProjectsRequestDto; | ||
import sopt.org.homepage.project.dto.response.ProjectDetailResponseDto; | ||
import sopt.org.homepage.project.dto.response.ProjectsResponseDto; | ||
import sopt.org.homepage.common.mapper.ResponseMapper; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
|
||
@Slf4j | ||
@RequiredArgsConstructor | ||
@Service | ||
public class PlaygroundService { | ||
private final PlaygroundClient playgroundClient; | ||
private final ResponseMapper responseMapper; | ||
private final AuthConfig authConfig; | ||
private final ArrayUtil arrayUtil; | ||
|
||
private final CacheService cacheService; | ||
private static final String PROJECT_CACHE_KEY = "all_projects"; | ||
|
||
|
||
|
||
public PlaygroundUserResponse getPlaygroundUserInfo(String authToken) { | ||
return playgroundClient.getPlaygroundUser(authToken); | ||
} | ||
|
||
public List<ProjectsResponseDto> getAllProjects(GetProjectsRequestDto projectRequest) { | ||
// 캐시에서 데이터 조회 시도 | ||
List<PlaygroundProjectResponseDto> projectListResponse = cacheService.get( | ||
CacheType.PROJECT_LIST, PROJECT_CACHE_KEY, new TypeReference<>() { | ||
} | ||
); | ||
|
||
if (projectListResponse == null) { // 캐시 미스인 경우 API 호출 | ||
try { | ||
projectListResponse = getProjectsWithPagination(); | ||
cacheService.put(CacheType.PROJECT_LIST, PROJECT_CACHE_KEY, projectListResponse); | ||
} catch (Exception e) { | ||
log.error("Projcet API Failed to fetch projects", e); | ||
return Collections.emptyList(); | ||
} | ||
} | ||
|
||
List<ProjectsResponseDto> result = new ArrayList<>(); | ||
var filter = projectRequest.getFilter(); | ||
var platform = projectRequest.getPlatform(); | ||
|
||
var uniqueResponse = arrayUtil.dropDuplication(projectListResponse, PlaygroundProjectResponseDto::name); | ||
|
||
var uniqueLinkResponse = uniqueResponse.stream() | ||
.map(response -> response.ProjectWithLink( | ||
arrayUtil.dropDuplication(response.links(), PlaygroundProjectResponseDto.ProjectLinkResponse::linkId) | ||
)) | ||
.toList(); | ||
|
||
|
||
if (uniqueLinkResponse.isEmpty()) { | ||
return Collections.emptyList(); | ||
} | ||
|
||
for (var data : projectListResponse) { | ||
result.add(responseMapper.toProjectResponse(data)); | ||
} | ||
|
||
if (filter != null) { | ||
result = result.stream() | ||
.filter(element -> element.getCategory().project().equals(filter)) | ||
.collect(Collectors.toList()); | ||
} | ||
if (platform != null) { | ||
result = result.stream() | ||
.filter(element -> element.getServiceType().contains(platform)) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
return result; | ||
} | ||
|
||
|
||
public List<PlaygroundProjectResponseDto> getProjectsWithPagination() { | ||
final int limit = 20; | ||
int cursor = 0; | ||
int totalCount = 10; | ||
List<PlaygroundProjectResponseDto> response = new ArrayList<>(); | ||
|
||
for (int i = 0; i < totalCount + 1; i = i + limit) { | ||
PlaygroundProjectAxiosResponseDto projectData = playgroundClient.getAllProjects( | ||
authConfig.getPlaygroundToken(), | ||
limit, | ||
cursor | ||
); | ||
|
||
if (projectData.projectList().isEmpty()) { | ||
break; | ||
} | ||
|
||
totalCount = projectData.totalCount(); | ||
response.addAll(projectData.projectList()); | ||
|
||
int lastDataIdx = projectData.projectList().size() - 1; | ||
cursor = projectData.projectList().get(lastDataIdx).id().intValue(); | ||
|
||
if (!projectData.hasNext()) { | ||
break; | ||
} | ||
} | ||
|
||
return response; | ||
} | ||
|
||
|
||
public ProjectDetailResponseDto getProjectDetail(Long projectId){ | ||
var projectResponse = playgroundClient.getProjectDetail(authConfig.getPlaygroundToken(), projectId); | ||
if (projectResponse == null) { | ||
throw new RuntimeException("프로젝트 데이터를 가져오지 못했습니다."); | ||
} | ||
|
||
return responseMapper.toProjectDetailResponse(projectResponse); | ||
} | ||
|
||
public PlaygroundMemberListResponse getAllMembers(Integer generation) { | ||
return playgroundClient.getAllMembers(authConfig.getPlaygroundToken(), null, generation); | ||
} | ||
} | ||
public interface PlaygroundService { | ||
PlaygroundUserResponse getPlaygroundUserInfo(String authToken); | ||
List<ProjectsResponseDto> getAllProjects(GetProjectsRequestDto projectRequest); | ||
List<PlaygroundProjectResponseDto> getProjectsWithPagination(); | ||
ProjectDetailResponseDto getProjectDetail(Long projectId); | ||
PlaygroundMemberListResponse getAllMembers(Integer generation); | ||
} |
Oops, something went wrong.