Skip to content

Commit

Permalink
Issue #34: Add Container Model, Rename Container Controller
Browse files Browse the repository at this point in the history
  • Loading branch information
Francois-Werbrouck committed Dec 27, 2024
1 parent 922e1f1 commit 12aab82
Show file tree
Hide file tree
Showing 8 changed files with 352 additions and 92 deletions.
334 changes: 254 additions & 80 deletions datastore/__init__.py

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions datastore/blob/azure_storage_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ async def create_dev_container_folder(
- user_id : the user id of the user archiving a folder
"""
try:
raise Exception("This function is not used")
# We want to enable 2 types of folder creation
if folder_uuid is None and folder_name is None:
raise CreateDirectoryError("Folder name and uuid not provided")
Expand Down
36 changes: 36 additions & 0 deletions datastore/db/queries/container/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,42 @@ def get_user_containers(cursor:Cursor, user_id:UUID):
return result
except Exception as e:
raise ContainerNotFoundError(f"Error: containers for user {user_id} not found\n" + str(e))

def get_user_group_containers(cursor:Cursor, user_id:UUID):
"""
This function gets all the containers of a group.
Parameters:
- cursor (cursor): The cursor of the database.
- group_id (str): The UUID of the group.
Returns:
- The containers of the group.
"""
try:
query = """
SELECT
cg.container_id
FROM
container_group as cg
LEFT JOIN
user_group as ug
ON
cg.group_id = ug.group_id
WHERE
ug.user_id = %s;
"""
cursor.execute(
query,
(user_id,),
)
result = cursor.fetchall()
if result is None:
return []
else :
return result
except Exception as e:
raise ContainerNotFoundError(f"Error: group containers for {user_id} not found\n" + str(e))

def is_a_container(cursor:Cursor, container_id:UUID):
"""
Expand Down
8 changes: 3 additions & 5 deletions datastore/db/queries/group/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,11 @@ def get_group_users(cursor : Cursor, group_id : UUID) -> dict:
try:
query = """
SELECT
id,
name,
created_by_id
user_id,
FROM
groups
user_group
WHERE
id = %s
group_id = %s
"""
cursor.execute(
query,
Expand Down
54 changes: 52 additions & 2 deletions datastore/db/queries/picture/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,34 @@ def get_picture_set_name(cursor : Cursor, picture_set_id: UUID):
except Exception:
raise PictureSetNotFoundError(f"Error: PictureSet not found:{picture_set_id}")

def get_picture_set_id(cursor: Cursor, container_id:UUID, name:str)->UUID:
"""
This function retrieves the picture_set_id of a picture_set from the database
based on the container_id and the name of the picture_set.
Parameters:
- cursor (cursor): The cursor of the database.
- container_id (str): The UUID of the container.
- name (str): The name of the picture_set.
"""
try:
query = """
SELECT
id
FROM
picture_set
WHERE
container_id = %s AND name ILIKE %s
"""
cursor.execute(query, (container_id,str(name)))
res = cursor.fetchone()
# res = (id,) or None
if res is None:
return None
else:
return res[0]
except Exception:
raise PictureSetNotFoundError(f"Error: PictureSet not found for container:{container_id} and name:{name}")

def get_user_picture_sets(cursor: Cursor, user_id: UUID):
"""
Expand Down Expand Up @@ -272,7 +300,7 @@ def get_picture_sets_by_container(cursor: Cursor, container_id: UUID):
SELECT
ps.id,
ps.name,
COALESCE(ps.name, ps.id::text) as folder_path,
COALESCE(ps.name, ps.id::text) as last_folder_path,
COALESCE(Array_Agg(p.id) FILTER (WHERE p.id IS NOT NULL), '{}') as picture_ids,
ps.parent_id
FROM
Expand All @@ -284,7 +312,7 @@ def get_picture_sets_by_container(cursor: Cursor, container_id: UUID):
WHERE
container_id = %s
GROUP BY
ps.id, ps.name, folder_path
ps.id, ps.name, last_folder_path
ORDER BY
ps.parent_id DESC;
"""
Expand Down Expand Up @@ -406,6 +434,28 @@ def get_validated_pictures(cursor : Cursor, picture_set_id: UUID):
f"Error: Error while getting validated pictures for picture_set:{picture_set_id}"
)

def get_picture_set_container_id(cursor : Cursor, picture_set_id: UUID)->UUID:
"""
This function retrieves the container_id of a picture_set from the database.
Parameters:
- cursor (cursor): The cursor of the database.
- picture_set_id (str): The UUID of the PictureSet to retrieve the container_id from.
"""
try:
query = """
SELECT
container_id
FROM
picture_set
WHERE
id = %s
"""
cursor.execute(query, (picture_set_id,))
return cursor.fetchone()[0]
except Exception:
raise PictureSetNotFoundError(f"Error: PictureSet not found:{picture_set_id}")


def is_picture_validated(cursor : Cursor, picture_id: UUID) -> bool:
"""
Expand Down
2 changes: 1 addition & 1 deletion datastore/db/queries/user/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def is_a_user_id(cursor : Cursor, user_id: str) -> bool:
raise Exception(f"Error: could not check if {user_id} given is a user id")


def get_user_id(cursor : Cursor, email: str) -> str:
def get_user_id(cursor : Cursor, email: str) -> UUID:
"""
This function retrieves the UUID of a user.
Expand Down
4 changes: 2 additions & 2 deletions datastore/doc/datastore.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ Storage account:
│ Container:
└───user-8367cc4e-1b61-42c2-a061-ca8662aeac37
| | Folder:
│ └───fb20146f-df2f-403f-a56f-f02a48092167/
│ └───folder-name/
| | | fb20146f-df2f-403f-a56f-f02a48092167.json
│ | │ f9b0ef75-6276-4ffc-a71c-975bc842063c.tiff
│ | │ 68e16a78-24bd-4b8c-91b6-75e6b84c40d8.tiff
│ | | ...
│ | └─────────────
| | Folder:
│ └───a6bc9da0-b1d0-42e5-8c41-696b86271d55/
│ └───other-folder-name/
│ | ...
│ └─────────────
| Container:
Expand Down
5 changes: 3 additions & 2 deletions nachet/db/bytebase/schema_0.1.1.sql
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ create schema "nachet_0.1.1";
"picture_set" json NOT NULL,
"owner_id" uuid NOT NULL REFERENCES "nachet_0.1.1".users(id),
"upload_date" date NOT NULL DEFAULT current_timestamp,
"name" text,
"container_id" uuid NOT NULL REFERENCES "nachet_0.1.1".container(id) ON DELETE CASCADE
"name" text NOT NULL,
"container_id" uuid NOT NULL REFERENCES "nachet_0.1.1".container(id) ON DELETE CASCADE,
"parent_id" uuid REFERENCES "nachet_0.1.1".picture_set(id) ON DELETE CASCADE
);

CREATE TABLE "nachet_0.1.1"."picture" (
Expand Down

0 comments on commit 12aab82

Please sign in to comment.