Merge pull request #25

Merge fix/wrong-database-access to staging
This commit is contained in:
Gustavo Henrique Miranda 2025-07-06 03:37:37 -03:00 committed by GitHub
commit a731d2adae
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 25 additions and 24 deletions

View File

@ -910,13 +910,11 @@ class EditEntryScreen(Screen):
self.call_later(self._async_update_entry, content, photos_to_link) self.call_later(self._async_update_entry, content, photos_to_link)
async def _async_create_entry(self, content: str, photos_to_link: List[Photo]): async def _async_create_entry(self, content: str, photos_to_link: List[Photo]):
"""Cria uma nova entrada e associa as fotos referenciadas.""" """Creates a new entry and links the referenced photos."""
service_manager = self.app.service_manager
db_session = service_manager.get_db_session()
try: try:
service_manager = self.app.service_manager
entry_service = service_manager.get_entry_service() entry_service = service_manager.get_entry_service()
# O service.create deve criar o objeto em memória, mas NÃO fazer o commit ainda.
new_entry = entry_service.create( new_entry = entry_service.create(
travel_diary_id=self.diary_id, travel_diary_id=self.diary_id,
title=self.new_entry_title, title=self.new_entry_title,
@ -926,7 +924,6 @@ class EditEntryScreen(Screen):
) )
if new_entry: if new_entry:
# A partir daqui, é só atualizar a UI como você já fazia
self.entries.append(new_entry) self.entries.append(new_entry)
self.entries.sort(key=lambda x: x.id) self.entries.sort(key=lambda x: x.id)
@ -937,47 +934,51 @@ class EditEntryScreen(Screen):
self.is_new_entry = False self.is_new_entry = False
self.has_unsaved_changes = False self.has_unsaved_changes = False
self._original_content = new_entry.text # Pode ser o texto com hashes curtos self._original_content = new_entry.text
self.new_entry_title = "New Entry" self.new_entry_title = "New Entry"
self.next_entry_id = max(entry.id for entry in self.entries) + 1 self.next_entry_id = max(entry.id for entry in self.entries) + 1
self._update_entry_display() self._update_entry_display()
self.notify(f"✅ New Entry: '{new_entry.title}' Successfully saved") self.notify(f"Entry '{new_entry.title}' saved successfully!")
else: else:
self.notify("Error creating the Entry") self.notify("Error creating entry")
except Exception as e: except Exception as e:
self.notify(f"Error creating the entry: {str(e)}") self.notify(f"Error creating entry: {str(e)}")
async def _async_update_entry(self, updated_content: str, photos_to_link: List[Photo]): async def _async_update_entry(self, updated_content: str, photos_to_link: List[Photo]):
"""Atualiza uma entrada existente e sua associação de fotos.""" """Updates an existing entry and its photo links."""
service_manager = self.app.service_manager
try: try:
if not self.entries: if not self.entries:
self.notify("No Entry to update") self.notify("No entry to update")
return return
service_manager = self.app.service_manager
entry_service = service_manager.get_entry_service() entry_service = service_manager.get_entry_service()
current_entry = self.entries[self.current_entry_index] current_entry = self.entries[self.current_entry_index]
entry_result : Entry = Entry(
entry_result = Entry(
id=current_entry.id,
title=current_entry.title, title=current_entry.title,
text=updated_content, text=updated_content,
photos=photos_to_link, photos=photos_to_link,
date=current_entry.date, date=current_entry.date,
travel_diary_id=self.diary_id travel_diary_id=self.diary_id,
fk_travel_diary_id=self.diary_id
) )
entry_service.update(current_entry, entry_result)
# A partir daqui, é só atualizar a UI result = entry_service.update(current_entry, entry_result)
self.has_unsaved_changes = False
self._original_content = updated_content # Pode ser o texto com hashes curtos if result:
self._update_sub_header() self.has_unsaved_changes = False
self.notify(f"✅ Entry: '{current_entry.title}' sucesfully saved") self._original_content = updated_content
self._update_sub_header()
self.notify(f"Entry '{current_entry.title}' saved successfully!")
else:
self.notify("Error updating entry")
except Exception as e: except Exception as e:
# Desfaz as mudanças em caso de erro self.notify(f"Error updating entry: {str(e)}")
self.notify(f"❌ Error on updating the entry:: {str(e)}")
def on_key(self, event): def on_key(self, event):