Skip to content

Commit

Permalink
[refactor] 폴더 조회시 객체 반환 API with h2 success #29
Browse files Browse the repository at this point in the history
  • Loading branch information
gdakate committed Mar 27, 2023
1 parent 0bbc42f commit 71135dc
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -25,8 +26,8 @@ private ApiResponse createFolder(@RequestBody FolderRequestDto folderRequestDto)
}

@GetMapping("/folder")
private ApiResponse<List<FolderResponseDto>> getFolder(){
List<FolderResponseDto> response = folderService.viewFolder();
private ApiResponse<Map<String, List<FolderResponseDto>>> getFolder(){
Map<String, List<FolderResponseDto>> response = folderService.viewFolder();
return ApiResponse.successCode(Success.GET_FOLDER_SUCCESS,response);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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<FolderResponseDto> folderList;

public FolderListResponseDto(List<FolderResponseDto> folderList) {
this.folderList = folderList;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,3 @@ public static FolderResponseDto from(Long id, String folderName){


}

Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<FolderResponseDto> viewFolder() {
public Map<String, List<FolderResponseDto>> viewFolder() {
List<Folder> folders = folderRepository.findAll();
List<FolderResponseDto> folderResponseDtos =new ArrayList<>();
List<FolderResponseDto> 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<String, List<FolderResponseDto>> response = new HashMap<>();
response.put("folder", folderResponseDtos);
return response;
}

// public List<FolderResponseDto> viewFolder() {
// List<Folder> folders = folderRepository.findAll();
// List<FolderResponseDto> 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> folder = folderRepository.findById(folder_id);
if(folder.isPresent()){
Expand Down

0 comments on commit 71135dc

Please sign in to comment.