Skip to content

Commit

Permalink
feat: 폴더 수정 기능 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
daeun084 committed Oct 18, 2024
1 parent 37d2d1b commit a670caf
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
@AllArgsConstructor
public enum FolderSuccessStatus implements BaseSuccessStatus {

FOLDER_CREATE_SUCCESS(HttpStatus.CREATED, "S601", "폴더 생성이 성공적으로 완료되었습니다.");
FOLDER_CREATE_SUCCESS(HttpStatus.CREATED, "S601", "폴더 생성이 성공적으로 완료되었습니다."),
FOLDER_DELETE_SUCCESS(HttpStatus.OK, "S601", "폴더 삭제 성공적으로 완료되었습니다."),
FOLDER_GET_SUCCESS(HttpStatus.OK, "S601", "폴더 리스트 조회가 성공적으로 완료되었습니다."),
FOLDER_UPDATE_SUCCESS(HttpStatus.OK, "S601", "폴더 수정이 성공적으로 완료되었습니다.");

private final HttpStatus httpStatus;
private final String code;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,30 @@ public ResponseEntity<ApiResponse<FolderResponse.FolderDtoList>> createFolder(
return ApiResponse.success(FolderSuccessStatus.FOLDER_CREATE_SUCCESS, folderResponse);
}


@DeleteMapping("/{folderId}")
public ResponseEntity<ApiResponse<FolderResponse.FolderDtoList>> deleteFolder(
@PathVariable(name = "folderId") Long folderId
) {
FolderResponse.FolderDtoList folderResponse = folderService.deleteFolder(folderId);

return ApiResponse.success(FolderSuccessStatus.FOLDER_CREATE_SUCCESS, folderResponse);
return ApiResponse.success(FolderSuccessStatus.FOLDER_DELETE_SUCCESS, folderResponse);
}

@GetMapping("")
public ResponseEntity<ApiResponse<FolderResponse.FolderDtoList>> getFolders(
) {
FolderResponse.FolderDtoList folderResponse = folderService.getFolderList();

return ApiResponse.success(FolderSuccessStatus.FOLDER_CREATE_SUCCESS, folderResponse);
return ApiResponse.success(FolderSuccessStatus.FOLDER_GET_SUCCESS, folderResponse);
}

@PatchMapping("")
public ResponseEntity<ApiResponse<FolderResponse.FolderDtoList>> updateFolder(
@RequestBody FolderRequest.FolderUpdateDto folderDto
) {
FolderResponse.FolderDtoList folderResponse = folderService.updateFolder(folderDto);

return ApiResponse.success(FolderSuccessStatus.FOLDER_UPDATE_SUCCESS, folderResponse);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,10 @@ public class FolderRequest {
public static class FolderDto {
private String title;
}

@Data
public static class FolderUpdateDto {
private Long folderId;
private String title;
}
}
4 changes: 4 additions & 0 deletions src/main/java/corecord/dev/domain/folder/entity/Folder.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,8 @@ public class Folder extends BaseEntity {

@OneToOne(mappedBy = "folder")
private Record record;

public void updateTitle(String title) {
this.title = title;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
@AllArgsConstructor
public enum FolderErrorStatus implements BaseErrorStatus {
DUPLICATED_FOLDER_TITLE(HttpStatus.BAD_REQUEST, "E0400_DUPLICATED_TITLE", "이미 존재하는 폴더 명입니다."),
OVERFLOW_FOLDER_TITLE(HttpStatus.BAD_REQUEST, "E0400_OVERFLOW_TITLE", "폴더 명은 15자 이내여야 합니다."),
FOLDER_NOT_FOUND(HttpStatus.NOT_FOUND, "E0404_FOLDER", "존재하지 않는 폴더입니다.");

private final HttpStatus httpStatus;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,23 @@ public FolderResponse.FolderDtoList deleteFolder(Long folderId) {
return getFolderList();
}

/*
* folderId를 받아, 해당 folder의 title을 수정
* @param folderDto
* @return
*/
@Transactional
public FolderResponse.FolderDtoList updateFolder(FolderRequest.FolderUpdateDto folderDto) {
Folder folder = findFolderById(folderDto.getFolderId());

validateDuplicatedFolderTitle(folderDto.getTitle());
validateTitleLength(folderDto.getTitle());

folder.updateTitle(folderDto.getTitle());

return getFolderList();
}

/*
* 생성일 오름차순으로 폴더 리스트를 조회
* @return
Expand All @@ -65,6 +82,13 @@ private void validateDuplicatedFolderTitle(String title) {
}
}

// title 글자 수 검사
private void validateTitleLength(String title) {
if (title.length() > 15) {
throw new FolderException(FolderErrorStatus.OVERFLOW_FOLDER_TITLE);
}
}

private Folder findFolderById(Long folderId) {
return folderRepository.findById(folderId)
.orElseThrow(() -> new FolderException(FolderErrorStatus.FOLDER_NOT_FOUND));
Expand Down

0 comments on commit a670caf

Please sign in to comment.