Skip to content

Commit

Permalink
feat: 검색 기능 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
CChuYong committed Oct 30, 2023
1 parent e3c9ae0 commit 9cd3241
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ interface CafeRepository {
fun findById(id: String): Cafe?
fun saveCafe(cafe: Cafe): Cafe
fun findAllByAddresses(addressOne: String, addressTwo: String): List<Cafe>
fun searchByQuery(query: String): List<Cafe>
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ class CafeService(
fun getById(cafeId: String): Cafe {
return cafeRepository.findById(cafeId) ?: throw CafeNotFoundException()
}

fun searchCafeByQuery(query: String) = cafeRepository.searchByQuery(query)
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import org.springframework.stereotype.Repository
@Repository
class CafeRepositoryImpl(
private val jpaCafeRepository: JpaCafeRepository,
private val qCafeRepository: QCafeRepository,
) : CafeRepository {
override fun findAll(): List<Cafe> {
return jpaCafeRepository.findAll().map { it.toModel() }
Expand All @@ -29,4 +30,10 @@ class CafeRepositoryImpl(
).map { it.toModel() }
}

override fun searchByQuery(query: String): List<Cafe> {
return qCafeRepository
.searchCafeByQuery(query)
.map { it.toModel() }
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package kr.nagaza.nagazaserver.infrastructure.jpa.repository

import com.querydsl.jpa.impl.JPAQueryFactory
import kr.nagaza.nagazaserver.infrastructure.jpa.entity.CafeEntity
import kr.nagaza.nagazaserver.infrastructure.jpa.entity.QCafeEntity.Companion.cafeEntity
import org.springframework.stereotype.Repository

@Repository
class QCafeRepository(
private val jpaQueryFactory: JPAQueryFactory,
) {
fun searchCafeByQuery(query: String): List<CafeEntity> {
return jpaQueryFactory
.select(cafeEntity)
.where(cafeEntity.cafeName.like("%${query}%"))
.fetch()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ class CafeSearchController(
private val cafeService: CafeService,
) : CafeSearchApi {
override fun searchCafe(query: String): List<CafeResponse> {
TODO("Not yet implemented")
return cafeService
.searchCafeByQuery(query)
.map { CafeResponse.fromModel(it) }
}

override fun searchCafeByAddress(addressOne: String, addressTwo: String): List<CafeResponse> {
Expand Down

0 comments on commit 9cd3241

Please sign in to comment.