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

Feature/haeun step3 #10

Open
wants to merge 15 commits into
base: base/haeun
Choose a base branch
from
Open
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
Expand Up @@ -8,15 +8,18 @@
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
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.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;

import com.c4cometrue.mystorage.dto.request.FileReq;
import com.c4cometrue.mystorage.dto.request.UploadFileReq;
import com.c4cometrue.mystorage.dto.response.FileDownloadRes;
import com.c4cometrue.mystorage.dto.response.FileMetaDataRes;
import com.c4cometrue.mystorage.dto.request.file.FileReq;
import com.c4cometrue.mystorage.dto.request.file.MoveFileReq;
import com.c4cometrue.mystorage.dto.request.file.UploadFileReq;
import com.c4cometrue.mystorage.dto.response.file.FileDownloadRes;
import com.c4cometrue.mystorage.dto.response.file.FileMetaDataRes;
import com.c4cometrue.mystorage.service.FileService;

import jakarta.validation.Valid;
Expand All @@ -34,7 +37,7 @@ public class FileController {
/**
* 파일 업로드 요청
* @param req (파일, 사용자 이름, 폴더 기본키)
* @return {@link com.c4cometrue.mystorage.dto.response.FileMetaDataRes}
* @return {@link FileMetaDataRes}
*/
@PostMapping
@ResponseStatus(HttpStatus.CREATED)
Expand All @@ -49,8 +52,8 @@ public FileMetaDataRes uploadFile(@Valid UploadFileReq req
*/
@DeleteMapping
@ResponseStatus(HttpStatus.NO_CONTENT)
public void deleteFile(@Valid FileReq req) {
fileService.deleteFile(req.fileStorageName(), req.userName(), req.folderId());
public void deleteFile(@RequestBody @Valid FileReq req) {
fileService.deleteFile(req.fileId(), req.userName(), req.folderId());
}

/**
Expand All @@ -60,10 +63,20 @@ public void deleteFile(@Valid FileReq req) {
*/
@GetMapping
public ResponseEntity<Resource> downloadFile(@Valid FileReq req) {
FileDownloadRes file = fileService.downloadFile(req.fileStorageName(), req.userName(), req.folderId());
FileDownloadRes file = fileService.downloadFile(req.fileId(), req.userName(), req.folderId());
return ResponseEntity.ok()
.contentType(MediaType.parseMediaType(file.mime()))
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + file.fileName() + "\"")
.body(file.resource());
}

/**
* 파일 이동 요청
* @param req (파일 기본키, 이동할 폴더 기본키)
*/
@PatchMapping
@ResponseStatus(HttpStatus.MOVED_PERMANENTLY)
public void moveFile(@RequestBody @Valid MoveFileReq req) {
fileService.moveFile(req.fileId(), req.folderId(), req.userName());
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.c4cometrue.mystorage.controller;

import java.util.List;

import org.springframework.http.HttpStatus;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PostMapping;
Expand All @@ -10,11 +13,16 @@
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;

import com.c4cometrue.mystorage.dto.request.CreateFolderReq;
import com.c4cometrue.mystorage.dto.request.GetFolderReq;
import com.c4cometrue.mystorage.dto.request.UpdateFolderNameReq;
import com.c4cometrue.mystorage.dto.response.CreateFolderRes;
import com.c4cometrue.mystorage.dto.response.FolderOverviewRes;
import com.c4cometrue.mystorage.dto.request.folder.CreateFolderReq;
import com.c4cometrue.mystorage.dto.request.folder.DeleteFolderReq;
import com.c4cometrue.mystorage.dto.request.folder.GetFolderReq;
import com.c4cometrue.mystorage.dto.request.folder.GetSubInfoReq;
import com.c4cometrue.mystorage.dto.request.folder.MoveFolderReq;
import com.c4cometrue.mystorage.dto.request.folder.UpdateFolderNameReq;
import com.c4cometrue.mystorage.dto.response.file.FileMetaDataRes;
import com.c4cometrue.mystorage.dto.response.folder.CreateFolderRes;
import com.c4cometrue.mystorage.dto.response.folder.FolderMetaDataRes;
import com.c4cometrue.mystorage.dto.response.folder.FolderOverviewRes;
import com.c4cometrue.mystorage.service.FolderService;

import jakarta.validation.Valid;
Expand All @@ -31,18 +39,40 @@ public class FolderController {
/**
* 폴더의 개략적인 정보 요청
* @param req (폴더 기본키, 폴더 이름, 사용자 이름, 부모 폴더 기본키)
* @return {@link com.c4cometrue.mystorage.dto.response.FolderOverviewRes}
* @return {@link FolderOverviewRes}
*/
@GetMapping
@ResponseStatus(HttpStatus.OK)
public FolderOverviewRes getFolderData(@Valid GetFolderReq req) {
return folderService.getFolderData(req.folderId(), req.userName());
return folderService.getFolderTotalInfo(req.folderId(), req.userName());
}

/**
* 폴더의 하위 폴더들을 페이징으로 조회
* @param req (폴더 기본키, 페이지 번호)
* @return page 번호에 맞는 하위 폴더 목록
*/
@GetMapping("/subFolder")
@ResponseStatus(HttpStatus.OK)
public List<FolderMetaDataRes> getSubFolders(@Valid GetSubInfoReq req) {
return folderService.getFolders(req.folderId(), req.page());
}

/**
* 폴더의 하위 파일들을 페이징으로 조회
* @param req (폴더 기본키, 페이지 번호)
* @return page 번호에 맞는 하위 파일 목록
*/
@GetMapping("/subFile")
@ResponseStatus(HttpStatus.OK)
public List<FileMetaDataRes> getSubFiles(@Valid GetSubInfoReq req) {
return folderService.getFiles(req.folderId(), req.page());
}

/**
* 폴더 생성 요청이 성공하면 해당 폴더 pk를 포함한 정보 반환
* @param req (폴더 이름, 사용자 이름, 부모 폴더 기본키)
* @return {@link com.c4cometrue.mystorage.dto.response.CreateFolderRes}
* @param req (폴더 기본키, 사용자 이름, 부모 폴더 기본키)
* @return {@link CreateFolderRes}
*/
@PostMapping
@ResponseStatus(HttpStatus.CREATED)
Expand All @@ -51,13 +81,33 @@ public CreateFolderRes createFolder(@RequestBody @Valid CreateFolderReq req) {
}

/**
* 폴더 이름 수정 요청
* @param updateFolderNameReq (이전 폴더 이름, 사용자 이름, 새로운 폴더 이름, 부모 폴더 기본키)
* 폴더 이름을 수정하는 요청
* @param req (폴더 기본키, 부모 폴더 기본키, 사용자 이름, 새로운 폴더 이름)
*/
@PatchMapping("/name")
@ResponseStatus(HttpStatus.OK)
public void updateFolderName(@RequestBody @Valid UpdateFolderNameReq updateFolderNameReq) {
folderService.updateFolderName(updateFolderNameReq.folderId(), updateFolderNameReq.parentFolderId(),
updateFolderNameReq.userName(), updateFolderNameReq.newFolderName());
public void updateFolderName(@RequestBody @Valid UpdateFolderNameReq req) {
folderService.updateFolderName(req.folderId(), req.parentFolderId(),
req.userName(), req.newFolderName());
}

/**
* 폴더를 삭제하는 요청
* @param req (폴더 기본키)
*/
@DeleteMapping
@ResponseStatus(HttpStatus.NO_CONTENT)
public void deleteFolder(@RequestBody @Valid DeleteFolderReq req) {
folderService.deleteFolder(req.folderId(), req.userName());
}

/**
* 폴더를 특정 폴더 위치로 이동하는 요청
* @param req (폴더 기본키, 이동할 폴더 기본키, 사용자 이름)
*/
@PatchMapping
@ResponseStatus(HttpStatus.OK)
public void moveFolder(@RequestBody @Valid MoveFolderReq req) {
folderService.moveFolder(req.folderId(), req.targetFolderId(), req.userName());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;

import com.c4cometrue.mystorage.dto.request.SignUpReq;
import com.c4cometrue.mystorage.dto.request.file.SignUpReq;
import com.c4cometrue.mystorage.dto.response.SignUpRes;
import com.c4cometrue.mystorage.service.UserService;

Expand Down
14 changes: 0 additions & 14 deletions src/main/java/com/c4cometrue/mystorage/dto/request/FileReq.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.c4cometrue.mystorage.dto.request.file;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Positive;

/**
* @see com.c4cometrue.mystorage.entity.FileMetaData
*/
public record FileReq(
@Positive(message = "file id should be positive") long fileId,
@NotBlank(message = "user name is blank") String userName,
@Positive(message = "folder id should be positive") long folderId
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.c4cometrue.mystorage.dto.request.file;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Positive;

/**
* DTO for {@link com.c4cometrue.mystorage.entity.FileMetaData}
*/
public record MoveFileReq(
@Positive(message = "file id should be positive") long fileId,
@Positive(message = "folder id should be positive") long folderId,
@NotBlank(message = "user name is blank") String userName
) {
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.c4cometrue.mystorage.dto.request;
package com.c4cometrue.mystorage.dto.request.file;

import jakarta.validation.constraints.NotBlank;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package com.c4cometrue.mystorage.dto.request;
package com.c4cometrue.mystorage.dto.request.file;

import org.springframework.web.multipart.MultipartFile;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Positive;

public record UploadFileReq(
@NotNull(message = "file doesn't exist") MultipartFile file,
@NotBlank(message = "user name is blank") String userName,
@NotNull(message = "folder id is null") long folderId
@Positive(message = "folder id should be positive") long folderId
) {
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.c4cometrue.mystorage.dto.request;
package com.c4cometrue.mystorage.dto.request.folder;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Positive;

/**
* @see com.c4cometrue.mystorage.entity.FolderMetaData
*/
public record CreateFolderReq(
@NotNull(message = "parent folder can't be null") long parentFolderId,
@Positive(message = "parent folder should be positive") long parentFolderId,
@NotBlank(message = "user name is blank") String userName,
@NotBlank(message = "folder name is blank") String folderName
) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.c4cometrue.mystorage.dto.request.folder;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Positive;

/**
* @see com.c4cometrue.mystorage.entity.FolderMetaData
*/
public record DeleteFolderReq(
@Positive(message = "folder id should be positive") long folderId,
@NotBlank(message = "user name is blank") String userName) {
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.c4cometrue.mystorage.dto.request;
package com.c4cometrue.mystorage.dto.request.folder;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Positive;

/**
* @see com.c4cometrue.mystorage.entity.FolderMetaData
*/
public record GetFolderReq(
@NotNull long folderId,
@Positive(message = "folder id should be positive") long folderId,
@NotBlank(message = "user name is blank") String userName
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.c4cometrue.mystorage.dto.request.folder;

import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.Positive;

public record GetSubInfoReq(
@Positive(message = "folder id should be positive") long folderId,
@Min(value = 0, message = "page number should be 0 or positive") int page
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.c4cometrue.mystorage.dto.request.folder;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Positive;

/**
* @see com.c4cometrue.mystorage.entity.FolderMetaData
*/
public record MoveFolderReq(
@Positive(message = "folder id should be positive") long folderId,
@Positive(message = "target folder should be positive") long targetFolderId,
@NotBlank(message = "user name is blank") String userName
) {
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package com.c4cometrue.mystorage.dto.request;
package com.c4cometrue.mystorage.dto.request.folder;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Positive;

/**
* @see com.c4cometrue.mystorage.entity.FolderMetaData
*/
public record UpdateFolderNameReq(
@NotNull long folderId,
@NotNull long parentFolderId,
@Positive(message = "folder id should be positive") long folderId,
@Positive(message = "parent folder id should be positive") long parentFolderId,
@NotBlank(message = "user name is blank") String userName,
@NotBlank(message = "new folder name is blank") String newFolderName
) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.c4cometrue.mystorage.dto.response;
package com.c4cometrue.mystorage.dto.response.file;

import org.springframework.core.io.Resource;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.c4cometrue.mystorage.dto.response;
package com.c4cometrue.mystorage.dto.response.file;

import com.c4cometrue.mystorage.entity.FileMetaData;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.c4cometrue.mystorage.dto.response;
package com.c4cometrue.mystorage.dto.response.folder;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
Expand All @@ -8,7 +8,6 @@
*/
public record CreateFolderRes(
@NotNull(message = "folder Number can't be null") long folderId,
@NotBlank(message = "folder name is blank") String folderName,
@NotBlank(message = "user name is blank") String userName
@NotBlank(message = "folder name is blank") String folderName
) {
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.c4cometrue.mystorage.dto.response;
package com.c4cometrue.mystorage.dto.response.folder;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.c4cometrue.mystorage.dto.response;
package com.c4cometrue.mystorage.dto.response.folder;

import java.util.List;

import com.c4cometrue.mystorage.dto.response.file.FileMetaDataRes;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;

Expand Down
Loading
Loading