From 83604785928383428d02a26b1d5776f297b2ca03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=8F=84=EA=B2=BD?= Date: Mon, 15 Apr 2024 20:06:02 +0900 Subject: [PATCH 1/2] add :: query api --- .../screen/presentation/ScreenController.kt | 33 +++++++++++++++++++ .../dto/response/QueryScreenResponse.kt | 11 +++++++ .../screen/service/QueryScreenService.kt | 28 ++++++++++++++++ 3 files changed, 72 insertions(+) create mode 100644 src/main/kotlin/hs/kr/equus/feed/domain/screen/presentation/ScreenController.kt create mode 100644 src/main/kotlin/hs/kr/equus/feed/domain/screen/presentation/dto/response/QueryScreenResponse.kt create mode 100644 src/main/kotlin/hs/kr/equus/feed/domain/screen/service/QueryScreenService.kt diff --git a/src/main/kotlin/hs/kr/equus/feed/domain/screen/presentation/ScreenController.kt b/src/main/kotlin/hs/kr/equus/feed/domain/screen/presentation/ScreenController.kt new file mode 100644 index 0000000..71a846b --- /dev/null +++ b/src/main/kotlin/hs/kr/equus/feed/domain/screen/presentation/ScreenController.kt @@ -0,0 +1,33 @@ +package hs.kr.equus.feed.domain.screen.presentation + +import hs.kr.equus.feed.domain.screen.presentation.dto.response.QueryScreenResponse +import hs.kr.equus.feed.domain.screen.presentation.dto.response.ScreenResponse +import hs.kr.equus.feed.domain.screen.service.CreateScreenService +import hs.kr.equus.feed.domain.screen.service.QueryScreenService +import org.springframework.http.HttpStatus +import org.springframework.web.bind.annotation.GetMapping +import org.springframework.web.bind.annotation.PostMapping +import org.springframework.web.bind.annotation.RequestMapping +import org.springframework.web.bind.annotation.RequestPart +import org.springframework.web.bind.annotation.ResponseStatus +import org.springframework.web.bind.annotation.RestController +import org.springframework.web.multipart.MultipartFile + +@RestController +@RequestMapping("/screen") +class ScreenController( + private val createScreenService: CreateScreenService, + private val queryScreenService: QueryScreenService +) { + + @ResponseStatus(value = HttpStatus.CREATED) + @PostMapping + fun createScreen( + @RequestPart(name = "image") image: MultipartFile + ): ScreenResponse = + createScreenService.execute(image) + + @GetMapping + fun queryScreen(): List = + queryScreenService.execute() +} diff --git a/src/main/kotlin/hs/kr/equus/feed/domain/screen/presentation/dto/response/QueryScreenResponse.kt b/src/main/kotlin/hs/kr/equus/feed/domain/screen/presentation/dto/response/QueryScreenResponse.kt new file mode 100644 index 0000000..910fb50 --- /dev/null +++ b/src/main/kotlin/hs/kr/equus/feed/domain/screen/presentation/dto/response/QueryScreenResponse.kt @@ -0,0 +1,11 @@ +package hs.kr.equus.feed.domain.screen.presentation.dto.response + +import java.time.LocalDateTime +import java.util.UUID + +data class QueryScreenResponse ( + val id: UUID, + val image: String, + val createAt: LocalDateTime, + val modifyAt: LocalDateTime +) diff --git a/src/main/kotlin/hs/kr/equus/feed/domain/screen/service/QueryScreenService.kt b/src/main/kotlin/hs/kr/equus/feed/domain/screen/service/QueryScreenService.kt new file mode 100644 index 0000000..7333803 --- /dev/null +++ b/src/main/kotlin/hs/kr/equus/feed/domain/screen/service/QueryScreenService.kt @@ -0,0 +1,28 @@ +package hs.kr.equus.feed.domain.screen.service + +import hs.kr.equus.feed.domain.screen.domain.repository.ScreenRepository +import hs.kr.equus.feed.domain.screen.presentation.dto.response.QueryScreenResponse +import hs.kr.equus.feed.infrastructure.s3.PathList +import hs.kr.equus.feed.infrastructure.s3.util.FileUtil +import org.springframework.stereotype.Service +import org.springframework.transaction.annotation.Transactional +import java.util.stream.Collectors + +@Service +class QueryScreenService( + private val screenRepository: ScreenRepository, + private val fileUtil: FileUtil +) { + @Transactional(readOnly = true) + fun execute(): List + = screenRepository.findAll() + .map { it -> + QueryScreenResponse( + it.id!!, + fileUtil.generateObjectUrl(it.image, PathList.SCREEN), + it.createdAt, + it.modifiedAt + ) + } +} + From 4e80bcd891ee765cc42ec2f995174c525a905cf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=8F=84=EA=B2=BD?= Date: Mon, 15 Apr 2024 20:18:18 +0900 Subject: [PATCH 2/2] ktlint --- .../screen/presentation/dto/response/QueryScreenResponse.kt | 2 +- .../equus/feed/domain/screen/service/QueryScreenService.kt | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/hs/kr/equus/feed/domain/screen/presentation/dto/response/QueryScreenResponse.kt b/src/main/kotlin/hs/kr/equus/feed/domain/screen/presentation/dto/response/QueryScreenResponse.kt index 910fb50..4181ef4 100644 --- a/src/main/kotlin/hs/kr/equus/feed/domain/screen/presentation/dto/response/QueryScreenResponse.kt +++ b/src/main/kotlin/hs/kr/equus/feed/domain/screen/presentation/dto/response/QueryScreenResponse.kt @@ -3,7 +3,7 @@ package hs.kr.equus.feed.domain.screen.presentation.dto.response import java.time.LocalDateTime import java.util.UUID -data class QueryScreenResponse ( +data class QueryScreenResponse( val id: UUID, val image: String, val createAt: LocalDateTime, diff --git a/src/main/kotlin/hs/kr/equus/feed/domain/screen/service/QueryScreenService.kt b/src/main/kotlin/hs/kr/equus/feed/domain/screen/service/QueryScreenService.kt index 7333803..aa5d2ab 100644 --- a/src/main/kotlin/hs/kr/equus/feed/domain/screen/service/QueryScreenService.kt +++ b/src/main/kotlin/hs/kr/equus/feed/domain/screen/service/QueryScreenService.kt @@ -6,7 +6,6 @@ import hs.kr.equus.feed.infrastructure.s3.PathList import hs.kr.equus.feed.infrastructure.s3.util.FileUtil import org.springframework.stereotype.Service import org.springframework.transaction.annotation.Transactional -import java.util.stream.Collectors @Service class QueryScreenService( @@ -14,8 +13,8 @@ class QueryScreenService( private val fileUtil: FileUtil ) { @Transactional(readOnly = true) - fun execute(): List - = screenRepository.findAll() + fun execute(): List = + screenRepository.findAll() .map { it -> QueryScreenResponse( it.id!!, @@ -25,4 +24,3 @@ class QueryScreenService( ) } } -