-
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: Banner 도메인 추가 * chore: Spring Cache 설정 추가 * feat: Banner 조회 로직 추가 * feat: Banner 조회 API 추가 * test: Banner Api test 추가 * test: Api test 공통화 * chore: 배포 오류 수정 - ddl-auto option으로 table 생성 - docker compose시 이전 Image 삭제 옵션 추가 * chore: CI scope 수정 - only push * refactor: Api resource url 수정 * style: method, dto naming 수정 * style: 변수명에 자료형 제거 * refactor: 불필요한 응답 필드 제거 * style: static import 제거 * test: SoftAssertions 적용
- Loading branch information
1 parent
c98a990
commit 69cd895
Showing
13 changed files
with
231 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,8 +2,6 @@ name: CI With Pull Request | |
|
||
on: | ||
push: | ||
pull_request: | ||
types: [opened, reopened] | ||
|
||
jobs: | ||
build: | ||
|
Submodule backend-submodule
updated
from 12a8c5 to b5ec60
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
21 changes: 21 additions & 0 deletions
21
src/main/kotlin/com/petqua/application/banner/BannerService.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,21 @@ | ||
package com.petqua.application.banner | ||
|
||
import com.petqua.application.banner.dto.BannerResponse | ||
import com.petqua.domain.banner.BannerRepository | ||
import org.springframework.cache.annotation.Cacheable | ||
import org.springframework.stereotype.Service | ||
import org.springframework.transaction.annotation.Transactional | ||
|
||
@Transactional | ||
@Service | ||
class BannerService( | ||
private val bannerRepository: BannerRepository, | ||
) { | ||
|
||
@Cacheable("banners") | ||
@Transactional(readOnly = true) | ||
fun readAll(): List<BannerResponse> { | ||
val banners = bannerRepository.findAll() | ||
return banners.map { BannerResponse.from(it) } | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/kotlin/com/petqua/application/banner/dto/BannerDtos.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,19 @@ | ||
package com.petqua.application.banner.dto | ||
|
||
import com.petqua.domain.banner.Banner | ||
|
||
data class BannerResponse( | ||
val id: Long, | ||
val imageUrl: String, | ||
val linkUrl: String, | ||
) { | ||
companion object { | ||
fun from(banner: Banner): BannerResponse { | ||
return BannerResponse( | ||
id = banner.id, | ||
imageUrl = banner.imageUrl, | ||
linkUrl = banner.linkUrl, | ||
) | ||
} | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/kotlin/com/petqua/common/cofig/CacheConfiguration.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,20 @@ | ||
package com.petqua.common.cofig | ||
|
||
import org.springframework.cache.CacheManager | ||
import org.springframework.cache.annotation.EnableCaching | ||
import org.springframework.cache.concurrent.ConcurrentMapCacheManager | ||
import org.springframework.context.annotation.Bean | ||
import org.springframework.context.annotation.Configuration | ||
|
||
|
||
@EnableCaching | ||
@Configuration | ||
class CacheConfiguration { | ||
|
||
@Bean | ||
fun cacheManager(): CacheManager { | ||
val cacheManager = ConcurrentMapCacheManager() | ||
cacheManager.setCacheNames(listOf("banners")) | ||
return cacheManager | ||
} | ||
} |
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,20 @@ | ||
package com.petqua.domain.banner | ||
|
||
import com.petqua.common.domain.BaseEntity | ||
import jakarta.persistence.Column | ||
import jakarta.persistence.Entity | ||
import jakarta.persistence.GeneratedValue | ||
import jakarta.persistence.GenerationType | ||
import jakarta.persistence.Id | ||
|
||
@Entity | ||
class Banner( | ||
@Id @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
val id: Long = 0L, | ||
|
||
@Column(nullable = false) | ||
val imageUrl: String, | ||
|
||
@Column(nullable = false) | ||
val linkUrl: String, | ||
) : BaseEntity() |
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,6 @@ | ||
package com.petqua.domain.banner | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository | ||
|
||
interface BannerRepository: JpaRepository<Banner, Long> { | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/kotlin/com/petqua/presentation/banner/BannerController.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,21 @@ | ||
package com.petqua.presentation.banner | ||
|
||
import com.petqua.application.banner.BannerService | ||
import com.petqua.application.banner.dto.BannerResponse | ||
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 | ||
|
||
@RequestMapping("/banners") | ||
@RestController | ||
class BannerController( | ||
private val bannerService: BannerService | ||
) { | ||
|
||
@GetMapping | ||
fun readAll(): ResponseEntity<List<BannerResponse>> { | ||
val response = bannerService.readAll() | ||
return ResponseEntity.ok(response) | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
src/test/kotlin/com/petqua/application/banner/BannerServiceTest.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,44 @@ | ||
package com.petqua.application.banner | ||
|
||
import com.petqua.domain.banner.Banner | ||
import com.petqua.domain.banner.BannerRepository | ||
import io.kotest.core.spec.style.BehaviorSpec | ||
import io.kotest.matchers.shouldBe | ||
import org.mockito.Mockito.atMost | ||
import org.mockito.Mockito.verify | ||
import org.springframework.boot.test.context.SpringBootTest | ||
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment.NONE | ||
import org.springframework.boot.test.mock.mockito.SpyBean | ||
|
||
@SpringBootTest(webEnvironment = NONE) | ||
class BannerServiceTest( | ||
private var bannerService: BannerService, | ||
@SpyBean private var bannerRepository: BannerRepository, | ||
) : BehaviorSpec({ | ||
|
||
Given("Banner 조회 테스트") { | ||
bannerRepository.saveAll( | ||
listOf( | ||
Banner(imageUrl = "imageUrlA", linkUrl = "linkUrlA"), | ||
Banner(imageUrl = "imageUrlB", linkUrl = "linkUrlB"), | ||
Banner(imageUrl = "imageUrlC", linkUrl = "linkUrlC"), | ||
) | ||
) | ||
|
||
When("Banner를 전체 조회 하면") { | ||
val results = bannerService.readAll() | ||
|
||
Then("모든 Banner가 조회 된다") { | ||
results.size shouldBe 3 | ||
} | ||
} | ||
|
||
When("Banner가 캐싱 되어 있으면") { | ||
repeat(5) { bannerService.readAll() } | ||
|
||
Then("퀴리가 발생 하지 않는다") { | ||
verify(bannerRepository, atMost(1)).findAll() | ||
} | ||
} | ||
} | ||
}) |
48 changes: 48 additions & 0 deletions
48
src/test/kotlin/com/petqua/presentation/banner/BannerControllerTest.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,48 @@ | ||
package com.petqua.presentation.banner | ||
|
||
import com.petqua.application.banner.dto.BannerResponse | ||
import com.petqua.domain.banner.Banner | ||
import com.petqua.domain.banner.BannerRepository | ||
import com.petqua.test.ApiTestConfig | ||
import io.restassured.module.kotlin.extensions.Extract | ||
import io.restassured.module.kotlin.extensions.Given | ||
import io.restassured.module.kotlin.extensions.Then | ||
import io.restassured.module.kotlin.extensions.When | ||
import org.assertj.core.api.SoftAssertions.assertSoftly | ||
import org.springframework.http.HttpStatus | ||
|
||
class BannerControllerTest( | ||
private val bannerRepository: BannerRepository | ||
) : ApiTestConfig() { | ||
init { | ||
Given("배너가 등록되어 있다.") { | ||
val banner = bannerRepository.saveAll( | ||
listOf( | ||
Banner(imageUrl = "imageUrlC", linkUrl = "linkUrlA"), | ||
Banner(imageUrl = "imageUrlB", linkUrl = "linkUrlB") | ||
) | ||
) | ||
|
||
When("배너 목록을 조회한다.") { | ||
val response = Given { | ||
log().all() | ||
} When { | ||
get("/banners") | ||
} Then { | ||
log().all() | ||
} Extract { | ||
response() | ||
} | ||
|
||
Then("배너 목록을 응답한다.") { | ||
val findBannerResponse = response.`as`(Array<BannerResponse>::class.java) | ||
|
||
assertSoftly { | ||
it.assertThat(response.statusCode).isEqualTo(HttpStatus.OK.value()) | ||
it.assertThat(findBannerResponse.size).isEqualTo(2) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
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.petqua.test | ||
|
||
import io.kotest.core.spec.style.BehaviorSpec | ||
import io.restassured.RestAssured | ||
import org.springframework.beans.factory.annotation.Autowired | ||
import org.springframework.boot.test.context.SpringBootTest | ||
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT | ||
import org.springframework.boot.test.web.server.LocalServerPort | ||
|
||
@SpringBootTest(webEnvironment = RANDOM_PORT) | ||
abstract class ApiTestConfig : BehaviorSpec() { | ||
|
||
@LocalServerPort | ||
protected val port: Int = RestAssured.port | ||
|
||
@Autowired | ||
private lateinit var dataCleaner: DataCleaner | ||
|
||
init { | ||
afterContainer { | ||
dataCleaner.clean() | ||
} | ||
} | ||
} |