diff --git a/src/main/kotlin/gdsc/plantory/plant/presentation/PlantCommandApi.kt b/src/main/kotlin/gdsc/plantory/plant/presentation/PlantCommandApi.kt index 45e174c..64f3770 100644 --- a/src/main/kotlin/gdsc/plantory/plant/presentation/PlantCommandApi.kt +++ b/src/main/kotlin/gdsc/plantory/plant/presentation/PlantCommandApi.kt @@ -22,7 +22,7 @@ import org.springframework.web.bind.annotation.RequestPart import org.springframework.web.bind.annotation.RestController import org.springframework.web.multipart.MultipartFile -@Tag(name = "Plant Query", description = "반려식물 정보 조회") +@Tag(name = "Plant Command", description = "반려식물 정보 수정") @RestController @RequestMapping("/api/v1/plants") class PlantCommandApi( diff --git a/src/main/kotlin/gdsc/plantory/plant/presentation/PlantQueryApi.kt b/src/main/kotlin/gdsc/plantory/plant/presentation/PlantQueryApi.kt index a9dcf9a..22071d6 100644 --- a/src/main/kotlin/gdsc/plantory/plant/presentation/PlantQueryApi.kt +++ b/src/main/kotlin/gdsc/plantory/plant/presentation/PlantQueryApi.kt @@ -18,7 +18,7 @@ import org.springframework.web.bind.annotation.RestController import java.time.LocalDate import java.time.YearMonth -@Tag(name = "Plant Command", description = "반려식물 정보 수정") +@Tag(name = "Plant Query", description = "반려식물 정보 조회") @RestController @RequestMapping("/api/v1/plants") class PlantQueryApi( diff --git a/src/main/kotlin/gdsc/plantory/plantInformation/domain/PlantInformationRepository.kt b/src/main/kotlin/gdsc/plantory/plantInformation/domain/PlantInformationRepository.kt index 83a7d94..7bb4729 100644 --- a/src/main/kotlin/gdsc/plantory/plantInformation/domain/PlantInformationRepository.kt +++ b/src/main/kotlin/gdsc/plantory/plantInformation/domain/PlantInformationRepository.kt @@ -1,7 +1,9 @@ package gdsc.plantory.plantInformation.domain import NotFoundException +import gdsc.plantory.plantInformation.presentation.dto.PlantInformationDto import org.springframework.data.jpa.repository.JpaRepository +import org.springframework.data.jpa.repository.Query import kotlin.jvm.optionals.getOrNull fun PlantInformationRepository.findByIdOrThrow(id: Long): PlantInformation { @@ -9,4 +11,15 @@ fun PlantInformationRepository.findByIdOrThrow(id: Long): PlantInformation { } interface PlantInformationRepository : JpaRepository { + @Query( + """ + SELECT new gdsc.plantory.plantInformation.presentation.dto.PlantInformationDto( + pi.id, + pi.species.name, + pi.species.familyName + ) + FROM PlantInformation pi + """ + ) + fun findAllSpeciesInformations(): List } diff --git a/src/main/kotlin/gdsc/plantory/plantInformation/presentation/PlantInformationQueryApi.kt b/src/main/kotlin/gdsc/plantory/plantInformation/presentation/PlantInformationQueryApi.kt new file mode 100644 index 0000000..440af38 --- /dev/null +++ b/src/main/kotlin/gdsc/plantory/plantInformation/presentation/PlantInformationQueryApi.kt @@ -0,0 +1,26 @@ +package gdsc.plantory.plantInformation.presentation + +import gdsc.plantory.plantInformation.presentation.dto.PlantInformationsLookupResponse +import gdsc.plantory.plantInformation.service.PlantInformationService +import io.swagger.v3.oas.annotations.Operation +import io.swagger.v3.oas.annotations.responses.ApiResponse +import io.swagger.v3.oas.annotations.tags.Tag +import org.springframework.http.ResponseEntity +import org.springframework.web.bind.annotation.GetMapping +import org.springframework.web.bind.annotation.RequestMapping +import org.springframework.web.bind.annotation.RestController + +@Tag(name = "Plant Information Query", description = "식물 정보 조회") +@RestController +@RequestMapping("/api/v1/plantInformations") +class PlantInformationQueryApi( + private val plantInformationService: PlantInformationService +) { + @Operation(summary = "식물 정보 조회", description = "등록된 모든 식물 정보를 조회합니다.") + @ApiResponse(responseCode = "200", description = "조회 성공") + @GetMapping + fun lookupAllPlantInformations(): ResponseEntity { + val plantInformations = plantInformationService.lookupAllPlantInformations() + return ResponseEntity.ok().body(plantInformations) + } +} \ No newline at end of file diff --git a/src/main/kotlin/gdsc/plantory/plantInformation/presentation/dto/PlantInformationDto.kt b/src/main/kotlin/gdsc/plantory/plantInformation/presentation/dto/PlantInformationDto.kt new file mode 100644 index 0000000..0bf6858 --- /dev/null +++ b/src/main/kotlin/gdsc/plantory/plantInformation/presentation/dto/PlantInformationDto.kt @@ -0,0 +1,7 @@ +package gdsc.plantory.plantInformation.presentation.dto + +data class PlantInformationDto( + val id: Long, + val species: String, + val familyName: String +) \ No newline at end of file diff --git a/src/main/kotlin/gdsc/plantory/plantInformation/presentation/dto/PlantInformationsLookupResponse.kt b/src/main/kotlin/gdsc/plantory/plantInformation/presentation/dto/PlantInformationsLookupResponse.kt new file mode 100644 index 0000000..659d5fc --- /dev/null +++ b/src/main/kotlin/gdsc/plantory/plantInformation/presentation/dto/PlantInformationsLookupResponse.kt @@ -0,0 +1,5 @@ +package gdsc.plantory.plantInformation.presentation.dto + +data class PlantInformationsLookupResponse( + val plantInformations: List +) diff --git a/src/main/kotlin/gdsc/plantory/plantInformation/service/PlantInformationService.kt b/src/main/kotlin/gdsc/plantory/plantInformation/service/PlantInformationService.kt new file mode 100644 index 0000000..b4e3753 --- /dev/null +++ b/src/main/kotlin/gdsc/plantory/plantInformation/service/PlantInformationService.kt @@ -0,0 +1,19 @@ +package gdsc.plantory.plantInformation.service + +import gdsc.plantory.plantInformation.domain.PlantInformationRepository +import gdsc.plantory.plantInformation.presentation.dto.PlantInformationsLookupResponse +import org.springframework.stereotype.Service +import org.springframework.transaction.annotation.Transactional + +@Service +@Transactional +class PlantInformationService( + private val plantInformationRepository: PlantInformationRepository, +) { + @Transactional(readOnly = true) + fun lookupAllPlantInformations(): PlantInformationsLookupResponse { + val findPlantInformations = plantInformationRepository.findAllSpeciesInformations() + + return PlantInformationsLookupResponse(findPlantInformations) + } +} \ No newline at end of file diff --git a/src/test/kotlin/gdsc/plantory/acceptance/PlantInformationAcceptanceTest.kt b/src/test/kotlin/gdsc/plantory/acceptance/PlantInformationAcceptanceTest.kt new file mode 100644 index 0000000..10f1c42 --- /dev/null +++ b/src/test/kotlin/gdsc/plantory/acceptance/PlantInformationAcceptanceTest.kt @@ -0,0 +1,20 @@ +package gdsc.plantory.acceptance + +import gdsc.plantory.acceptance.PlantInformationStep.Companion.식물_정보_조회_요청 +import gdsc.plantory.acceptance.PlantInformationStep.Companion.식물_정보_조회_응답_확인 +import gdsc.plantory.util.AcceptanceTest +import org.junit.jupiter.api.DisplayName +import org.junit.jupiter.api.Test + +@DisplayName("인수 : PlantInformation") +class PlantInformationAcceptanceTest : AcceptanceTest() { + + @Test + fun `식물 정보 조회`() { + // when + val 식물_정보_조회_요청_응답 = 식물_정보_조회_요청() + + // then + 식물_정보_조회_응답_확인(식물_정보_조회_요청_응답) + } +} diff --git a/src/test/kotlin/gdsc/plantory/acceptance/PlantInformationStep.kt b/src/test/kotlin/gdsc/plantory/acceptance/PlantInformationStep.kt new file mode 100644 index 0000000..9d21d89 --- /dev/null +++ b/src/test/kotlin/gdsc/plantory/acceptance/PlantInformationStep.kt @@ -0,0 +1,32 @@ +package gdsc.plantory.acceptance + +import io.restassured.RestAssured +import io.restassured.response.ExtractableResponse +import io.restassured.response.Response +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.assertAll +import org.springframework.http.HttpStatus + +class PlantInformationStep { + companion object { + fun 식물_정보_조회_요청(): ExtractableResponse { + return RestAssured + .given() + .log().all() + .`when`() + .get("/api/v1/plantInformations") + .then() + .log().all() + .extract() + } + + fun 식물_정보_조회_응답_확인(response: ExtractableResponse) { + assertAll( + { assertThat(response.statusCode()).isEqualTo(HttpStatus.OK.value()) }, + { assertThat(response.jsonPath().getString("plantInformations[].id")).isNotBlank() }, + { assertThat(response.jsonPath().getString("plantInformations[].species")).isNotBlank() }, + { assertThat(response.jsonPath().getString("plantInformations[].familyName")).isNotBlank() }, + ) + } + } +}