2025-03-10 11:03:00 +00:00
|
|
|
package client
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type Status string
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
|
NOT_SYNCED Status = "not_synced"
|
|
|
|
|
NOT_SYNCING Status = "not_syncing"
|
|
|
|
|
IN_SYNC Status = "in_sync"
|
|
|
|
|
)
|
|
|
|
|
|
2025-04-02 18:50:03 +00:00
|
|
|
func (s *Service) GetStatus(ctx context.Context, id string) (Status, error) {
|
|
|
|
|
client, err := s.cfg.GetDBQueries().GetClient(ctx, id)
|
2025-03-10 11:03:00 +00:00
|
|
|
if err != nil {
|
|
|
|
|
return NOT_SYNCING, err
|
|
|
|
|
} else if !client.Cansync {
|
|
|
|
|
return NOT_SYNCING, nil
|
|
|
|
|
}
|
|
|
|
|
|
2025-05-05 09:31:21 +00:00
|
|
|
issynced, err := s.cfg.GetDBQueries().IsClientSynced(ctx, &client.Clientid)
|
2025-03-10 11:03:00 +00:00
|
|
|
if err != nil {
|
|
|
|
|
return NOT_SYNCING, err
|
|
|
|
|
} else if issynced {
|
|
|
|
|
return IN_SYNC, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return NOT_SYNCED, nil
|
|
|
|
|
}
|