Sector models represent subdivisions within a greenhouse. Each sector can contain multiple devices and has its own monitoring and control settings.
Sector
Domain model representing a sector within a greenhouse. Used internally in the app for business logic.
@Serializable
data class Sector(
val id: Long,
val code: String,
val tenantId: Long,
val greenhouseId: Long,
val greenhouseCode: String? = null,
val name: String? = null
)
Fields
Unique identifier for the sector
Unique code assigned to the sector
ID of the tenant/client that owns this sector
ID of the greenhouse this sector belongs to
Code of the parent greenhouse (for display purposes)
Optional display name for the sector
Computed Properties
The Sector class provides computed properties for display purposes:
Returns the first letter of the sector name in uppercase for avatars, or “S” as default.val initial: String
get() = name?.firstOrNull()?.uppercaseChar()?.toString() ?: "S"
Example: “Zone A” → “Z”, null → “S”
Returns the display name, or a default “Sector” string if name is null.val displayName: String
get() = name ?: "Sector"
Example: “Zone A” → “Zone A”, null → “Sector”
API DTOs
SectorResponse
Response DTO from the API representing a sector. Matches the SectorResponse structure from the API.
@Serializable
data class SectorResponse(
val id: Long,
val code: String,
val tenantId: Long,
val greenhouseId: Long,
val greenhouseCode: String? = null,
val name: String? = null
)
Unique identifier for the sector
Unique code assigned to the sector
ID of the parent greenhouse
Code of the parent greenhouse
Converts SectorResponse to Sector domain model.fun SectorResponse.toSector() = Sector(
id = id,
code = code,
tenantId = tenantId,
greenhouseId = greenhouseId,
greenhouseCode = greenhouseCode,
name = name
)
SectorCreateRequest
Request DTO for creating a new sector.
@Serializable
data class SectorCreateRequest(
val greenhouseId: Long,
val name: String? = null
)
ID of the greenhouse to create the sector in
Optional display name for the sector
SectorUpdateRequest
Request DTO for updating an existing sector. All fields are optional for partial updates.
@Serializable
data class SectorUpdateRequest(
val greenhouseId: Long? = null,
val name: String? = null
)
Updated parent greenhouse ID (to move sector to different greenhouse)
Usage Examples
Creating a Sector
val sector = Sector(
id = 1L,
code = "SEC001",
tenantId = 1L,
greenhouseId = 1L,
greenhouseCode = "GH001",
name = "Zone A"
)
println(sector.initial) // "Z"
println(sector.displayName) // "Zone A"
Creating a Sector via API
val createRequest = SectorCreateRequest(
greenhouseId = 1L,
name = "Zone B"
)
val response: SectorResponse = apiClient.createSector(
tenantId = 1L,
request = createRequest
)
val sector: Sector = response.toSector()
Updating a Sector
val updateRequest = SectorUpdateRequest(
name = "Zone A (North Side)"
)
val response: SectorResponse = apiClient.updateSector(
tenantId = 1L,
sectorId = 1L,
request = updateRequest
)
val sector = getSector(1L)
println("Sector: ${sector.displayName}")
println("Code: ${sector.code}")
println("Greenhouse: ${sector.greenhouseCode ?: "Unknown"}")
println("Initial: ${sector.initial}")
Moving a Sector to Another Greenhouse
val updateRequest = SectorUpdateRequest(
greenhouseId = 2L // Move to different greenhouse
)
val response: SectorResponse = apiClient.updateSector(
tenantId = 1L,
sectorId = 1L,
request = updateRequest
)