Compare commits

...

3 Commits

Author SHA1 Message Date
c6edcc73e8 Add get info 2024-09-01 19:35:11 +05:30
bd6b87177d Remove unnessasary import 2024-09-01 18:16:44 +05:30
2c42e8a759 Add upload project files 2024-09-01 18:06:26 +05:30
3 changed files with 62 additions and 2 deletions

View File

View File

@ -1,4 +1,4 @@
from re import T import os
import secrets import secrets
import sqlite3 import sqlite3
import flask import flask
@ -172,3 +172,42 @@ def update_ideas() -> flask.Response:
except KeyError: except KeyError:
return flask.Response("Something is missing", 422) return flask.Response("Something is missing", 422)
return flask.Response() return flask.Response()
@app.post("/upload-project-file")
def upload_project_files() -> flask.Response:
try:
user_id = flask.session["user_id"]
except KeyError:
return flask.Response("Not logged in", 428)
team_id = utils.UserHandler.get_user_by_id(user_id).team_id
try:
file = flask.request.files["file"]
except KeyError:
return flask.Response("file missing", 422)
file_name = file.filename if file.filename else secrets.token_urlsafe(20)
if not os.path.isdir(f"./data/project-files/{team_id}"):
os.mkdir(f"./data/project-files/{team_id}")
file.save(f"./data/project-files/{team_id}/{file_name}")
return flask.Response()
@app.post("/get-info")
def get_info() -> flask.Response:
info: dict = {
"team_members" : [],
"project_details": {},
"project_files": [],
}
try:
user_id = flask.session["user_id"]
except KeyError:
return flask.Response("Not logged in", 428)
team_id = utils.UserHandler.get_user_by_id(user_id).team_id
team_members = utils.TeamHandler.get_team_members(team_id)
print(team_members)
for team_member in team_members:
info["team_members"].append(utils.UserHandler.get_user_by_id(team_member).to_dict())
info["project_details"] = vars(utils.TeamHandler.get_project(team_id))
info["project_files"] = os.listdir(f"./data/project-files/{team_id}")
return flask.jsonify(info)

View File

@ -68,7 +68,7 @@ class TeamHandler:
""", """,
(team_id, ) (team_id, )
).fetchall() ).fetchall()
return users return [user[0] for user in users]
@classmethod @classmethod
def update_project_information( def update_project_information(
@ -105,3 +105,24 @@ class TeamHandler:
) )
) )
cls.__connection.commit() cls.__connection.commit()
@classmethod
def get_project(cls, team_id: int) -> Team:
teams = cls.__cursor.execute(
f"""
SELECT * FROM teams WHERE team_id = ?
""", (team_id, )
).fetchall()[0]
return Team(
teams[0],
teams[1],
teams[2],
teams[3],
teams[4],
teams[5],
teams[6],
teams[7],
teams[8],
teams[9],
teams[10],
)