From 71135dca4572943eaaa09277e2f8df47bcd59472 Mon Sep 17 00:00:00 2001 From: gdakate Date: Mon, 27 Mar 2023 12:01:56 +0900 Subject: [PATCH] =?UTF-8?q?[refactor]=20=ED=8F=B4=EB=8D=94=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=EC=8B=9C=20=EA=B0=9D=EC=B2=B4=20=EB=B0=98=ED=99=98=20?= =?UTF-8?q?API=20with=20h2=20success=20#29?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../HighLight/Folder/FolderController.java | 5 ++-- .../Folder/FolderListResponseDto.java | 18 +++++++++++++ .../HighLight/Folder/FolderResponseDto.java | 1 - .../HighLight/Folder/FolderService.java | 25 +++++++++++++++---- 4 files changed, 41 insertions(+), 8 deletions(-) create mode 100644 src/main/java/com/SollutionChallenge/HighLight/Folder/FolderListResponseDto.java diff --git a/src/main/java/com/SollutionChallenge/HighLight/Folder/FolderController.java b/src/main/java/com/SollutionChallenge/HighLight/Folder/FolderController.java index b3ac378..3d0f76c 100644 --- a/src/main/java/com/SollutionChallenge/HighLight/Folder/FolderController.java +++ b/src/main/java/com/SollutionChallenge/HighLight/Folder/FolderController.java @@ -1,6 +1,7 @@ package com.SollutionChallenge.HighLight.Folder; import java.util.List; +import java.util.Map; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; @@ -25,8 +26,8 @@ private ApiResponse createFolder(@RequestBody FolderRequestDto folderRequestDto) } @GetMapping("/folder") - private ApiResponse> getFolder(){ - List response = folderService.viewFolder(); + private ApiResponse>> getFolder(){ + Map> response = folderService.viewFolder(); return ApiResponse.successCode(Success.GET_FOLDER_SUCCESS,response); } diff --git a/src/main/java/com/SollutionChallenge/HighLight/Folder/FolderListResponseDto.java b/src/main/java/com/SollutionChallenge/HighLight/Folder/FolderListResponseDto.java new file mode 100644 index 0000000..1ae784f --- /dev/null +++ b/src/main/java/com/SollutionChallenge/HighLight/Folder/FolderListResponseDto.java @@ -0,0 +1,18 @@ +package com.SollutionChallenge.HighLight.Folder; + +import java.util.List; + +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Getter +@Setter +@NoArgsConstructor +public class FolderListResponseDto { + private List folderList; + + public FolderListResponseDto(List folderList) { + this.folderList = folderList; + } +} diff --git a/src/main/java/com/SollutionChallenge/HighLight/Folder/FolderResponseDto.java b/src/main/java/com/SollutionChallenge/HighLight/Folder/FolderResponseDto.java index 625acf7..a0b53b3 100644 --- a/src/main/java/com/SollutionChallenge/HighLight/Folder/FolderResponseDto.java +++ b/src/main/java/com/SollutionChallenge/HighLight/Folder/FolderResponseDto.java @@ -24,4 +24,3 @@ public static FolderResponseDto from(Long id, String folderName){ } - diff --git a/src/main/java/com/SollutionChallenge/HighLight/Folder/FolderService.java b/src/main/java/com/SollutionChallenge/HighLight/Folder/FolderService.java index 46fcdef..67bb1bd 100644 --- a/src/main/java/com/SollutionChallenge/HighLight/Folder/FolderService.java +++ b/src/main/java/com/SollutionChallenge/HighLight/Folder/FolderService.java @@ -2,7 +2,9 @@ import java.util.ArrayList; import java.util.Collections; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Optional; import java.util.stream.Collectors; @@ -51,20 +53,33 @@ public FolderResponseDto save(FolderRequestDto folderRequestDto) { Folder savedFolder = folderRepository.save(Folder.createFolder(userId, folderName)); return FolderResponseDto.from(savedFolder.getId(), savedFolder.getName()); } - - - public List viewFolder() { + public Map> viewFolder() { List folders = folderRepository.findAll(); - List folderResponseDtos =new ArrayList<>(); + List folderResponseDtos = new ArrayList<>(); if (folders != null && !folders.isEmpty()) { folderResponseDtos = folders.stream() .filter(f -> f.getName() != null) .map(f-> new FolderResponseDto(f.getId(),f.getName())) .collect(Collectors.toList()); } - return folderResponseDtos; + + Map> response = new HashMap<>(); + response.put("folder", folderResponseDtos); + return response; } + // public List viewFolder() { + // List folders = folderRepository.findAll(); + // List folderResponseDtos =new ArrayList<>(); + // if (folders != null && !folders.isEmpty()) { + // folderResponseDtos = folders.stream() + // .filter(f -> f.getName() != null) + // .map(f-> new FolderResponseDto(f.getId(),f.getName())) + // .collect(Collectors.toList()); + // } + // return folderResponseDtos; + // } + public FolderResponseDto viewOneFolder(Long folder_id) { Optional folder = folderRepository.findById(folder_id); if(folder.isPresent()){