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.Owner == other.Owner &&
|
||||||
t.Deleted == other.Deleted
|
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 {
|
for _, clientTodo := range todoList.Todos {
|
||||||
serverTodo, exists := serverTodos[clientTodo.Name]
|
serverTodo, exists := serverTodos[clientTodo.Name]
|
||||||
|
|
||||||
if clientTodo.Deleted && clientTodo.LastModified.After(serverTodo.LastModified) {
|
if !exists {
|
||||||
|
if clientTodo.Deleted {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
err = clientTodo.Store(store, user)
|
||||||
|
if handleError(w, http.StatusInternalServerError, err) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
serverTodos[clientTodo.Name] = clientTodo
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if clientTodo.Deleted {
|
||||||
|
if clientTodo.LastModified.After(serverTodo.LastModified) {
|
||||||
err = store.RemoveValueFromBucket(user, clientTodo.Name)
|
err = store.RemoveValueFromBucket(user, clientTodo.Name)
|
||||||
if handleError(w, http.StatusInternalServerError, err) {
|
if handleError(w, http.StatusInternalServerError, err) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else if !exists {
|
delete(serverTodos, clientTodo.Name)
|
||||||
|
}
|
||||||
|
} else if !serverTodo.IsEqual(clientTodo) {
|
||||||
|
if serverTodo.IsEqualIgnoringStatus(clientTodo) && clientTodo.LastModified.After(serverTodo.LastModified) {
|
||||||
err = clientTodo.Store(store, user)
|
err = clientTodo.Store(store, user)
|
||||||
if handleError(w, http.StatusInternalServerError, err) {
|
if handleError(w, http.StatusInternalServerError, err) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
serverTodos[clientTodo.Name] = clientTodo
|
serverTodos[clientTodo.Name] = clientTodo
|
||||||
} else {
|
} else {
|
||||||
if !serverTodo.IsEqual(clientTodo) {
|
|
||||||
response.MisMatchingTodos = append(response.MisMatchingTodos, common.MisMatchingTodo{
|
response.MisMatchingTodos = append(response.MisMatchingTodos, common.MisMatchingTodo{
|
||||||
ServerTodo: serverTodo,
|
ServerTodo: serverTodo,
|
||||||
LocalTodo: clientTodo,
|
LocalTodo: clientTodo,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user