From cd33333b5597a5b900c67ea2a83039b5742daa8b Mon Sep 17 00:00:00 2001 From: Xevion Date: Tue, 19 Dec 2023 08:01:43 -0600 Subject: [PATCH] Code requirement db funcs, enum, code removal --- data.go | 26 ++++++++++++++++++++++++++ types.go | 6 ++++++ 2 files changed, 32 insertions(+) diff --git a/data.go b/data.go index 2f715c8..3e0cf64 100644 --- a/data.go +++ b/data.go @@ -16,3 +16,29 @@ func GetCode(location int64, member_id int) string { key := fmt.Sprintf("code:%d:%d", location, member_id) return db.Get(key).Val() } + +func RemoveCode(location int64, member_id int) { + key := fmt.Sprintf("code:%d:%d", location, member_id) + db.Del(key) +} + +// SetCodeRequired sets whether or not a guest code is required for a given location. +// This acts as sort of a 'cache' to avoid testing guest code requirements every time. +func SetCodeRequired(location int64, required bool) { + key := fmt.Sprintf("code_required:%d", location) + db.Set(key, required, 0) +} + +// GetCodeRequired returns whether or not a guest code is required for a given location. +// This uses the const values defined in types.go: GuestCodeRequired, GuestCodeNotRequired, and Unknown. +// In the case that no tests have been performed, Unknown will be returned. +func GetCodeRequired(location int64) uint { + key := fmt.Sprintf("code_required:%d", location) + if db.Exists(key).Val() == 0 { + return Unknown + } + if db.Get(key).Val() == "true" { + return GuestCodeRequired + } + return GuestCodeNotRequired +} diff --git a/types.go b/types.go index d28d9c2..f8f4239 100644 --- a/types.go +++ b/types.go @@ -11,3 +11,9 @@ type Field struct { text string // The text displayed id string // The id of the field } + +const ( + GuestCodeRequired = iota + GuestCodeNotRequired = iota + Unknown = iota +)