-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
94 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/main/java/org/ioteatime/meonghanyangserver/common/type/ImageSuccessType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/main/java/org/ioteatime/meonghanyangserver/image/controller/ImageDeviceApi.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package org.ioteatime.meonghanyangserver.image.controller; | ||
|
||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import org.ioteatime.meonghanyangserver.common.api.Api; | ||
import org.ioteatime.meonghanyangserver.image.dto.response.ImageSaveUrlResponse; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
|
||
@Tag(name = "Image Api", description = "Image 관련 API 목록입니다.") | ||
public interface ImageDeviceApi { | ||
@Operation(summary = "이미지 저장을 위한 presigned url을 발급 받습니다.", description = "담당자: 임지인") | ||
public Api<ImageSaveUrlResponse> getImageSaveUrl( | ||
@PathVariable Long cctvId, @PathVariable String fileName); | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/org/ioteatime/meonghanyangserver/image/controller/ImageDeviceController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package org.ioteatime.meonghanyangserver.image.controller; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.ioteatime.meonghanyangserver.common.api.Api; | ||
import org.ioteatime.meonghanyangserver.common.type.ImageSuccessType; | ||
import org.ioteatime.meonghanyangserver.image.dto.response.ImageSaveUrlResponse; | ||
import org.ioteatime.meonghanyangserver.image.service.ImageService; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/open-api/image") | ||
public class ImageDeviceController implements ImageDeviceApi { | ||
private final ImageService imageService; | ||
|
||
@GetMapping("/{cctvId}/{fileName}") | ||
public Api<ImageSaveUrlResponse> getImageSaveUrl( | ||
@PathVariable Long cctvId, @PathVariable String fileName) { | ||
ImageSaveUrlResponse imageSaveUrlResponse = imageService.getImageSaveUrl(cctvId, fileName); | ||
return Api.success(ImageSuccessType.CREATE_PRESIGNED_URL, imageSaveUrlResponse); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/org/ioteatime/meonghanyangserver/image/dto/response/ImageSaveUrlResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package org.ioteatime.meonghanyangserver.image.dto.response; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import jakarta.validation.constraints.NotNull; | ||
|
||
@Schema(description = "이미지 저장 Url 요청 응답") | ||
public record ImageSaveUrlResponse( | ||
@NotNull | ||
@Schema( | ||
description = "이미지 저장용 presigned url", | ||
example = "https://bucket.s3.ap-northeast-2.amazonaws.com/test?") | ||
String presignedUrl) {} |
9 changes: 9 additions & 0 deletions
9
src/main/java/org/ioteatime/meonghanyangserver/image/mapper/ImageResponseMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package org.ioteatime.meonghanyangserver.image.mapper; | ||
|
||
import org.ioteatime.meonghanyangserver.image.dto.response.ImageSaveUrlResponse; | ||
|
||
public class ImageResponseMapper { | ||
public static ImageSaveUrlResponse form(String presignedUrl) { | ||
return new ImageSaveUrlResponse(presignedUrl); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/org/ioteatime/meonghanyangserver/image/service/ImageService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package org.ioteatime.meonghanyangserver.image.service; | ||
|
||
import com.amazonaws.HttpMethod; | ||
import lombok.RequiredArgsConstructor; | ||
import org.ioteatime.meonghanyangserver.cctv.repository.CctvRepository; | ||
import org.ioteatime.meonghanyangserver.clients.s3.S3Client; | ||
import org.ioteatime.meonghanyangserver.common.exception.NotFoundException; | ||
import org.ioteatime.meonghanyangserver.common.type.CctvErrorType; | ||
import org.ioteatime.meonghanyangserver.image.dto.response.ImageSaveUrlResponse; | ||
import org.ioteatime.meonghanyangserver.image.mapper.ImageResponseMapper; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class ImageService { | ||
private final S3Client s3Client; | ||
private final CctvRepository cctvRepository; | ||
|
||
public ImageSaveUrlResponse getImageSaveUrl(Long cctvId, String fileName) { | ||
if (!cctvRepository.existsById(cctvId)) { | ||
throw new NotFoundException(CctvErrorType.NOT_FOUND); | ||
} | ||
|
||
String presignedUrl = s3Client.generatePreSignUrl(fileName, HttpMethod.PUT); | ||
return ImageResponseMapper.form(presignedUrl); | ||
} | ||
} |