Skip to content

Commit

Permalink
Merge pull request #11 from PLADI-ALM/feat/PDS-136-delete-project
Browse files Browse the repository at this point in the history
[PDS-136] 아카이빙 프로젝트 삭제 API
  • Loading branch information
leeseunghakhello authored Oct 21, 2023
2 parents 247aece + 0566c8e commit 32e4803
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -183,4 +183,25 @@ public ResponseCustom<?> updateProject(
archivingService.updateProject(projectId, updateProjectReq);
return ResponseCustom.OK();
}

/**
* 프로젝트를 삭제한다.
*/
@Operation(summary = "프로젝트 삭제 (김민기)", description = "아카이빙 프로젝트를 삭제한다.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "(S0001)요청에 성공했습니다."),
@ApiResponse(responseCode = "404", description = "(P0002)존재하지 않는 프로젝트입니다.", content = @Content(schema = @Schema(implementation = ResponseCustom.class))),
@ApiResponse(responseCode = "401", description = "(P0005)관리자 계정이 아니므로 프로젝트를 삭제할 수 없습니다.", content = @Content(schema = @Schema(implementation = ResponseCustom.class))),
})
@DeleteMapping("/projects/{projectId}")
public ResponseCustom<?> deleteProject(
@Parameter(description = "(Long) 프로젝트 Id", example = "1") @PathVariable Long projectId,
@Account User user

)
{
archivingService.deleteProject(projectId, user);
return ResponseCustom.OK();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,6 @@
@Repository
public interface MaterialRepository extends JpaRepository<Material, Long> {
Page<Material> findByProjectAndExtensionInAndNameContaining(Project project, List<String> extensions, String cond, Pageable pageable);

Page<Material> findByProject(Project project, Pageable pageable);
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ public Page<SearchMaterialRes> searchMaterial(Long projectId, SearchMaterialReq
} else if (category == Category.DOCS) {
extension = List.of(Constants.EXTENSION.DOCS.split(" "));
}
filteredMaterials = materialRepository.findByProjectAndExtensionInAndNameContaining(project, extension, searchMaterialReq.getCond(), pageable);
filteredMaterials = materialRepository.findByProjectAndExtensionInAndNameContaining(project, extension, searchMaterialReq.getCond(), pageable);
} else {
filteredMaterials = materialRepository.findAll(pageable);
filteredMaterials = materialRepository.findByProject(project, pageable);
}

return filteredMaterials.map(SearchMaterialRes::toDto);
Expand All @@ -106,4 +106,13 @@ public void updateProject(Long projectId, UpdateProjectReq updateProjectReq) {
Project project = projectRepository.findById(projectId).orElseThrow(() -> new BaseException(BaseResponseCode.PROJECT_NOT_FOUND));
project.update(updateProjectReq.getName());
}

@Transactional
public void deleteProject(Long projectId, User user) {
Project project = projectRepository.findById(projectId).orElseThrow(() -> new BaseException(BaseResponseCode.PROJECT_NOT_FOUND));
if(user.getRole() != Role.ADMIN) throw new BaseException(BaseResponseCode.UNAUTHORIZED_USER);

materialRepository.deleteAll(project.getMaterialList());
projectRepository.delete(project);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public enum BaseResponseCode {
PROJECT_NOT_FOUND("P0002", HttpStatus.NOT_FOUND, "존재하지 않는 프로젝트입니다."),
CATEGORY_NOT_FOUND("P0003", HttpStatus.NOT_FOUND, "존재하지 않는 카테고리입니다."),
MATERIAL_NOT_FOUND("P0004", HttpStatus.NOT_FOUND, "존재하지 않는 자료입니다."),
UNAUTHORIZED_USER("P0005", HttpStatus.UNAUTHORIZED, "관리자 계정 또는 자료를 업로드한 유저가 아니므로 자료를 삭제할 수 없습니다."),
UNAUTHORIZED_USER("P0005", HttpStatus.UNAUTHORIZED, "관리자 계정 또는 자료 또는 프로젝트를 업로드한 유저가 아니므로 삭제할 수 없습니다."),
INVALID_NAME("P0006", HttpStatus.BAD_REQUEST, "올바르지 않은 이름 형식입니다. 다시 입력해주세요. (공백, 특수문자 제외 20자 이내)"),
INVALID_UPLOAD_MATERIAL_REQUEST("P0007", HttpStatus.BAD_REQUEST, "부적절한 자료 업로드 요청입니다. 공백및 특수문자를 제외하고 다시 입력해주세요."),
;
Expand Down

0 comments on commit 32e4803

Please sign in to comment.