-
Notifications
You must be signed in to change notification settings - Fork 3
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/folder api 생성 #29
- Loading branch information
Showing
23 changed files
with
512 additions
and
47 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
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
29 changes: 19 additions & 10 deletions
29
src/main/java/com/SollutionChallenge/HighLight/Folder/FolderController.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,30 +1,39 @@ | ||
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; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import com.SollutionChallenge.HighLight.User.Entity.User; | ||
import com.SollutionChallenge.HighLight.common.ApiResponse; | ||
import com.SollutionChallenge.HighLight.common.Success; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@RestController | ||
@RequestMapping() | ||
@RequiredArgsConstructor | ||
public class FolderController { | ||
FolderService folderService; | ||
private final FolderService folderService; | ||
|
||
@PostMapping("/folder") | ||
private ApiResponse createFolder(@RequestBody User userId){ | ||
return ApiResponse.successCode(Success.CREATE_FOLDER_SUCCESS,userId); | ||
private ApiResponse createFolder(@RequestBody FolderRequestDto folderRequestDto){ | ||
FolderResponseDto response = folderService.save(folderRequestDto); | ||
return ApiResponse.successCode(Success.CREATE_FOLDER_SUCCESS,response); | ||
} | ||
|
||
@GetMapping("/folder") | ||
private ApiResponse<Map<String, List<FolderResponseDto>>> getFolder(){ | ||
Map<String, List<FolderResponseDto>> response = folderService.viewFolder(); | ||
return ApiResponse.successCode(Success.GET_FOLDER_SUCCESS,response); | ||
} | ||
|
||
// @GetMapping("/folder") | ||
// private Folder getFolder(){ | ||
// return folderService.getFolder(); | ||
// } | ||
@GetMapping("/folder/{folder_id}") | ||
private ApiResponse getOneFolder(@PathVariable Long folder_id){ | ||
FolderResponseDto response = folderService.viewOneFolder(folder_id); | ||
return ApiResponse.successCode(Success.GET_FOLDER_SUCCESS,response); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/com/SollutionChallenge/HighLight/Folder/FolderListResponseDto.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,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; | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/com/SollutionChallenge/HighLight/Folder/FolderRepository.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,7 +1,15 @@ | ||
package com.SollutionChallenge.HighLight.Folder; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Component; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import com.sun.istack.NotNull; | ||
|
||
@Repository | ||
public interface FolderRepository extends JpaRepository<Folder, Long> { | ||
// List<Folder> findAll(); | ||
|
||
} |
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
26 changes: 26 additions & 0 deletions
26
src/main/java/com/SollutionChallenge/HighLight/Folder/FolderResponseDto.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,26 @@ | ||
package com.SollutionChallenge.HighLight.Folder; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class FolderResponseDto { | ||
private Long id; | ||
private String folderName; | ||
|
||
public FolderResponseDto(Long id, String folderName) { | ||
this.id = id; | ||
this.folderName = folderName; | ||
} | ||
|
||
public static FolderResponseDto from(Long id, String folderName){ | ||
FolderResponseDto folderResponseDto = new FolderResponseDto(id, folderName); | ||
folderResponseDto.id = id; | ||
folderResponseDto.folderName = folderName; | ||
return folderResponseDto; | ||
} | ||
|
||
|
||
} |
82 changes: 79 additions & 3 deletions
82
src/main/java/com/SollutionChallenge/HighLight/Folder/FolderService.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,16 +1,92 @@ | ||
package com.SollutionChallenge.HighLight.Folder; | ||
|
||
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; | ||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import com.SollutionChallenge.HighLight.User.User; | ||
import com.SollutionChallenge.HighLight.User.UserRepository; | ||
import com.SollutionChallenge.HighLight.auth.ConfigUtils; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@RequiredArgsConstructor | ||
@Service | ||
public class FolderService { | ||
FolderRepository folderRepository; | ||
|
||
private final FolderRepository folderRepository; | ||
// private final | ||
private final Folder folder; | ||
// private final UserRepository userRepository; | ||
|
||
@Autowired | ||
public FolderService(FolderRepository folderRepository) { | ||
this.folderRepository = folderRepository; | ||
this.folder = Folder.createFolder(null, null); | ||
} | ||
|
||
// @Transactional | ||
// public Folder getFolder() { | ||
// return folderRepository.findAll(); | ||
// public FolderResponseDto save(FolderRequestDto folderRequestDto) { | ||
// String folderName = folderRequestDto.getFolderName(); | ||
// return FolderResponseDto.from( folderName); | ||
// } | ||
|
||
// public FolderViewResponseDto viewFolder() { | ||
// String id = folder.getName(); | ||
// List<Folder> folderName= folderRepository.findAll(); | ||
// return FolderViewResponseDto.of(folderName); | ||
// } | ||
|
||
@Transactional | ||
public FolderResponseDto save(FolderRequestDto folderRequestDto) { | ||
User userId = folder.getUserId(); // 해당 폴더를 생성한 유저 정보 | ||
String folderName = folderRequestDto.getFolderName(); | ||
Folder savedFolder = folderRepository.save(Folder.createFolder(userId, folderName)); | ||
return FolderResponseDto.from(savedFolder.getId(), savedFolder.getName()); | ||
} | ||
public Map<String, 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()); | ||
} | ||
|
||
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()){ | ||
String folderName = folder.get().getName(); | ||
} | ||
return FolderResponseDto.from(folder_id,folder.get().getName()); | ||
|
||
} | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/com/SollutionChallenge/HighLight/Folder/FolderViewResponseDto.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,22 @@ | ||
package com.SollutionChallenge.HighLight.Folder; | ||
|
||
import java.util.List; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class FolderViewResponseDto { | ||
private List<Long> id; | ||
private List<String> folderName; | ||
|
||
public static FolderViewResponseDto of(List <Long> id,List<String >folderName){ | ||
FolderViewResponseDto folderViewResponseDto = new FolderViewResponseDto(); | ||
folderViewResponseDto.id= id; | ||
folderViewResponseDto.folderName = folderName; | ||
|
||
return folderViewResponseDto; | ||
} | ||
} |
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
57 changes: 57 additions & 0 deletions
57
src/main/java/com/SollutionChallenge/HighLight/User/User.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,57 @@ | ||
package com.SollutionChallenge.HighLight.User; | ||
|
||
import javax.persistence.Column; | ||
import javax.persistence.Entity; | ||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.GenerationType; | ||
import javax.persistence.Id; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
@Entity | ||
public class User { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@Column(nullable = false) | ||
private String name; | ||
|
||
@Column(nullable = false) | ||
private String email; | ||
|
||
@Column | ||
private String picture; | ||
|
||
/* | ||
@Enumerated(EnumType.STRING) | ||
JPA로 데이터베이스로 저장할 때 Enum 값을 어떤 형태로 저장할지를 결정함 | ||
기본적으로는 int로 된 숫자가 저장된다. | ||
숫자로 저장되면 데이터베이스로 확인할 때 그 값이 무슨 코드를 의미하는지 알 수 가 없다. | ||
그래서 문자열로 저장될 수 있도록 선언 | ||
*/ | ||
|
||
|
||
@Builder | ||
public User(String name, String email, String picture){ | ||
this.name = name; | ||
this.email = email; | ||
this.picture = picture; | ||
|
||
} | ||
|
||
public User update(String name, String picture){ | ||
this.name = name; | ||
this.picture = picture; | ||
|
||
return this; | ||
} | ||
|
||
|
||
|
||
} |
Oops, something went wrong.