Skip to content

Commit

Permalink
DTO 관련 추가 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
dennis0405 committed Jan 16, 2025
1 parent 4e3633a commit 1ac6071
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ data class Reservation(

data class ReservationDetails(
val reservationId: Long,
val userId: Long,
val roomId: Long,
val startDate: LocalDate,
val endDate: LocalDate,
Expand All @@ -29,7 +28,6 @@ data class ReservationDetails(
fun fromEntity(entity: ReservationEntity): ReservationDetails {
return ReservationDetails(
reservationId = entity.id!!,
userId = entity.user.id!!,
roomId = entity.room.id!!,
startDate = entity.startDate,
endDate = entity.endDate,
Expand Down
28 changes: 15 additions & 13 deletions src/main/kotlin/com/example/toyTeam6Airbnb/room/controller/Room.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import java.time.Instant

data class Room(
val roomId: Long,
val name: String,
val type: RoomType,
val roomName: String,
val roomType: RoomType,
val sido: String,
val price: Double,
val averageRating: Double
// val imageUrl: String
// val imageUrl: String //대표 이미지 1개만 return
) {
companion object {
fun fromEntity(entity: RoomEntity): Room {
Expand All @@ -23,8 +23,8 @@ data class Room(

return Room(
roomId = entity.id!!,
name = entity.name,
type = entity.type,
roomName = entity.name,
roomType = entity.type,
sido = entity.address.sido,
price = entity.price.perNight,
averageRating = averageRating
Expand All @@ -37,9 +37,10 @@ data class Room(
data class RoomDetailsDTO(
val roomId: Long,
val hostId: Long,
val name: String,
val hostName: String?,
val roomName: String,
val description: String,
val type: RoomType,
val roomType: RoomType,
val address: Address,
val roomDetails: RoomDetails,
val price: Price,
Expand All @@ -49,7 +50,7 @@ data class RoomDetailsDTO(
val isSuperHost: Boolean,
val createdAt: Instant,
val updatedAt: Instant
// val imageUrl: String,
// val imageUrl: List<String>, //방에 대한 모든 image url 전달
) {
companion object {
fun fromEntity(entity: RoomEntity): RoomDetailsDTO {
Expand All @@ -59,9 +60,10 @@ data class RoomDetailsDTO(
return RoomDetailsDTO(
roomId = entity.id!!,
hostId = entity.host.id!!,
name = entity.name,
hostName = entity.host.profile?.nickname,
roomName = entity.name,
description = entity.description,
type = entity.type,
roomType = entity.type,
address = entity.address,
roomDetails = entity.roomDetails,
price = entity.price,
Expand All @@ -71,21 +73,21 @@ data class RoomDetailsDTO(
isSuperHost = entity.host.isSuperhost(),
createdAt = entity.createdAt,
updatedAt = entity.updatedAt
// imageUrl = entity.images.firstOrNull()?.url ?: ""
// imageUrl = entity.images.map { imageService(it.url) }
)
}
}
}

data class RoomShortDTO(
val roomId: Long
// val imageUrl: String,
// val imageUrl: String, // 이미지가 여러 개면 List<String> 형태로 여러 개의 cloudfront url 전달
) {
companion object {
fun fromEntity(entity: RoomEntity): RoomShortDTO {
return RoomShortDTO(
roomId = entity.id!!
// imageUrl = entity.images.firstOrNull()?.url ?: ""
// imageUrl = entity.images.map { imageService(it.url) }
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ class RoomController(
): ResponseEntity<RoomShortDTO> {
val room = roomService.createRoom(
hostId = User.fromEntity(principalDetails.getUser()).id,
name = request.name,
name = request.roomName,
description = request.description,
type = request.type,
type = request.roomType,
address = request.address,
roomDetails = request.roomDetails,
price = request.price,
Expand Down Expand Up @@ -79,9 +79,9 @@ class RoomController(
val updatedRoom = roomService.updateRoom(
User.fromEntity(principalDetails.getUser()).id,
roomId,
request.name,
request.roomName,
request.description,
request.type,
request.roomType,
request.address,
request.roomDetails,
request.price,
Expand All @@ -107,8 +107,8 @@ class RoomController(
@GetMapping("/rooms/main/search")
@Operation(summary = "방 검색", description = "방을 검색합니다(페이지네이션 적용)")
fun searchRooms(
@RequestParam(required = false) name: String?,
@RequestParam(required = false) type: RoomType?,
@RequestParam(required = false) roomName: String?,
@RequestParam(required = false) roomType: RoomType?,
@RequestParam(required = false) minPrice: Double?,
@RequestParam(required = false) maxPrice: Double?,
@RequestParam(required = false) sido: String?,
Expand All @@ -122,7 +122,7 @@ class RoomController(
pageable: Pageable
): ResponseEntity<Page<Room>> {
val address = AddressSearchDTO(sido, sigungu, street, detail)
val rooms = roomService.searchRooms(name, type, minPrice, maxPrice, address, maxOccupancy, rating, startDate, endDate, pageable)
val rooms = roomService.searchRooms(roomName, roomType, minPrice, maxPrice, address, maxOccupancy, rating, startDate, endDate, pageable)
return ResponseEntity.ok(rooms)
}
}
Expand All @@ -135,19 +135,19 @@ data class AddressSearchDTO(
)

data class CreateRoomRequest(
val name: String,
val roomName: String,
val description: String,
val type: RoomType,
val roomType: RoomType,
val address: Address,
val roomDetails: RoomDetails,
val price: Price,
val maxOccupancy: Int
)

data class UpdateRoomRequest(
val name: String,
val roomName: String,
val description: String,
val type: RoomType,
val roomType: RoomType,
val address: Address,
val roomDetails: RoomDetails,
val price: Price,
Expand Down

0 comments on commit 1ac6071

Please sign in to comment.