-
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 #40 from TEAM-CLIP/feat/9
feat : 가게 리스트 조회 API 구현
- Loading branch information
Showing
23 changed files
with
526 additions
and
12 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
Application-Module/src/main/kotlin/com/clip/application/store/port/in/GetStoreUseCase.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,38 @@ | ||
package com.clip.application.store.port.`in` | ||
|
||
interface GetStoreUseCase { | ||
|
||
fun getAll(query: GetAllQuery): GetAllResponse | ||
|
||
data class GetAllQuery( | ||
val userId: String, | ||
val zoneId: String? | ||
) | ||
|
||
data class GetAllResponse( | ||
val registeredStore: List<RegisteredStore>, | ||
val unregisteredStore: List<UnregisteredStore>, | ||
) | ||
|
||
data class RegisteredStore( | ||
val storeId: String, | ||
val storeName: String, | ||
val storeImgUrl: String, | ||
val favoriteUserCount: Long, | ||
val isFavorited: Boolean, | ||
val storeType: String, | ||
val discountPolicy : List<DiscountPolicy> | ||
) | ||
|
||
data class DiscountPolicy( | ||
val discountType: String, | ||
val discountDescription: String | ||
) | ||
|
||
data class UnregisteredStore( | ||
val storeId: String, | ||
val storeName: String, | ||
val storeImgUrl: String, | ||
val storeType: String | ||
) | ||
} |
8 changes: 8 additions & 0 deletions
8
...Module/src/main/kotlin/com/clip/application/store/port/out/StoreCategoryManagementPort.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 com.clip.application.store.port.out | ||
|
||
import com.clip.domain.common.DomainId | ||
import com.clip.domain.store.entity.StoreCategory | ||
|
||
interface StoreCategoryManagementPort { | ||
fun getCategoriesBy(categoryIds: List<DomainId>): List<StoreCategory> | ||
} |
10 changes: 10 additions & 0 deletions
10
...ication-Module/src/main/kotlin/com/clip/application/store/port/out/StoreManagementPort.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,10 @@ | ||
package com.clip.application.store.port.out | ||
|
||
import com.clip.domain.common.DomainId | ||
import com.clip.domain.store.entity.Store | ||
|
||
interface StoreManagementPort { | ||
fun getAllStores(zoneId: DomainId?): List<Store> | ||
fun countFavoriteUsersBy(storeIds: List<DomainId>): LinkedHashMap<DomainId, Long> | ||
fun getFavoritedStoreIdsBy(userId: DomainId, storeIds: List<DomainId>): LinkedHashSet<DomainId> | ||
} |
58 changes: 58 additions & 0 deletions
58
Application-Module/src/main/kotlin/com/clip/application/store/service/StoreQueryService.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,58 @@ | ||
package com.clip.application.store.service | ||
|
||
import com.clip.application.store.port.`in`.GetStoreUseCase | ||
import com.clip.application.store.port.out.StoreCategoryManagementPort | ||
import com.clip.application.store.port.out.StoreManagementPort | ||
import com.clip.domain.common.DomainId | ||
import org.springframework.stereotype.Service | ||
import org.springframework.transaction.annotation.Transactional | ||
|
||
@Service | ||
@Transactional(readOnly = true) | ||
class StoreQueryService( | ||
private val storeManagementPort: StoreManagementPort, | ||
private val storeCategoryManagementPort: StoreCategoryManagementPort | ||
) : GetStoreUseCase{ | ||
|
||
override fun getAll(query: GetStoreUseCase.GetAllQuery): GetStoreUseCase.GetAllResponse { | ||
val stores = storeManagementPort.getAllStores(query.zoneId?.let { DomainId(it) }) | ||
val storeIds = stores.map { it.id } | ||
|
||
val favoriteCountsMap = storeManagementPort.countFavoriteUsersBy(storeIds) | ||
val userFavoritedStoreIds = storeManagementPort.getFavoritedStoreIdsBy(DomainId(query.userId), storeIds) | ||
|
||
val categories = storeCategoryManagementPort.getCategoriesBy(stores.map { it.storeCategory.categoryId }) | ||
val categoryMap = categories.associateBy { it.id } | ||
|
||
return GetStoreUseCase.GetAllResponse( | ||
registeredStore = stores.filter { it.storeInfo.isRegistered }.map { store -> | ||
with(store) { | ||
GetStoreUseCase.RegisteredStore( | ||
storeId = id.value, | ||
storeName = storeInfo.name, | ||
storeImgUrl = storeInfo.imgUrl, | ||
favoriteUserCount = favoriteCountsMap[id] ?: 0, | ||
isFavorited = userFavoritedStoreIds.contains(id), | ||
storeType = categoryMap.getValue(storeCategory.categoryId).type.name, | ||
discountPolicy = discount.map { | ||
GetStoreUseCase.DiscountPolicy( | ||
discountType = it.discountPolicyMethod.name, | ||
discountDescription = it.title | ||
) | ||
} | ||
) | ||
} | ||
}, | ||
unregisteredStore = stores.filterNot { it.storeInfo.isRegistered }.map { store -> | ||
with(store) { | ||
GetStoreUseCase.UnregisteredStore( | ||
storeId = id.value, | ||
storeName = storeInfo.name, | ||
storeImgUrl = storeInfo.imgUrl, | ||
storeType = categoryMap.getValue(storeCategory.categoryId).type.name, | ||
) | ||
} | ||
} | ||
) | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
Bootstrap-Module/Api/src/main/kotlin/com/clip/api/store/api/StoreApi.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 |
---|---|---|
@@ -1,11 +1,46 @@ | ||
package com.clip.api.store.api | ||
|
||
import com.clip.api.common.security.annotation.AccessUser | ||
import com.clip.api.store.dto.GetAllStoreResponse | ||
import io.swagger.v3.oas.annotations.Operation | ||
import io.swagger.v3.oas.annotations.media.Content | ||
import io.swagger.v3.oas.annotations.media.Schema | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse | ||
import io.swagger.v3.oas.annotations.responses.ApiResponses | ||
import io.swagger.v3.oas.annotations.tags.Tag | ||
import org.springframework.web.bind.annotation.GetMapping | ||
import org.springframework.web.bind.annotation.RequestMapping | ||
import org.springframework.web.bind.annotation.RequestParam | ||
|
||
@Tag(name = "Store", description = "Store API") | ||
@RequestMapping("/api/v1/stores") | ||
interface StoreApi { | ||
|
||
@Operation(summary = "가게 목록 조회") | ||
@GetMapping | ||
@ApiResponse | ||
@ApiResponses( | ||
value = [ | ||
ApiResponse( | ||
responseCode = "200", | ||
description = "전체 가게 목록 조회 성공", | ||
content = [ | ||
Content( | ||
mediaType = "application/json", | ||
schema = Schema(implementation = GetAllStoreResponse::class), | ||
), | ||
], | ||
), | ||
], | ||
) | ||
fun getSpaces( | ||
@AccessUser userId: String, | ||
@RequestParam(value = "region") region: String? | ||
): GetAllStoreResponse | ||
|
||
|
||
|
||
|
||
|
||
|
||
} |
47 changes: 47 additions & 0 deletions
47
Bootstrap-Module/Api/src/main/kotlin/com/clip/api/store/controller/StoreController.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,47 @@ | ||
package com.clip.api.store.controller | ||
|
||
import com.clip.api.store.api.StoreApi | ||
import com.clip.api.store.dto.GetAllStoreResponse | ||
import com.clip.api.store.dto.GetAllStoreResponse.UnregisteredStoreResponse | ||
import com.clip.api.store.dto.GetAllStoreResponse.RegisteredStoreResponse | ||
import com.clip.application.store.port.`in`.GetStoreUseCase | ||
import org.springframework.web.bind.annotation.RestController | ||
|
||
@RestController | ||
class StoreController( | ||
private val getStoreUseCase: GetStoreUseCase | ||
) : StoreApi { | ||
|
||
override fun getSpaces(userId: String, zoneId: String?): GetAllStoreResponse { | ||
val response = getStoreUseCase.getAll( | ||
GetStoreUseCase.GetAllQuery(userId, zoneId) | ||
) | ||
return GetAllStoreResponse( | ||
response.registeredStore.map { registeredStore -> | ||
RegisteredStoreResponse( | ||
registeredStore.storeId, | ||
registeredStore.storeName, | ||
registeredStore.storeImgUrl, | ||
registeredStore.favoriteUserCount, | ||
registeredStore.isFavorited, | ||
registeredStore.storeType, | ||
registeredStore.discountPolicy.map { | ||
RegisteredStoreResponse.DiscountPolicyResponse( | ||
it.discountType, | ||
it.discountDescription | ||
) | ||
} | ||
) | ||
}, | ||
response.unregisteredStore.map { | ||
UnregisteredStoreResponse( | ||
it.storeId, | ||
it.storeName, | ||
it.storeImgUrl, | ||
it.storeType | ||
) | ||
} | ||
|
||
) | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
Bootstrap-Module/Api/src/main/kotlin/com/clip/api/store/dto/GetAllStoreResponse.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,51 @@ | ||
package com.clip.api.store.dto | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema | ||
|
||
@Schema(description = "가게 리스트 확인 응답") | ||
data class GetAllStoreResponse( | ||
@Schema(description = "입점된 가게 리스트") | ||
val registered: List<RegisteredStoreResponse> = emptyList(), | ||
@Schema(description = "미입점 가게 리스트") | ||
val unregistered: List<UnregisteredStoreResponse> = emptyList() | ||
) { | ||
@Schema(description = "입점된 가게 정보") | ||
data class RegisteredStoreResponse( | ||
@Schema(description = "가게 ID") | ||
val storeId: String, | ||
@Schema(description = "가게 이름") | ||
val storeName: String, | ||
@Schema(description = "가게 이미지 URL") | ||
val storeImgUrl: String, | ||
@Schema(description = "가게 단골 수") | ||
val favoriteUserCount: Long, | ||
@Schema(description = "가게 단골 지정 여부") | ||
val isFavorited: Boolean, | ||
@Schema(description = "가게 타입") | ||
val storeType: String, | ||
@Schema(description = "할인 정책") | ||
val discountPolicy: List<DiscountPolicyResponse> = emptyList() | ||
) { | ||
@Schema(description = "할인 정책") | ||
data class DiscountPolicyResponse( | ||
@Schema(description = "할인 타입") | ||
val discountType: String?, | ||
@Schema(description = "할인 설명") | ||
val discountDescription: String? | ||
) | ||
} | ||
|
||
@Schema(description = "입점된 가게 정보") | ||
data class UnregisteredStoreResponse( | ||
@Schema(description = "가게 ID") | ||
val storeId: String, | ||
@Schema(description = "가게 이름") | ||
val storeName: String, | ||
@Schema(description = "가게 이미지 URL") | ||
val storeImgUrl: String, | ||
@Schema(description = "가게 타입") | ||
val storeType: String | ||
) { | ||
} | ||
|
||
} |
7 changes: 7 additions & 0 deletions
7
Domain-Module/src/main/kotlin/com/clip/domain/common/Aggregate.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,7 @@ | ||
package com.clip.domain.common | ||
|
||
abstract class Aggregate<T : Aggregate<T>>( | ||
val id: DomainId, | ||
) { | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
Domain-Module/src/main/kotlin/com/clip/domain/store/entity/Store.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,16 @@ | ||
package com.clip.domain.store.entity | ||
|
||
import com.clip.domain.common.Aggregate | ||
import com.clip.domain.common.DomainId | ||
import com.clip.domain.store.vo.StoreCategoryInfo | ||
import com.clip.domain.store.vo.DiscountInfo | ||
import com.clip.domain.store.vo.StoreInfo | ||
|
||
class Store( | ||
id: DomainId, | ||
val storeInfo: StoreInfo, | ||
val storeCategory: StoreCategoryInfo, | ||
val discount : List<DiscountInfo> | ||
) : Aggregate<Store>(id) { | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
Domain-Module/src/main/kotlin/com/clip/domain/store/entity/StoreCategory.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,11 @@ | ||
package com.clip.domain.store.entity | ||
|
||
import com.clip.domain.common.Aggregate | ||
import com.clip.domain.common.DomainId | ||
import com.clip.domain.store.enums.Storetype | ||
|
||
class StoreCategory( | ||
id : DomainId, | ||
val type : Storetype | ||
) : Aggregate<StoreCategory>(id) { | ||
} |
11 changes: 11 additions & 0 deletions
11
Domain-Module/src/main/kotlin/com/clip/domain/store/vo/DiscountInfo.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,11 @@ | ||
package com.clip.domain.store.vo | ||
|
||
import com.clip.domain.common.DomainId | ||
import com.clip.domain.store.enums.DiscountPolicyMethod | ||
|
||
data class DiscountInfo( | ||
val discountId: DomainId, | ||
val discountPolicyMethod: DiscountPolicyMethod, | ||
val title: String, | ||
) { | ||
} |
6 changes: 6 additions & 0 deletions
6
Domain-Module/src/main/kotlin/com/clip/domain/store/vo/StoreCategoryInfo.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,6 @@ | ||
package com.clip.domain.store.vo | ||
|
||
import com.clip.domain.common.DomainId | ||
|
||
data class StoreCategoryInfo(val categoryId: DomainId) { | ||
} |
15 changes: 15 additions & 0 deletions
15
Domain-Module/src/main/kotlin/com/clip/domain/store/vo/StoreInfo.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,15 @@ | ||
package com.clip.domain.store.vo | ||
|
||
data class StoreInfo( | ||
val name: String, | ||
val imgUrl: String, | ||
val introduction: String?, | ||
val isRegistered: Boolean, | ||
val storePlace: StorePlace, | ||
) { | ||
data class StorePlace( | ||
val longitude: Double, | ||
val latitude: Double, | ||
) { | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
...-Module/Persistence/src/main/kotlin/com/clip/persistence/jpa/store/StoreCategoryMapper.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,14 @@ | ||
package com.clip.persistence.jpa.store | ||
|
||
import com.clip.domain.common.DomainId | ||
import com.clip.domain.store.entity.StoreCategory | ||
import com.clip.persistence.jpa.store.entity.StoreCategoryEntity | ||
|
||
object StoreCategoryMapper { | ||
fun toStoreCategory(storeCategoryEntity: StoreCategoryEntity): StoreCategory { | ||
return StoreCategory( | ||
id = DomainId(storeCategoryEntity.id), | ||
type = storeCategoryEntity.type | ||
) | ||
} | ||
} |
Oops, something went wrong.