Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions .github/workflows/dev_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ jobs:
echo "${{ secrets.APPLICATION_PROD_YML }}" > ./src/main/resources/application-prod.yml
shell: bash

- name: Generate Google Service Account Key
run: |
echo "${{ secrets.GOOGLE_SERVICE_ACCOUNT_KEY }}" > ./src/main/resources/jovial-monument-432709-s0-5455a7338d58.json
shell: bash

- name: Grant permission to gradlew
run: chmod +x gradlew

Expand Down
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,8 @@ node_modules/
### Application specific ###
application-dev.yml
application-prod.yml
application-local.yml
application-local.yml

### Google Service Account Keys ###
jovial-monument-432709-s0-5455a7338d58.json
*service-account*.json
5 changes: 5 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ dependencies {
// Jackson JSR310 모듈 (LocalDateTime 직렬화 지원)
implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310'

// Google Drive API 의존성
implementation 'com.google.apis:google-api-services-drive:v3-rev20220815-2.0.0'
implementation 'com.google.auth:google-auth-library-oauth2-http:1.19.0'
implementation 'com.google.http-client:google-http-client-jackson2:1.43.3'

}

tasks.named('test') {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package com.umc.domain.file.controller;

import com.umc.domain.file.dto.FileUploadResponse;
import com.umc.domain.file.service.GoogleDriveService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/files")
@RequiredArgsConstructor
@Slf4j
public class FileUploadController {

private final GoogleDriveService googleDriveService;

/**
* 파일 업로드
*/
@PostMapping("/upload/{recordId}")
public ResponseEntity<?> uploadFile(
@PathVariable String recordId,
@RequestParam("file") MultipartFile file) {

try {
if (file.isEmpty()) {
return ResponseEntity.badRequest().body("파일이 비어있습니다.");
}

FileUploadResponse response = googleDriveService.uploadFile(file, recordId);

return ResponseEntity.ok(Map.of(
"success", true,
"data", response
));

} catch (IOException e) {
log.error("파일 업로드 실패", e);
return ResponseEntity.internalServerError().body(Map.of(
"success", false,
"error", "파일 업로드에 실패했습니다: " + e.getMessage()
));
}
}

/**
* 레코드의 모든 파일 조회
*/
@GetMapping("/record/{recordId}")
public ResponseEntity<?> getRecordFiles(@PathVariable String recordId) {
try {
Map<String, List<FileUploadResponse>> files = googleDriveService.getRecordFiles(recordId);

return ResponseEntity.ok(Map.of(
"success", true,
"data", files
));

} catch (IOException e) {
log.error("파일 조회 실패", e);
return ResponseEntity.internalServerError().body(Map.of(
"success", false,
"error", "파일 조회에 실패했습니다: " + e.getMessage()
));
}
}

/**
* 파일 삭제
*/
@DeleteMapping("/{fileId}")
public ResponseEntity<?> deleteFile(@PathVariable String fileId) {
try {
googleDriveService.deleteFile(fileId);

return ResponseEntity.ok(Map.of(
"success", true,
"message", "파일이 성공적으로 삭제되었습니다."
));

} catch (IOException e) {
log.error("파일 삭제 실패", e);
return ResponseEntity.internalServerError().body(Map.of(
"success", false,
"error", "파일 삭제에 실패했습니다: " + e.getMessage()
));
}
}
}
28 changes: 28 additions & 0 deletions src/main/java/com/umc/domain/file/dto/FileUploadResponse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.umc.domain.file.dto;

import lombok.Data;

@Data
public class FileUploadResponse {
private String fileId;
private String fileName;
private String publicUrl;
private String directUrl;
private String recordId;
private String fileType;
private Long fileSize;
private String mimeType;

public FileUploadResponse(String fileId, String fileName, String publicUrl,
String directUrl, String recordId, String fileType,
Long fileSize, String mimeType) {
this.fileId = fileId;
this.fileName = fileName;
this.publicUrl = publicUrl;
this.directUrl = directUrl;
this.recordId = recordId;
this.fileType = fileType;
this.fileSize = fileSize;
this.mimeType = mimeType;
}
}
Loading