Skip to content

Commit

Permalink
추가 entity 및 ENUM 관련 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
dennis0405 committed Jan 10, 2025
1 parent 8682f85 commit 41fe2c4
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.example.toyTeam6Airbnb.room.controller

import com.example.toyTeam6Airbnb.room.persistence.Address
import com.example.toyTeam6Airbnb.room.persistence.Price
import com.example.toyTeam6Airbnb.room.persistence.RoomDetails
import com.example.toyTeam6Airbnb.room.persistence.RoomType
import java.time.Instant
Expand All @@ -13,9 +14,10 @@ data class Room(
val type: RoomType,
val address: Address,
val roomDetails: RoomDetails,
val price: Double,
val price: Price,
val maxOccupancy: Int,
val rating: Double,
val reviewCount: Int,
val isSuperhost: Boolean,
val createdAt: Instant,
val updatedAt: Instant
Expand All @@ -36,6 +38,7 @@ data class Room(
price = entity.price,
maxOccupancy = entity.maxOccupancy,
rating = averageRating,
reviewCount = entity.reviews.size,
isSuperhost = entity.host.isSuperhost(),
createdAt = entity.createdAt,
updatedAt = entity.updatedAt
Expand Down Expand Up @@ -69,6 +72,7 @@ data class Room(
price = this.price,
maxOccupancy = this.maxOccupancy,
rating = this.rating,
reviewCount = this.reviewCount,
isSuperhost = this.isSuperhost,
createdAt = this.createdAt,
updatedAt = this.updatedAt
Expand All @@ -83,7 +87,7 @@ data class RoomDTO(
val description: String,
val type: RoomType,
val address: Address,
val price: Double,
val price: Price,
val maxOccupancy: Int,
val rating: Double
)
Expand All @@ -96,9 +100,10 @@ data class RoomDetailsDTO(
val type: RoomType,
val address: Address,
val roomDetails: RoomDetails,
val price: Double,
val price: Price,
val maxOccupancy: Int,
val rating: Double,
val reviewCount: Int,
val isSuperhost: Boolean,
val createdAt: Instant,
val updatedAt: Instant
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.example.toyTeam6Airbnb.room.controller

import com.example.toyTeam6Airbnb.room.persistence.Address
import com.example.toyTeam6Airbnb.room.persistence.Price
import com.example.toyTeam6Airbnb.room.persistence.RoomDetails
import com.example.toyTeam6Airbnb.room.persistence.RoomType
import com.example.toyTeam6Airbnb.room.service.RoomService
Expand Down Expand Up @@ -137,7 +138,7 @@ data class CreateRoomRequest(
val type: RoomType,
val address: Address,
val roomDetails: RoomDetails,
val price: Double,
val price: Price,
val maxOccupancy: Int
)

Expand All @@ -147,6 +148,6 @@ data class UpdateRoomRequest(
val type: RoomType,
val address: Address,
val roomDetails: RoomDetails,
val price: Double,
val price: Price,
val maxOccupancy: Int
)
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.example.toyTeam6Airbnb.room.service
import com.example.toyTeam6Airbnb.room.controller.AddressSearchDTO
import com.example.toyTeam6Airbnb.room.controller.Room
import com.example.toyTeam6Airbnb.room.persistence.Address
import com.example.toyTeam6Airbnb.room.persistence.Price
import com.example.toyTeam6Airbnb.room.persistence.RoomDetails
import com.example.toyTeam6Airbnb.room.persistence.RoomType
import org.springframework.data.domain.Page
Expand All @@ -17,7 +18,7 @@ interface RoomService {
type: RoomType,
address: Address,
roomDetails: RoomDetails,
price: Double,
price: Price,
maxOccupancy: Int
): Room

Expand All @@ -33,7 +34,7 @@ interface RoomService {
type: RoomType,
address: Address,
roomDetails: RoomDetails,
price: Double,
price: Price,
maxOccupancy: Int
): Room

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import com.example.toyTeam6Airbnb.room.persistence.RoomDetails
import com.example.toyTeam6Airbnb.room.persistence.RoomEntity
import com.example.toyTeam6Airbnb.room.persistence.RoomRepository
import com.example.toyTeam6Airbnb.room.persistence.RoomType
import com.example.toyTeam6Airbnb.room.persistence.Price
import com.example.toyTeam6Airbnb.user.AuthenticateException
import com.example.toyTeam6Airbnb.user.persistence.UserRepository
import org.springframework.dao.DataIntegrityViolationException
Expand All @@ -40,16 +41,14 @@ class RoomServiceImpl(
type: RoomType,
address: Address,
roomDetails: RoomDetails,
price: Double,
price: Price,
maxOccupancy: Int
): Room {
val hostEntity = userRepository.findByIdOrNull(hostId) ?: throw AuthenticateException()

validateRoomInfo(name, description, type, address, price, maxOccupancy)

if (roomRepository.existsByNameAndTypeAndAddress(name, type, address)) {
throw DuplicateRoomException()
}
if (roomRepository.existsByAddress(address)) throw DuplicateRoomException()

try {
val roomEntity = RoomEntity(
Expand Down Expand Up @@ -93,20 +92,18 @@ class RoomServiceImpl(
type: RoomType,
address: Address,
roomDetails: RoomDetails,
price: Double,
price: Price,
maxOccupancy: Int
): Room {
val hostEntity = userRepository.findByIdOrNull(hostId) ?: throw AuthenticateException()
val roomEntity = roomRepository.findByIdOrNullForUpdate(roomId) ?: throw RoomNotFoundException()

if (roomEntity.host.id != hostEntity.id) {
throw RoomPermissionDeniedException()
}
if (roomEntity.host.id != hostEntity.id) throw RoomPermissionDeniedException()

validateRoomInfo(name, description, type, address, price, maxOccupancy)

if (roomRepository.existsByNameAndTypeAndAddress(name, type, address) &&
(roomEntity.name != name || roomEntity.type != type || roomEntity.address != address)
if (roomRepository.existsByAddress(address) &&
(roomEntity.address != address)
) {
throw DuplicateRoomException()
}
Expand Down Expand Up @@ -171,12 +168,12 @@ class RoomServiceImpl(
description: String,
type: RoomType,
address: Address,
price: Double,
price: Price,
maxOccupancy: Int
) {
if (name.isBlank()) throw InvalidNameException()
if (description.isBlank()) throw InvalidDescriptionException()
if (price <= 0) throw InvalidPriceException()
validatePrice(price)
if (maxOccupancy <= 0) throw InvalidMaxOccupancyException()

try {
Expand All @@ -188,6 +185,16 @@ class RoomServiceImpl(
validateAddress(address)
}

private fun validatePrice(price: Price){
if (price.perNight <= 0 ||
price.cleaningFee < 0 ||
price.charge < 0 ||
price.updateTotal() <= 0
){
throw InvalidPriceException()
}
}

private fun validateAddress(address: Address) {
if (address.sido.isBlank() ||
address.sigungu.isBlank() ||
Expand Down

0 comments on commit 41fe2c4

Please sign in to comment.