From 536eb9df2b8b2c171d2c5eb92f2a09332b4e278e Mon Sep 17 00:00:00 2001 From: HyungJu Date: Tue, 4 Jun 2024 13:42:15 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=9E=A5=EB=A5=B4=20=ED=83=80=EC=9E=85?= =?UTF-8?q?=EC=9D=84=20int=EB=A1=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../nagaza/nagazaserver/domain/model/Genre.kt | 2 +- .../domain/repository/CafeRoomRepository.kt | 2 +- .../infrastructure/jpa/entity/GenreEntity.kt | 2 +- .../jpa/repository/CafeRoomRepositoryImpl.kt | 2 +- .../presenter/restapi/api/CafeRoomApi.kt | 2 +- .../restapi/controller/CafeRoomController.kt | 2 +- .../controller/CafeSearchController.kt | 24 ++++++++++++------- .../restapi/dto/request/RoomSearchQuery.kt | 2 +- .../restapi/dto/response/CafeRoomResponse.kt | 2 +- src/main/resources/db/migration/V2__.sql | 10 ++++++++ 10 files changed, 34 insertions(+), 16 deletions(-) create mode 100644 src/main/resources/db/migration/V2__.sql diff --git a/src/main/kotlin/kr/nagaza/nagazaserver/domain/model/Genre.kt b/src/main/kotlin/kr/nagaza/nagazaserver/domain/model/Genre.kt index 74ff35f..8316a94 100644 --- a/src/main/kotlin/kr/nagaza/nagazaserver/domain/model/Genre.kt +++ b/src/main/kotlin/kr/nagaza/nagazaserver/domain/model/Genre.kt @@ -1,6 +1,6 @@ package kr.nagaza.nagazaserver.domain.model data class Genre( - val genreId: String, + val genreId: Int, val name: String, ) diff --git a/src/main/kotlin/kr/nagaza/nagazaserver/domain/repository/CafeRoomRepository.kt b/src/main/kotlin/kr/nagaza/nagazaserver/domain/repository/CafeRoomRepository.kt index 653890f..bdd8aa6 100644 --- a/src/main/kotlin/kr/nagaza/nagazaserver/domain/repository/CafeRoomRepository.kt +++ b/src/main/kotlin/kr/nagaza/nagazaserver/domain/repository/CafeRoomRepository.kt @@ -10,7 +10,7 @@ interface CafeRoomRepository { fun search( queryString: String?, - genre: String?, + genre: Int?, address1: String?, address2: String?, cafeId: String?, diff --git a/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/entity/GenreEntity.kt b/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/entity/GenreEntity.kt index 9fdc3de..9d10be4 100644 --- a/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/entity/GenreEntity.kt +++ b/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/entity/GenreEntity.kt @@ -9,7 +9,7 @@ import kr.nagaza.nagazaserver.domain.model.Genre class GenreEntity( @Id @Column(name = "genre_id") - val genreId: String, + val genreId: Int, @Column(name = "name", nullable = false) val name: String, ) { diff --git a/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/repository/CafeRoomRepositoryImpl.kt b/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/repository/CafeRoomRepositoryImpl.kt index a1320f2..a7c09cd 100644 --- a/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/repository/CafeRoomRepositoryImpl.kt +++ b/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/repository/CafeRoomRepositoryImpl.kt @@ -30,7 +30,7 @@ class CafeRoomRepositoryImpl( override fun search( queryString: String?, - genre: String?, + genre: Int?, address1: String?, address2: String?, cafeId: String?, diff --git a/src/main/kotlin/kr/nagaza/nagazaserver/presenter/restapi/api/CafeRoomApi.kt b/src/main/kotlin/kr/nagaza/nagazaserver/presenter/restapi/api/CafeRoomApi.kt index c5d9285..334ec30 100644 --- a/src/main/kotlin/kr/nagaza/nagazaserver/presenter/restapi/api/CafeRoomApi.kt +++ b/src/main/kotlin/kr/nagaza/nagazaserver/presenter/restapi/api/CafeRoomApi.kt @@ -18,7 +18,7 @@ interface CafeRoomApi { @GetMapping("/search") fun searchRooms( @Param("queryString") queryString: String?, - @Param("genre") genre: String?, + @Param("genre") genre: Int?, @Param("address1") address1: String?, @Param("address2") address2: String?, @Param("cafeId") cafeId: String?, diff --git a/src/main/kotlin/kr/nagaza/nagazaserver/presenter/restapi/controller/CafeRoomController.kt b/src/main/kotlin/kr/nagaza/nagazaserver/presenter/restapi/controller/CafeRoomController.kt index da5d89b..8e60fe9 100644 --- a/src/main/kotlin/kr/nagaza/nagazaserver/presenter/restapi/controller/CafeRoomController.kt +++ b/src/main/kotlin/kr/nagaza/nagazaserver/presenter/restapi/controller/CafeRoomController.kt @@ -22,7 +22,7 @@ class CafeRoomController( override fun searchRooms( queryString: String?, - genre: String?, + genre: Int?, address1: String?, address2: String?, cafeId: String?, diff --git a/src/main/kotlin/kr/nagaza/nagazaserver/presenter/restapi/controller/CafeSearchController.kt b/src/main/kotlin/kr/nagaza/nagazaserver/presenter/restapi/controller/CafeSearchController.kt index dd2ea77..55c7482 100644 --- a/src/main/kotlin/kr/nagaza/nagazaserver/presenter/restapi/controller/CafeSearchController.kt +++ b/src/main/kotlin/kr/nagaza/nagazaserver/presenter/restapi/controller/CafeSearchController.kt @@ -1,5 +1,6 @@ package kr.nagaza.nagazaserver.presenter.restapi.controller +import kr.nagaza.nagazaserver.domain.service.CafeRoomService import kr.nagaza.nagazaserver.domain.service.CafeService import kr.nagaza.nagazaserver.presenter.restapi.api.CafeSearchApi import kr.nagaza.nagazaserver.presenter.restapi.dto.response.CafeAreaFilterResponse @@ -9,6 +10,7 @@ import org.springframework.stereotype.Controller @Controller class CafeSearchController( private val cafeService: CafeService, + private val cafeRoomService: CafeRoomService, ) : CafeSearchApi { override fun searchCafe(query: String): List { return cafeService @@ -16,7 +18,10 @@ class CafeSearchController( .map(CafeResponse::fromModel) } - override fun searchCafeByAddress(addressOne: String, addressTwo: String): List { + override fun searchCafeByAddress( + addressOne: String, + addressTwo: String, + ): List { return cafeService.getAllByAddresses( addressOne = addressOne, addressTwo = addressTwo, @@ -24,13 +29,16 @@ class CafeSearchController( } override fun getCafeAreaFilters(): List { - val cafes = cafeService - .getAllCafes() - .filter { it.addressOne != null && it.addressTwo != null } - val addrOneGroup = cafes - .groupBy { it.addressOne!! } //i.e. 서울시 전체 - val addrTwoGroup = cafes - .groupBy { it.addressOne!! to it.addressTwo!! } //i.e. 강남구 전체 + val cafes = + cafeService + .getAllCafes() + .filter { it.addressOne != null && it.addressTwo != null } + val addrOneGroup = + cafes + .groupBy { it.addressOne!! } // i.e. 서울시 전체 + val addrTwoGroup = + cafes + .groupBy { it.addressOne!! to it.addressTwo!! } // i.e. 강남구 전체 val resultList = addrTwoGroup.toMutableMap() resultList["전국" to "전국 전체"] = cafes diff --git a/src/main/kotlin/kr/nagaza/nagazaserver/presenter/restapi/dto/request/RoomSearchQuery.kt b/src/main/kotlin/kr/nagaza/nagazaserver/presenter/restapi/dto/request/RoomSearchQuery.kt index bec02f4..a40aa8f 100644 --- a/src/main/kotlin/kr/nagaza/nagazaserver/presenter/restapi/dto/request/RoomSearchQuery.kt +++ b/src/main/kotlin/kr/nagaza/nagazaserver/presenter/restapi/dto/request/RoomSearchQuery.kt @@ -4,6 +4,6 @@ class RoomSearchQuery( val queryString: String?, val address1: String?, val address2: String?, - val genre: String?, + val genre: Int?, val cafeId: String?, ) diff --git a/src/main/kotlin/kr/nagaza/nagazaserver/presenter/restapi/dto/response/CafeRoomResponse.kt b/src/main/kotlin/kr/nagaza/nagazaserver/presenter/restapi/dto/response/CafeRoomResponse.kt index a9b0ecd..c6b39f0 100644 --- a/src/main/kotlin/kr/nagaza/nagazaserver/presenter/restapi/dto/response/CafeRoomResponse.kt +++ b/src/main/kotlin/kr/nagaza/nagazaserver/presenter/restapi/dto/response/CafeRoomResponse.kt @@ -14,7 +14,7 @@ data class CafeRoomResponse( @Schema(description = "설명", example = "형주의 방탈출 설명") val description: String, @Schema(description = "장르 (장르 Id)", example = "['1', '2']") - val genre: Set, + val genre: Set, @Schema(description = "추천인원", example = "4") val recommendedUser: Int, @Schema(description = "방 이미지", example = "https://nagaza.kr/room/01HDNFJHCNS5E2W35YTB030TJ8.jpg") diff --git a/src/main/resources/db/migration/V2__.sql b/src/main/resources/db/migration/V2__.sql new file mode 100644 index 0000000..6c53f49 --- /dev/null +++ b/src/main/resources/db/migration/V2__.sql @@ -0,0 +1,10 @@ +ALTER TABLE cafe_room_genre DROP CONSTRAINT fk_cafroogen_on_genre_entity; +ALTER TABLE genre MODIFY genre_id INT NOT NULL; + + +ALTER TABLE genre DROP PRIMARY KEY; +ALTER TABLE genre ADD PRIMARY KEY (genre_id); + +ALTER TABLE cafe_room_genre MODIFY genre_id INT NOT NULL; +ALTER TABLE cafe_room_genre + ADD CONSTRAINT fk_cafroogen_on_genre_entity FOREIGN KEY (genre_id) REFERENCES genre (genre_id);