Spaces:
Building
Building
Delete project_controller.py
Browse files- project_controller.py +0 -103
project_controller.py
DELETED
@@ -1,103 +0,0 @@
|
|
1 |
-
from fastapi import APIRouter, Depends, HTTPException
|
2 |
-
from config_provider import get_config, ServiceConfig
|
3 |
-
from utils import save_service_config, log
|
4 |
-
import copy
|
5 |
-
|
6 |
-
router = APIRouter()
|
7 |
-
|
8 |
-
@router.get("/project/details")
|
9 |
-
def get_project_details(config: ServiceConfig = Depends(get_config)):
|
10 |
-
project = config.get_current_project()
|
11 |
-
return project
|
12 |
-
|
13 |
-
@router.post("/project/update")
|
14 |
-
def update_project(config: ServiceConfig = Depends(get_config)):
|
15 |
-
# Implement project update logic here if needed
|
16 |
-
save_service_config(config)
|
17 |
-
log("β
Project updated")
|
18 |
-
return { "status": "updated" }
|
19 |
-
|
20 |
-
@router.post("/project/publish")
|
21 |
-
def publish_project(config: ServiceConfig = Depends(get_config)):
|
22 |
-
project = config.get_current_project()
|
23 |
-
current_version = next((v for v in project['versions'] if not v.get('published', False)), None)
|
24 |
-
if not current_version:
|
25 |
-
raise HTTPException(status_code=400, detail="No unpublished version found")
|
26 |
-
current_version['published'] = True
|
27 |
-
save_service_config(config)
|
28 |
-
log(f"β
Version {current_version['no']} published for project {project['name']}")
|
29 |
-
return { "status": "published" }
|
30 |
-
|
31 |
-
@router.post("/project/new")
|
32 |
-
def create_project(name: str, config: ServiceConfig = Depends(get_config)):
|
33 |
-
if any(p['name'] == name for p in config.data['projects']):
|
34 |
-
raise HTTPException(status_code=400, detail="Project already exists")
|
35 |
-
new_project = {
|
36 |
-
"name": name,
|
37 |
-
"versions": []
|
38 |
-
}
|
39 |
-
config.data['projects'].append(new_project)
|
40 |
-
save_service_config(config)
|
41 |
-
log(f"β
New project '{name}' created")
|
42 |
-
return { "status": "success" }
|
43 |
-
|
44 |
-
@router.post("/project/delete")
|
45 |
-
def delete_project(name: str, config: ServiceConfig = Depends(get_config)):
|
46 |
-
project = next((p for p in config.data['projects'] if p['name'] == name), None)
|
47 |
-
if not project:
|
48 |
-
raise HTTPException(status_code=404, detail="Project not found")
|
49 |
-
config.data['projects'].remove(project)
|
50 |
-
save_service_config(config)
|
51 |
-
log(f"ποΈ Project '{name}' deleted")
|
52 |
-
return { "status": "success" }
|
53 |
-
|
54 |
-
@router.get("/project/versions")
|
55 |
-
def get_project_versions(config: ServiceConfig = Depends(get_config)):
|
56 |
-
project = config.get_current_project()
|
57 |
-
return project['versions']
|
58 |
-
|
59 |
-
@router.post("/project/new-version")
|
60 |
-
def create_new_version(project_name: str, base_version_no: int, config: ServiceConfig = Depends(get_config)):
|
61 |
-
project = next((p for p in config.data['projects'] if p['name'] == project_name), None)
|
62 |
-
if not project:
|
63 |
-
raise HTTPException(status_code=404, detail="Project not found")
|
64 |
-
base_version = next((v for v in project['versions'] if v['no'] == base_version_no), None)
|
65 |
-
if not base_version:
|
66 |
-
raise HTTPException(status_code=404, detail="Base version not found")
|
67 |
-
new_version_no = max((v['no'] for v in project['versions']), default=0) + 1
|
68 |
-
new_version = copy.deepcopy(base_version)
|
69 |
-
new_version['no'] = new_version_no
|
70 |
-
new_version['published'] = False
|
71 |
-
project['versions'].append(new_version)
|
72 |
-
save_service_config(config)
|
73 |
-
log(f"β
New version {new_version_no} created for project {project_name}")
|
74 |
-
return { "status": "success", "new_version": new_version_no }
|
75 |
-
|
76 |
-
@router.post("/project/delete-version")
|
77 |
-
def delete_version(project_name: str, version_no: int, config: ServiceConfig = Depends(get_config)):
|
78 |
-
project = next((p for p in config.data['projects'] if p['name'] == project_name), None)
|
79 |
-
if not project:
|
80 |
-
raise HTTPException(status_code=404, detail="Project not found")
|
81 |
-
version = next((v for v in project['versions'] if v['no'] == version_no), None)
|
82 |
-
if not version:
|
83 |
-
raise HTTPException(status_code=404, detail="Version not found")
|
84 |
-
project['versions'].remove(version)
|
85 |
-
save_service_config(config)
|
86 |
-
log(f"ποΈ Version {version_no} deleted from project {project_name}")
|
87 |
-
return { "status": "success" }
|
88 |
-
|
89 |
-
@router.post("/project/update-api")
|
90 |
-
def update_api(project_name: str, version_no: int, api_data: dict, config: ServiceConfig = Depends(get_config)):
|
91 |
-
project = next((p for p in config.data['projects'] if p['name'] == project_name), None)
|
92 |
-
if not project:
|
93 |
-
raise HTTPException(status_code=404, detail="Project not found")
|
94 |
-
version = next((v for v in project['versions'] if v['no'] == version_no), None)
|
95 |
-
if not version:
|
96 |
-
raise HTTPException(status_code=404, detail="Version not found")
|
97 |
-
existing_api = next((a for a in version['apis'] if a['name'] == api_data['name']), None)
|
98 |
-
if existing_api:
|
99 |
-
version['apis'].remove(existing_api)
|
100 |
-
version['apis'].append(api_data)
|
101 |
-
save_service_config(config)
|
102 |
-
log(f"π§ API '{api_data['name']}' updated in project {project_name} version {version_no}")
|
103 |
-
return { "status": "success" }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|