Skip to content

Commit

Permalink
feat: 장르 타입을 int로 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
HyungJu committed Jun 4, 2024
1 parent aaf0ab0 commit 536eb9d
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package kr.nagaza.nagazaserver.domain.model

data class Genre(
val genreId: String,
val genreId: Int,
val name: String,
)
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ interface CafeRoomRepository {

fun search(
queryString: String?,
genre: String?,
genre: Int?,
address1: String?,
address2: String?,
cafeId: String?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class CafeRoomRepositoryImpl(

override fun search(
queryString: String?,
genre: String?,
genre: Int?,
address1: String?,
address2: String?,
cafeId: String?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class CafeRoomController(

override fun searchRooms(
queryString: String?,
genre: String?,
genre: Int?,
address1: String?,
address2: String?,
cafeId: String?,
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -9,28 +10,35 @@ import org.springframework.stereotype.Controller
@Controller
class CafeSearchController(
private val cafeService: CafeService,
private val cafeRoomService: CafeRoomService,
) : CafeSearchApi {
override fun searchCafe(query: String): List<CafeResponse> {
return cafeService
.searchCafeByQuery(query)
.map(CafeResponse::fromModel)
}

override fun searchCafeByAddress(addressOne: String, addressTwo: String): List<CafeResponse> {
override fun searchCafeByAddress(
addressOne: String,
addressTwo: String,
): List<CafeResponse> {
return cafeService.getAllByAddresses(
addressOne = addressOne,
addressTwo = addressTwo,
).map(CafeResponse::fromModel)
}

override fun getCafeAreaFilters(): List<CafeAreaFilterResponse> {
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ class RoomSearchQuery(
val queryString: String?,
val address1: String?,
val address2: String?,
val genre: String?,
val genre: Int?,
val cafeId: String?,
)
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ data class CafeRoomResponse(
@Schema(description = "설명", example = "형주의 방탈출 설명")
val description: String,
@Schema(description = "장르 (장르 Id)", example = "['1', '2']")
val genre: Set<String>,
val genre: Set<Int>,
@Schema(description = "추천인원", example = "4")
val recommendedUser: Int,
@Schema(description = "방 이미지", example = "https://nagaza.kr/room/01HDNFJHCNS5E2W35YTB030TJ8.jpg")
Expand Down
10 changes: 10 additions & 0 deletions src/main/resources/db/migration/V2__.sql
Original file line number Diff line number Diff line change
@@ -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);

0 comments on commit 536eb9d

Please sign in to comment.