-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #53 from wafflestudio/feat/reservation
Reservation API (인원 고려) 및 순환참조 에러 해결
- Loading branch information
Showing
11 changed files
with
141 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 15 additions & 16 deletions
31
src/main/kotlin/com/example/toyTeam6Airbnb/reservation/controller/Reservation.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,55 @@ | ||
package com.example.toyTeam6Airbnb.reservation.controller | ||
|
||
import com.example.toyTeam6Airbnb.reservation.persistence.ReservationEntity | ||
import com.example.toyTeam6Airbnb.review.controller.Review | ||
import com.example.toyTeam6Airbnb.room.controller.Room | ||
import com.example.toyTeam6Airbnb.user.controller.User | ||
import java.time.Instant | ||
import java.time.LocalDate | ||
|
||
data class Reservation( | ||
val id: Long, | ||
val user: User, | ||
val room: Room, | ||
val review: Review?, | ||
val userId: Long, | ||
val roomId: Long, | ||
val reviewId: Long?, | ||
val startDate: LocalDate, | ||
val endDate: LocalDate, | ||
val totalPrice: Double, | ||
val numberofGuests: Int, | ||
val createdAt: Instant, | ||
val updatedAt: Instant | ||
) { | ||
companion object { | ||
fun fromEntity(entity: ReservationEntity): Reservation { | ||
return Reservation( | ||
id = entity.id!!, | ||
user = User.fromEntity(entity.user), | ||
room = Room.fromEntity(entity.room), | ||
review = entity.review?.let { Review.fromEntity(it) }, | ||
userId = entity.user.id!!, | ||
roomId = entity.room.id!!, | ||
reviewId = entity.review?.id, | ||
startDate = entity.startDate, | ||
endDate = entity.endDate, | ||
totalPrice = entity.totalPrice, | ||
createdAt = entity.createdAt, | ||
updatedAt = entity.updatedAt | ||
updatedAt = entity.updatedAt, | ||
numberofGuests = entity.numberOfGuests | ||
) | ||
} | ||
} | ||
|
||
fun toDTO(): ReservationDTO { | ||
return ReservationDTO( | ||
id = this.id, | ||
userId = this.user.id, | ||
roomId = this.room.id, | ||
userId = this.userId, | ||
roomId = this.roomId, | ||
startDate = this.startDate, | ||
endDate = this.endDate | ||
endDate = this.endDate, | ||
numberOfGuests = this.numberofGuests | ||
) | ||
} | ||
} | ||
|
||
// Reservation DTO | ||
// 추후, 가격이나 특정 프로퍼티 추가할 수 있음. | ||
data class ReservationDTO( | ||
val id: Long, | ||
val roomId: Long, | ||
val userId: Long, | ||
val startDate: LocalDate, | ||
val endDate: LocalDate | ||
val endDate: LocalDate, | ||
val numberOfGuests: Int | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.