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 7 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,11 @@
package com.c4cometrue.mystorage.controller;

import java.util.List;

import org.springframework.data.domain.Pageable;
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 +14,15 @@
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.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,42 @@ 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 folderId 폴더 기본키
* @param pageable paging을 위한 파라미터
* @return page 번호에 맞는 하위 폴더 목록
*/
@GetMapping("/subFolder")
@ResponseStatus(HttpStatus.OK)
public List<FolderMetaDataRes> getSubFolders(long folderId, Pageable pageable) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

folderId는 어디서 주입받나요?

return folderService.getFolders(folderId, pageable.getPageNumber());
}

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

/**
* 폴더 생성 요청이 성공하면 해당 폴더 pk를 포함한 정보 반환
* @param req (폴더 이름, 사용자 이름, 부모 폴더 기본키)
* @return {@link com.c4cometrue.mystorage.dto.response.CreateFolderRes}
* @param req (폴더 기본키, 사용자 이름, 부모 폴더 기본키)
* @return {@link CreateFolderRes}
*/
@PostMapping
@ResponseStatus(HttpStatus.CREATED)
Expand All @@ -51,13 +83,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.MOVED_PERMANENTLY)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MOVED_PERMANENTLY는 리다이렉트를 위한 HttpStatusCode입니다.

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
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;
import jakarta.validation.constraints.NotNull;
Expand All @@ -7,7 +7,7 @@
* @see com.c4cometrue.mystorage.entity.FileMetaData
*/
public record FileReq(
@NotBlank(message = "file storage name is blank") String fileStorageName,
@NotNull(message = "file id is blank") long fileId,
@NotBlank(message = "user name is blank") String userName,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

전체적인 로직을 고려했을 때, @Positive가 좀 더 자연스러워보여요.

@NotNull(message = "folder id is blank") long folderId
) {
Expand Down
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.NotNull;

/**
* DTO for {@link com.c4cometrue.mystorage.entity.FileMetaData}
*/
public record MoveFileReq(
@NotNull(message = "file id is blank") long fileId,
@NotNull(message = "folder id is blank") 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,4 +1,4 @@
package com.c4cometrue.mystorage.dto.request;
package com.c4cometrue.mystorage.dto.request.file;

import org.springframework.web.multipart.MultipartFile;

Expand Down
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.folder;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
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.NotNull;

/**
* @see com.c4cometrue.mystorage.entity.FolderMetaData
*/
public record DeleteFolderReq(
@NotNull(message = "folder id can't be null") 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.folder;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
Expand Down
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.NotNull;

/**
* @see com.c4cometrue.mystorage.entity.FolderMetaData
*/
public record MoveFolderReq(
@NotNull(message = "folder id can't be null") long folderId,
@NotNull(message = "target folder can't be null") long targetFolderId,
@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.folder;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
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
31 changes: 31 additions & 0 deletions src/main/java/com/c4cometrue/mystorage/entity/DeleteLog.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.c4cometrue.mystorage.entity;

import java.time.ZoneId;
import java.time.ZonedDateTime;

import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;

@Entity
@RequiredArgsConstructor
public class DeleteLog {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long logId;

@NotBlank(message = "file storage name is blank")
private String fileStorageName;

@NotNull
private ZonedDateTime deleteTime;

public DeleteLog(String fileStorageName) {
this.fileStorageName = fileStorageName;
this.deleteTime = ZonedDateTime.now(ZoneId.of("Asia/Seoul"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,7 @@ public FileMetaData(String fileName, String fileStorageName, long size, String m
this.folderId = folderId;
}

public void setFolderId(Long folderId) {
this.folderId = folderId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,8 @@ public FolderMetaData(String folderName, String userName, long parentFolderId) {
public void setFolderName(String folderName) {
this.folderName = folderName;
}

public void setParentFolderId(Long parentFolderId) {
this.parentFolderId = parentFolderId;
}
}
3 changes: 2 additions & 1 deletion src/main/java/com/c4cometrue/mystorage/entity/UserData.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
@RequiredArgsConstructor
@Getter
public class UserData {
@Id @GeneratedValue(strategy = GenerationType.IDENTITY)
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long userId;

@NotBlank(message = "user name is blank")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public enum ErrorCd {
// Folder 관련 에러
FOLDER_NOT_EXIST(HttpStatus.NOT_FOUND, "Folder doesn't exist"), // 폴더가 존재하지 않는 경우
DUPLICATE_FOLDER(HttpStatus.BAD_REQUEST, "Duplicate Folder"), // 이미 존재하는 폴더명

FOLDER_CANT_BE_MOVED(HttpStatus.BAD_REQUEST, "folder route might have cycle"), // 하위 폴더로 이동하려는 경우

// User 관련 에러
DUPLICATE_USER(HttpStatus.BAD_REQUEST, "User name Duplicate"), // 이미 존재하는 유저 이름
Expand Down
Loading
Loading