-
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.
Merge pull request #105 from TeamMiso/feat/recyclables-process
๐ :: AI ํต์ API ๊ตฌํ
- Loading branch information
Showing
9 changed files
with
125 additions
and
0 deletions.
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
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
5 changes: 5 additions & 0 deletions
5
...s311/miso/domain/recyclables/adapter/input/data/response/ListDetailRecyclablesResponse.kt
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,5 @@ | ||
package andreas311.miso.domain.recyclables.adapter.input.data.response | ||
|
||
data class ListDetailRecyclablesResponse( | ||
val recyclablesList: List<DetailRecyclablesResponse> | ||
) |
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
8 changes: 8 additions & 0 deletions
8
...in/andreas311/miso/domain/recyclables/application/port/input/ProcessRecyclablesUseCase.kt
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,8 @@ | ||
package andreas311.miso.domain.recyclables.application.port.input | ||
|
||
import andreas311.miso.domain.recyclables.application.port.input.dto.ListDetailRecyclablesDto | ||
import org.springframework.web.multipart.MultipartFile | ||
|
||
interface ProcessRecyclablesUseCase { | ||
fun execute(multipartFile: MultipartFile): ListDetailRecyclablesDto | ||
} |
5 changes: 5 additions & 0 deletions
5
...andreas311/miso/domain/recyclables/application/port/input/dto/ListDetailRecyclablesDto.kt
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,5 @@ | ||
package andreas311.miso.domain.recyclables.application.port.input.dto | ||
|
||
data class ListDetailRecyclablesDto( | ||
val recyclablesList: List<DetailRecyclablesDto> | ||
) |
46 changes: 46 additions & 0 deletions
46
...otlin/andreas311/miso/domain/recyclables/application/service/ProcessRecyclablesService.kt
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,46 @@ | ||
package andreas311.miso.domain.recyclables.application.service | ||
|
||
import andreas311.miso.common.annotation.ReadOnlyRollbackService | ||
import andreas311.miso.domain.recyclables.application.exception.RecyclablesNotFoundException | ||
import andreas311.miso.domain.recyclables.application.port.input.ProcessRecyclablesUseCase | ||
import andreas311.miso.domain.recyclables.application.port.input.dto.DetailRecyclablesDto | ||
import andreas311.miso.domain.recyclables.application.port.input.dto.ListDetailRecyclablesDto | ||
import andreas311.miso.domain.recyclables.application.port.output.QueryRecyclablesPort | ||
import andreas311.miso.domain.recyclables.domain.RecyclablesType | ||
import andreas311.miso.thirdparty.aws.s3.util.S3Util | ||
import org.springframework.beans.factory.annotation.Value | ||
import org.springframework.web.multipart.MultipartFile | ||
import org.springframework.web.reactive.function.BodyInserters | ||
import org.springframework.web.reactive.function.client.WebClient | ||
|
||
@ReadOnlyRollbackService | ||
class ProcessRecyclablesService( | ||
private val s3Util: S3Util, | ||
private val webClient: WebClient, | ||
private val queryRecyclablesPort: QueryRecyclablesPort | ||
) : ProcessRecyclablesUseCase { | ||
|
||
@Value("\${ai.url}") | ||
private val url: String = "" | ||
|
||
override fun execute(multipartFile: MultipartFile): ListDetailRecyclablesDto { | ||
val imageUrl = s3Util.execute(multipartFile) | ||
|
||
val resultList = | ||
webClient.post() | ||
.uri(url) | ||
.body(BodyInserters.fromValue(mapOf("imageURL" to imageUrl))) | ||
.retrieve() | ||
.bodyToMono(List::class.java) | ||
.map { it as List<String> } | ||
.block() ?: throw RecyclablesNotFoundException() | ||
|
||
val detailRecyclablesList = resultList.map { recyclablesType -> | ||
queryRecyclablesPort.findByRecyclablesTypeOrNull(RecyclablesType.valueOf(recyclablesType)) | ||
} | ||
|
||
val recyclablesList = detailRecyclablesList.filterNotNull().map { DetailRecyclablesDto(it) } | ||
|
||
return ListDetailRecyclablesDto(recyclablesList) | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/main/kotlin/andreas311/miso/global/webclient/WebClientConfig.kt
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 andreas311.miso.global.webclient | ||
|
||
import org.springframework.context.annotation.Bean | ||
import org.springframework.context.annotation.Configuration | ||
import org.springframework.http.client.reactive.ClientHttpConnector | ||
import org.springframework.http.client.reactive.ReactorClientHttpConnector | ||
import org.springframework.web.reactive.function.client.ExchangeStrategies | ||
import org.springframework.web.reactive.function.client.WebClient | ||
import reactor.netty.http.client.HttpClient | ||
import java.time.Duration | ||
|
||
@Configuration | ||
class WebClientConfig { | ||
@Bean | ||
fun webClient(): WebClient { | ||
val httpClient = HttpClient.create().responseTimeout(Duration.ofMinutes(1)) | ||
val connector: ClientHttpConnector = ReactorClientHttpConnector(httpClient) | ||
|
||
return WebClient.builder() | ||
.clientConnector(connector) | ||
.exchangeStrategies(ExchangeStrategies.builder() | ||
.codecs { configurer -> | ||
configurer.defaultCodecs().maxInMemorySize(16 * 1024 * 1024) | ||
} | ||
.build()) | ||
.build() | ||
} | ||
} |