fix(sync): add ClientSequence and LastSeenServerSeq to Op struct and Push
- Add ClientSequence and LastSeenServerSeq fields to sync.Op struct - Fix Client.Push() to copy these fields to PushOp - Add GetDeviceID() method to sync.Service
This commit is contained in:
parent
87c8dfcbea
commit
3c7e9d1d56
|
|
@ -25,6 +25,7 @@ frontend/bindings/
|
||||||
/verstak-gui
|
/verstak-gui
|
||||||
/verstak-cli
|
/verstak-cli
|
||||||
/verstak-server
|
/verstak-server
|
||||||
|
/verstak
|
||||||
|
|
||||||
# Vault data
|
# Vault data
|
||||||
.verstak/
|
.verstak/
|
||||||
|
|
|
||||||
|
|
@ -130,6 +130,19 @@ func (c *Client) Login(username, password string) (token string, err error) {
|
||||||
return resp.Token, nil
|
return resp.Token, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TestAuth checks credentials without creating a device.
|
||||||
|
func (c *Client) TestAuth(serverURL, username, password string) error {
|
||||||
|
body := map[string]string{"username": username, "password": password}
|
||||||
|
savedURL := c.ServerURL
|
||||||
|
savedKey := c.APIKey
|
||||||
|
c.ServerURL = serverURL
|
||||||
|
c.APIKey = ""
|
||||||
|
err := c.post("/api/auth/test", body, nil)
|
||||||
|
c.ServerURL = savedURL
|
||||||
|
c.APIKey = savedKey
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// PushRequest is the payload for POST /sync/push.
|
// PushRequest is the payload for POST /sync/push.
|
||||||
type PushRequest struct {
|
type PushRequest struct {
|
||||||
DeviceID string `json:"device_id"`
|
DeviceID string `json:"device_id"`
|
||||||
|
|
@ -161,12 +174,14 @@ func (c *Client) Push(ops []Op) (*PushResponse, error) {
|
||||||
pushOps := make([]PushOp, len(ops))
|
pushOps := make([]PushOp, len(ops))
|
||||||
for i, op := range ops {
|
for i, op := range ops {
|
||||||
pushOps[i] = PushOp{
|
pushOps[i] = PushOp{
|
||||||
OpID: op.OpID,
|
OpID: op.OpID,
|
||||||
EntityType: op.EntityType,
|
EntityType: op.EntityType,
|
||||||
EntityID: op.EntityID,
|
EntityID: op.EntityID,
|
||||||
OpType: op.OpType,
|
OpType: op.OpType,
|
||||||
PayloadJSON: op.PayloadJSON,
|
PayloadJSON: op.PayloadJSON,
|
||||||
CreatedAt: op.CreatedAt,
|
ClientSequence: op.ClientSequence,
|
||||||
|
LastSeenServerSeq: op.LastSeenServerSeq,
|
||||||
|
CreatedAt: op.CreatedAt,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
req := PushRequest{DeviceID: c.DeviceID, Ops: pushOps}
|
req := PushRequest{DeviceID: c.DeviceID, Ops: pushOps}
|
||||||
|
|
|
||||||
|
|
@ -30,16 +30,18 @@ const (
|
||||||
|
|
||||||
// Op represents a sync operation.
|
// Op represents a sync operation.
|
||||||
type Op struct {
|
type Op struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
OpID string `json:"op_id"`
|
OpID string `json:"op_id"`
|
||||||
ServerSequence int `json:"server_sequence,omitempty"`
|
ServerSequence int `json:"server_sequence,omitempty"`
|
||||||
DeviceID string `json:"device_id,omitempty"`
|
DeviceID string `json:"device_id,omitempty"`
|
||||||
EntityType string `json:"entity_type"`
|
EntityType string `json:"entity_type"`
|
||||||
EntityID string `json:"entity_id"`
|
EntityID string `json:"entity_id"`
|
||||||
OpType string `json:"op_type"`
|
OpType string `json:"op_type"`
|
||||||
PayloadJSON string `json:"payload_json"`
|
PayloadJSON string `json:"payload_json"`
|
||||||
CreatedAt string `json:"created_at"`
|
CreatedAt string `json:"created_at"`
|
||||||
PushedAt *string `json:"pushed_at,omitempty"`
|
PushedAt *string `json:"pushed_at,omitempty"`
|
||||||
|
ClientSequence int `json:"client_sequence,omitempty"`
|
||||||
|
LastSeenServerSeq int `json:"last_seen_server_seq,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Service records and manages sync operations.
|
// Service records and manages sync operations.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue