User Device Identity Query Documentation
This code provides functions for querying and manipulating user device identity data in the database. It uses the PocketBase DAO for database interactions and includes functions for synchronizing user device identities and downloading files.
Functions
SyncUserDeviceIdentities
func SyncUserDeviceIdentities(app core.App, dao *daos.Dao, brand machinescanner.MachineBrand, ud *entity.UserDeviceTable) error
Synchronizes user device identities in the database.
app: The PocketBase app instance.dao: The PocketBase DAO.brand: The brand of the machine.ud: A pointer to aUserDeviceTablestruct containing the user device data.- Returns: An error if the operation fails.
DownloadFile
func DownloadFile(url string) (string, error)
Downloads a file from a given URL and returns its base64-encoded content.
url: The URL of the file to be downloaded.- Returns: A string containing the base64-encoded content of the file, or an error if the operation fails.
Example Usage
Initializing the DAO
Before using the functions, you need to initialize the PocketBase DAO.
package main
import (
"fio-backend/queries"
"github.com/pocketbase/pocketbase"
"github.com/pocketbase/pocketbase/daos"
)
func main() {
// Initialize PocketBase
pb := pocketbase.New()
// Initialize the DAO
dao := daos.New(pb.DB())
}
Synchronizing User Device Identities
package main
import (
"fio-backend/entity"
"fio-backend/queries"
"fio-backend/utils/machine_scanner"
"github.com/pocketbase/pocketbase"
"github.com/pocketbase/pocketbase/daos"
"fmt"
)
func main() {
// Initialize PocketBase
pb := pocketbase.New()
// Initialize the DAO
dao := daos.New(pb.DB())
// Create a new user device with identities
newUserDevice := &entity.UserDeviceTable{
UserProfileID: "user123",
Identities: []entity.UserDeviceIdentity{
{
IdentityID: "identity123",
IdentityType: attendancemachine.IT_FACE,
Data: "base64-encoded-face-data",
DataFormat: "image/jpeg",
IsDefault: true,
},
},
}
// Synchronize user device identities
brand := machinescanner.MachineBrand("BrandX")
err := queries.SyncUserDeviceIdentities(pb, dao, brand, newUserDevice)
if err != nil {
fmt.Println("Error:", err)
return
}
fmt.Println("User device identities synchronized successfully")
}
Downloading a File
package main
import (
"fio-backend/queries"
"fmt"
)
func main() {
// URL of the file to be downloaded
fileURL := "https://example.com/path/to/file.jpg"
// Download the file and get its base64-encoded content
base64Content, err := queries.DownloadFile(fileURL)
if err != nil {
fmt.Println("Error:", err)
return
}
fmt.Println("Base64-encoded file content:", base64Content)
}
This documentation provides an overview of the user device identity query functions, their parameters, and example usage. By following the examples, you can synchronize user device identities and download files in the database.