Default timezone to India; switch rate calendar to range API
All checks were successful
build-and-deploy / build-deploy (push) Successful in 36s
All checks were successful
build-and-deploy / build-deploy (push) Successful in 36s
This commit is contained in:
@@ -3,11 +3,13 @@ package com.android.trisolarisserver
|
|||||||
import org.springframework.boot.autoconfigure.SpringBootApplication
|
import org.springframework.boot.autoconfigure.SpringBootApplication
|
||||||
import org.springframework.boot.runApplication
|
import org.springframework.boot.runApplication
|
||||||
import org.springframework.scheduling.annotation.EnableScheduling
|
import org.springframework.scheduling.annotation.EnableScheduling
|
||||||
|
import java.util.TimeZone
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
@EnableScheduling
|
@EnableScheduling
|
||||||
class TrisolarisServerApplication
|
class TrisolarisServerApplication
|
||||||
|
|
||||||
fun main(args: Array<String>) {
|
fun main(args: Array<String>) {
|
||||||
|
TimeZone.setDefault(TimeZone.getTimeZone("Asia/Kolkata"))
|
||||||
runApplication<TrisolarisServerApplication>(*args)
|
runApplication<TrisolarisServerApplication>(*args)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package com.android.trisolarisserver.controller
|
|||||||
|
|
||||||
import com.android.trisolarisserver.component.PropertyAccess
|
import com.android.trisolarisserver.component.PropertyAccess
|
||||||
import com.android.trisolarisserver.controller.dto.RateCalendarResponse
|
import com.android.trisolarisserver.controller.dto.RateCalendarResponse
|
||||||
import com.android.trisolarisserver.controller.dto.RateCalendarUpsertRequest
|
import com.android.trisolarisserver.controller.dto.RateCalendarRangeUpsertRequest
|
||||||
import com.android.trisolarisserver.controller.dto.RatePlanCreateRequest
|
import com.android.trisolarisserver.controller.dto.RatePlanCreateRequest
|
||||||
import com.android.trisolarisserver.controller.dto.RatePlanResponse
|
import com.android.trisolarisserver.controller.dto.RatePlanResponse
|
||||||
import com.android.trisolarisserver.controller.dto.RatePlanUpdateRequest
|
import com.android.trisolarisserver.controller.dto.RatePlanUpdateRequest
|
||||||
@@ -126,25 +126,36 @@ class RatePlans(
|
|||||||
@PathVariable propertyId: UUID,
|
@PathVariable propertyId: UUID,
|
||||||
@PathVariable ratePlanId: UUID,
|
@PathVariable ratePlanId: UUID,
|
||||||
@AuthenticationPrincipal principal: MyPrincipal?,
|
@AuthenticationPrincipal principal: MyPrincipal?,
|
||||||
@RequestBody requests: List<RateCalendarUpsertRequest>
|
@RequestBody request: RateCalendarRangeUpsertRequest
|
||||||
): List<RateCalendarResponse> {
|
): List<RateCalendarResponse> {
|
||||||
requireRole(propertyAccess, propertyId, principal, Role.ADMIN, Role.MANAGER)
|
requireRole(propertyAccess, propertyId, principal, Role.ADMIN, Role.MANAGER)
|
||||||
val plan = ratePlanRepo.findByIdAndPropertyId(ratePlanId, propertyId)
|
val plan = ratePlanRepo.findByIdAndPropertyId(ratePlanId, propertyId)
|
||||||
?: throw ResponseStatusException(HttpStatus.NOT_FOUND, "Rate plan not found")
|
?: throw ResponseStatusException(HttpStatus.NOT_FOUND, "Rate plan not found")
|
||||||
if (requests.isEmpty()) return emptyList()
|
val fromDate = parseDate(request.from)
|
||||||
|
val toDate = parseDate(request.to)
|
||||||
|
if (toDate.isBefore(fromDate)) {
|
||||||
|
throw ResponseStatusException(HttpStatus.BAD_REQUEST, "to must be on/after from")
|
||||||
|
}
|
||||||
|
val existing = rateCalendarRepo.findByRatePlanIdAndRateDateBetweenOrderByRateDateAsc(
|
||||||
|
plan.id!!,
|
||||||
|
fromDate,
|
||||||
|
toDate
|
||||||
|
).associateBy { it.rateDate }
|
||||||
|
|
||||||
val updates = requests.map { req ->
|
val updates = mutableListOf<RateCalendar>()
|
||||||
val date = parseDate(req.rateDate)
|
for (date in datesBetween(fromDate, toDate)) {
|
||||||
val existing = rateCalendarRepo.findByRatePlanIdAndRateDate(plan.id!!, date)
|
val row = existing[date]
|
||||||
if (existing != null) {
|
if (row != null) {
|
||||||
existing.rate = req.rate
|
row.rate = request.rate
|
||||||
existing
|
updates.add(row)
|
||||||
} else {
|
} else {
|
||||||
|
updates.add(
|
||||||
RateCalendar(
|
RateCalendar(
|
||||||
property = plan.property,
|
property = plan.property,
|
||||||
ratePlan = plan,
|
ratePlan = plan,
|
||||||
rateDate = date,
|
rateDate = date,
|
||||||
rate = req.rate
|
rate = request.rate
|
||||||
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -192,6 +203,13 @@ class RatePlans(
|
|||||||
throw ResponseStatusException(HttpStatus.BAD_REQUEST, "Invalid date")
|
throw ResponseStatusException(HttpStatus.BAD_REQUEST, "Invalid date")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun datesBetween(from: LocalDate, to: LocalDate): Sequence<LocalDate> {
|
||||||
|
return generateSequence(from) { current ->
|
||||||
|
val next = current.plusDays(1)
|
||||||
|
if (next.isAfter(to)) null else next
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun RatePlan.toResponse(): RatePlanResponse {
|
private fun RatePlan.toResponse(): RatePlanResponse {
|
||||||
|
|||||||
@@ -28,8 +28,9 @@ data class RatePlanResponse(
|
|||||||
val currency: String
|
val currency: String
|
||||||
)
|
)
|
||||||
|
|
||||||
data class RateCalendarUpsertRequest(
|
data class RateCalendarRangeUpsertRequest(
|
||||||
val rateDate: String,
|
val from: String,
|
||||||
|
val to: String,
|
||||||
val rate: Long
|
val rate: Long
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user