diff --git a/backend/src/main/kotlin/com/lightswitch/infrastructure/database/entity/SdkClient.kt b/backend/src/main/kotlin/com/lightswitch/infrastructure/database/entity/SdkClient.kt index 44b597b..c3c8c4f 100644 --- a/backend/src/main/kotlin/com/lightswitch/infrastructure/database/entity/SdkClient.kt +++ b/backend/src/main/kotlin/com/lightswitch/infrastructure/database/entity/SdkClient.kt @@ -2,9 +2,12 @@ package com.lightswitch.infrastructure.database.entity import jakarta.persistence.Column import jakarta.persistence.Entity +import jakarta.persistence.FetchType import jakarta.persistence.GeneratedValue import jakarta.persistence.GenerationType import jakarta.persistence.Id +import jakarta.persistence.JoinColumn +import jakarta.persistence.ManyToOne import java.time.Instant @Entity @@ -17,4 +20,7 @@ class SdkClient( @Column(nullable = false) val sdkType: String, var connectedAt: Instant, + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "user_id", nullable = false) + val user: User, ) : BaseEntity() diff --git a/backend/src/main/kotlin/com/lightswitch/infrastructure/database/model/SdkType.kt b/backend/src/main/kotlin/com/lightswitch/infrastructure/database/model/SdkType.kt new file mode 100644 index 0000000..20a134a --- /dev/null +++ b/backend/src/main/kotlin/com/lightswitch/infrastructure/database/model/SdkType.kt @@ -0,0 +1,17 @@ +package com.lightswitch.infrastructure.database.model + +enum class SdkType { + JAVA, + PYTHON, + ; + + companion object { + fun from(type: String): SdkType { + return when (type.uppercase()) { + "JAVA" -> JAVA + "PYTHON" -> PYTHON + else -> throw IllegalArgumentException("Unsupported type: $type") + } + } + } +} diff --git a/backend/src/main/kotlin/com/lightswitch/presentation/controller/SdkController.kt b/backend/src/main/kotlin/com/lightswitch/presentation/controller/SdkController.kt new file mode 100644 index 0000000..52ef00f --- /dev/null +++ b/backend/src/main/kotlin/com/lightswitch/presentation/controller/SdkController.kt @@ -0,0 +1,67 @@ +package com.lightswitch.presentation.controller + +import com.lightswitch.infrastructure.database.model.SdkType +import com.lightswitch.presentation.model.PayloadResponse +import com.lightswitch.presentation.model.StatusResponse +import com.lightswitch.presentation.model.sdk.CreateSdkKeyRequest +import com.lightswitch.presentation.model.sdk.SdkKeyResponse +import io.swagger.v3.oas.annotations.Operation +import org.springframework.http.HttpStatus +import org.springframework.web.bind.annotation.GetMapping +import org.springframework.web.bind.annotation.PostMapping +import org.springframework.web.bind.annotation.RequestBody +import org.springframework.web.bind.annotation.RequestMapping +import org.springframework.web.bind.annotation.RequestParam +import org.springframework.web.bind.annotation.ResponseStatus +import org.springframework.web.bind.annotation.RestController + +@RestController +@RequestMapping("/api/v1/sdks") +class SdkController { + @Operation( + summary = "Create SDK key", + ) + @PostMapping + @ResponseStatus(HttpStatus.CREATED) + fun createKey( + @RequestBody request: CreateSdkKeyRequest, + ): PayloadResponse { + return PayloadResponse( + status = "status", + message = "message", + data = null, + ) + } + + @Operation( + summary = "Get SDK key", + ) + @GetMapping + fun getKey( + @RequestParam sdkType: String, + ): PayloadResponse { + checkSdkType(sdkType) + return PayloadResponse( + status = "status", + message = "message", + data = null, + ) + } + + @Operation( + summary = "Connect to SSE", + ) + @GetMapping("/sse-connect") + fun connectSse( + @RequestParam sdkKey: String, + ): StatusResponse { + return StatusResponse( + status = "status", + message = "message", + ) + } + + fun checkSdkType(sdkType: String) { + SdkType.from(sdkType) + } +} diff --git a/backend/src/main/kotlin/com/lightswitch/presentation/model/sdk/CreateSdkKeyRequest.kt b/backend/src/main/kotlin/com/lightswitch/presentation/model/sdk/CreateSdkKeyRequest.kt new file mode 100644 index 0000000..c21ba46 --- /dev/null +++ b/backend/src/main/kotlin/com/lightswitch/presentation/model/sdk/CreateSdkKeyRequest.kt @@ -0,0 +1,8 @@ +package com.lightswitch.presentation.model.sdk + +import jakarta.validation.constraints.Pattern + +data class CreateSdkKeyRequest( + @field:Pattern(regexp = "(?i)^(java|python)$", message = "Type must be one of: java, python") + val type: String, +) diff --git a/backend/src/main/kotlin/com/lightswitch/presentation/model/sdk/SdkKeyResponse.kt b/backend/src/main/kotlin/com/lightswitch/presentation/model/sdk/SdkKeyResponse.kt new file mode 100644 index 0000000..fe8f240 --- /dev/null +++ b/backend/src/main/kotlin/com/lightswitch/presentation/model/sdk/SdkKeyResponse.kt @@ -0,0 +1,20 @@ +package com.lightswitch.presentation.model.sdk + +import com.lightswitch.infrastructure.database.entity.SdkClient +import java.time.Instant + +class SdkKeyResponse( + val key: String, + val type: String, + val connectedAt: Instant, +) { + companion object { + fun from(sdk: SdkClient): SdkKeyResponse { + return SdkKeyResponse( + key = sdk.sdkKey, + type = sdk.sdkType, + connectedAt = sdk.connectedAt, + ) + } + } +}