Skip to content

Commit

Permalink
Add Database API for remote API Structures
Browse files Browse the repository at this point in the history
  • Loading branch information
theAkito committed Aug 23, 2023
1 parent daa59c2 commit 1892ce7
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/zoominvitr/database.nim
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,27 @@ proc deleteNotified(n: DatabaseNotified): RedisReply {.discardable.} =
("EXEC", @[])
].exec

proc saveZoomResponse(r: DatabaseZoomResponse): RedisReply {.discardable.} =
## https://redis.io/commands/multi/
## https://redis.io/commands/hmset/
## https://redis.io/commands/exec/
[
("MULTI", @[]),
("HMSET", @[r.zoomUserID, "timestamp", r.timestamp, "meetings", r.meetings]),
("EXEC", @[])
].exec

proc deleteZoomResponse(r: DatabaseZoomResponse): RedisReply {.discardable.} =
## https://redis.io/commands/del/
[
("MULTI", @[]),
("DEL", @[r.zoomUserID]),
("EXEC", @[])
].exec

proc loadZoomResponse(r: DatabaseZoomResponse): seq[string] =
redis.command("HGETALL", r.zoomUserID).to(seq[string])

proc loadNotified(n: DatabaseNotified): seq[string] =
redis.command("HGETALL", n.keywordSignature).to(seq[string])

Expand All @@ -81,6 +102,12 @@ proc saveNotified*(config: ConfigZoom) =
proc deleteNotified*(config: ConfigZoom) =
config.createDatabaseNotified.deleteNotified

proc saveZoomResponse*(auth: ConfigZoomAuthentication, meetingsBody: string) =
auth.createDatabaseZoomResponse(meetingsBody.some).saveZoomResponse

proc deleteZoomResponse*(auth: ConfigZoomAuthentication, meetingsBody: string) =
auth.createDatabaseZoomResponse(meetingsBody.some).deleteZoomResponse

proc initNotifiedIfNotExists*(config: ConfigZoom) =
## https://redis.io/commands/hset/
let
Expand All @@ -90,12 +117,27 @@ proc initNotifiedIfNotExists*(config: ConfigZoom) =
n.saveNotified
[("HSET", @[key, "timestamp", rootTimestampStr])].exec

proc initZoomResponseIfNotExists*(auth: ConfigZoomAuthentication) =
## https://redis.io/commands/hset/
let
r = auth.createDatabaseZoomResponse
key = auth.userID
if not key.keyExists:
r.saveZoomResponse
[("HSET", @[key, "timestamp", rootTimestampStr])].exec

proc loadNotified*(config: ConfigZoom): DatabaseNotified =
config.createDatabaseNotified.loadNotified.deserialiseDatabaseNotified

proc loadZoomResponse*(auth: ConfigZoomAuthentication): DatabaseZoomResponse =
auth.createDatabaseZoomResponse.loadZoomResponse.deserialiseDatabaseZoomResponse

proc loadNotifiedTimestamp*(config: ConfigZoom): Timestamp =
config.createDatabaseNotified.loadNotified.deserialiseDatabaseNotifiedTimestamp

proc loadZoomResponseTimestamp*(auth: ConfigZoomAuthentication): Timestamp =
auth.createDatabaseZoomResponse.loadZoomResponse.deserialiseDatabaseZoomResponseTimestamp


when isMainModule:
const redisTestList = [
Expand Down

0 comments on commit 1892ce7

Please sign in to comment.