Skip to content

Commit

Permalink
Merge pull request #6 from PLADI-ALM/feat/PDS-57-download-material
Browse files Browse the repository at this point in the history
[PDS-57] 아카이빙 자료 다운로드 API 기능구현
  • Loading branch information
dangnak2 authored Oct 18, 2023
2 parents 50fabc1 + 5172743 commit 60a05f3
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,14 @@ public ResponseCustom<?> deleteMaterial(
archivingService.deleteMaterial(materialId, user);
return ResponseCustom.OK();
}

/**
* 자료를 다운로드한다.
*/
@GetMapping("/materials/{materialsId}")
public ResponseCustom<?> downloadMaterial(
@PathVariable Long materialsId
) {
return ResponseCustom.OK(archivingService.downloadMaterial(materialsId));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.example.PLADIALMArchiving.archiving.dto.response;

import com.example.PLADIALMArchiving.global.utils.AwsS3FileUrlUtil;
import lombok.Builder;
import lombok.Data;
import lombok.RequiredArgsConstructor;

@Data
@RequiredArgsConstructor
public class DownloadMaterialRes {
private String awsS3FileUrl;

@Builder
public DownloadMaterialRes(String awsS3FileUrl) {
this.awsS3FileUrl = awsS3FileUrl;
}

public static DownloadMaterialRes toDto(String fileKey) {
return DownloadMaterialRes.builder()
.awsS3FileUrl(AwsS3FileUrlUtil.toUrl(fileKey))
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.example.PLADIALMArchiving.archiving.dto.request.RegisterProjectReq;
import com.example.PLADIALMArchiving.archiving.dto.request.SearchMaterialReq;
import com.example.PLADIALMArchiving.archiving.dto.request.UploadMaterialReq;
import com.example.PLADIALMArchiving.archiving.dto.response.DownloadMaterialRes;
import com.example.PLADIALMArchiving.archiving.dto.response.SearchMaterialRes;
import com.example.PLADIALMArchiving.archiving.entity.Category;
import com.example.PLADIALMArchiving.archiving.entity.Material;
Expand Down Expand Up @@ -79,4 +80,9 @@ public Page<SearchMaterialRes> searchMaterial(Long projectId, SearchMaterialReq

return filteredMaterials.map(SearchMaterialRes::toDto);
}

public DownloadMaterialRes downloadMaterial(Long materialsId) {
Material material = materialRepository.findById(materialsId).orElseThrow(() -> new BaseException(BaseResponseCode.MATERIAL_NOT_FOUND));
return DownloadMaterialRes.toDto(material.getFileKey());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

@RequiredArgsConstructor
@Component
public class AwsS3ImageUrlUtil {
public class AwsS3FileUrlUtil {

public static String bucket;
public static String region;
Expand All @@ -21,7 +21,7 @@ public void setBucket(String value) {
bucket = value;
}

public static String toUrl(String imageKey) {
return "https://"+bucket+".s3."+region+".amazonaws.com/"+imageKey;
public static String toUrl(String fileKey) {
return "https://"+bucket+".s3."+region+".amazonaws.com/"+fileKey;
}
}

0 comments on commit 60a05f3

Please sign in to comment.