Skip to content

Commit 753d272

Browse files
committed
feat: add update coll.
1 parent 3429e7f commit 753d272

File tree

2 files changed

+40
-9
lines changed

2 files changed

+40
-9
lines changed

videodb/client.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,22 @@ def create_collection(self, name: str, description: str) -> Collection:
6868
collection_data.get("description"),
6969
)
7070

71+
def update_collection(self, id: str, name: str, description: str) -> Collection:
72+
collection_data = self.patch(
73+
path=f"{ApiPath.collection}/{id}",
74+
data={
75+
"name": name,
76+
"description": description,
77+
},
78+
)
79+
self.collection_id = collection_data.get("id", "default")
80+
return Collection(
81+
self,
82+
collection_data.get("id"),
83+
collection_data.get("name"),
84+
collection_data.get("description"),
85+
)
86+
7187
def upload(
7288
self,
7389
file_path: str = None,

videodb/collection.py

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,15 @@ def __repr__(self) -> str:
3737

3838
def get_videos(self) -> List[Video]:
3939
videos_data = self._connection.get(
40-
path=f"{ApiPath.collection}/{self.id}/{ApiPath.video}"
40+
path=f"{ApiPath.video}",
41+
params={"collection_id": self.id},
4142
)
4243
return [Video(self._connection, **video) for video in videos_data.get("videos")]
4344

4445
def get_video(self, video_id: str) -> Video:
45-
video_data = self._connection.get(path=f"{ApiPath.video}/{video_id}")
46+
video_data = self._connection.get(
47+
path=f"{ApiPath.video}/{video_id}", params={"collection_id": self.id}
48+
)
4649
return Video(self._connection, **video_data)
4750

4851
def delete_video(self, video_id: str) -> None:
@@ -53,33 +56,45 @@ def delete_video(self, video_id: str) -> None:
5356
:return: None if the delete is successful
5457
:rtype: None
5558
"""
56-
return self._connection.delete(path=f"{ApiPath.video}/{video_id}")
59+
return self._connection.delete(
60+
path=f"{ApiPath.video}/{video_id}", params={"collection_id": self.id}
61+
)
5762

5863
def get_audios(self) -> List[Audio]:
5964
audios_data = self._connection.get(
60-
path=f"{ApiPath.collection}/{self.id}/{ApiPath.audio}"
65+
path=f"{ApiPath.audio}",
66+
params={"collection_id": self.id},
6167
)
6268
return [Audio(self._connection, **audio) for audio in audios_data.get("audios")]
6369

6470
def get_audio(self, audio_id: str) -> Audio:
65-
audio_data = self._connection.get(path=f"{ApiPath.audio}/{audio_id}")
71+
audio_data = self._connection.get(
72+
path=f"{ApiPath.audio}/{audio_id}", params={"collection_id": self.id}
73+
)
6674
return Audio(self._connection, **audio_data)
6775

6876
def delete_audio(self, audio_id: str) -> None:
69-
return self._connection.delete(path=f"{ApiPath.audio}/{audio_id}")
77+
return self._connection.delete(
78+
path=f"{ApiPath.audio}/{audio_id}", params={"collection_id": self.id}
79+
)
7080

7181
def get_images(self) -> List[Image]:
7282
images_data = self._connection.get(
73-
path=f"{ApiPath.collection}/{self.id}/{ApiPath.image}"
83+
path=f"{ApiPath.image}",
84+
params={"collection_id": self.id},
7485
)
7586
return [Image(self._connection, **image) for image in images_data.get("images")]
7687

7788
def get_image(self, image_id: str) -> Image:
78-
image_data = self._connection.get(path=f"{ApiPath.image}/{image_id}")
89+
image_data = self._connection.get(
90+
path=f"{ApiPath.image}/{image_id}", params={"collection_id": self.id}
91+
)
7992
return Image(self._connection, **image_data)
8093

8194
def delete_image(self, image_id: str) -> None:
82-
return self._connection.delete(path=f"{ApiPath.image}/{image_id}")
95+
return self._connection.delete(
96+
path=f"{ApiPath.image}/{image_id}", params={"collection_id": self.id}
97+
)
8398

8499
def search(
85100
self,

0 commit comments

Comments
 (0)