diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 70c8282..0930a60 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -4,17 +4,11 @@
-
-
+
+
-
-
-
-
-
-
-
-
+
+
@@ -35,6 +29,7 @@
+
{
"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"
}
}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -99,18 +125,48 @@
1749004109515
-
+
+
+ 1749006784623
+
+
+
+ 1749006784623
+
+
+
+ 1749140898576
+
+
+
+ 1749140898576
+
+
+
+
+
-
+
+
+
+
diff --git a/src/pilgrim/models/photo.py b/src/pilgrim/models/photo.py
index b197061..0e327f1 100644
--- a/src/pilgrim/models/photo.py
+++ b/src/pilgrim/models/photo.py
@@ -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
+
diff --git a/src/pilgrim/service/photo_service.py b/src/pilgrim/service/photo_service.py
new file mode 100644
index 0000000..340dd72
--- /dev/null
+++ b/src/pilgrim/service/photo_service.py
@@ -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
+