mirror of https://github.com/gmbrax/Pilgrim.git
Added the photo_service.py and modified photo.py to have all the crud operations
This commit is contained in:
parent
8ad57b548f
commit
7e29a590a2
|
|
@ -4,17 +4,11 @@
|
|||
<option name="autoReloadType" value="SELECTIVE" />
|
||||
</component>
|
||||
<component name="ChangeListManager">
|
||||
<list default="true" id="0a7f92e2-b44a-4dfe-8e01-136d1c0c18be" name="Changes" comment="Added a Back Relationship in Entry to list all the photos">
|
||||
<change afterPath="$PROJECT_DIR$/src/pilgrim/models/photo_in_entry.py" afterDir="false" />
|
||||
<list default="true" id="0a7f92e2-b44a-4dfe-8e01-136d1c0c18be" name="Changes" comment="Added the Services layer to the code to do the database operation">
|
||||
<change afterPath="$PROJECT_DIR$/src/pilgrim/service/photo_service.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/Pilgrim/Application.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/pilgrim/application.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/Pilgrim/Database.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/pilgrim/database.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/Pilgrim/Models/Entry.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/pilgrim/models/Entry.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/Pilgrim/Models/Photo.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/pilgrim/models/Photo.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/Pilgrim/Models/TravelDiary.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/pilgrim/models/TravelDiary.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/Pilgrim/Models/__init__.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/pilgrim/models/__init__.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/Pilgrim/__init__.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/pilgrim/__init__.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/Pilgrim/command.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/pilgrim/command.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/pilgrim/command.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/pilgrim/command.py" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/src/pilgrim/models/photo.py" beforeDir="false" afterPath="$PROJECT_DIR$/src/pilgrim/models/photo.py" afterDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
|
|
@ -35,6 +29,7 @@
|
|||
</map>
|
||||
</option>
|
||||
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
|
||||
<option name="UPDATE_TYPE" value="REBASE" />
|
||||
</component>
|
||||
<component name="GitHubPullRequestSearchHistory">{
|
||||
"lastFilter": {
|
||||
|
|
@ -62,6 +57,7 @@
|
|||
"Python.Database.executor": "Run",
|
||||
"Python.command.executor": "Run",
|
||||
"Python.main.executor": "Run",
|
||||
"Python.pilgrim.executor": "Run",
|
||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||
"RunOnceActivity.git.unshallow": "true",
|
||||
"git-widget-placeholder": "master",
|
||||
|
|
@ -73,6 +69,36 @@
|
|||
"vue.rearranger.settings.migration": "true"
|
||||
}
|
||||
}</component>
|
||||
<component name="RunManager">
|
||||
<configuration name="pilgrim" type="PythonConfigurationType" factoryName="Python" temporary="true" nameIsGenerated="true">
|
||||
<module name="Pilgrim" />
|
||||
<option name="ENV_FILES" value="" />
|
||||
<option name="INTERPRETER_OPTIONS" value="" />
|
||||
<option name="PARENT_ENVS" value="true" />
|
||||
<envs>
|
||||
<env name="PYTHONUNBUFFERED" value="1" />
|
||||
</envs>
|
||||
<option name="SDK_HOME" value="" />
|
||||
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/.venv/bin" />
|
||||
<option name="IS_MODULE_SDK" value="false" />
|
||||
<option name="ADD_CONTENT_ROOTS" value="true" />
|
||||
<option name="ADD_SOURCE_ROOTS" value="true" />
|
||||
<EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" />
|
||||
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/.venv/bin/pilgrim" />
|
||||
<option name="PARAMETERS" value="" />
|
||||
<option name="SHOW_COMMAND_LINE" value="false" />
|
||||
<option name="EMULATE_TERMINAL" value="false" />
|
||||
<option name="MODULE_MODE" value="false" />
|
||||
<option name="REDIRECT_INPUT" value="false" />
|
||||
<option name="INPUT_FILE" value="" />
|
||||
<method v="2" />
|
||||
</configuration>
|
||||
<recent_temporary>
|
||||
<list>
|
||||
<item itemvalue="Python.pilgrim" />
|
||||
</list>
|
||||
</recent_temporary>
|
||||
</component>
|
||||
<component name="SharedIndexes">
|
||||
<attachedChunks>
|
||||
<set>
|
||||
|
|
@ -99,18 +125,48 @@
|
|||
<option name="project" value="LOCAL" />
|
||||
<updated>1749004109515</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="2" />
|
||||
<task id="LOCAL-00002" summary="Changed the names of the files to conform the python convection and also added photo_in_entry.py to diminish the cyclic import error in pylint">
|
||||
<option name="closed" value="true" />
|
||||
<created>1749006784623</created>
|
||||
<option name="number" value="00002" />
|
||||
<option name="presentableId" value="LOCAL-00002" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1749006784623</updated>
|
||||
</task>
|
||||
<task id="LOCAL-00003" summary="Added the Services layer to the code to do the database operation">
|
||||
<option name="closed" value="true" />
|
||||
<created>1749140898576</created>
|
||||
<option name="number" value="00003" />
|
||||
<option name="presentableId" value="LOCAL-00003" />
|
||||
<option name="project" value="LOCAL" />
|
||||
<updated>1749140898576</updated>
|
||||
</task>
|
||||
<option name="localTasksCounter" value="4" />
|
||||
<servers />
|
||||
</component>
|
||||
<component name="TypeScriptGeneratedFilesManager">
|
||||
<option name="version" value="3" />
|
||||
</component>
|
||||
<component name="Vcs.Log.Tabs.Properties">
|
||||
<option name="TAB_STATES">
|
||||
<map>
|
||||
<entry key="MAIN">
|
||||
<value>
|
||||
<State />
|
||||
</value>
|
||||
</entry>
|
||||
</map>
|
||||
</option>
|
||||
</component>
|
||||
<component name="VcsManagerConfiguration">
|
||||
<MESSAGE value="Added a Back Relationship in Entry to list all the photos" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="Added a Back Relationship in Entry to list all the photos" />
|
||||
<MESSAGE value="Changed the names of the files to conform the python convection and also added photo_in_entry.py to diminish the cyclic import error in pylint" />
|
||||
<MESSAGE value="Added the Services layer to the code to do the database operation" />
|
||||
<option name="LAST_COMMIT_MESSAGE" value="Added the Services layer to the code to do the database operation" />
|
||||
</component>
|
||||
<component name="com.intellij.coverage.CoverageDataManagerImpl">
|
||||
<SUITE FILE_PATH="coverage/Pilgrim$Database.coverage" NAME="Database Coverage Results" MODIFIED="1748987101492" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/src/Database" />
|
||||
<SUITE FILE_PATH="coverage/Pilgrim$pilgrim.coverage" NAME="pilgrim Coverage Results" MODIFIED="1749097142827" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/.venv/bin" />
|
||||
<SUITE FILE_PATH="coverage/Pilgrim$main.coverage" NAME="main Coverage Results" MODIFIED="1748992510527" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/src" />
|
||||
<SUITE FILE_PATH="coverage/Pilgrim$command.coverage" NAME="command Coverage Results" MODIFIED="1748992876551" SOURCE_PROVIDER="com.intellij.coverage.DefaultCoverageFileProvider" RUNNER="coverage.py" COVERAGE_BY_TEST_ENABLED="false" COVERAGE_TRACING_ENABLED="false" WORKING_DIRECTORY="$PROJECT_DIR$/src/Pilgrim" />
|
||||
</component>
|
||||
|
|
|
|||
|
|
@ -1,3 +1,5 @@
|
|||
from typing import Any
|
||||
|
||||
from sqlalchemy import Column, Integer, String
|
||||
from sqlalchemy.orm import relationship
|
||||
|
||||
|
|
@ -12,8 +14,16 @@ class Photo(Base):
|
|||
name = Column(String)
|
||||
addition_date = Column(String)
|
||||
caption = Column(String)
|
||||
entries = relationship(
|
||||
entries:relationship = relationship(
|
||||
"Entry",
|
||||
secondary=photo_entry_association,
|
||||
back_populates="photos"
|
||||
)
|
||||
def __init__(self, filepath, name, addition_date=None, caption=None, entries=None, **kw: Any):
|
||||
super().__init__(**kw)
|
||||
self.filepath = filepath
|
||||
self.name = name
|
||||
self.addition_date = addition_date
|
||||
self.caption = caption
|
||||
self.entries = entries
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,46 @@
|
|||
from pathlib import Path
|
||||
from typing import List
|
||||
|
||||
from pilgrim import Photo
|
||||
|
||||
|
||||
class PhotoService:
|
||||
def __init__(self, session):
|
||||
self.session = session
|
||||
|
||||
def create(self, filepath:Path, name:str, addition_date=None, caption=None,) -> Photo:
|
||||
|
||||
new_photo = Photo(filepath, name, addition_date=addition_date, caption=caption)
|
||||
self.session.add(new_photo)
|
||||
self.session.commit()
|
||||
self.session.refresh(new_photo)
|
||||
|
||||
return new_photo
|
||||
def read_by_id(self, photo_id:int) -> Photo:
|
||||
return self.session.query(Photo).get(photo_id)
|
||||
|
||||
def read_all(self) -> List[Photo]:
|
||||
return self.session.query(Photo).all()
|
||||
|
||||
def update(self,photo_src:Photo,photo_dst:Photo) -> Photo | None:
|
||||
original:Photo = self.read_by_id(photo_src.id)
|
||||
if original:
|
||||
original.filepath = photo_dst.filepath
|
||||
original.name = photo_dst.name
|
||||
original.addition_date = photo_dst.addition_date
|
||||
original.caption = photo_dst.caption
|
||||
original.entries.extend(photo_dst.entries)
|
||||
self.session.commit()
|
||||
self.session.refresh(original)
|
||||
return original
|
||||
return None
|
||||
|
||||
def delete(self, photo_src:Photo) -> Photo | None:
|
||||
excluded = self.read_by_id(photo_src.id)
|
||||
if excluded:
|
||||
self.session.delete(excluded)
|
||||
self.session.commit()
|
||||
self.session.refresh(excluded)
|
||||
return excluded
|
||||
return None
|
||||
|
||||
Loading…
Reference in New Issue