-
Notifications
You must be signed in to change notification settings - Fork 2
feat: Implement feature flag creation #43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
2119a9f
fix: JsonConverter to throw IllegalArgumentException
inourbubble2 4f16595
fix: Refactor FeatureFlag entity
inourbubble2 ebd798b
feat: Implement FeatureFlagService.create
inourbubble2 da260f4
feat: Connect FeatureFlagController with FeatureFlagService.create
inourbubble2 f585ed7
chore: Add configuration for @WebMvcTest
inourbubble2 e6a3edd
test: Add FeatureFlagControllerTest
inourbubble2 0383348
chore: Disable Open-in-View for JPA
inourbubble2 d8d77f5
fix: Add validation for 'type' field in CreateFeatureFlagRequest
inourbubble2 6f3063a
feat: Define 'Type' enum
inourbubble2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
backend/src/main/kotlin/com/lightswitch/application/service/FeatureFlagService.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| package com.lightswitch.application.service | ||
|
|
||
| import com.lightswitch.infrastructure.database.entity.Condition | ||
| import com.lightswitch.infrastructure.database.entity.FeatureFlag | ||
| import com.lightswitch.infrastructure.database.entity.User | ||
| import com.lightswitch.infrastructure.database.model.Type | ||
| import com.lightswitch.infrastructure.database.repository.ConditionRepository | ||
| import com.lightswitch.infrastructure.database.repository.FeatureFlagRepository | ||
| import com.lightswitch.presentation.exception.BusinessException | ||
| import com.lightswitch.presentation.model.flag.CreateFeatureFlagRequest | ||
| import org.springframework.stereotype.Service | ||
| import org.springframework.transaction.annotation.Transactional | ||
|
|
||
| @Service | ||
| class FeatureFlagService( | ||
| private val conditionRepository: ConditionRepository, | ||
| private val featureFlagRepository: FeatureFlagRepository, | ||
| ) { | ||
| @Transactional | ||
| fun create( | ||
| user: User, | ||
| request: CreateFeatureFlagRequest, | ||
| ): FeatureFlag { | ||
| featureFlagRepository.findByName(request.key)?.let { | ||
| throw BusinessException("FeatureFlag with key ${request.key} already exists") | ||
| } | ||
|
|
||
| val flag = | ||
| featureFlagRepository.save( | ||
| FeatureFlag( | ||
| name = request.key, | ||
| type = Type.from(request.type), | ||
| enabled = request.status, | ||
| description = request.description, | ||
| createdBy = user, | ||
| updatedBy = user, | ||
| ), | ||
| ) | ||
|
|
||
| request.defaultValueAsPair() | ||
| .let { (key, value) -> Condition(flag = flag, key = key, value = value) } | ||
| .let { conditionRepository.save(it) } | ||
| .also { | ||
| flag.defaultCondition = it | ||
| flag.conditions.add(it) | ||
| } | ||
|
|
||
| request.variantPairs() | ||
| ?.map { variant -> Condition(flag = flag, key = variant.first, value = variant.second) } | ||
| ?.let { conditionRepository.saveAll(it) } | ||
| ?.also { flag.conditions.addAll(it) } | ||
|
|
||
| return featureFlagRepository.save(flag) | ||
| } | ||
| } |
8 changes: 8 additions & 0 deletions
8
backend/src/main/kotlin/com/lightswitch/infrastructure/database/JpaConfig.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| package com.lightswitch.infrastructure.database | ||
|
|
||
| import org.springframework.context.annotation.Configuration | ||
| import org.springframework.data.jpa.repository.config.EnableJpaAuditing | ||
|
|
||
| @Configuration | ||
| @EnableJpaAuditing | ||
| class JpaConfig |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
backend/src/main/kotlin/com/lightswitch/infrastructure/database/model/Type.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| package com.lightswitch.infrastructure.database.model | ||
|
|
||
| enum class Type { | ||
| NUMBER, | ||
| BOOLEAN, | ||
| STRING; | ||
|
|
||
| companion object { | ||
| fun from(type: String): Type { | ||
| return when (type.uppercase()) { | ||
| "NUMBER" -> NUMBER | ||
| "BOOLEAN" -> BOOLEAN | ||
| "STRING" -> STRING | ||
| else -> throw IllegalArgumentException("Unsupported type: $type") | ||
| } | ||
| } | ||
| } | ||
| } |
6 changes: 6 additions & 0 deletions
6
...src/main/kotlin/com/lightswitch/infrastructure/database/repository/ConditionRepository.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| package com.lightswitch.infrastructure.database.repository | ||
|
|
||
| import com.lightswitch.infrastructure.database.entity.Condition | ||
| import org.springframework.data.jpa.repository.JpaRepository | ||
|
|
||
| interface ConditionRepository : JpaRepository<Condition, Long> |
8 changes: 8 additions & 0 deletions
8
...c/main/kotlin/com/lightswitch/infrastructure/database/repository/FeatureFlagRepository.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| package com.lightswitch.infrastructure.database.repository | ||
|
|
||
| import com.lightswitch.infrastructure.database.entity.FeatureFlag | ||
| import org.springframework.data.jpa.repository.JpaRepository | ||
|
|
||
| interface FeatureFlagRepository : JpaRepository<FeatureFlag, Int> { | ||
| fun findByName(name: String): FeatureFlag? | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,14 @@ | ||
| spring: | ||
| application: | ||
| name: LightSwitch | ||
| jpa: | ||
| hibernate: | ||
| ddl-auto: create | ||
| database-platform: org.hibernate.community.dialect.SQLiteDialect | ||
| datasource: | ||
| url: jdbc:sqlite:lightswitch.sqlite | ||
| driver-class-name: org.sqlite.JDBC | ||
| application: | ||
| name: LightSwitch | ||
| jpa: | ||
| database-platform: org.hibernate.community.dialect.SQLiteDialect | ||
| hibernate: | ||
| ddl-auto: create | ||
| open-in-view: false | ||
| datasource: | ||
| driver-class-name: org.sqlite.JDBC | ||
| url: jdbc:sqlite:lightswitch.sqlite | ||
|
|
||
| jwt: | ||
| secret: 64461f01e1af406da538b9c48d801ce59142452199ff112fb5404c8e7e98e3ff | ||
| secret: 64461f01e1af406da538b9c48d801ce59142452199ff112fb5404c8e7e98e3ff |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍