From a74d43c8a87abd5799d04c231ffabbe255fe96d2 Mon Sep 17 00:00:00 2001 From: HyungJu Date: Sat, 24 Feb 2024 19:33:46 +0900 Subject: [PATCH 1/4] =?UTF-8?q?feat:=20=EB=B0=A9=20=EA=B2=80=EC=83=89=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../nagazaserver/domain/model/CafeRoom.kt | 9 ++- .../nagaza/nagazaserver/domain/model/Genre.kt | 6 ++ .../domain/repository/CafeRoomRepository.kt | 8 +- .../domain/service/CafeRoomService.kt | 11 ++- .../jpa/entity/CafeRoomEntity.kt | 75 +++++++++++-------- .../infrastructure/jpa/entity/GenreEntity.kt | 29 +++++++ .../jpa/repository/CafeRoomRepositoryImpl.kt | 22 +++++- .../jpa/repository/JpaCafeRoomRepository.kt | 24 +++++- .../presenter/restapi/api/CafeRoomApi.kt | 14 ++-- .../restapi/controller/CafeRoomController.kt | 26 +++++-- .../restapi/dto/request/RoomSearchQuery.kt | 9 +++ 11 files changed, 180 insertions(+), 53 deletions(-) create mode 100644 src/main/kotlin/kr/nagaza/nagazaserver/domain/model/Genre.kt create mode 100644 src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/entity/GenreEntity.kt create mode 100644 src/main/kotlin/kr/nagaza/nagazaserver/presenter/restapi/dto/request/RoomSearchQuery.kt diff --git a/src/main/kotlin/kr/nagaza/nagazaserver/domain/model/CafeRoom.kt b/src/main/kotlin/kr/nagaza/nagazaserver/domain/model/CafeRoom.kt index 0820394..4522f08 100644 --- a/src/main/kotlin/kr/nagaza/nagazaserver/domain/model/CafeRoom.kt +++ b/src/main/kotlin/kr/nagaza/nagazaserver/domain/model/CafeRoom.kt @@ -1,11 +1,16 @@ package kr.nagaza.nagazaserver.domain.model +import java.util.* + data class CafeRoom( val roomId: String, val cafeId: String, - val genre: String, + val title: String, + val description: String, + val genre: Set, val timeout: Int, val recommendedUserCnt: Int, val roomImgUrl: String?, - val description: String, + val createdAt: Date, + val updatedAt: Date, ) diff --git a/src/main/kotlin/kr/nagaza/nagazaserver/domain/model/Genre.kt b/src/main/kotlin/kr/nagaza/nagazaserver/domain/model/Genre.kt new file mode 100644 index 0000000..74ff35f --- /dev/null +++ b/src/main/kotlin/kr/nagaza/nagazaserver/domain/model/Genre.kt @@ -0,0 +1,6 @@ +package kr.nagaza.nagazaserver.domain.model + +data class Genre( + val genreId: String, + 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 40a0962..6dd6bd9 100644 --- a/src/main/kotlin/kr/nagaza/nagazaserver/domain/repository/CafeRoomRepository.kt +++ b/src/main/kotlin/kr/nagaza/nagazaserver/domain/repository/CafeRoomRepository.kt @@ -7,5 +7,11 @@ interface CafeRoomRepository { fun findByRoomId(roomId: String): CafeRoom? - fun getAllGenres(): List + fun search( + queryString: String?, + genre: String?, + address1: String?, + address2: String?, + cafeId: String?, + ): List } diff --git a/src/main/kotlin/kr/nagaza/nagazaserver/domain/service/CafeRoomService.kt b/src/main/kotlin/kr/nagaza/nagazaserver/domain/service/CafeRoomService.kt index a9b5ea6..4b1be70 100644 --- a/src/main/kotlin/kr/nagaza/nagazaserver/domain/service/CafeRoomService.kt +++ b/src/main/kotlin/kr/nagaza/nagazaserver/domain/service/CafeRoomService.kt @@ -6,6 +6,7 @@ import kr.nagaza.nagazaserver.domain.exception.CafeRoomNotFoundException import kr.nagaza.nagazaserver.domain.model.CafeRoom import kr.nagaza.nagazaserver.domain.repository.CafeRepository import kr.nagaza.nagazaserver.domain.repository.CafeRoomRepository +import kr.nagaza.nagazaserver.presenter.restapi.dto.request.RoomSearchQuery import org.springframework.stereotype.Service @Service @@ -25,7 +26,13 @@ class CafeRoomService( return cafeRoomRepository.findByRoomId(roomId) ?: throw CafeRoomNotFoundException() } - fun getAllGenres(): List { - return cafeRoomRepository.getAllGenres() + fun search(cafeRoomSearchQuery: RoomSearchQuery): List { + return cafeRoomRepository.search( + queryString = cafeRoomSearchQuery.queryString, + genre = cafeRoomSearchQuery.genre, + address1 = cafeRoomSearchQuery.address1, + address2 = cafeRoomSearchQuery.address2, + cafeId = cafeRoomSearchQuery.cafeId, + ) } } diff --git a/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/entity/CafeRoomEntity.kt b/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/entity/CafeRoomEntity.kt index e4c4416..6afd144 100644 --- a/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/entity/CafeRoomEntity.kt +++ b/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/entity/CafeRoomEntity.kt @@ -2,62 +2,75 @@ package kr.nagaza.nagazaserver.infrastructure.jpa.entity import jakarta.persistence.* import kr.nagaza.nagazaserver.domain.model.CafeRoom +import org.hibernate.annotations.CreationTimestamp +import java.util.* @Entity(name = "cafe_room") class CafeRoomEntity( @Id @Column(name = "room_id") val roomId: String, - @Column(name = "cafe_id") val cafeId: String, - - @Column(name = "genre") - val genre: String, - + @Column(name = "title") + val title: String, + @Column(name = "description") + val description: String, + @ManyToMany + @JoinTable( + name = "cafe_room_genre", + joinColumns = [JoinColumn(name = "room_id")], + inverseJoinColumns = [JoinColumn(name = "genre_id")], + ) + val genre: MutableSet = mutableSetOf(), @Column(name = "timeout") val timeout: Int, - @Column(name = "recommend_user") val recommendUserCnt: Int, - @Column(name = "room_img_url") val roomImgUrl: String?, - - @Column(name = "description") - val description: String, - @ManyToMany(fetch = FetchType.LAZY) @JoinTable( name = "cafe_room_like", joinColumns = [JoinColumn(name = "room_id")], - inverseJoinColumns = [JoinColumn(name = "user_id")] + inverseJoinColumns = [JoinColumn(name = "user_id")], ) val likedUsers: MutableSet = mutableSetOf(), - @OneToMany(fetch = FetchType.LAZY) @JoinColumn(name = "room_id") val reviews: MutableList = mutableListOf(), + @Column(name = "created_at") + @CreationTimestamp() + val createdAt: Date, + val updatedAt: Date, ) { - fun toModel() = CafeRoom( - roomId = roomId, - cafeId = cafeId, - genre = genre, - timeout = timeout, - recommendedUserCnt = recommendUserCnt, - roomImgUrl = roomImgUrl, - description = description, - ) + fun toModel() = + CafeRoom( + roomId = roomId, + cafeId = cafeId, + genre = genre.map { GenreEntity.toModel(it) }.toSet(), + timeout = timeout, + recommendedUserCnt = recommendUserCnt, + roomImgUrl = roomImgUrl, + description = description, + title = title, + createdAt = createdAt, + updatedAt = updatedAt, + ) companion object { - fun fromModel(model: CafeRoom) = CafeRoomEntity( - roomId = model.roomId, - cafeId = model.cafeId, - genre = model.genre, - timeout = model.timeout, - recommendUserCnt = model.recommendedUserCnt, - roomImgUrl = model.roomImgUrl, - description = model.description, - ) + fun fromModel(model: CafeRoom) = + CafeRoomEntity( + roomId = model.roomId, + cafeId = model.cafeId, + genre = model.genre.map { GenreEntity.fromModel(it) }.toMutableSet(), + timeout = model.timeout, + recommendUserCnt = model.recommendedUserCnt, + roomImgUrl = model.roomImgUrl, + title = model.title, + description = model.description, + createdAt = model.createdAt, + updatedAt = model.updatedAt, + ) } } 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 new file mode 100644 index 0000000..e0f57d3 --- /dev/null +++ b/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/entity/GenreEntity.kt @@ -0,0 +1,29 @@ +package kr.nagaza.nagazaserver.infrastructure.jpa.entity + +import jakarta.persistence.Column +import jakarta.persistence.Entity +import jakarta.persistence.Id +import kr.nagaza.nagazaserver.domain.model.Genre + +@Entity(name = "genre") +class GenreEntity( + @Id + @Column(name = "genre_id") + val genreId: String, + @Column(name = "name") + val name: String, +) { + companion object { + fun fromModel(genre: Genre) = + GenreEntity( + genreId = genre.genreId, + name = genre.name, + ) + + fun toModel(genreEntity: GenreEntity) = + Genre( + genreId = genreEntity.genreId, + name = genreEntity.name, + ) + } +} 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 475f6be..e716702 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 @@ -9,10 +9,6 @@ import org.springframework.stereotype.Repository class CafeRoomRepositoryImpl( private val jpaCafeRoomRepository: JpaCafeRoomRepository, ) : CafeRoomRepository { - override fun getAllGenres(): List { - return jpaCafeRoomRepository.findAllGenres() - } - override fun getAllRoomByCafeId(cafeId: String): List { return jpaCafeRoomRepository.findAllByCafeId(cafeId) .map { @@ -23,4 +19,22 @@ class CafeRoomRepositoryImpl( override fun findByRoomId(roomId: String): CafeRoom? { return jpaCafeRoomRepository.findByIdOrNull(roomId)?.toModel() } + + override fun search( + queryString: String?, + genre: String?, + address1: String?, + address2: String?, + cafeId: String?, + ): List { + return jpaCafeRoomRepository.search( + queryString = queryString, + genre = genre, + address1 = address1, + address2 = address2, + cafeId = cafeId, + ).map { + it.toModel() + } + } } diff --git a/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/repository/JpaCafeRoomRepository.kt b/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/repository/JpaCafeRoomRepository.kt index 88b7e6d..1b1a60e 100644 --- a/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/repository/JpaCafeRoomRepository.kt +++ b/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/repository/JpaCafeRoomRepository.kt @@ -3,10 +3,30 @@ package kr.nagaza.nagazaserver.infrastructure.jpa.repository import kr.nagaza.nagazaserver.infrastructure.jpa.entity.CafeRoomEntity import org.springframework.data.jpa.repository.JpaRepository import org.springframework.data.jpa.repository.Query +import org.springframework.data.repository.query.Param interface JpaCafeRoomRepository : JpaRepository { fun findAllByCafeId(cafeId: String): List - @Query("SELECT DISTINCT cafe_room.genre FROM cafe_room") - fun findAllGenres(): List + @Query( + """ + SELECT cr FROM cafe_room cr + JOIN cafe c ON cr.cafeId = c.cafeId + LEFT JOIN cr.genre g + WHERE ( + (:queryString IS null OR cr.title LIKE %:queryString% ) AND + (:genre IS null OR g.genreId = :genre) AND + (:address1 IS null OR c.addressOne = :address1) AND + (:address2 IS null OR c.addressTwo = :address2) AND + (:cafeId IS null OR cr.cafeId = :cafeId) + ) + """, + ) + fun search( + @Param("queryString") queryString: String?, + @Param("genre") genre: String?, + @Param("address1") address1: String?, + @Param("address2") address2: String?, + @Param("cafeId") cafeId: String?, + ): List } 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 5134f86..0b0f625 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 @@ -3,6 +3,7 @@ package kr.nagaza.nagazaserver.presenter.restapi.api import io.swagger.v3.oas.annotations.Operation import io.swagger.v3.oas.annotations.tags.Tag import kr.nagaza.nagazaserver.presenter.restapi.dto.response.CafeRoomResponse +import org.springframework.data.repository.query.Param import org.springframework.web.bind.annotation.GetMapping import org.springframework.web.bind.annotation.PathVariable import org.springframework.web.bind.annotation.RequestMapping @@ -10,18 +11,21 @@ import org.springframework.web.bind.annotation.RestController @Tag(name = "카페 방 API", description = "카페 방 관련 API") @RestController -@RequestMapping("/v1/cafes/{cafeId}/rooms") +@RequestMapping("/v1/rooms") interface CafeRoomApi { @Operation(summary = "카페 전체 방 목록", description = "카페 내의 전체 방 목록을 반환합니다.") - @GetMapping - fun getCafeRooms( - @PathVariable cafeId: String, + @GetMapping("/search") + fun searchRooms( + @Param("queryString") queryString: String?, + @Param("genre") genre: String?, + @Param("address1") address1: String?, + @Param("address2") address2: String?, + @Param("cafeId") cafeId: String?, ): List @Operation(summary = "특정 방 조회", description = "카페 내의 특정 방 정보를 조회합니다.") @GetMapping("/{roomId}") fun getCafeRoom( - @PathVariable cafeId: String, @PathVariable roomId: String, ): CafeRoomResponse } 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 137ee48..5e65c21 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 @@ -2,6 +2,7 @@ package kr.nagaza.nagazaserver.presenter.restapi.controller import kr.nagaza.nagazaserver.domain.service.CafeRoomService import kr.nagaza.nagazaserver.presenter.restapi.api.CafeRoomApi +import kr.nagaza.nagazaserver.presenter.restapi.dto.request.RoomSearchQuery import kr.nagaza.nagazaserver.presenter.restapi.dto.response.CafeRoomResponse import org.springframework.stereotype.Controller @@ -9,13 +10,26 @@ import org.springframework.stereotype.Controller class CafeRoomController( private val cafeRoomService: CafeRoomService, ) : CafeRoomApi { - override fun getCafeRooms(cafeId: String): List { - return cafeRoomService.getRoomsByCafeId(cafeId) - .map(CafeRoomResponse::fromModel) - } - - override fun getCafeRoom(cafeId: String, roomId: String): CafeRoomResponse { + override fun getCafeRoom(roomId: String): CafeRoomResponse { return cafeRoomService.getRoomByRoomId(roomId) .let(CafeRoomResponse::fromModel) } + + override fun searchRooms( + queryString: String?, + genre: String?, + address1: String?, + address2: String?, + cafeId: String?, + ): List { + return cafeRoomService.search( + RoomSearchQuery( + queryString = queryString, + genre = genre, + address1 = address1, + address2 = address2, + cafeId = cafeId, + ), + ).map(CafeRoomResponse::fromModel) + } } 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 new file mode 100644 index 0000000..bec02f4 --- /dev/null +++ b/src/main/kotlin/kr/nagaza/nagazaserver/presenter/restapi/dto/request/RoomSearchQuery.kt @@ -0,0 +1,9 @@ +package kr.nagaza.nagazaserver.presenter.restapi.dto.request + +class RoomSearchQuery( + val queryString: String?, + val address1: String?, + val address2: String?, + val genre: String?, + val cafeId: String?, +) From e73ee9d3d6f74ed65e37ea4b5ab73e0ecfa91ec5 Mon Sep 17 00:00:00 2001 From: HyungJu Date: Sun, 25 Feb 2024 14:31:10 +0900 Subject: [PATCH 2/4] =?UTF-8?q?feat:=20=EB=B0=A9=20=EA=B2=80=EC=83=89=20qu?= =?UTF-8?q?erydsl=EB=A1=9C=20=EB=A7=8C=EB=93=A4=EC=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../jpa/repository/CafeRoomRepositoryImpl.kt | 44 ++++++++++++++++--- .../jpa/repository/JpaCafeRoomRepository.kt | 24 ---------- 2 files changed, 37 insertions(+), 31 deletions(-) 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 e716702..faed2f5 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 @@ -1,13 +1,20 @@ package kr.nagaza.nagazaserver.infrastructure.jpa.repository +import com.querydsl.jpa.impl.JPAQuery +import jakarta.persistence.EntityManager +import jakarta.persistence.PersistenceContext import kr.nagaza.nagazaserver.domain.model.CafeRoom import kr.nagaza.nagazaserver.domain.repository.CafeRoomRepository +import kr.nagaza.nagazaserver.infrastructure.jpa.entity.QCafeEntity +import kr.nagaza.nagazaserver.infrastructure.jpa.entity.QCafeRoomEntity import org.springframework.data.repository.findByIdOrNull import org.springframework.stereotype.Repository @Repository class CafeRoomRepositoryImpl( private val jpaCafeRoomRepository: JpaCafeRoomRepository, + @PersistenceContext + private val entityManager: EntityManager, ) : CafeRoomRepository { override fun getAllRoomByCafeId(cafeId: String): List { return jpaCafeRoomRepository.findAllByCafeId(cafeId) @@ -27,13 +34,36 @@ class CafeRoomRepositoryImpl( address2: String?, cafeId: String?, ): List { - return jpaCafeRoomRepository.search( - queryString = queryString, - genre = genre, - address1 = address1, - address2 = address2, - cafeId = cafeId, - ).map { + val cafeRoomEntity = QCafeRoomEntity.cafeRoomEntity + val cafeEntity = QCafeEntity.cafeEntity + val query = + JPAQuery(entityManager) + .select(cafeRoomEntity) + .from(cafeRoomEntity) + .leftJoin(cafeEntity).on(cafeRoomEntity.cafeId.eq(cafeEntity.cafeId)) + .leftJoin(cafeRoomEntity.genre) + + if (queryString != null) { + query.where(cafeRoomEntity.title.contains(queryString)) + } + + if (genre != null) { + query.where(cafeRoomEntity.genre.any().genreId.eq(genre)) + } + + if (address1 != null) { + query.where(cafeEntity.addressOne.eq(address1)) + } + + if (address2 != null) { + query.where(cafeEntity.addressTwo.eq(address2)) + } + + if (cafeId != null) { + query.where(cafeRoomEntity.cafeId.eq(cafeId)) + } + + return query.fetch().map { it.toModel() } } diff --git a/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/repository/JpaCafeRoomRepository.kt b/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/repository/JpaCafeRoomRepository.kt index 1b1a60e..abddbd9 100644 --- a/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/repository/JpaCafeRoomRepository.kt +++ b/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/repository/JpaCafeRoomRepository.kt @@ -2,31 +2,7 @@ package kr.nagaza.nagazaserver.infrastructure.jpa.repository import kr.nagaza.nagazaserver.infrastructure.jpa.entity.CafeRoomEntity import org.springframework.data.jpa.repository.JpaRepository -import org.springframework.data.jpa.repository.Query -import org.springframework.data.repository.query.Param interface JpaCafeRoomRepository : JpaRepository { fun findAllByCafeId(cafeId: String): List - - @Query( - """ - SELECT cr FROM cafe_room cr - JOIN cafe c ON cr.cafeId = c.cafeId - LEFT JOIN cr.genre g - WHERE ( - (:queryString IS null OR cr.title LIKE %:queryString% ) AND - (:genre IS null OR g.genreId = :genre) AND - (:address1 IS null OR c.addressOne = :address1) AND - (:address2 IS null OR c.addressTwo = :address2) AND - (:cafeId IS null OR cr.cafeId = :cafeId) - ) - """, - ) - fun search( - @Param("queryString") queryString: String?, - @Param("genre") genre: String?, - @Param("address1") address1: String?, - @Param("address2") address2: String?, - @Param("cafeId") cafeId: String?, - ): List } From 578362f203549d6c0e6a7a29f2d8e7c2efb7b37e Mon Sep 17 00:00:00 2001 From: HyungJu Date: Sun, 25 Feb 2024 14:33:16 +0900 Subject: [PATCH 3/4] =?UTF-8?q?refactor:=20toModel=EC=9D=80=20=EB=A9=A4?= =?UTF-8?q?=EB=B2=84=20=EB=A9=94=EC=86=8C=EB=93=9C=EB=A1=9C=20=EC=9D=B4?= =?UTF-8?q?=EB=8F=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../jpa/entity/CafeRoomEntity.kt | 2 +- .../infrastructure/jpa/entity/GenreEntity.kt | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/entity/CafeRoomEntity.kt b/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/entity/CafeRoomEntity.kt index 6afd144..97dba0c 100644 --- a/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/entity/CafeRoomEntity.kt +++ b/src/main/kotlin/kr/nagaza/nagazaserver/infrastructure/jpa/entity/CafeRoomEntity.kt @@ -48,7 +48,7 @@ class CafeRoomEntity( CafeRoom( roomId = roomId, cafeId = cafeId, - genre = genre.map { GenreEntity.toModel(it) }.toSet(), + genre = genre.map { it.toModel() }.toSet(), timeout = timeout, recommendedUserCnt = recommendUserCnt, roomImgUrl = roomImgUrl, 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 e0f57d3..9ab11fd 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 @@ -13,17 +13,19 @@ class GenreEntity( @Column(name = "name") val name: String, ) { + fun toModel(): Genre { + return Genre( + genreId = genreId, + name = name, + ) + } + companion object { - fun fromModel(genre: Genre) = - GenreEntity( + fun fromModel(genre: Genre): GenreEntity { + return GenreEntity( genreId = genre.genreId, name = genre.name, ) - - fun toModel(genreEntity: GenreEntity) = - Genre( - genreId = genreEntity.genreId, - name = genreEntity.name, - ) + } } } From 69174ada9121ab0d5453df7689374d57417f2ef1 Mon Sep 17 00:00:00 2001 From: HyungJu Date: Mon, 26 Feb 2024 18:18:10 +0900 Subject: [PATCH 4/4] =?UTF-8?q?feat:=20=EB=A3=B8=20=EA=B2=80=EC=83=89=20?= =?UTF-8?q?=EA=B2=B0=EA=B3=BC=EC=97=90=EC=84=9C=20=EB=B3=B4=EB=8B=A4=20?= =?UTF-8?q?=EC=83=81=EC=84=B8=ED=95=9C=20=EC=9D=91=EB=8B=B5=EC=9D=84=20?= =?UTF-8?q?=ED=95=B4=EC=A3=BC=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../restapi/dto/response/CafeRoomResponse.kt | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) 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 bee1e95..a9b0ecd 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 @@ -7,11 +7,32 @@ import kr.nagaza.nagazaserver.domain.model.CafeRoom data class CafeRoomResponse( @Schema(description = "카페 방 아이디", example = "01HDNFJHCNS5E2W35YTB030TJ8") val roomId: String, + @Schema(description = "카페 아이디", example = "01HDNFJHCNS5E2W35YTB030TJ8") + val cafeId: String, + @Schema(description = "제목", example = "형주의 방탈출") + val title: String, + @Schema(description = "설명", example = "형주의 방탈출 설명") + val description: String, + @Schema(description = "장르 (장르 Id)", example = "['1', '2']") + val genre: Set, + @Schema(description = "추천인원", example = "4") + val recommendedUser: Int, + @Schema(description = "방 이미지", example = "https://nagaza.kr/room/01HDNFJHCNS5E2W35YTB030TJ8.jpg") + val roomImage: String, + @Schema(description = "탈출 제한 시간", example = "60") + val timeout: Int, ) { companion object { fun fromModel(model: CafeRoom): CafeRoomResponse { return CafeRoomResponse( roomId = model.roomId, + cafeId = model.cafeId, + title = model.title, + description = model.description, + genre = model.genre.map { it.genreId }.toSet(), + recommendedUser = model.recommendedUserCnt, + roomImage = model.roomImgUrl ?: "", + timeout = model.timeout, ) } }