-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: FastAPI 서버 api 호출을 통한 이미지 분류 기능 구현 (#98)
* feat: Feign 클라이언트 요청의 헤더를 확인하여 Content-Type 헤더를 설정 * feat: 이미지 분류 요청, 응답 dto 생성 * feat: FastAPI 서버 URL 및 엔드포인트 상수 정의 * feat: FastAPI 서버와의 통신을 위한 Feign 클라이언트 설정 * feat: 이미지 분류 기능 구현 * fix: fastapi 서버 민감한 정보 .env 파일에 관리 * fix: 이미지 API 상위 파라미터 RequestMapping으로 수정 * feat: task definition에 .env 파일에 작성한 환경 변수 추가
- Loading branch information
Showing
13 changed files
with
136 additions
and
20 deletions.
There are no files selected for viewing
12 changes: 11 additions & 1 deletion
12
src/main/java/com/api/pickle/domain/image/api/ImageController.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 |
---|---|---|
@@ -1,25 +1,35 @@ | ||
package com.api.pickle.domain.image.api; | ||
|
||
import com.api.pickle.domain.image.application.ImageService; | ||
import com.api.pickle.domain.image.dto.request.ImageClassificationRequest; | ||
import com.api.pickle.domain.image.dto.request.PresignedUrlRequest; | ||
import com.api.pickle.domain.image.dto.response.ClassifiedImageResponse; | ||
import com.api.pickle.domain.image.dto.response.PresignedUrlResponse; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@Tag(name = "이미지 API", description = "이미지 API입니다.") | ||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/images") | ||
public class ImageController { | ||
|
||
private final ImageService imageService; | ||
|
||
@Operation(summary = "이미지 Presigned URL 생성", description = "이미지 Presigned URL을 생성합니다.") | ||
@PostMapping("/images/upload-url") | ||
@PostMapping("/upload-url") | ||
public PresignedUrlResponse imagePresignedUrlCreate(@RequestBody PresignedUrlRequest request) { | ||
return imageService.createImagePresignedUrl(request); | ||
} | ||
|
||
@Operation(summary = "이미지 분류 결과", description = "이미지 분류 결과를 반환합니다.") | ||
@PostMapping("/classify") | ||
public ClassifiedImageResponse classifyImages(@RequestBody ImageClassificationRequest request) { | ||
return imageService.classifyImages(request); | ||
} | ||
} |
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
24 changes: 24 additions & 0 deletions
24
src/main/java/com/api/pickle/domain/image/dto/request/ImageClassificationRequest.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,24 @@ | ||
package com.api.pickle.domain.image.dto.request; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
import java.util.List; | ||
|
||
@AllArgsConstructor | ||
@Getter | ||
public class ImageClassificationRequest { | ||
|
||
@Schema(description = "업로드 한 이미지 URL 리스트") | ||
private List<String> imageUrls; | ||
|
||
@Schema(description = "그룹 간 유사도 설정 (true: 강하게, false: 약하게)") | ||
private Boolean strongClustering; | ||
|
||
@Schema(description = "선명하지 않은 사진 제외 (true: 체크)") | ||
private Boolean eyeClosing; | ||
|
||
@Schema(description = "눈 감은 사진 제외 (true: 체크)") | ||
private Boolean blurred; | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/com/api/pickle/domain/image/dto/response/ClassifiedImageResponse.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,15 @@ | ||
package com.api.pickle.domain.image.dto.response; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.util.List; | ||
|
||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Getter | ||
public class ClassifiedImageResponse { | ||
|
||
private List<List<String>> groupedImages; | ||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/com/api/pickle/global/config/feign/FeignConfig.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,28 @@ | ||
package com.api.pickle.global.config.feign; | ||
|
||
import feign.RequestInterceptor; | ||
import org.springframework.cloud.openfeign.EnableFeignClients; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
import java.util.Collections; | ||
|
||
@Configuration | ||
@EnableFeignClients(basePackages = "com.api.pickle.infra.config.feign") | ||
public class FeignConfig { | ||
@Bean | ||
public RequestInterceptor requestInterceptor() { | ||
return template -> { | ||
String contentType = template.headers() | ||
.getOrDefault("Content-Type", Collections.emptyList()) | ||
.stream() | ||
.findFirst() | ||
.orElse(""); | ||
if (contentType.equals("application/json")) { | ||
template.header("Content-Type", "application/json;charset=utf-8"); | ||
} else { | ||
template.header("Content-Type", "application/x-www-form-urlencoded;charset=utf-8"); | ||
} | ||
}; | ||
} | ||
} |
15 changes: 0 additions & 15 deletions
15
src/main/java/com/api/pickle/global/config/feign/KakaoFeignConfig.java
This file was deleted.
Oops, something went wrong.
13 changes: 13 additions & 0 deletions
13
src/main/java/com/api/pickle/infra/config/fastapi/FastAPIProperties.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,13 @@ | ||
package com.api.pickle.infra.config.fastapi; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
|
||
@ConfigurationProperties(prefix = "fastapi") | ||
@Getter | ||
@Setter | ||
public class FastAPIProperties { | ||
private String serverUrl; | ||
private String endpoint; | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/com/api/pickle/infra/config/feign/ImageClassificationClient.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,17 @@ | ||
package com.api.pickle.infra.config.feign; | ||
|
||
import com.api.pickle.domain.image.dto.request.ImageClassificationRequest; | ||
import com.api.pickle.domain.image.dto.response.ClassifiedImageResponse; | ||
import com.api.pickle.global.config.feign.FeignConfig; | ||
import org.springframework.cloud.openfeign.FeignClient; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
|
||
@FeignClient( | ||
name = "imageClassificationClient", | ||
url = "${fastapi.serverUrl}", | ||
configuration = FeignConfig.class) | ||
public interface ImageClassificationClient { | ||
@PostMapping(value = "${fastapi.endpoint}") | ||
ClassifiedImageResponse getClassifiedImages(@RequestBody ImageClassificationRequest request); | ||
} |
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
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,3 @@ | ||
fastapi: | ||
serverUrl: ${FAST_API_SERVER_URL} | ||
endpoint: ${FAST_API_SERVER_ENDPOINT} |
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