Skip to content

Commit 14b9ab8

Browse files
authored
Merge branch 'main' into rename-lease
2 parents c9fc854 + e6bf2fa commit 14b9ab8

3 files changed

Lines changed: 9 additions & 6 deletions

File tree

realty-common/src/main/java/io/github/md5sha256/realty/database/entity/LeaseContractEntity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* @param price Rental price (must be > 0)
1616
* @param durationSeconds Lease duration in seconds (must be > 0)
1717
* @param startDate When the lease started
18-
* @param endDate When the current lease period ends, or {@code null} if unknown
18+
* @param endDate When the current lease period ends, or {@code null} if no tenant
1919
* @param currentMaxExtensions Current extension count (nullable; must be ≤ maxExtensions when present)
2020
* @param maxExtensions Maximum allowed extensions (nullable)
2121
* @see io.github.md5sha256.realty.api.LeaseContract

realty-common/src/main/java/io/github/md5sha256/realty/database/maria/mapper/MariaLeaseContractMapper.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ INSERT INTO LeaseContract (landlordId, tenantId, price, durationSeconds, startDa
5555
#{price},
5656
#{durationSeconds},
5757
NOW(),
58-
NOW() + INTERVAL #{durationSeconds} SECOND,
58+
CASE WHEN #{tenantId} IS NOT NULL THEN NOW() + INTERVAL #{durationSeconds} SECOND ELSE NULL END,
5959
CASE WHEN #{maxRenewals} >= 0 THEN 0 ELSE NULL END,
6060
CASE WHEN #{maxRenewals} >= 0 THEN #{maxRenewals} ELSE NULL END
6161
)
@@ -166,6 +166,7 @@ AND lc.endDate < NOW()
166166
@Update("""
167167
UPDATE LeaseContract
168168
SET tenantId = NULL,
169+
endDate = NULL,
169170
currentMaxExtensions = CASE WHEN maxExtensions IS NOT NULL THEN 0 ELSE NULL END
170171
WHERE leaseContractId = #{leaseContractId}
171172
""")
@@ -203,6 +204,10 @@ int updateLandlordByRegion(@Param("worldGuardRegionId") @NotNull String worldGua
203204
INNER JOIN Contract c ON c.contractId = lc.leaseContractId AND c.contractType = 'contract'
204205
INNER JOIN RealtyRegion rr ON rr.realtyRegionId = c.realtyRegionId
205206
SET lc.tenantId = #{tenantId},
207+
lc.endDate = CASE
208+
WHEN #{tenantId} IS NULL THEN NULL
209+
ELSE lc.endDate
210+
END,
206211
lc.currentMaxExtensions = CASE
207212
WHEN #{tenantId} IS NULL AND lc.maxExtensions IS NOT NULL THEN 0
208213
ELSE lc.currentMaxExtensions

realty-common/src/main/resources/sql/migrations/V7__lease_end_date.sql

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,5 @@ ALTER TABLE LeaseContract
22
ADD COLUMN endDate DATETIME;
33

44
UPDATE LeaseContract
5-
SET endDate = startDate + INTERVAL durationSeconds SECOND;
6-
7-
ALTER TABLE LeaseContract
8-
MODIFY COLUMN endDate DATETIME NOT NULL;
5+
SET endDate = startDate + INTERVAL durationSeconds SECOND
6+
WHERE tenant IS NOT NULL;

0 commit comments

Comments
 (0)