improvements to sync logic
All checks were successful
build and deploy kleinTodo / build (push) Successful in 14s
All checks were successful
build and deploy kleinTodo / build (push) Successful in 14s
This commit is contained in:
parent
28393ee46e
commit
579015cd7b
@ -80,3 +80,10 @@ func (t Todo) IsEqual(other Todo) bool {
|
||||
t.Owner == other.Owner &&
|
||||
t.Deleted == other.Deleted
|
||||
}
|
||||
|
||||
func (t Todo) IsEqualIgnoringStatus(other Todo) bool {
|
||||
return t.Name == other.Name &&
|
||||
t.Description == other.Description &&
|
||||
t.Owner == other.Owner &&
|
||||
t.Deleted == other.Deleted
|
||||
}
|
||||
|
||||
@ -35,19 +35,33 @@ func SyncHandler(w http.ResponseWriter, r *http.Request) {
|
||||
for _, clientTodo := range todoList.Todos {
|
||||
serverTodo, exists := serverTodos[clientTodo.Name]
|
||||
|
||||
if clientTodo.Deleted && clientTodo.LastModified.After(serverTodo.LastModified) {
|
||||
err = store.RemoveValueFromBucket(user, clientTodo.Name)
|
||||
if handleError(w, http.StatusInternalServerError, err) {
|
||||
return
|
||||
if !exists {
|
||||
if clientTodo.Deleted {
|
||||
continue
|
||||
}
|
||||
} else if !exists {
|
||||
err = clientTodo.Store(store, user)
|
||||
if handleError(w, http.StatusInternalServerError, err) {
|
||||
return
|
||||
}
|
||||
serverTodos[clientTodo.Name] = clientTodo
|
||||
} else {
|
||||
if !serverTodo.IsEqual(clientTodo) {
|
||||
continue
|
||||
}
|
||||
if clientTodo.Deleted {
|
||||
if clientTodo.LastModified.After(serverTodo.LastModified) {
|
||||
err = store.RemoveValueFromBucket(user, clientTodo.Name)
|
||||
if handleError(w, http.StatusInternalServerError, err) {
|
||||
return
|
||||
}
|
||||
delete(serverTodos, clientTodo.Name)
|
||||
}
|
||||
} else if !serverTodo.IsEqual(clientTodo) {
|
||||
if serverTodo.IsEqualIgnoringStatus(clientTodo) && clientTodo.LastModified.After(serverTodo.LastModified) {
|
||||
err = clientTodo.Store(store, user)
|
||||
if handleError(w, http.StatusInternalServerError, err) {
|
||||
return
|
||||
}
|
||||
serverTodos[clientTodo.Name] = clientTodo
|
||||
} else {
|
||||
response.MisMatchingTodos = append(response.MisMatchingTodos, common.MisMatchingTodo{
|
||||
ServerTodo: serverTodo,
|
||||
LocalTodo: clientTodo,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user