Skip to content

Commit cd211ee

Browse files
refactor: extract rollback functionality
1 parent 42f8ded commit cd211ee

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

src/main/kotlin/application/controller/RoomController.kt

+1-6
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ package application.controller
1010

1111
import application.controller.manager.RoomDatabaseManager
1212
import application.controller.manager.RoomDigitalTwinManager
13+
import application.controller.util.rollback
1314
import entity.zone.Room
1415
import entity.zone.RoomID
1516
import usecase.repository.RoomRepository
@@ -43,10 +44,4 @@ class RoomController(
4344
}
4445

4546
override fun getRooms(): Set<Room> = this.roomDatabaseManager.getAllRooms()
46-
47-
private fun Boolean.rollback(rollbackActions: () -> Unit): Boolean =
48-
if (!this) {
49-
rollbackActions()
50-
false
51-
} else true
5247
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* Copyright (c) 2023. Smart Operating Block
3+
*
4+
* Use of this source code is governed by an MIT-style
5+
* license that can be found in the LICENSE file or at
6+
* https://opensource.org/licenses/MIT.
7+
*/
8+
9+
package application.controller.util
10+
11+
/**
12+
* Extension method used with methods that return a boolean result status
13+
* that allows to perform [rollbackActions] when it returns false.
14+
*/
15+
fun Boolean.rollback(rollbackActions: () -> Unit): Boolean =
16+
if (!this) {
17+
rollbackActions()
18+
false
19+
} else true

0 commit comments

Comments
 (0)