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.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)
} }

View File

@@ -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 {
RateCalendar( updates.add(
property = plan.property, RateCalendar(
ratePlan = plan, property = plan.property,
rateDate = date, ratePlan = plan,
rate = req.rate rateDate = date,
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 {

View File

@@ -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
) )