Skip to main content
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

id
Long
required
Unique identifier for the sector
code
String
required
Unique code assigned to the sector
tenantId
Long
required
ID of the tenant/client that owns this sector
greenhouseId
Long
required
ID of the greenhouse this sector belongs to
greenhouseCode
String
default:"null"
Code of the parent greenhouse (for display purposes)
name
String
default:"null"
Optional display name for the sector

Computed Properties

The Sector class provides computed properties for display purposes:
initial
String
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”
displayName
String
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
)
id
Long
required
Unique identifier for the sector
code
String
required
Unique code assigned to the sector
tenantId
Long
required
ID of the tenant/client
greenhouseId
Long
required
ID of the parent greenhouse
greenhouseCode
String
default:"null"
Code of the parent greenhouse
name
String
default:"null"
Optional display name
toSector
() -> Sector
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
)
greenhouseId
Long
required
ID of the greenhouse to create the sector in
name
String
default:"null"
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
)
greenhouseId
Long
default:"null"
Updated parent greenhouse ID (to move sector to different greenhouse)
name
String
default:"null"
Updated display name

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
)

Displaying Sector Information

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
)

Build docs developers (and LLMs) love