Default timezone to India; switch rate calendar to range API
All checks were successful
build-and-deploy / build-deploy (push) Successful in 36s

This commit is contained in:
androidlover5842
2026-01-29 05:47:47 +05:30
parent 3546b2de62
commit 97f09f6f75
3 changed files with 37 additions and 16 deletions

View File

@@ -3,11 +3,13 @@ package com.android.trisolarisserver
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication
import org.springframework.scheduling.annotation.EnableScheduling
import java.util.TimeZone
@SpringBootApplication
@EnableScheduling
class TrisolarisServerApplication
fun main(args: Array<String>) {
TimeZone.setDefault(TimeZone.getTimeZone("Asia/Kolkata"))
runApplication<TrisolarisServerApplication>(*args)
}

View File

@@ -2,7 +2,7 @@ package com.android.trisolarisserver.controller
import com.android.trisolarisserver.component.PropertyAccess
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.RatePlanResponse
import com.android.trisolarisserver.controller.dto.RatePlanUpdateRequest
@@ -126,25 +126,36 @@ class RatePlans(
@PathVariable propertyId: UUID,
@PathVariable ratePlanId: UUID,
@AuthenticationPrincipal principal: MyPrincipal?,
@RequestBody requests: List<RateCalendarUpsertRequest>
@RequestBody request: RateCalendarRangeUpsertRequest
): List<RateCalendarResponse> {
requireRole(propertyAccess, propertyId, principal, Role.ADMIN, Role.MANAGER)
val plan = ratePlanRepo.findByIdAndPropertyId(ratePlanId, propertyId)
?: 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 date = parseDate(req.rateDate)
val existing = rateCalendarRepo.findByRatePlanIdAndRateDate(plan.id!!, date)
if (existing != null) {
existing.rate = req.rate
existing
val updates = mutableListOf<RateCalendar>()
for (date in datesBetween(fromDate, toDate)) {
val row = existing[date]
if (row != null) {
row.rate = request.rate
updates.add(row)
} else {
RateCalendar(
property = plan.property,
ratePlan = plan,
rateDate = date,
rate = req.rate
updates.add(
RateCalendar(
property = plan.property,
ratePlan = plan,
rateDate = date,
rate = request.rate
)
)
}
}
@@ -192,6 +203,13 @@ class RatePlans(
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 {

View File

@@ -28,8 +28,9 @@ data class RatePlanResponse(
val currency: String
)
data class RateCalendarUpsertRequest(
val rateDate: String,
data class RateCalendarRangeUpsertRequest(
val from: String,
val to: String,
val rate: Long
)