From a249becc4d503b9b37cf8fc448ff701379e329c3 Mon Sep 17 00:00:00 2001 From: eunhwa99 Date: Tue, 25 Feb 2025 08:57:17 +0900 Subject: [PATCH 1/6] feat: Add sdk controller --- .../infrastructure/database/model/SdkType.kt | 16 ++++++ .../presentation/controller/SdkController.kt | 50 +++++++++++++++++++ .../presentation/model/sdk/SdkKeyResponse.kt | 20 ++++++++ 3 files changed, 86 insertions(+) create mode 100644 backend/src/main/kotlin/com/lightswitch/infrastructure/database/model/SdkType.kt create mode 100644 backend/src/main/kotlin/com/lightswitch/presentation/controller/SdkController.kt create mode 100644 backend/src/main/kotlin/com/lightswitch/presentation/model/sdk/SdkKeyResponse.kt 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..060bf7d --- /dev/null +++ b/backend/src/main/kotlin/com/lightswitch/infrastructure/database/model/SdkType.kt @@ -0,0 +1,16 @@ +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..98824c4 --- /dev/null +++ b/backend/src/main/kotlin/com/lightswitch/presentation/controller/SdkController.kt @@ -0,0 +1,50 @@ +package com.lightswitch.presentation.controller + +import com.lightswitch.presentation.model.PayloadResponse +import com.lightswitch.presentation.model.StatusResponse +import com.lightswitch.presentation.model.sdk.SdkKeyResponse +import io.swagger.v3.oas.annotations.Operation +import org.springframework.web.bind.annotation.GetMapping +import org.springframework.web.bind.annotation.PostMapping +import org.springframework.web.bind.annotation.RequestMapping +import org.springframework.web.bind.annotation.RestController + + +@RestController +@RequestMapping("/api/v1/sdks") +class SdkController { + @Operation( + summary = "Create SDK key", + ) + @PostMapping + fun createKey(): PayloadResponse { + return PayloadResponse( + status = "status", + message = "message", + data = null + ) + } + + @Operation( + summary = "Get SDK key", + ) + @GetMapping + fun getKey(): PayloadResponse { + return PayloadResponse( + status = "status", + message = "message", + data = null + ) + } + + @Operation( + summary = "Connect to SSE", + ) + @GetMapping("/sse-connect") + fun connectSse(): StatusResponse { + return StatusResponse( + status = "status", + message = "message" + ) + } +} 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..1a872b0 --- /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 + ) + } + } +} From 557517e680c9584bad2b9efbbccaf70843c88872 Mon Sep 17 00:00:00 2001 From: eunhwa99 Date: Tue, 25 Feb 2025 10:09:36 +0900 Subject: [PATCH 2/6] feat: Add controller request body, request param --- .../presentation/controller/SdkController.kt | 21 ++++++++++++------- .../model/sdk/CreateSdkKeyRequest.kt | 8 +++++++ 2 files changed, 22 insertions(+), 7 deletions(-) create mode 100644 backend/src/main/kotlin/com/lightswitch/presentation/model/sdk/CreateSdkKeyRequest.kt diff --git a/backend/src/main/kotlin/com/lightswitch/presentation/controller/SdkController.kt b/backend/src/main/kotlin/com/lightswitch/presentation/controller/SdkController.kt index 98824c4..2079c14 100644 --- a/backend/src/main/kotlin/com/lightswitch/presentation/controller/SdkController.kt +++ b/backend/src/main/kotlin/com/lightswitch/presentation/controller/SdkController.kt @@ -1,13 +1,13 @@ 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.web.bind.annotation.GetMapping -import org.springframework.web.bind.annotation.PostMapping -import org.springframework.web.bind.annotation.RequestMapping -import org.springframework.web.bind.annotation.RestController +import org.springframework.http.HttpStatus +import org.springframework.web.bind.annotation.* @RestController @@ -17,7 +17,9 @@ class SdkController { summary = "Create SDK key", ) @PostMapping - fun createKey(): PayloadResponse { + @ResponseStatus(HttpStatus.CREATED) + fun createKey(@RequestBody request: CreateSdkKeyRequest): PayloadResponse { + return PayloadResponse( status = "status", message = "message", @@ -29,7 +31,8 @@ class SdkController { summary = "Get SDK key", ) @GetMapping - fun getKey(): PayloadResponse { + fun getKey(@RequestParam sdkType: String): PayloadResponse { + checkSdkType(sdkType); return PayloadResponse( status = "status", message = "message", @@ -41,10 +44,14 @@ class SdkController { summary = "Connect to SSE", ) @GetMapping("/sse-connect") - fun connectSse(): StatusResponse { + 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..a5d7f54 --- /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: number, boolean, string") + val type: String +) From ba455bcea5bf6add84aef8b73c3e90749d2d8af2 Mon Sep 17 00:00:00 2001 From: eunhwa99 Date: Tue, 25 Feb 2025 10:09:55 +0900 Subject: [PATCH 3/6] feat: Add user entity to SdkClient entity --- .../infrastructure/database/entity/SdkClient.kt | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) 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..7ee50b9 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 @@ -1,10 +1,6 @@ package com.lightswitch.infrastructure.database.entity -import jakarta.persistence.Column -import jakarta.persistence.Entity -import jakarta.persistence.GeneratedValue -import jakarta.persistence.GenerationType -import jakarta.persistence.Id +import jakarta.persistence.* import java.time.Instant @Entity @@ -17,4 +13,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() From 27759d783977555c1522448ed02bd838cb05ece2 Mon Sep 17 00:00:00 2001 From: eunhwa99 Date: Fri, 28 Feb 2025 18:27:22 +0900 Subject: [PATCH 4/6] fix: Modify pattern matching message --- .../lightswitch/presentation/model/sdk/CreateSdkKeyRequest.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index a5d7f54..a7df6de 100644 --- a/backend/src/main/kotlin/com/lightswitch/presentation/model/sdk/CreateSdkKeyRequest.kt +++ b/backend/src/main/kotlin/com/lightswitch/presentation/model/sdk/CreateSdkKeyRequest.kt @@ -3,6 +3,6 @@ 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: number, boolean, string") + @field:Pattern(regexp = "(?i)^(java|python)$", message = "Type must be one of: java, python") val type: String ) From 55b562d9af4797ecf9f5b2a96aa364f957b947ec Mon Sep 17 00:00:00 2001 From: eunhwa99 Date: Fri, 28 Feb 2025 18:47:01 +0900 Subject: [PATCH 5/6] chore: Apply ktlint --- .../database/entity/SdkClient.kt | 2 +- .../infrastructure/database/model/SdkType.kt | 3 ++- .../presentation/controller/SdkController.kt | 24 +++++++++++-------- .../model/sdk/CreateSdkKeyRequest.kt | 2 +- .../presentation/model/sdk/SdkKeyResponse.kt | 2 +- 5 files changed, 19 insertions(+), 14 deletions(-) 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 7ee50b9..4f84cfd 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 @@ -15,5 +15,5 @@ class SdkClient( var connectedAt: Instant, @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "user_id", nullable = false) - val user: User + 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 index 060bf7d..20a134a 100644 --- a/backend/src/main/kotlin/com/lightswitch/infrastructure/database/model/SdkType.kt +++ b/backend/src/main/kotlin/com/lightswitch/infrastructure/database/model/SdkType.kt @@ -2,7 +2,8 @@ package com.lightswitch.infrastructure.database.model enum class SdkType { JAVA, - PYTHON; + PYTHON, + ; companion object { fun from(type: String): SdkType { diff --git a/backend/src/main/kotlin/com/lightswitch/presentation/controller/SdkController.kt b/backend/src/main/kotlin/com/lightswitch/presentation/controller/SdkController.kt index 2079c14..de35fba 100644 --- a/backend/src/main/kotlin/com/lightswitch/presentation/controller/SdkController.kt +++ b/backend/src/main/kotlin/com/lightswitch/presentation/controller/SdkController.kt @@ -9,7 +9,6 @@ import io.swagger.v3.oas.annotations.Operation import org.springframework.http.HttpStatus import org.springframework.web.bind.annotation.* - @RestController @RequestMapping("/api/v1/sdks") class SdkController { @@ -18,12 +17,13 @@ class SdkController { ) @PostMapping @ResponseStatus(HttpStatus.CREATED) - fun createKey(@RequestBody request: CreateSdkKeyRequest): PayloadResponse { - + fun createKey( + @RequestBody request: CreateSdkKeyRequest, + ): PayloadResponse { return PayloadResponse( status = "status", message = "message", - data = null + data = null, ) } @@ -31,12 +31,14 @@ class SdkController { summary = "Get SDK key", ) @GetMapping - fun getKey(@RequestParam sdkType: String): PayloadResponse { - checkSdkType(sdkType); + fun getKey( + @RequestParam sdkType: String, + ): PayloadResponse { + checkSdkType(sdkType) return PayloadResponse( status = "status", message = "message", - data = null + data = null, ) } @@ -44,14 +46,16 @@ class SdkController { summary = "Connect to SSE", ) @GetMapping("/sse-connect") - fun connectSse(@RequestParam sdkKey: String): StatusResponse { + fun connectSse( + @RequestParam sdkKey: String, + ): StatusResponse { return StatusResponse( status = "status", - message = "message" + message = "message", ) } - fun checkSdkType(sdkType: String){ + 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 index a7df6de..c21ba46 100644 --- a/backend/src/main/kotlin/com/lightswitch/presentation/model/sdk/CreateSdkKeyRequest.kt +++ b/backend/src/main/kotlin/com/lightswitch/presentation/model/sdk/CreateSdkKeyRequest.kt @@ -4,5 +4,5 @@ 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 + 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 index 1a872b0..fe8f240 100644 --- a/backend/src/main/kotlin/com/lightswitch/presentation/model/sdk/SdkKeyResponse.kt +++ b/backend/src/main/kotlin/com/lightswitch/presentation/model/sdk/SdkKeyResponse.kt @@ -13,7 +13,7 @@ class SdkKeyResponse( return SdkKeyResponse( key = sdk.sdkKey, type = sdk.sdkType, - connectedAt = sdk.connectedAt + connectedAt = sdk.connectedAt, ) } } From 221587834d517bb7cec761b50f530ae746b633b4 Mon Sep 17 00:00:00 2001 From: eunhwa99 Date: Fri, 28 Feb 2025 19:09:27 +0900 Subject: [PATCH 6/6] chore: Apply ktlint - 2 --- .../infrastructure/database/entity/SdkClient.kt | 9 ++++++++- .../lightswitch/presentation/controller/SdkController.kt | 8 +++++++- 2 files changed, 15 insertions(+), 2 deletions(-) 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 4f84cfd..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 @@ -1,6 +1,13 @@ package com.lightswitch.infrastructure.database.entity -import jakarta.persistence.* +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 diff --git a/backend/src/main/kotlin/com/lightswitch/presentation/controller/SdkController.kt b/backend/src/main/kotlin/com/lightswitch/presentation/controller/SdkController.kt index de35fba..52ef00f 100644 --- a/backend/src/main/kotlin/com/lightswitch/presentation/controller/SdkController.kt +++ b/backend/src/main/kotlin/com/lightswitch/presentation/controller/SdkController.kt @@ -7,7 +7,13 @@ 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.* +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")