[API] 파일삭제 추가
This commit is contained in:
@@ -1,10 +1,7 @@
|
|||||||
package com.alist.api.modules.file;
|
package com.alist.api.modules.file;
|
||||||
|
|
||||||
import com.alist.api.modules.file.dto.*;
|
import com.alist.api.modules.file.dto.*;
|
||||||
import com.alist.api.modules.file.form.FileUploadForm;
|
import com.alist.api.modules.file.form.*;
|
||||||
import com.alist.api.modules.file.form.TusHookForm;
|
|
||||||
import com.alist.api.modules.file.form.UploadCancelForm;
|
|
||||||
import com.alist.api.modules.file.form.UploadStatusForm;
|
|
||||||
import com.alist.api.common.response.ApiResponse;
|
import com.alist.api.common.response.ApiResponse;
|
||||||
import com.alist.api.common.response.ApiResponseCode;
|
import com.alist.api.common.response.ApiResponseCode;
|
||||||
import com.alist.api.modules.file.service.FileService;
|
import com.alist.api.modules.file.service.FileService;
|
||||||
@@ -265,4 +262,21 @@ public class FileController {
|
|||||||
.toString())
|
.toString())
|
||||||
.body(resource);
|
.body(resource);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Operation(
|
||||||
|
summary = "파일 삭제 처리",
|
||||||
|
description = "fileUuid 기준으로 완료된 파일(STATUS = 3)을 논리 삭제 처리합니다. 실제 파일은 삭제하지 않고 DEL_YN = 'Y'만 반영합니다."
|
||||||
|
)
|
||||||
|
@PostMapping("/delete")
|
||||||
|
public ResponseEntity<ApiResponse<String>> fileDelete(
|
||||||
|
@Valid @RequestBody FileDeleteForm fileDeleteForm
|
||||||
|
) {
|
||||||
|
boolean deleted = fileService.updateFileDelete(fileDeleteForm.fileDeleteDto());
|
||||||
|
|
||||||
|
if (!deleted) {
|
||||||
|
return ApiResponse.entity("", ApiResponseCode.CODE_2005, "파일 삭제");
|
||||||
|
}
|
||||||
|
|
||||||
|
return ApiResponse.entity("", ApiResponseCode.CODE_200);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
package com.alist.api.modules.file.dto;
|
||||||
|
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
public class FileDeleteDto {
|
||||||
|
private Integer userTokenIdx;
|
||||||
|
private String fileUuid;
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package com.alist.api.modules.file.form;
|
||||||
|
|
||||||
|
import com.alist.api.modules.file.dto.FileDeleteDto;
|
||||||
|
import jakarta.validation.constraints.NotBlank;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
public class FileDeleteForm {
|
||||||
|
@NotBlank
|
||||||
|
private String fileUuid;
|
||||||
|
|
||||||
|
public FileDeleteDto fileDeleteDto() {
|
||||||
|
FileDeleteDto fileDeleteDto = new FileDeleteDto();
|
||||||
|
fileDeleteDto.setFileUuid(fileUuid == null ? null : fileUuid.trim());
|
||||||
|
return fileDeleteDto;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -42,4 +42,10 @@ public interface FileMapper {
|
|||||||
FileDownloadDto selectFileDetailByFileUuid(FileDownloadDto fileDownloadDto);
|
FileDownloadDto selectFileDetailByFileUuid(FileDownloadDto fileDownloadDto);
|
||||||
|
|
||||||
void insertFileDownloadEventLog(FileDownloadDto fileDetailInfo);
|
void insertFileDownloadEventLog(FileDownloadDto fileDetailInfo);
|
||||||
|
|
||||||
|
int selectFileDeleteTargetCount(FileDeleteDto fileDeleteDto);
|
||||||
|
|
||||||
|
int updateFileDetailDeleteByFileUuid(FileDeleteDto fileDeleteDto);
|
||||||
|
|
||||||
|
int updateFileMasterDeleteByFileUuid(FileDeleteDto fileDeleteDto);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -667,4 +667,32 @@ public class FileService {
|
|||||||
|
|
||||||
return resolved;
|
return resolved;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Transactional
|
||||||
|
public boolean updateFileDelete(FileDeleteDto fileDeleteDto) {
|
||||||
|
if (fileDeleteDto == null || fileDeleteDto.getFileUuid() == null || fileDeleteDto.getFileUuid().isBlank()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Integer userTokenIdx = getLoginUserTokenIdx();
|
||||||
|
if (userTokenIdx == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
fileDeleteDto.setUserTokenIdx(userTokenIdx);
|
||||||
|
fileDeleteDto.setFileUuid(fileDeleteDto.getFileUuid().trim());
|
||||||
|
|
||||||
|
int allowed = fileMapper.selectFileDeleteTargetCount(fileDeleteDto);
|
||||||
|
if (allowed <= 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
int detailUpdated = fileMapper.updateFileDetailDeleteByFileUuid(fileDeleteDto);
|
||||||
|
if (detailUpdated <= 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
fileMapper.updateFileMasterDeleteByFileUuid(fileDeleteDto);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -299,4 +299,64 @@
|
|||||||
AND DEL_YN = 'N'
|
AND DEL_YN = 'N'
|
||||||
AND STATUS = 3
|
AND STATUS = 3
|
||||||
</update>
|
</update>
|
||||||
|
|
||||||
|
<select id="selectFileDeleteTargetCount" resultType="java.lang.Integer">
|
||||||
|
/*FileMapper.selectFileDeleteTargetCount*/
|
||||||
|
SELECT COUNT(*)
|
||||||
|
FROM ALISTLMS.FILE_DETAIL LFD
|
||||||
|
INNER JOIN ALISTLMS.FILE_MASTER LFM
|
||||||
|
ON LFM.FILE_MASTER_IDX = LFD.FILE_MASTER_IDX
|
||||||
|
AND LFM.DEL_YN = 'N'
|
||||||
|
INNER JOIN ALISTLMS.test_user_token LTUT
|
||||||
|
ON LTUT.user_idx = LFM.USER_IDX
|
||||||
|
WHERE LFD.FILE_UUID = #{fileUuid}
|
||||||
|
AND LTUT.user_token_idx = #{userTokenIdx}
|
||||||
|
AND LFD.DEL_YN = 'N'
|
||||||
|
AND LFD.STATUS = 3
|
||||||
|
AND LFM.STATUS = 3
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<update id="updateFileDetailDeleteByFileUuid">
|
||||||
|
/*FileMapper.updateFileDetailDeleteByFileUuid*/
|
||||||
|
UPDATE ALISTLMS.FILE_DETAIL LFD
|
||||||
|
INNER JOIN ALISTLMS.FILE_MASTER LFM
|
||||||
|
ON LFM.FILE_MASTER_IDX = LFD.FILE_MASTER_IDX
|
||||||
|
AND LFM.DEL_YN = 'N'
|
||||||
|
INNER JOIN ALISTLMS.test_user_token LTUT
|
||||||
|
ON LTUT.user_idx = LFM.USER_IDX
|
||||||
|
SET LFD.DEL_YN = 'Y'
|
||||||
|
, LFD.UPDATE_DATE = NOW()
|
||||||
|
WHERE LFD.FILE_UUID = #{fileUuid}
|
||||||
|
AND LTUT.user_token_idx = #{userTokenIdx}
|
||||||
|
AND LFD.DEL_YN = 'N'
|
||||||
|
AND LFD.STATUS = 3
|
||||||
|
AND LFM.STATUS = 3
|
||||||
|
</update>
|
||||||
|
|
||||||
|
<update id="updateFileMasterDeleteByFileUuid">
|
||||||
|
/*FileMapper.updateFileMasterDeleteByFileUuid*/
|
||||||
|
UPDATE ALISTLMS.FILE_MASTER LFM
|
||||||
|
INNER JOIN (
|
||||||
|
SELECT LFD.FILE_MASTER_IDX
|
||||||
|
FROM ALISTLMS.FILE_DETAIL LFD
|
||||||
|
WHERE LFD.FILE_UUID = #{fileUuid}
|
||||||
|
AND LFD.DEL_YN = 'Y'
|
||||||
|
LIMIT 1
|
||||||
|
) TARGET
|
||||||
|
ON TARGET.FILE_MASTER_IDX = LFM.FILE_MASTER_IDX
|
||||||
|
INNER JOIN ALISTLMS.test_user_token LTUT
|
||||||
|
ON LTUT.user_idx = LFM.USER_IDX
|
||||||
|
SET LFM.DEL_YN = 'Y'
|
||||||
|
, LFM.UPDATE_DATE = NOW()
|
||||||
|
WHERE LTUT.user_token_idx = #{userTokenIdx}
|
||||||
|
AND LFM.DEL_YN = 'N'
|
||||||
|
AND LFM.STATUS = 3
|
||||||
|
AND NOT EXISTS (
|
||||||
|
SELECT 1
|
||||||
|
FROM ALISTLMS.FILE_DETAIL CHK
|
||||||
|
WHERE CHK.FILE_MASTER_IDX = LFM.FILE_MASTER_IDX
|
||||||
|
AND CHK.DEL_YN = 'N'
|
||||||
|
)
|
||||||
|
</update>
|
||||||
|
|
||||||
</mapper>
|
</mapper>
|
||||||
Reference in New Issue
Block a user