Skip to content
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

Persistence layer interface #3

Merged
merged 5 commits into from
Dec 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions internal/models/common.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package models

type Id string
33 changes: 33 additions & 0 deletions internal/models/queue.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package models

import (
"time"
)

// This ID will be exposed to clients, and hence have to be properly random and unguessable.
type QueueId Id

type Queue struct {
// Unique ID for the queue.
Id QueueId

// Name of the queue. The name is used in generating queue urls, for ex
// https://simplq.me/j/<QueueName>. The storage layer guarantees sure that
// there is only one queue by a given name.
QueueName string

// Set to true if the queue is temporarily not issuing tokens
bool IsPaused

// Set to true if the queue has been deleted
bool IsDeleted

// Tokens present in the queue.
Tokens []Token

// Creation time.
CreationTime time.Time

// Deletion time.
DeletionTime time.Time
}
38 changes: 38 additions & 0 deletions internal/models/token.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package models

import (
"time"
)

// This ID will be exposed to clients, and hence have to be properly random and unguessable.
type TokenId Id

type Token struct {
// Unique ID for the token.
Id TokenId

// Name of the token, typically name of the person to whom the token was
// issued.
Name string

// Contact Number
ContactNumber string

// Optional. Email ID if the queue collects email ID of users.
EmailId string

// Set to true if the token has been deleted
bool IsDeleted

// Number of times the token was notified.
NotifiedCount uint32

// Timestamp when the token was last notified.
LastNotifiedTime time.Time

// Creation time.
CreationTime time.Time

// Deletion time.
DeletionTime time.Time
}
25 changes: 25 additions & 0 deletions internal/persistence/persistence.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package persistence

import (
"github.com/SimplQ/simplQ-golang/internal/models"
)

type QueueStore interface {
// Create a new queue and return the queue ID.
CreateQueue(models.Queue) models.QueueId

// Read a queue by id.
ReadQueue(models.QueueId) models.Queue

// Set the queue status to new value.
UpdateQueueStatus(models.QueueId, models.QueueStatus)

// Add a new token to the queue.
AddTokenToQueue(models.QueueId, models.Token)

// Read token by id.
ReadToken(models.TokenId)

// Set token status to new value.
UpdateTokenStatus(models.TokenId, models.TokenStatus)
}