사용 가능 공간 조회 API 추가
This commit is contained in:
@@ -4,6 +4,7 @@ import com.kamco.cd.training.config.api.ApiResponseDto;
|
||||
import com.kamco.cd.training.dataset.dto.DatasetDto;
|
||||
import com.kamco.cd.training.dataset.dto.DatasetObjDto;
|
||||
import com.kamco.cd.training.dataset.dto.DatasetObjDto.DatasetClass;
|
||||
import com.kamco.cd.training.dataset.dto.DatasetObjDto.DatasetStorage;
|
||||
import com.kamco.cd.training.dataset.service.DatasetService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
@@ -216,4 +217,22 @@ public class DatasetApiController {
|
||||
@Parameter(description = "compare, target", example = "compare") @RequestParam String type) {
|
||||
return ApiResponseDto.ok(datasetService.getDatasetObjByUuid(uuid, type));
|
||||
}
|
||||
|
||||
@Operation(summary = "남은 저장공간 조회", description = "남은 저장공간 조회 API")
|
||||
@ApiResponses(
|
||||
value = {
|
||||
@ApiResponse(
|
||||
responseCode = "200",
|
||||
description = "조회 성공",
|
||||
content =
|
||||
@Content(
|
||||
mediaType = "application/json",
|
||||
schema = @Schema(implementation = Page.class))),
|
||||
@ApiResponse(responseCode = "404", description = "저장 공간 조회 오류", content = @Content),
|
||||
@ApiResponse(responseCode = "500", description = "서버 오류", content = @Content)
|
||||
})
|
||||
@GetMapping("/usable-bytes")
|
||||
public ApiResponseDto<DatasetStorage> getUsableBytes() {
|
||||
return ApiResponseDto.ok(datasetService.getUsableBytes());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,4 +121,10 @@ public class DatasetObjDto {
|
||||
return DetectionClassification.valueOf(classCd.toUpperCase()).getDesc();
|
||||
}
|
||||
}
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public static class DatasetStorage {
|
||||
private String usableBytes;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,20 @@
|
||||
package com.kamco.cd.training.dataset.service;
|
||||
|
||||
import com.kamco.cd.training.common.exception.CustomApiException;
|
||||
import com.kamco.cd.training.common.service.FormatStorage;
|
||||
import com.kamco.cd.training.dataset.dto.DatasetDto;
|
||||
import com.kamco.cd.training.dataset.dto.DatasetObjDto;
|
||||
import com.kamco.cd.training.dataset.dto.DatasetObjDto.DatasetClass;
|
||||
import com.kamco.cd.training.dataset.dto.DatasetObjDto.DatasetStorage;
|
||||
import com.kamco.cd.training.dataset.dto.DatasetObjDto.SearchReq;
|
||||
import com.kamco.cd.training.postgres.core.DatasetCoreService;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
@@ -105,4 +110,26 @@ public class DatasetService {
|
||||
public List<DatasetClass> getDatasetObjByUuid(UUID uuid, String type) {
|
||||
return datasetCoreService.findDatasetObjClassByUuid(uuid, type);
|
||||
}
|
||||
|
||||
/**
|
||||
* 사용 가능 공간 조회
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public DatasetStorage getUsableBytes() {
|
||||
// 현재 실행 위치가 속한 디스크 기준
|
||||
try {
|
||||
FormatStorage.DiskUsage usage = FormatStorage.getDiskUsage(Path.of("."));
|
||||
log.debug("경로 : {}", usage.path());
|
||||
log.debug("총 저장공간 : {}", usage.totalText());
|
||||
log.debug("남은 저장공간 : {}", usage.usableText());
|
||||
log.debug("사용률 : {}", usage.usedPercent());
|
||||
|
||||
DatasetStorage datasetStorage = new DatasetStorage();
|
||||
datasetStorage.setUsableBytes(usage.usableText());
|
||||
return datasetStorage;
|
||||
} catch (Exception e) {
|
||||
throw new CustomApiException("NOT_FOUND", HttpStatus.NOT_FOUND);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user