Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Original file line number Diff line number Diff line change
@@ -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")
}
}
}
}
Original file line number Diff line number Diff line change
@@ -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<SdkKeyResponse> {
return PayloadResponse<SdkKeyResponse>(
status = "status",
message = "message",
data = null,
)
}

@Operation(
summary = "Get SDK key",
)
@GetMapping
fun getKey(
@RequestParam sdkType: String,
): PayloadResponse<SdkKeyResponse> {
checkSdkType(sdkType)
return PayloadResponse<SdkKeyResponse>(
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)
}
}
Original file line number Diff line number Diff line change
@@ -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,
)
Original file line number Diff line number Diff line change
@@ -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,
)
}
}
}
Loading