Skip to content
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

#32 [feat] 미션 카테고리 전체 조회하기 Api 구현 #38

Merged
merged 1 commit into from
Jul 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.universe.uni.controller;

import java.util.List;

import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
Expand All @@ -23,4 +25,10 @@ public class MissionController {
public MissionCategoryResponseDto getMissionCategory(@PathVariable Long missionCategoryId) {
return missionService.getMissionCategory(missionCategoryId);
}

@GetMapping()
@ResponseStatus(HttpStatus.OK)
public List<MissionCategoryResponseDto> getMissionCategoryList() {
return missionService.getMissionCategoryList();
}
}
12 changes: 10 additions & 2 deletions src/main/java/com/universe/uni/service/MissionService.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,21 @@ public MissionCategoryResponseDto getMissionCategory(Long missionCategoryId) {
return fromMissionCategoryToMissionCategoryResponseDto(missionCategory);
}

public List<MissionCategoryResponseDto> getMissionCategoryList() {
List<MissionCategory> missionCategoryList = missionCategoryRepository.findAll();
return missionCategoryList
.stream()
.map(this::fromMissionCategoryToMissionCategoryResponseDto)
.toList();
}

private MissionCategoryResponseDto fromMissionCategoryToMissionCategoryResponseDto(
MissionCategory missionCategory) {

List<MissionContent> missionContents = missionContentRepository.findByMissionCategoryId(
List<MissionContent> missionContentList = missionContentRepository.findByMissionCategoryId(
missionCategory.getId());

List<MissionContentResponseDto> missionContentResponseDtoList = missionContents.stream()
List<MissionContentResponseDto> missionContentResponseDtoList = missionContentList.stream()
.map(this::fromMissionContentToMissionContentResponseDto)
.collect(Collectors.toList());

Expand Down
Loading