-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add first integration with neo4j
- Loading branch information
1 parent
000e919
commit 587246c
Showing
4 changed files
with
61 additions
and
1 deletion.
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
10 changes: 10 additions & 0 deletions
10
src/main/kotlin/online/danielstefani/paddy/db/device/Device.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,10 @@ | ||
package online.danielstefani.paddy.db.device | ||
|
||
import org.neo4j.ogm.annotation.Id | ||
import org.neo4j.ogm.annotation.NodeEntity | ||
|
||
@NodeEntity | ||
class Device( | ||
@Id val serial: String, | ||
var jwt: String | ||
) |
28 changes: 28 additions & 0 deletions
28
src/main/kotlin/online/danielstefani/paddy/db/device/DeviceRepository.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,28 @@ | ||
package online.danielstefani.paddy.db.device | ||
|
||
import jakarta.enterprise.context.ApplicationScoped | ||
import jakarta.inject.Inject | ||
import org.neo4j.ogm.session.SessionFactory | ||
import org.neo4j.ogm.session.queryForObject | ||
|
||
@ApplicationScoped | ||
class DeviceRepository { | ||
|
||
@Inject | ||
private lateinit var sessionFactory: SessionFactory | ||
|
||
fun createDevice(serial: String, jwt: String) { | ||
with(sessionFactory.openSession()) { | ||
val existingDevice = this.queryForObject<Device>( | ||
"MATCH (deviceNode:Device {serial: $serial}) RETURN deviceNode", | ||
emptyMap() | ||
) | ||
|
||
if (existingDevice != null) | ||
this.save(existingDevice.also { it.jwt = jwt }) | ||
else | ||
this.save(Device(serial, jwt)) | ||
} | ||
} | ||
|
||
} |
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