Skip to content

Commit

Permalink
Feat: Docs update Delete
Browse files Browse the repository at this point in the history
  • Loading branch information
Hawardshin committed Nov 22, 2024
1 parent f9322de commit bccb19f
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/main/java/capstone/relation/document/domain/Folder.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Entity
@Getter
Expand All @@ -35,6 +36,7 @@ public class Folder extends BaseEntity {
private Long id;

@Column(name = "folder_name")
@Setter
private String folderName;

@Builder.Default
Expand Down
45 changes: 39 additions & 6 deletions src/main/java/capstone/relation/document/service/DocsService.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,28 @@ public FolderInfoDto createFolder(String folderName, Long userId) {
.folderName(folderName)
.build();
}
@Transactional
public FolderInfoDto updateFolder(Long folderId, String folderName) {
Folder folder = folderRepository.findById(folderId).orElseThrow(() -> new DocumentException(
DocumentErrorCode.FOLDER_NOT_EXIST));
folder.setFolderName(folderName);
folderRepository.save(folder);
return FolderInfoDto.builder()
.folderId(folder.getId())
.folderName(folderName)
.build();
}

@Transactional
public void deleteFolder(Long userId, Long folderId) {
Folder folder = folderRepository.findById(folderId).orElseThrow(() -> new DocumentException(
DocumentErrorCode.FOLDER_NOT_EXIST));
WorkSpace workSpace = folder.getWorkSpace();
User user = userRepository.findById(userId).orElseThrow(() -> new UserException(UserErrorCode.INVALID_USER));
if (!workSpace.getId().equals(user.getWorkSpace().getId()))
throw new DocumentException(DocumentErrorCode.USER_NOT_ACCESS);
folderRepository.delete(folder);
}

public List<FolderInfoDto> getAllDocs(Long userId) {
User user = userRepository.findById(userId).orElseThrow(() -> new UserException(UserErrorCode.INVALID_USER));
Expand Down Expand Up @@ -78,14 +100,14 @@ public List<FolderInfoDto> getAllDocs(Long userId) {
}

@Transactional
public FileContentDto createFile(Long userId, String fileName, Long folderId, String content) {
public FileContentDto createFile(Long userId, String fileName, Long folderId) {
Folder folder = folderRepository.findById(folderId).orElseThrow(() -> new DocumentException(
DocumentErrorCode.FOLDER_NOT_EXIST));
WorkSpace workSpace = folder.getWorkSpace();
User user = userRepository.findById(userId).orElseThrow(() -> new UserException(UserErrorCode.INVALID_USER));
if (!workSpace.getId().equals(user.getWorkSpace().getId()))
throw new DocumentException(DocumentErrorCode.USER_NOT_ACCESS);
NoteInfo noteInfo = NoteInfo.builder().content(content).build();
NoteInfo noteInfo = NoteInfo.builder().build();
noteInfoRepository.save(noteInfo);
FileInfo file = FileInfo.builder()
.fileName(fileName)
Expand All @@ -97,27 +119,38 @@ public FileContentDto createFile(Long userId, String fileName, Long folderId, St
return FileContentDto.builder()
.fileId(file.getId())
.fileName(fileName)
.content(content)
.build();
}

@Transactional
public FileContentDto updateFile(Long fileId, String fileName, Long folderId, String content) {
public FileContentDto updateFile(Long userId, Long fileId, String content) {
FileInfo fileInfo = fileRepository.findById(fileId)
.orElseThrow(() -> new DocumentException(DocumentErrorCode.FILE_NOT_EXIST));
NoteInfo noteInfo = noteInfoRepository.findById(fileInfo.getNoteInfoId())
.orElseThrow(() -> new DocumentException(DocumentErrorCode.FILE_NOT_EXIST));
noteInfo.setContent(content);
noteInfoRepository.save(noteInfo);
fileInfo.setFileName(fileName);
fileInfo.setFileName(fileInfo.getFileName());
fileRepository.save(fileInfo);
return FileContentDto.builder()
.fileId(fileInfo.getId())
.fileName(fileName)
.fileName(fileInfo.getFileName())
.content(content)
.build();
}

@Transactional
public void deleteFile(Long userId, Long fileId) {
FileInfo fileInfo = fileRepository.findById(fileId)
.orElseThrow(() -> new DocumentException(DocumentErrorCode.FILE_NOT_EXIST));
Folder folder = fileInfo.getFolder();
WorkSpace workSpace = folder.getWorkSpace();
User user = userRepository.findById(userId).orElseThrow(() -> new UserException(UserErrorCode.INVALID_USER));
if (!workSpace.getId().equals(user.getWorkSpace().getId()))
throw new DocumentException(DocumentErrorCode.USER_NOT_ACCESS);
fileRepository.delete(fileInfo);
}

public FolderInfoDto getFolder(Long folderId) {
Folder folder = folderRepository.findById(folderId)
.orElseThrow(() -> new DocumentException(DocumentErrorCode.FOLDER_NOT_EXIST));
Expand Down

0 comments on commit bccb19f

Please sign in to comment.