-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* remove allWidgets property from config * Boards API - refactored * remove Confirmation Sender | Simplify Services * Test refactor * IntelliJ Run Configurations added Gradle Tasks for running Cypress tests added Co-authored-by: szymon.owczarzak <[email protected]>
- Loading branch information
1 parent
75c5024
commit c077b13
Showing
40 changed files
with
594 additions
and
349 deletions.
There are no files selected for viewing
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
34 changes: 19 additions & 15 deletions
34
cogboard-app/src/main/kotlin/com/cognifide/cogboard/config/controller/BoardsController.kt
This file contains 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,40 +1,44 @@ | ||
package com.cognifide.cogboard.config.controller | ||
|
||
import com.cognifide.cogboard.CogboardConstants | ||
import com.cognifide.cogboard.config.helper.EntityCleanupHelper | ||
import com.cognifide.cogboard.config.service.BoardsConfigService | ||
import com.cognifide.cogboard.storage.ContentRepository | ||
import io.vertx.core.AbstractVerticle | ||
import io.vertx.core.json.JsonObject | ||
|
||
class BoardsController(private val factory: ControllerFactory = ControllerFactory()) : AbstractVerticle() { | ||
|
||
private lateinit var boardsConfigService: BoardsConfigService | ||
private lateinit var sender: ConfirmationSender | ||
|
||
override fun start() { | ||
val contentRepository = ContentRepository() | ||
sender = ConfirmationSender(vertx) | ||
boardsConfigService = BoardsConfigService( | ||
contentRepository, | ||
EntityCleanupHelper(vertx) | ||
) | ||
|
||
boardsConfigService = BoardsConfigService(vertx) | ||
factory.create(CogboardConstants.Event.BOARDS_CONFIG, vertx, prepareConfig()) | ||
} | ||
|
||
private fun prepareConfig() = mapOf<String, (JsonObject) -> String>( | ||
"save" to { body -> save(body) }, | ||
"update" to { body -> update(body) }, | ||
"delete" to { body -> delete(body) }, | ||
"get" to { _ -> get() } | ||
) | ||
|
||
private fun update(body: JsonObject): String { | ||
private fun save(body: JsonObject): String { | ||
boardsConfigService.saveBoardsConfig(body) | ||
sender.sendOk() | ||
return JsonObject() | ||
.put("message", "OK") | ||
.toString() | ||
return OK_MESSAGE | ||
} | ||
|
||
private fun update(body: JsonObject): String { | ||
boardsConfigService.updateBoard(body) | ||
return OK_MESSAGE | ||
} | ||
|
||
private fun delete(body: JsonObject): String { | ||
boardsConfigService.deleteBoard(body.getString("id")) | ||
return OK_MESSAGE | ||
} | ||
|
||
private fun get() = boardsConfigService.loadBoardsConfig().toString() | ||
|
||
companion object { | ||
const val OK_MESSAGE = "{\"message\":\"OK\"}" | ||
} | ||
} |
24 changes: 0 additions & 24 deletions
24
cogboard-app/src/main/kotlin/com/cognifide/cogboard/config/controller/ConfirmationSender.kt
This file was deleted.
Oops, something went wrong.
This file contains 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 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 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
3 changes: 1 addition & 2 deletions
3
cogboard-app/src/main/kotlin/com/cognifide/cogboard/config/model/Widgets.kt
This file contains 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,6 +1,5 @@ | ||
package com.cognifide.cogboard.config.model | ||
|
||
data class Widgets( | ||
val widgetsById: Map<String, Widget>, | ||
val allWidgets: List<String> | ||
val widgetsById: Map<String, Widget> | ||
) |
34 changes: 34 additions & 0 deletions
34
cogboard-app/src/main/kotlin/com/cognifide/cogboard/config/service/BoardsConfigHelper.kt
This file contains 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,34 @@ | ||
package com.cognifide.cogboard.config.service | ||
|
||
import com.cognifide.cogboard.CogboardConstants.Props | ||
import io.vertx.core.json.JsonArray | ||
import io.vertx.core.json.JsonObject | ||
|
||
class BoardsConfigHelper { | ||
companion object { | ||
fun removeBoard(config: JsonObject, id: String): JsonObject { | ||
val copy = config.copy() | ||
copy.allBoards()?.remove(id) | ||
copy.boardsById()?.remove(id) | ||
return copy | ||
} | ||
|
||
fun updateBoard(config: JsonObject, board: JsonObject): JsonObject { | ||
val id = board.getString(Props.ID) | ||
val copy = config.copy() | ||
val prevWidgets = copy.boardsById()?.getJsonObject(id)?.getJsonArray(Props.WIDGETS) ?: JsonArray() | ||
if (!copy.allBoards()?.contains(id)!!) { | ||
copy.allBoards()?.add(id) | ||
} | ||
if (board.widgetsNotPresent()) { | ||
board.put(Props.WIDGETS, prevWidgets) | ||
} | ||
copy.boardsById()?.put(id, board) | ||
return copy | ||
} | ||
} | ||
} | ||
|
||
private fun JsonObject.allBoards(): JsonArray? = this.getJsonObject(Props.BOARDS).getJsonArray(Props.BOARDS_ALL) | ||
private fun JsonObject.boardsById(): JsonObject? = this.getJsonObject(Props.BOARDS).getJsonObject(Props.BOARDS_BY_ID) | ||
private fun JsonObject.widgetsNotPresent() = !this.containsKey(Props.WIDGETS) |
Oops, something went wrong.