Skip to content

Commit

Permalink
Merge branch 'add-list-delete' of github.com:geoff-powell/tidy into a…
Browse files Browse the repository at this point in the history
…dd-list-delete

* 'add-list-delete' of github.com:geoff-powell/tidy:
  Add delete function for list
  Cleanup edit list
  • Loading branch information
geoff-powell committed Dec 14, 2023
1 parent 87dea48 commit e360cf5
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,19 @@ package com.greenmiststudios.common.persistance
import com.greenmiststudios.common.data.TidyList
import com.greenmiststudios.tidy.TidyListQueries


public val USER_ID: String = "USER"

public fun TidyListQueries.updateList(tidyList: TidyList) {
updateListName(name = tidyList.name, id = tidyList.id)
tidyList.items.forEach {
addOrUpdateListItem(it.id, tidyList.id, it.text, it.completed,"USER")
addOrUpdateListItem(it.id, tidyList.id, it.text, it.completed, USER_ID)
}
}

public fun TidyListQueries.createList(tidyList: TidyList) {
addList(id = tidyList.id, name = tidyList.name, "", USER_ID)
tidyList.items.forEach {
addOrUpdateListItem(it.id, tidyList.id, it.text, it.completed,USER_ID)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import com.greenmiststudios.common.components.screens.EditListScreen
import com.greenmiststudios.common.data.TidyList
import com.greenmiststudios.common.data.TidyListItem
import com.greenmiststudios.common.data.asTidyList
import com.greenmiststudios.common.persistance.createList
import com.greenmiststudios.common.persistance.updateList
import com.greenmiststudios.common.viewmodels.EditListViewEvent
import com.greenmiststudios.common.viewmodels.EditListViewModel
Expand Down Expand Up @@ -67,7 +68,11 @@ public class EditListPresenter(

is EditListViewEvent.UpdateList -> {
launch(ioContext) {
tidyListQueries.updateList(tidyList)
if (newItemText.isNotEmpty()) {
tidyList = tidyList.copy(items = tidyList.items + TidyListItem(id = uuid4().toString(), text = newItemText))
newItemText = ""
}
tidyListQueries.createList(tidyList)
}
}

Expand Down Expand Up @@ -95,6 +100,7 @@ public class EditListPresenter(
return EditListViewModel.Loaded.Add(
title = "Add List",
name = tidyList.name,
newItemText = newItemText,
items = tidyList.items,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,7 @@ updateListItem:
UPDATE TidyListItem SET text = :text, completed = :completed, updated_at = CURRENT_TIMESTAMP WHERE id = :id;

deleteListItems:
DELETE FROM TidyListItem WHERE list_id = :id;
DELETE FROM TidyListItem WHERE list_id = :id;

deleteListItemById:
DELETE FROM TidyListItem WHERE id = :id;

0 comments on commit e360cf5

Please sign in to comment.